checker.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. #include "../exact_value.cpp"
  2. #include "entity.cpp"
  3. #include "type.cpp"
  4. enum AddressingMode {
  5. Addressing_Invalid,
  6. Addressing_NoValue,
  7. Addressing_Value,
  8. Addressing_Variable,
  9. Addressing_Constant,
  10. Addressing_Type,
  11. Addressing_Builtin,
  12. Addressing_Count,
  13. };
  14. struct Operand {
  15. AddressingMode mode;
  16. Type *type;
  17. ExactValue value;
  18. AstNode *expr;
  19. BuiltinProcId builtin_id;
  20. };
  21. struct TypeAndValue {
  22. AddressingMode mode;
  23. Type *type;
  24. ExactValue value;
  25. };
  26. struct DeclInfo {
  27. Scope *scope;
  28. Entity **entities;
  29. isize entity_count;
  30. AstNode *type_expr;
  31. AstNode *init_expr;
  32. AstNode *proc_decl; // AstNode_ProcDecl
  33. Map<b32> deps; // Key: Entity *
  34. i32 mark;
  35. };
  36. void init_declaration_info(DeclInfo *d, Scope *scope) {
  37. d->scope = scope;
  38. map_init(&d->deps, gb_heap_allocator());
  39. }
  40. DeclInfo *make_declaration_info(gbAllocator a, Scope *scope) {
  41. DeclInfo *d = gb_alloc_item(a, DeclInfo);
  42. init_declaration_info(d, scope);
  43. return d;
  44. }
  45. void destroy_declaration_info(DeclInfo *d) {
  46. map_destroy(&d->deps);
  47. }
  48. b32 has_init(DeclInfo *d) {
  49. if (d->init_expr != NULL)
  50. return true;
  51. if (d->proc_decl != NULL) {
  52. ast_node(pd, ProcDecl, d->proc_decl);
  53. if (pd->body != NULL)
  54. return true;
  55. }
  56. return false;
  57. }
  58. struct ExpressionInfo {
  59. b32 is_lhs; // Debug info
  60. AddressingMode mode;
  61. Type *type; // Type_Basic
  62. ExactValue value;
  63. };
  64. ExpressionInfo make_expression_info(b32 is_lhs, AddressingMode mode, Type *type, ExactValue value) {
  65. ExpressionInfo ei = {};
  66. ei.is_lhs = is_lhs;
  67. ei.mode = mode;
  68. ei.type = type;
  69. ei.value = value;
  70. return ei;
  71. }
  72. struct ProcedureInfo {
  73. AstFile *file;
  74. Token token;
  75. DeclInfo *decl;
  76. Type * type; // Type_Procedure
  77. AstNode * body; // AstNode_BlockStatement
  78. };
  79. struct Scope {
  80. Scope *parent;
  81. Scope *prev, *next;
  82. Scope *first_child, *last_child;
  83. Map<Entity *> elements; // Key: String
  84. };
  85. enum ExpressionKind {
  86. Expression_Expression,
  87. Expression_Conversion,
  88. Expression_Statement,
  89. };
  90. enum BuiltinProcId {
  91. BuiltinProc_Invalid,
  92. BuiltinProc_size_of,
  93. BuiltinProc_size_of_val,
  94. BuiltinProc_align_of,
  95. BuiltinProc_align_of_val,
  96. BuiltinProc_offset_of,
  97. BuiltinProc_offset_of_val,
  98. BuiltinProc_static_assert,
  99. BuiltinProc_len,
  100. BuiltinProc_cap,
  101. BuiltinProc_copy,
  102. BuiltinProc_append,
  103. BuiltinProc_swizzle,
  104. BuiltinProc_Count,
  105. };
  106. struct BuiltinProc {
  107. String name;
  108. isize arg_count;
  109. b32 variadic;
  110. ExpressionKind kind;
  111. };
  112. gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
  113. {STR_LIT(""), 0, false, Expression_Statement},
  114. {STR_LIT("size_of"), 1, false, Expression_Expression},
  115. {STR_LIT("size_of_val"), 1, false, Expression_Expression},
  116. {STR_LIT("align_of"), 1, false, Expression_Expression},
  117. {STR_LIT("align_of_val"), 1, false, Expression_Expression},
  118. {STR_LIT("offset_of"), 2, false, Expression_Expression},
  119. {STR_LIT("offset_of_val"), 1, false, Expression_Expression},
  120. {STR_LIT("static_assert"), 1, false, Expression_Statement},
  121. {STR_LIT("len"), 1, false, Expression_Expression},
  122. {STR_LIT("cap"), 1, false, Expression_Expression},
  123. {STR_LIT("copy"), 2, false, Expression_Expression},
  124. {STR_LIT("append"), 2, false, Expression_Expression},
  125. {STR_LIT("swizzle"), 1, true, Expression_Expression},
  126. };
  127. struct CheckerContext {
  128. Scope *scope;
  129. DeclInfo *decl;
  130. };
  131. // NOTE(bill): Symbol tables
  132. struct CheckerInfo {
  133. Map<TypeAndValue> types; // Key: AstNode * | Expression -> Type (and value)
  134. Map<Entity *> definitions; // Key: AstNode * | Identifier -> Entity
  135. Map<Entity *> uses; // Key: AstNode * | Identifier -> Entity
  136. Map<Scope *> scopes; // Key: AstNode * | Node -> Scope
  137. Map<ExpressionInfo> untyped; // Key: AstNode * | Expression -> ExpressionInfo
  138. Map<DeclInfo *> entities; // Key: Entity *
  139. };
  140. struct Checker {
  141. Parser * parser;
  142. CheckerInfo info;
  143. AstFile * curr_ast_file;
  144. BaseTypeSizes sizes;
  145. Scope * global_scope;
  146. gbArray(ProcedureInfo) procs; // NOTE(bill): Procedures to check
  147. gbArena arena;
  148. gbAllocator allocator;
  149. CheckerContext context;
  150. gbArray(Type *) proc_stack;
  151. b32 in_defer; // TODO(bill): Actually handle correctly
  152. ErrorCollector error_collector;
  153. };
  154. gb_global Scope *universal_scope = NULL;
  155. Scope *make_scope(Scope *parent, gbAllocator allocator) {
  156. Scope *s = gb_alloc_item(allocator, Scope);
  157. s->parent = parent;
  158. map_init(&s->elements, gb_heap_allocator());
  159. if (parent != NULL && parent != universal_scope) {
  160. DLIST_APPEND(parent->first_child, parent->last_child, s);
  161. }
  162. return s;
  163. }
  164. void destroy_scope(Scope *scope) {
  165. gb_for_array(i, scope->elements.entries) {
  166. Entity *e =scope->elements.entries[i].value;
  167. if (e->kind == Entity_Variable) {
  168. if (!e->Variable.used) {
  169. #if 0
  170. warning(e->token, "Unused variable `%.*s`", LIT(e->token.string));
  171. #endif
  172. }
  173. }
  174. }
  175. for (Scope *child = scope->first_child; child != NULL; child = child->next) {
  176. destroy_scope(child);
  177. }
  178. map_destroy(&scope->elements);
  179. // NOTE(bill): No need to free scope as it "should" be allocated in an arena (except for the global scope)
  180. }
  181. void add_scope(Checker *c, AstNode *node, Scope *scope) {
  182. GB_ASSERT(node != NULL);
  183. GB_ASSERT(scope != NULL);
  184. map_set(&c->info.scopes, hash_pointer(node), scope);
  185. }
  186. void check_open_scope(Checker *c, AstNode *stmt) {
  187. GB_ASSERT(is_ast_node_stmt(stmt) || stmt->kind == AstNode_ProcType);
  188. Scope *scope = make_scope(c->context.scope, c->allocator);
  189. add_scope(c, stmt, scope);
  190. c->context.scope = scope;
  191. }
  192. void check_close_scope(Checker *c) {
  193. c->context.scope = c->context.scope->parent;
  194. }
  195. void scope_lookup_parent_entity(Scope *s, String name, Scope **scope, Entity **entity) {
  196. HashKey key = hash_string(name);
  197. for (; s != NULL; s = s->parent) {
  198. Entity **found = map_get(&s->elements, key);
  199. if (found) {
  200. if (entity) *entity = *found;
  201. if (scope) *scope = s;
  202. return;
  203. }
  204. }
  205. if (entity) *entity = NULL;
  206. if (scope) *scope = NULL;
  207. }
  208. Entity *scope_lookup_entity(Scope *s, String name) {
  209. Entity *entity = NULL;
  210. scope_lookup_parent_entity(s, name, NULL, &entity);
  211. return entity;
  212. }
  213. Entity *current_scope_lookup_entity(Scope *s, String name) {
  214. HashKey key = hash_string(name);
  215. Entity **found = map_get(&s->elements, key);
  216. if (found)
  217. return *found;
  218. return NULL;
  219. }
  220. Entity *scope_insert_entity(Scope *s, Entity *entity) {
  221. String name = entity->token.string;
  222. HashKey key = hash_string(name);
  223. Entity **found = map_get(&s->elements, key);
  224. if (found)
  225. return *found;
  226. map_set(&s->elements, key, entity);
  227. if (entity->parent == NULL)
  228. entity->parent = s;
  229. return NULL;
  230. }
  231. void add_dependency(DeclInfo *d, Entity *e) {
  232. map_set(&d->deps, hash_pointer(e), cast(b32)true);
  233. }
  234. void add_declaration_dependency(Checker *c, Entity *e) {
  235. if (c->context.decl) {
  236. auto found = map_get(&c->info.entities, hash_pointer(e));
  237. if (found) {
  238. add_dependency(c->context.decl, e);
  239. }
  240. }
  241. }
  242. void add_global_entity(Entity *entity) {
  243. String name = entity->token.string;
  244. if (gb_memchr(name.text, ' ', name.len)) {
  245. return; // NOTE(bill): `untyped thing`
  246. }
  247. if (scope_insert_entity(universal_scope, entity)) {
  248. GB_PANIC("Compiler error: double declaration");
  249. }
  250. }
  251. void add_global_constant(gbAllocator a, String name, Type *type, ExactValue value) {
  252. Token token = {Token_Identifier};
  253. token.string = name;
  254. Entity *entity = alloc_entity(a, Entity_Constant, NULL, token, type);
  255. entity->Constant.value = value;
  256. add_global_entity(entity);
  257. }
  258. void init_universal_scope(void) {
  259. // NOTE(bill): No need to free these
  260. gbAllocator a = gb_heap_allocator();
  261. universal_scope = make_scope(NULL, a);
  262. // Types
  263. for (isize i = 0; i < gb_count_of(basic_types); i++) {
  264. Token token = {Token_Identifier};
  265. token.string = basic_types[i].basic.name;
  266. add_global_entity(make_entity_type_name(a, NULL, token, &basic_types[i]));
  267. }
  268. for (isize i = 0; i < gb_count_of(basic_type_aliases); i++) {
  269. Token token = {Token_Identifier};
  270. token.string = basic_type_aliases[i].basic.name;
  271. add_global_entity(make_entity_type_name(a, NULL, token, &basic_type_aliases[i]));
  272. }
  273. // Constants
  274. add_global_constant(a, make_string("true"), t_untyped_bool, make_exact_value_bool(true));
  275. add_global_constant(a, make_string("false"), t_untyped_bool, make_exact_value_bool(false));
  276. add_global_constant(a, make_string("null"), t_untyped_pointer, make_exact_value_pointer(NULL));
  277. // Builtin Procedures
  278. for (isize i = 0; i < gb_count_of(builtin_procs); i++) {
  279. BuiltinProcId id = cast(BuiltinProcId)i;
  280. Token token = {Token_Identifier};
  281. token.string = builtin_procs[i].name;
  282. Entity *entity = alloc_entity(a, Entity_Builtin, NULL, token, t_invalid);
  283. entity->Builtin.id = id;
  284. add_global_entity(entity);
  285. }
  286. }
  287. void init_checker_info(CheckerInfo *i) {
  288. gbAllocator a = gb_heap_allocator();
  289. map_init(&i->types, a);
  290. map_init(&i->definitions, a);
  291. map_init(&i->uses, a);
  292. map_init(&i->scopes, a);
  293. map_init(&i->entities, a);
  294. map_init(&i->untyped, a);
  295. }
  296. void destroy_checker_info(CheckerInfo *i) {
  297. map_destroy(&i->types);
  298. map_destroy(&i->definitions);
  299. map_destroy(&i->uses);
  300. map_destroy(&i->scopes);
  301. map_destroy(&i->entities);
  302. map_destroy(&i->untyped);
  303. }
  304. void init_checker(Checker *c, Parser *parser) {
  305. gbAllocator a = gb_heap_allocator();
  306. c->parser = parser;
  307. init_checker_info(&c->info);
  308. c->sizes.word_size = 8;
  309. c->sizes.max_align = 8;
  310. gb_array_init(c->proc_stack, a);
  311. gb_array_init(c->procs, a);
  312. // NOTE(bill): Is this big enough or too small?
  313. isize item_size = gb_max(gb_max(gb_size_of(Entity), gb_size_of(Type)), gb_size_of(Scope));
  314. isize total_token_count = 0;
  315. gb_for_array(i, c->parser->files) {
  316. AstFile *f = &c->parser->files[i];
  317. total_token_count += gb_array_count(f->tokens);
  318. }
  319. isize arena_size = 2 * item_size * total_token_count;
  320. gb_arena_init_from_allocator(&c->arena, a, arena_size);
  321. c->allocator = gb_arena_allocator(&c->arena);
  322. c->global_scope = make_scope(universal_scope, c->allocator);
  323. c->context.scope = c->global_scope;
  324. }
  325. void destroy_checker(Checker *c) {
  326. destroy_checker_info(&c->info);
  327. destroy_scope(c->global_scope);
  328. gb_array_free(c->proc_stack);
  329. gb_array_free(c->procs);
  330. gb_arena_free(&c->arena);
  331. }
  332. TypeAndValue *type_and_value_of_expression(CheckerInfo *i, AstNode *expression) {
  333. TypeAndValue *found = map_get(&i->types, hash_pointer(expression));
  334. return found;
  335. }
  336. Entity *entity_of_ident(CheckerInfo *i, AstNode *identifier) {
  337. GB_ASSERT(identifier->kind == AstNode_Ident);
  338. Entity **found = map_get(&i->definitions, hash_pointer(identifier));
  339. if (found)
  340. return *found;
  341. found = map_get(&i->uses, hash_pointer(identifier));
  342. if (found)
  343. return *found;
  344. return NULL;
  345. }
  346. Type *type_of_expr(CheckerInfo *i, AstNode *expression) {
  347. TypeAndValue *found = type_and_value_of_expression(i, expression);
  348. if (found)
  349. return found->type;
  350. if (expression->kind == AstNode_Ident) {
  351. Entity *entity = entity_of_ident(i, expression);
  352. if (entity)
  353. return entity->type;
  354. }
  355. return NULL;
  356. }
  357. void add_untyped(CheckerInfo *i, AstNode *expression, b32 lhs, AddressingMode mode, Type *basic_type, ExactValue value) {
  358. map_set(&i->untyped, hash_pointer(expression), make_expression_info(lhs, mode, basic_type, value));
  359. }
  360. void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode, Type *type, ExactValue value) {
  361. GB_ASSERT(expression != NULL);
  362. if (mode == Addressing_Invalid)
  363. return;
  364. if (mode == Addressing_Constant) {
  365. GB_ASSERT(value.kind != ExactValue_Invalid);
  366. GB_ASSERT_MSG(type != t_invalid || is_type_constant_type(type),
  367. "type: %s", type_to_string(type));
  368. }
  369. TypeAndValue tv = {};
  370. tv.type = type;
  371. tv.value = value;
  372. tv.mode = mode;
  373. map_set(&i->types, hash_pointer(expression), tv);
  374. }
  375. void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
  376. GB_ASSERT(identifier != NULL);
  377. GB_ASSERT(identifier->kind == AstNode_Ident);
  378. HashKey key = hash_pointer(identifier);
  379. map_set(&i->definitions, key, entity);
  380. }
  381. void add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
  382. if (!are_strings_equal(entity->token.string, make_string("_"))) {
  383. Entity *insert_entity = scope_insert_entity(scope, entity);
  384. if (insert_entity) {
  385. error(&c->error_collector, entity->token,
  386. "Redeclararation of `%.*s` in this scope\n"
  387. "\tat %.*s(%td:%td)",
  388. LIT(entity->token.string),
  389. LIT(entity->token.pos.file), entity->token.pos.line, entity->token.pos.column);
  390. return;
  391. }
  392. }
  393. if (identifier != NULL)
  394. add_entity_definition(&c->info, identifier, entity);
  395. }
  396. void add_entity_use(CheckerInfo *i, AstNode *identifier, Entity *entity) {
  397. GB_ASSERT(identifier != NULL);
  398. GB_ASSERT(identifier->kind == AstNode_Ident);
  399. HashKey key = hash_pointer(identifier);
  400. map_set(&i->uses, key, entity);
  401. }
  402. void add_file_entity(Checker *c, AstNode *identifier, Entity *e, DeclInfo *d) {
  403. GB_ASSERT(are_strings_equal(identifier->Ident.token.string, e->token.string));
  404. add_entity(c, c->global_scope, identifier, e);
  405. map_set(&c->info.entities, hash_pointer(e), d);
  406. e->order = gb_array_count(c->info.entities.entries);
  407. }
  408. void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, AstNode *body) {
  409. ProcedureInfo info = {};
  410. info.file = file;
  411. info.token = token;
  412. info.decl = decl;
  413. info.type = type;
  414. info.body = body;
  415. gb_array_append(c->procs, info);
  416. }
  417. void push_procedure(Checker *c, Type *type) {
  418. gb_array_append(c->proc_stack, type);
  419. }
  420. void pop_procedure(Checker *c) {
  421. gb_array_pop(c->proc_stack);
  422. }
  423. Type *const curr_procedure(Checker *c) {
  424. isize count = gb_array_count(c->proc_stack);
  425. if (count > 0) {
  426. return c->proc_stack[count-1];
  427. }
  428. return NULL;
  429. }
  430. void add_curr_ast_file(Checker *c, AstFile *file) {
  431. TokenPos zero_pos = {};
  432. c->error_collector.prev = zero_pos;
  433. c->curr_ast_file = file;
  434. }
  435. #include "expr.cpp"
  436. #include "stmt.cpp"
  437. void check_parsed_files(Checker *c) {
  438. // Collect Entities
  439. gb_for_array(i, c->parser->files) {
  440. AstFile *f = &c->parser->files[i];
  441. add_curr_ast_file(c, f);
  442. for (AstNode *decl = f->decls; decl != NULL; decl = decl->next) {
  443. if (!is_ast_node_decl(decl))
  444. continue;
  445. switch (decl->kind) {
  446. case_ast_node(bd, BadDecl, decl);
  447. case_end;
  448. case_ast_node(vd, VarDecl, decl);
  449. switch (vd->kind) {
  450. case Declaration_Immutable: {
  451. for (AstNode *name = vd->name_list, *value = vd->value_list;
  452. name != NULL && value != NULL;
  453. name = name->next, value = value->next) {
  454. ast_node(n, Ident, name);
  455. ExactValue v = {ExactValue_Invalid};
  456. Entity *e = make_entity_constant(c->allocator, c->context.scope, n->token, NULL, v);
  457. DeclInfo *di = make_declaration_info(c->allocator, c->global_scope);
  458. di->type_expr = vd->type;
  459. di->init_expr = value;
  460. add_file_entity(c, name, e, di);
  461. }
  462. isize lhs_count = vd->name_count;
  463. isize rhs_count = vd->value_count;
  464. if (rhs_count == 0 && vd->type == NULL) {
  465. error(&c->error_collector, ast_node_token(decl), "Missing type or initial expression");
  466. } else if (lhs_count < rhs_count) {
  467. error(&c->error_collector, ast_node_token(decl), "Extra initial expression");
  468. }
  469. } break;
  470. case Declaration_Mutable: {
  471. isize entity_count = vd->name_count;
  472. isize entity_index = 0;
  473. Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
  474. DeclInfo *di = NULL;
  475. if (vd->value_count > 0) {
  476. di = make_declaration_info(gb_heap_allocator(), c->global_scope);
  477. di->entities = entities;
  478. di->entity_count = entity_count;
  479. di->type_expr = vd->type;
  480. di->init_expr = vd->value_list;
  481. }
  482. AstNode *value = vd->value_list;
  483. for (AstNode *name = vd->name_list; name != NULL; name = name->next) {
  484. ast_node(n, Ident, name);
  485. Entity *e = make_entity_variable(c->allocator, c->global_scope, n->token, NULL);
  486. entities[entity_index++] = e;
  487. DeclInfo *d = di;
  488. if (d == NULL) {
  489. AstNode *init_expr = value;
  490. d = make_declaration_info(gb_heap_allocator(), c->global_scope);
  491. d->type_expr = vd->type;
  492. d->init_expr = init_expr;
  493. }
  494. add_file_entity(c, name, e, d);
  495. if (value != NULL)
  496. value = value->next;
  497. }
  498. } break;
  499. }
  500. case_end;
  501. case_ast_node(td, TypeDecl, decl);
  502. ast_node(n, Ident, td->name);
  503. Entity *e = make_entity_type_name(c->allocator, c->global_scope, n->token, NULL);
  504. DeclInfo *d = make_declaration_info(c->allocator, e->parent);
  505. d->type_expr = td->type;
  506. add_file_entity(c, td->name, e, d);
  507. case_end;
  508. case_ast_node(pd, ProcDecl, decl);
  509. ast_node(n, Ident, pd->name);
  510. Token token = n->token;
  511. Entity *e = make_entity_procedure(c->allocator, c->global_scope, token, NULL);
  512. add_entity(c, c->global_scope, pd->name, e);
  513. DeclInfo *d = make_declaration_info(c->allocator, e->parent);
  514. d->proc_decl = decl;
  515. map_set(&c->info.entities, hash_pointer(e), d);
  516. e->order = gb_array_count(c->info.entities.entries);
  517. case_end;
  518. case_ast_node(ld, LoadDecl, decl);
  519. // NOTE(bill): ignore
  520. case_end;
  521. default:
  522. error(&c->error_collector, ast_node_token(decl), "Only declarations are allowed at file scope");
  523. break;
  524. }
  525. }
  526. }
  527. gb_for_array(i, c->info.entities.entries) {
  528. auto *entry = &c->info.entities.entries[i];
  529. Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
  530. DeclInfo *d = entry->value;
  531. check_entity_decl(c, e, d, NULL);
  532. }
  533. // Check procedure bodies
  534. gb_for_array(i, c->procs) {
  535. ProcedureInfo *pi = &c->procs[i];
  536. add_curr_ast_file(c, pi->file);
  537. check_proc_body(c, pi->token, pi->decl, pi->type, pi->body);
  538. }
  539. // Add untyped expression values
  540. gb_for_array(i, c->info.untyped.entries) {
  541. auto *entry = c->info.untyped.entries + i;
  542. HashKey key = entry->key;
  543. AstNode *expr = cast(AstNode *)cast(uintptr)key.key;
  544. ExpressionInfo *info = &entry->value;
  545. if (info != NULL && expr != NULL) {
  546. if (is_type_typed(info->type)) {
  547. GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
  548. }
  549. add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
  550. }
  551. }
  552. }