aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-02 16:58:50 +0100
committergingerBill <bill@gingerbill.org>2021-08-02 16:58:50 +0100
commitccbdf086ff1d160cec707f5fe5560509afeda495 (patch)
treef0b3affe661eab3a6eda589087d3d12eb37d12fb /src
parentb0e64ca7e88a357dda71cb784ae2b12bd3f0be20 (diff)
Add `@(warning=<string>)`
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp1
-rw-r--r--src/checker.cpp18
-rw-r--r--src/checker.hpp1
-rw-r--r--src/entity.cpp1
4 files changed, 21 insertions, 0 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 32a333ce3..a87a29193 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -724,6 +724,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
e->Procedure.is_export = ac.is_export;
e->deprecated_message = ac.deprecated_message;
+ e->warning_message = ac.warning_message;
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix);
if (ac.has_disabled_proc) {
if (ac.disabled_proc) {
diff --git a/src/checker.cpp b/src/checker.cpp
index d4094d6ed..19577ef70 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -1303,6 +1303,10 @@ void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) {
if (dmsg.len > 0) {
warning(identifier, "%.*s is deprecated: %.*s", LIT(entity->token.string), LIT(dmsg));
}
+ String wmsg = entity->warning_message;
+ if (wmsg.len > 0) {
+ warning(identifier, "%.*s: %.*s", LIT(entity->token.string), LIT(wmsg));
+ }
}
entity->flags |= EntityFlag_Used;
add_declaration_dependency(c, entity);
@@ -2698,6 +2702,20 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
error(elem, "Expected a string value for '%.*s'", LIT(name));
}
return true;
+ } else if (name == "warning") {
+ ExactValue ev = check_decl_attribute_value(c, value);
+
+ if (ev.kind == ExactValue_String) {
+ String msg = ev.value_string;
+ if (msg.len == 0) {
+ error(elem, "Warning message cannot be an empty string");
+ } else {
+ ac->warning_message = msg;
+ }
+ } else {
+ error(elem, "Expected a string value for '%.*s'", LIT(name));
+ }
+ return true;
} else if (name == "require_results") {
if (value != nullptr) {
error(elem, "Expected no value for '%.*s'", LIT(name));
diff --git a/src/checker.hpp b/src/checker.hpp
index 18c686dff..bf462de71 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -113,6 +113,7 @@ struct AttributeContext {
isize init_expr_list_count;
String thread_local_model;
String deprecated_message;
+ String warning_message;
DeferredProcedure deferred_procedure;
u32 optimization_mode; // ProcedureOptimizationMode
};
diff --git a/src/entity.cpp b/src/entity.cpp
index f875b9607..cd9d3a88b 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -136,6 +136,7 @@ struct Entity {
u64 order_in_src;
String deprecated_message;
+ String warning_message;
// IMPORTANT NOTE(bill): This must be a discriminated union because of patching
// later entity kinds