diff options
| author | gingerBill <bill@gingerbill.org> | 2019-02-23 23:21:27 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-02-23 23:21:27 +0000 |
| commit | 2878cd8241d6cbb57a7a2f927be7407d11ad80d8 (patch) | |
| tree | 9c1f961de032d9cda8bd118d833727f8e6334d52 /src/checker.cpp | |
| parent | a9ab90bd2488783c3523fa30315f9754937fd52e (diff) | |
New build flag: -define:foo=123
Diffstat (limited to 'src/checker.cpp')
| -rw-r--r-- | src/checker.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/checker.cpp b/src/checker.cpp index 6389e3d30..907dbd26c 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -721,6 +721,44 @@ void init_universal(void) { add_global_entity(entity, intrinsics_pkg->scope); } + bool defined_values_double_declaration = true; + for_array(i, bc->defined_values.entries) { + String name = bc->defined_values.entries[i].key.string; + ExactValue value = bc->defined_values.entries[i].value; + GB_ASSERT(value.kind != ExactValue_Invalid); + + Type *type = nullptr; + switch (value.kind) { + case ExactValue_Bool: + type = t_untyped_bool; + break; + case ExactValue_String: + type = t_untyped_string; + break; + case ExactValue_Integer: + type = t_untyped_integer; + break; + case ExactValue_Float: + type = t_untyped_float; + break; + } + GB_ASSERT(type != nullptr); + + + + Entity *entity = alloc_entity_constant(nullptr, make_token_ident(name), type, value); + entity->state = EntityState_Resolved; + if (scope_insert(builtin_pkg->scope, entity)) { + error(entity->token, "'%.*s' defined as an argument is already declared at the global scope", LIT(name)); + defined_values_double_declaration = true; + // NOTE(bill): Just exit early before anything, even though the compiler will do that anyway + } + } + + if (defined_values_double_declaration) { + gb_exit(1); + } + t_u8_ptr = alloc_type_pointer(t_u8); t_int_ptr = alloc_type_pointer(t_int); |