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

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