Add @(warning=<string>)

This commit is contained in:
gingerBill
2021-08-02 16:58:50 +01:00
parent b0e64ca7e8
commit ccbdf086ff
4 changed files with 21 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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));

View File

@@ -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
};

View File

@@ -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