aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-06-20 11:45:52 +0100
committerGitHub <noreply@github.com>2024-06-20 11:45:52 +0100
commit23351ca8bec5862be531e886a3a3513c31bb2c30 (patch)
tree2f8e0c98c4b9c4ace3e8531abdf74ba95f54ef01 /src/check_builtin.cpp
parent56383e45a7441fc789cd44c5e0dbaf9b2079a0f1 (diff)
parentf2be35f1f0cd23f0264f174bcc6ce608a9076af7 (diff)
Merge pull request #3137 from laytan/show-defineable
Add flags to show/export defineable values and warn if a -define is unused in the project
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 3aee804df..203ae11ea 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -1756,9 +1756,21 @@ gb_internal bool check_builtin_procedure_directive(CheckerContext *c, Operand *o
operand->mode = Addressing_Constant;
operand->value = exact_value_bool(is_defined);
+ // If the arg is a selector expression we don't add it, `-define` only allows identifiers.
+ if (arg->kind == Ast_Ident) {
+ Defineable defineable = {};
+ defineable.docs = nullptr;
+ defineable.name = arg->Ident.token.string;
+ defineable.default_value = exact_value_bool(false);
+ defineable.pos = arg->Ident.token.pos;
+
+ MUTEX_GUARD(&c->info->defineables_mutex);
+ array_add(&c->info->defineables, defineable);
+ }
+
} else if (name == "config") {
if (ce->args.count != 2) {
- error(call, "'#config' expects 2 argument, got %td", ce->args.count);
+ error(call, "'#config' expects 2 arguments, got %td", ce->args.count);
return false;
}
Ast *arg = unparen_expr(ce->args[0]);
@@ -1793,6 +1805,20 @@ gb_internal bool check_builtin_procedure_directive(CheckerContext *c, Operand *o
operand->value = found->Constant.value;
}
}
+
+ Defineable defineable = {};
+ defineable.docs = nullptr;
+ defineable.name = name;
+ defineable.default_value = def.value;
+ defineable.pos = arg->Ident.token.pos;
+
+ if (c->decl) {
+ defineable.docs = c->decl->docs;
+ }
+
+ MUTEX_GUARD(&c->info->defineables_mutex);
+ array_add(&c->info->defineables, defineable);
+
} else {
error(call, "Unknown directive call: #%.*s", LIT(name));
}