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. BuiltinProcedureId 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_ProcedureDeclaration
  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. gbArray(AstNode *) deferred_stmts;
  85. };
  86. enum ExpressionKind {
  87. Expression_Expression,
  88. Expression_Conversion,
  89. Expression_Statement,
  90. };
  91. enum BuiltinProcedureId {
  92. BuiltinProcedure_Invalid,
  93. BuiltinProcedure_size_of,
  94. BuiltinProcedure_size_of_val,
  95. BuiltinProcedure_align_of,
  96. BuiltinProcedure_align_of_val,
  97. BuiltinProcedure_offset_of,
  98. BuiltinProcedure_offset_of_val,
  99. BuiltinProcedure_static_assert,
  100. BuiltinProcedure_len,
  101. BuiltinProcedure_cap,
  102. BuiltinProcedure_copy,
  103. BuiltinProcedure_print,
  104. BuiltinProcedure_println,
  105. BuiltinProcedure_Count,
  106. };
  107. struct BuiltinProcedure {
  108. String name;
  109. isize arg_count;
  110. b32 variadic;
  111. ExpressionKind kind;
  112. };
  113. gb_global BuiltinProcedure builtin_procedures[BuiltinProcedure_Count] = {
  114. {STR_LIT(""), 0, false, Expression_Statement},
  115. {STR_LIT("size_of"), 1, false, Expression_Expression},
  116. {STR_LIT("size_of_val"), 1, false, Expression_Expression},
  117. {STR_LIT("align_of"), 1, false, Expression_Expression},
  118. {STR_LIT("align_of_val"), 1, false, Expression_Expression},
  119. {STR_LIT("offset_of"), 2, false, Expression_Expression},
  120. {STR_LIT("offset_of_val"), 1, false, Expression_Expression},
  121. {STR_LIT("static_assert"), 1, false, Expression_Statement},
  122. {STR_LIT("len"), 1, false, Expression_Expression},
  123. {STR_LIT("cap"), 1, false, Expression_Expression},
  124. {STR_LIT("copy"), 2, false, Expression_Expression},
  125. {STR_LIT("print"), 1, true, Expression_Statement},
  126. {STR_LIT("println"), 1, true, Expression_Statement},
  127. };
  128. struct CheckerContext {
  129. Scope *scope;
  130. DeclInfo *decl;
  131. };
  132. // NOTE(bill): Symbol tables
  133. struct CheckerInfo {
  134. Map<TypeAndValue> types; // Key: AstNode * | Expression -> Type (and value)
  135. Map<Entity *> definitions; // Key: AstNode * | Identifier -> Entity
  136. Map<Entity *> uses; // Key: AstNode * | Identifier -> Entity
  137. Map<Scope *> scopes; // Key: AstNode * | Node -> Scope
  138. Map<ExpressionInfo> untyped; // Key: AstNode * | Expression -> ExpressionInfo
  139. Map<DeclInfo *> entities; // Key: Entity *
  140. };
  141. struct Checker {
  142. Parser * parser;
  143. CheckerInfo info;
  144. AstFile * curr_ast_file;
  145. BaseTypeSizes sizes;
  146. Scope * global_scope;
  147. gbArray(ProcedureInfo) procedures; // NOTE(bill): Procedures to check
  148. gbArena arena;
  149. gbAllocator allocator;
  150. CheckerContext context;
  151. gbArray(Type *) procedure_stack;
  152. b32 in_defer; // TODO(bill): Actually handle correctly
  153. ErrorCollector error_collector;
  154. };
  155. gb_global Scope *universal_scope = NULL;
  156. Scope *make_scope(Scope *parent, gbAllocator allocator) {
  157. Scope *s = gb_alloc_item(allocator, Scope);
  158. s->parent = parent;
  159. map_init(&s->elements, gb_heap_allocator());
  160. gb_array_init(s->deferred_stmts, gb_heap_allocator());
  161. if (parent != NULL && parent != universal_scope) {
  162. DLIST_APPEND(parent->first_child, parent->last_child, s);
  163. }
  164. return s;
  165. }
  166. void destroy_scope(Scope *scope) {
  167. gb_for_array(i, scope->elements.entries) {
  168. Entity *e =scope->elements.entries[i].value;
  169. if (e->kind == Entity_Variable) {
  170. if (!e->variable.used) {
  171. #if 0
  172. warning(e->token, "Unused variable `%.*s`", LIT(e->token.string));
  173. #endif
  174. }
  175. }
  176. }
  177. for (Scope *child = scope->first_child; child != NULL; child = child->next) {
  178. destroy_scope(child);
  179. }
  180. map_destroy(&scope->elements);
  181. // NOTE(bill): No need to free scope as it "should" be allocated in an arena (except for the global scope)
  182. }
  183. void scope_lookup_parent_entity(Scope *s, String name, Scope **scope, Entity **entity) {
  184. u64 key = hash_string(name);
  185. for (; s != NULL; s = s->parent) {
  186. Entity **found = map_get(&s->elements, key);
  187. if (found) {
  188. if (entity) *entity = *found;
  189. if (scope) *scope = s;
  190. return;
  191. }
  192. }
  193. if (entity) *entity = NULL;
  194. if (scope) *scope = NULL;
  195. }
  196. Entity *scope_lookup_entity(Scope *s, String name) {
  197. Entity *entity = NULL;
  198. scope_lookup_parent_entity(s, name, NULL, &entity);
  199. return entity;
  200. }
  201. Entity *current_scope_lookup_entity(Scope *s, String name) {
  202. u64 key = hash_string(name);
  203. Entity **found = map_get(&s->elements, key);
  204. if (found)
  205. return *found;
  206. return NULL;
  207. }
  208. Entity *scope_insert_entity(Scope *s, Entity *entity) {
  209. String name = entity->token.string;
  210. u64 key = hash_string(name);
  211. Entity **found = map_get(&s->elements, key);
  212. if (found)
  213. return *found;
  214. map_set(&s->elements, key, entity);
  215. if (entity->parent == NULL)
  216. entity->parent = s;
  217. return NULL;
  218. }
  219. void add_dependency(DeclInfo *d, Entity *e) {
  220. map_set(&d->deps, hash_pointer(e), cast(b32)true);
  221. }
  222. void add_declaration_dependency(Checker *c, Entity *e) {
  223. if (c->context.decl) {
  224. auto found = map_get(&c->info.entities, hash_pointer(e));
  225. if (found) {
  226. add_dependency(c->context.decl, e);
  227. }
  228. }
  229. }
  230. void add_global_entity(Entity *entity) {
  231. String name = entity->token.string;
  232. if (gb_memchr(name.text, ' ', name.len)) {
  233. return; // NOTE(bill): `untyped thing`
  234. }
  235. if (scope_insert_entity(universal_scope, entity)) {
  236. GB_PANIC("Compiler error: double declaration");
  237. }
  238. }
  239. void add_global_constant(gbAllocator a, String name, Type *type, ExactValue value) {
  240. Token token = {Token_Identifier};
  241. token.string = name;
  242. Entity *entity = alloc_entity(a, Entity_Constant, NULL, token, type);
  243. entity->constant.value = value;
  244. add_global_entity(entity);
  245. }
  246. void init_universal_scope(void) {
  247. // NOTE(bill): No need to free these
  248. gbAllocator a = gb_heap_allocator();
  249. universal_scope = make_scope(NULL, a);
  250. // Types
  251. for (isize i = 0; i < gb_count_of(basic_types); i++) {
  252. Token token = {Token_Identifier};
  253. token.string = basic_types[i].basic.name;
  254. add_global_entity(make_entity_type_name(a, NULL, token, &basic_types[i]));
  255. }
  256. for (isize i = 0; i < gb_count_of(basic_type_aliases); i++) {
  257. Token token = {Token_Identifier};
  258. token.string = basic_type_aliases[i].basic.name;
  259. add_global_entity(make_entity_type_name(a, NULL, token, &basic_type_aliases[i]));
  260. }
  261. // Constants
  262. add_global_constant(a, make_string("true"), &basic_types[Basic_UntypedBool], make_exact_value_bool(true));
  263. add_global_constant(a, make_string("false"), &basic_types[Basic_UntypedBool], make_exact_value_bool(false));
  264. add_global_constant(a, make_string("null"), &basic_types[Basic_UntypedPointer], make_exact_value_pointer(NULL));
  265. // Builtin Procedures
  266. for (isize i = 0; i < gb_count_of(builtin_procedures); i++) {
  267. BuiltinProcedureId id = cast(BuiltinProcedureId)i;
  268. Token token = {Token_Identifier};
  269. token.string = builtin_procedures[i].name;
  270. Entity *entity = alloc_entity(a, Entity_Builtin, NULL, token, &basic_types[Basic_Invalid]);
  271. entity->builtin.id = id;
  272. add_global_entity(entity);
  273. }
  274. }
  275. void init_checker_info(CheckerInfo *i) {
  276. gbAllocator a = gb_heap_allocator();
  277. map_init(&i->types, a);
  278. map_init(&i->definitions, a);
  279. map_init(&i->uses, a);
  280. map_init(&i->scopes, a);
  281. map_init(&i->entities, a);
  282. map_init(&i->untyped, a);
  283. }
  284. void destroy_checker_info(CheckerInfo *i) {
  285. map_destroy(&i->types);
  286. map_destroy(&i->definitions);
  287. map_destroy(&i->uses);
  288. map_destroy(&i->scopes);
  289. map_destroy(&i->entities);
  290. map_destroy(&i->untyped);
  291. }
  292. void init_checker(Checker *c, Parser *parser) {
  293. gbAllocator a = gb_heap_allocator();
  294. c->parser = parser;
  295. init_checker_info(&c->info);
  296. c->sizes.word_size = 8;
  297. c->sizes.max_align = 8;
  298. gb_array_init(c->procedure_stack, a);
  299. gb_array_init(c->procedures, a);
  300. // NOTE(bill): Is this big enough or too small?
  301. isize item_size = gb_max(gb_max(gb_size_of(Entity), gb_size_of(Type)), gb_size_of(Scope));
  302. isize total_token_count = 0;
  303. gb_for_array(i, c->parser->files) {
  304. AstFile *f = &c->parser->files[i];
  305. total_token_count += gb_array_count(f->tokens);
  306. }
  307. isize arena_size = 2 * item_size * total_token_count;
  308. gb_arena_init_from_allocator(&c->arena, a, arena_size);
  309. c->allocator = gb_arena_allocator(&c->arena);
  310. c->global_scope = make_scope(universal_scope, c->allocator);
  311. c->context.scope = c->global_scope;
  312. }
  313. void destroy_checker(Checker *c) {
  314. destroy_checker_info(&c->info);
  315. destroy_scope(c->global_scope);
  316. gb_array_free(c->procedure_stack);
  317. gb_array_free(c->procedures);
  318. gb_arena_free(&c->arena);
  319. }
  320. TypeAndValue *type_and_value_of_expression(CheckerInfo *i, AstNode *expression) {
  321. TypeAndValue *found = map_get(&i->types, hash_pointer(expression));
  322. return found;
  323. }
  324. Entity *entity_of_ident(CheckerInfo *i, AstNode *identifier) {
  325. GB_ASSERT(identifier->kind == AstNode_Ident);
  326. Entity **found = map_get(&i->definitions, hash_pointer(identifier));
  327. if (found)
  328. return *found;
  329. found = map_get(&i->uses, hash_pointer(identifier));
  330. if (found)
  331. return *found;
  332. return NULL;
  333. }
  334. Type *type_of_expr(CheckerInfo *i, AstNode *expression) {
  335. TypeAndValue *found = type_and_value_of_expression(i, expression);
  336. if (found)
  337. return found->type;
  338. if (expression->kind == AstNode_Ident) {
  339. Entity *entity = entity_of_ident(i, expression);
  340. if (entity)
  341. return entity->type;
  342. }
  343. return NULL;
  344. }
  345. void add_untyped(CheckerInfo *i, AstNode *expression, b32 lhs, AddressingMode mode, Type *basic_type, ExactValue value) {
  346. map_set(&i->untyped, hash_pointer(expression), make_expression_info(lhs, mode, basic_type, value));
  347. }
  348. void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode, Type *type, ExactValue value) {
  349. GB_ASSERT(expression != NULL);
  350. GB_ASSERT(type != NULL);
  351. if (mode == Addressing_Invalid)
  352. return;
  353. if (mode == Addressing_Constant) {
  354. GB_ASSERT(value.kind != ExactValue_Invalid);
  355. GB_ASSERT(type == &basic_types[Basic_Invalid] || is_type_constant_type(type));
  356. }
  357. TypeAndValue tv = {};
  358. tv.type = type;
  359. tv.value = value;
  360. map_set(&i->types, hash_pointer(expression), tv);
  361. }
  362. void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
  363. GB_ASSERT(identifier != NULL);
  364. GB_ASSERT(identifier->kind == AstNode_Ident);
  365. u64 key = hash_pointer(identifier);
  366. map_set(&i->definitions, key, entity);
  367. }
  368. void add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
  369. if (!are_strings_equal(entity->token.string, make_string("_"))) {
  370. Entity *insert_entity = scope_insert_entity(scope, entity);
  371. if (insert_entity) {
  372. error(&c->error_collector, entity->token, "Redeclared entity in this scope: %.*s", LIT(entity->token.string));
  373. return;
  374. }
  375. }
  376. if (identifier != NULL)
  377. add_entity_definition(&c->info, identifier, entity);
  378. }
  379. void add_entity_use(CheckerInfo *i, AstNode *identifier, Entity *entity) {
  380. GB_ASSERT(identifier != NULL);
  381. GB_ASSERT(identifier->kind == AstNode_Ident);
  382. u64 key = hash_pointer(identifier);
  383. map_set(&i->uses, key, entity);
  384. }
  385. void add_file_entity(Checker *c, AstNode *identifier, Entity *e, DeclInfo *d) {
  386. GB_ASSERT(are_strings_equal(identifier->Ident.token.string, e->token.string));
  387. add_entity(c, c->global_scope, identifier, e);
  388. map_set(&c->info.entities, hash_pointer(e), d);
  389. e->order = gb_array_count(c->info.entities.entries);
  390. }
  391. void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, AstNode *body) {
  392. ProcedureInfo info = {};
  393. info.file = file;
  394. info.token = token;
  395. info.decl = decl;
  396. info.type = type;
  397. info.body = body;
  398. gb_array_append(c->procedures, info);
  399. }
  400. void add_scope(Checker *c, AstNode *node, Scope *scope) {
  401. GB_ASSERT(node != NULL);
  402. GB_ASSERT(scope != NULL);
  403. map_set(&c->info.scopes, hash_pointer(node), scope);
  404. }
  405. void check_open_scope(Checker *c, AstNode *statement) {
  406. Scope *scope = make_scope(c->context.scope, c->allocator);
  407. add_scope(c, statement, scope);
  408. c->context.scope = scope;
  409. }
  410. void check_close_scope(Checker *c) {
  411. c->context.scope = c->context.scope->parent;
  412. }
  413. void check_add_deferred_stmt(Checker *c, AstNode *stmt) {
  414. GB_ASSERT(stmt != NULL);
  415. GB_ASSERT(is_ast_node_stmt(stmt));
  416. gb_array_append(c->context.scope->deferred_stmts, stmt);
  417. }
  418. void push_procedure(Checker *c, Type *procedure_type) {
  419. gb_array_append(c->procedure_stack, procedure_type);
  420. }
  421. void pop_procedure(Checker *c) {
  422. gb_array_pop(c->procedure_stack);
  423. }
  424. void add_curr_ast_file(Checker *c, AstFile *file) {
  425. gb_zero_item(&c->error_collector);
  426. c->curr_ast_file = file;
  427. }
  428. #include "expression.cpp"
  429. #include "statements.cpp"
  430. void check_parsed_files(Checker *c) {
  431. // Collect Entities
  432. gb_for_array(i, c->parser->files) {
  433. AstFile *f = &c->parser->files[i];
  434. add_curr_ast_file(c, f);
  435. for (AstNode *decl = f->decls; decl != NULL; decl = decl->next) {
  436. if (!is_ast_node_decl(decl))
  437. continue;
  438. switch (decl->kind) {
  439. case_ast_node(bd, BadDecl, decl);
  440. case_end;
  441. case_ast_node(vd, VarDecl, decl);
  442. switch (vd->kind) {
  443. case Declaration_Immutable: {
  444. for (AstNode *name = vd->name_list, *value = vd->value_list;
  445. name != NULL && value != NULL;
  446. name = name->next, value = value->next) {
  447. ast_node(n, Ident, name);
  448. ExactValue v = {ExactValue_Invalid};
  449. Entity *e = make_entity_constant(c->allocator, c->context.scope, n->token, NULL, v);
  450. DeclInfo *di = make_declaration_info(c->allocator, c->global_scope);
  451. di->type_expr = vd->type;
  452. di->init_expr = value;
  453. add_file_entity(c, name, e, di);
  454. }
  455. isize lhs_count = vd->name_count;
  456. isize rhs_count = vd->value_count;
  457. if (rhs_count == 0 && vd->type == NULL) {
  458. error(&c->error_collector, ast_node_token(decl), "Missing type or initial expression");
  459. } else if (lhs_count < rhs_count) {
  460. error(&c->error_collector, ast_node_token(decl), "Extra initial expression");
  461. }
  462. } break;
  463. case Declaration_Mutable: {
  464. isize entity_count = vd->name_count;
  465. isize entity_index = 0;
  466. Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
  467. DeclInfo *di = NULL;
  468. if (vd->value_count == 1) {
  469. di = make_declaration_info(gb_heap_allocator(), c->global_scope);
  470. di->entities = entities;
  471. di->entity_count = entity_count;
  472. di->type_expr = vd->type;
  473. di->init_expr = vd->value_list;
  474. }
  475. AstNode *value = vd->value_list;
  476. for (AstNode *name = vd->name_list; name != NULL; name = name->next) {
  477. ast_node(n, Ident, name);
  478. Entity *e = make_entity_variable(c->allocator, c->global_scope, n->token, NULL);
  479. entities[entity_index++] = e;
  480. DeclInfo *d = di;
  481. if (d == NULL) {
  482. AstNode *init_expr = value;
  483. d = make_declaration_info(gb_heap_allocator(), c->global_scope);
  484. d->type_expr = vd->type;
  485. d->init_expr = init_expr;
  486. }
  487. add_file_entity(c, name, e, d);
  488. if (value != NULL)
  489. value = value->next;
  490. }
  491. } break;
  492. }
  493. case_end;
  494. case_ast_node(td, TypeDecl, decl);
  495. ast_node(n, Ident, td->name);
  496. Entity *e = make_entity_type_name(c->allocator, c->global_scope, n->token, NULL);
  497. DeclInfo *d = make_declaration_info(c->allocator, e->parent);
  498. d->type_expr = td->type;
  499. add_file_entity(c, td->name, e, d);
  500. case_end;
  501. case_ast_node(ad, AliasDecl, decl);
  502. ast_node(n, Ident, ad->name);
  503. Entity *e = make_entity_alias_name(c->allocator, c->global_scope, n->token, NULL);
  504. DeclInfo *d = make_declaration_info(c->allocator, e->parent);
  505. d->type_expr = ad->type;
  506. add_file_entity(c, ad->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(id, ImportDecl, 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;
  530. DeclInfo *d = entry->value;
  531. check_entity_decl(c, e, d, NULL);
  532. }
  533. // Check procedure bodies
  534. gb_for_array(i, c->procedures) {
  535. ProcedureInfo *pi = &c->procedures[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. u64 key = entry->key;
  543. AstNode *expr = cast(AstNode *)cast(uintptr)key;
  544. ExpressionInfo *info = &entry->value;
  545. if (is_type_typed(info->type)) {
  546. GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
  547. }
  548. add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
  549. }
  550. }