authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-01 13:55:56-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-01 13:55:56-05:00
logc6ace9720c8666f893f236c00ea9b370b1b2bb70
treee7167eca7801103efe46bb1b89d6c23bcc70dc06
parenteb5693d91f7ff92b88c4a0dc3e5499dd0a700b34

rename BlockContext to Scope


7 files changed, 200 insertions(+), 200 deletions(-)

src/all_types.hpp+16-16
...@@ -19,7 +19,7 @@...@@ -19,7 +19,7 @@
19struct AstNode;19struct AstNode;
20struct ImportTableEntry;20struct ImportTableEntry;
21struct FnTableEntry;21struct FnTableEntry;
22struct BlockContext;22struct Scope;
23struct TypeTableEntry;23struct TypeTableEntry;
24struct VariableTableEntry;24struct VariableTableEntry;
25struct ErrorTableEntry;25struct ErrorTableEntry;
...@@ -115,7 +115,7 @@ struct ConstExprValue {...@@ -115,7 +115,7 @@ struct ConstExprValue {
115 ConstArrayValue x_array;115 ConstArrayValue x_array;
116 ConstPtrValue x_ptr;116 ConstPtrValue x_ptr;
117 ImportTableEntry *x_import;117 ImportTableEntry *x_import;
118 BlockContext *x_block;118 Scope *x_block;
119 } data;119 } data;
120};120};
121121
...@@ -252,7 +252,7 @@ struct AstNodeFnDef {...@@ -252,7 +252,7 @@ struct AstNodeFnDef {
252 // populated by semantic analyzer252 // populated by semantic analyzer
253 TypeTableEntry *implicit_return_type;253 TypeTableEntry *implicit_return_type;
254 // the first child block context254 // the first child block context
255 BlockContext *block_context;255 Scope *scope;
256};256};
257257
258struct AstNodeFnDecl {258struct AstNodeFnDecl {
...@@ -274,11 +274,11 @@ struct AstNodeBlock {...@@ -274,11 +274,11 @@ struct AstNodeBlock {
274274
275 // populated by semantic analyzer275 // populated by semantic analyzer
276 // this one is the scope that the block itself introduces276 // this one is the scope that the block itself introduces
277 BlockContext *child_block;277 Scope *child_block;
278 // this is the innermost scope created by defers and var decls.278 // this is the innermost scope created by defers and var decls.
279 // you can follow its parents up to child_block. it will equal279 // you can follow its parents up to child_block. it will equal
280 // child_block if there are no defers or var decls in the block.280 // child_block if there are no defers or var decls in the block.
281 BlockContext *nested_block;281 Scope *nested_block;
282};282};
283283
284enum ReturnKind {284enum ReturnKind {
...@@ -300,7 +300,7 @@ struct AstNodeDefer {...@@ -300,7 +300,7 @@ struct AstNodeDefer {
300 // populated by semantic analyzer:300 // populated by semantic analyzer:
301 size_t index_in_block;301 size_t index_in_block;
302 LLVMBasicBlockRef basic_block;302 LLVMBasicBlockRef basic_block;
303 BlockContext *child_block;303 Scope *child_block;
304};304};
305305
306struct AstNodeVariableDeclaration {306struct AstNodeVariableDeclaration {
...@@ -638,7 +638,7 @@ struct AstNodeStructDecl {...@@ -638,7 +638,7 @@ struct AstNodeStructDecl {
638 ZigList<AstNode *> decls;638 ZigList<AstNode *> decls;
639639
640 // populated by semantic analyzer640 // populated by semantic analyzer
641 BlockContext *block_context;641 Scope *scope;
642 TypeTableEntry *type_entry;642 TypeTableEntry *type_entry;
643 TypeTableEntry *generic_fn_type;643 TypeTableEntry *generic_fn_type;
644 bool skip;644 bool skip;
...@@ -762,7 +762,7 @@ struct AstNode {...@@ -762,7 +762,7 @@ struct AstNode {
762 ImportTableEntry *owner;762 ImportTableEntry *owner;
763 // the context in which this expression/node is evaluated.763 // the context in which this expression/node is evaluated.
764 // for blocks, this points to the containing scope, not the block's own scope for its children.764 // for blocks, this points to the containing scope, not the block's own scope for its children.
765 BlockContext *block_context;765 Scope *scope;
766 union {766 union {
767 AstNodeRoot root;767 AstNodeRoot root;
768 AstNodeFnDef fn_def;768 AstNodeFnDef fn_def;
...@@ -884,7 +884,7 @@ struct TypeTableEntryStruct {...@@ -884,7 +884,7 @@ struct TypeTableEntryStruct {
884 uint64_t size_bytes;884 uint64_t size_bytes;
885 bool is_invalid; // true if any fields are invalid885 bool is_invalid; // true if any fields are invalid
886 bool is_slice;886 bool is_slice;
887 BlockContext *block_context;887 Scope *scope;
888888
889 // set this flag temporarily to detect infinite loops889 // set this flag temporarily to detect infinite loops
890 bool embedded_in_current;890 bool embedded_in_current;
...@@ -910,7 +910,7 @@ struct TypeTableEntryEnum {...@@ -910,7 +910,7 @@ struct TypeTableEntryEnum {
910 TypeTableEntry *tag_type;910 TypeTableEntry *tag_type;
911 TypeTableEntry *union_type;911 TypeTableEntry *union_type;
912912
913 BlockContext *block_context;913 Scope *scope;
914914
915 // set this flag temporarily to detect infinite loops915 // set this flag temporarily to detect infinite loops
916 bool embedded_in_current;916 bool embedded_in_current;
...@@ -926,7 +926,7 @@ struct TypeTableEntryUnion {...@@ -926,7 +926,7 @@ struct TypeTableEntryUnion {
926 TypeStructField *fields;926 TypeStructField *fields;
927 uint64_t size_bytes;927 uint64_t size_bytes;
928 bool is_invalid; // true if any fields are invalid928 bool is_invalid; // true if any fields are invalid
929 BlockContext *block_context;929 Scope *scope;
930930
931 // set this flag temporarily to detect infinite loops931 // set this flag temporarily to detect infinite loops
932 bool embedded_in_current;932 bool embedded_in_current;
...@@ -1044,7 +1044,7 @@ struct ImportTableEntry {...@@ -1044,7 +1044,7 @@ struct ImportTableEntry {
1044 ZigLLVMDIFile *di_file;1044 ZigLLVMDIFile *di_file;
1045 Buf *source_code;1045 Buf *source_code;
1046 ZigList<size_t> *line_offsets;1046 ZigList<size_t> *line_offsets;
1047 BlockContext *block_context;1047 Scope *scope;
1048 AstNode *c_import_node;1048 AstNode *c_import_node;
1049 bool any_imports_failed;1049 bool any_imports_failed;
10501050
...@@ -1071,7 +1071,7 @@ struct FnTableEntry {...@@ -1071,7 +1071,7 @@ struct FnTableEntry {
1071 AstNode *fn_def_node;1071 AstNode *fn_def_node;
1072 ImportTableEntry *import_entry;1072 ImportTableEntry *import_entry;
1073 // Required to be a pre-order traversal of the AST. (parents must come before children)1073 // Required to be a pre-order traversal of the AST. (parents must come before children)
1074 ZigList<BlockContext *> all_block_contexts;1074 ZigList<Scope *> all_block_contexts;
1075 Buf symbol_name;1075 Buf symbol_name;
1076 TypeTableEntry *type_entry; // function type1076 TypeTableEntry *type_entry; // function type
1077 bool internal_linkage;1077 bool internal_linkage;
...@@ -1310,7 +1310,7 @@ struct VariableTableEntry {...@@ -1310,7 +1310,7 @@ struct VariableTableEntry {
1310 ZigLLVMDILocalVariable *di_loc_var;1310 ZigLLVMDILocalVariable *di_loc_var;
1311 size_t src_arg_index;1311 size_t src_arg_index;
1312 size_t gen_arg_index;1312 size_t gen_arg_index;
1313 BlockContext *block_context;1313 Scope *scope;
1314 LLVMValueRef param_value_ref;1314 LLVMValueRef param_value_ref;
1315 bool force_depends_on_compile_var;1315 bool force_depends_on_compile_var;
1316 ImportTableEntry *import;1316 ImportTableEntry *import;
...@@ -1331,7 +1331,7 @@ struct LabelTableEntry {...@@ -1331,7 +1331,7 @@ struct LabelTableEntry {
1331 bool used;1331 bool used;
1332};1332};
13331333
1334struct BlockContext {1334struct Scope {
1335 AstNode *node;1335 AstNode *node;
13361336
1337 // any variables that are introduced by this scope1337 // any variables that are introduced by this scope
...@@ -1343,7 +1343,7 @@ struct BlockContext {...@@ -1343,7 +1343,7 @@ struct BlockContext {
1343 FnTableEntry *fn_entry;1343 FnTableEntry *fn_entry;
13441344
1345 // if the block has a parent, this is it1345 // if the block has a parent, this is it
1346 BlockContext *parent;1346 Scope *parent;
13471347
1348 // if break or continue is valid in this context, this is the loop node that1348 // if break or continue is valid in this context, this is the loop node that
1349 // it would pertain to1349 // it would pertain to
src/analyze.cpp+44-44
...@@ -115,26 +115,26 @@ TypeTableEntry *new_type_table_entry(TypeTableEntryId id) {...@@ -115,26 +115,26 @@ TypeTableEntry *new_type_table_entry(TypeTableEntryId id) {
115 return entry;115 return entry;
116}116}
117117
118static BlockContext **get_container_block_context_ptr(TypeTableEntry *type_entry) {118static Scope **get_container_block_context_ptr(TypeTableEntry *type_entry) {
119 if (type_entry->id == TypeTableEntryIdStruct) {119 if (type_entry->id == TypeTableEntryIdStruct) {
120 return &type_entry->data.structure.block_context;120 return &type_entry->data.structure.scope;
121 } else if (type_entry->id == TypeTableEntryIdEnum) {121 } else if (type_entry->id == TypeTableEntryIdEnum) {
122 return &type_entry->data.enumeration.block_context;122 return &type_entry->data.enumeration.scope;
123 } else if (type_entry->id == TypeTableEntryIdUnion) {123 } else if (type_entry->id == TypeTableEntryIdUnion) {
124 return &type_entry->data.unionation.block_context;124 return &type_entry->data.unionation.scope;
125 }125 }
126 zig_unreachable();126 zig_unreachable();
127}127}
128128
129BlockContext *get_container_block_context(TypeTableEntry *type_entry) {129Scope *get_container_block_context(TypeTableEntry *type_entry) {
130 return *get_container_block_context_ptr(type_entry);130 return *get_container_block_context_ptr(type_entry);
131}131}
132132
133static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node,133static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node,
134 BlockContext *parent_context)134 Scope *parent_context)
135{135{
136 TypeTableEntry *entry = new_type_table_entry(id);136 TypeTableEntry *entry = new_type_table_entry(id);
137 *get_container_block_context_ptr(entry) = new_block_context(source_node, parent_context);137 *get_container_block_context_ptr(entry) = new_scope(source_node, parent_context);
138 return entry;138 return entry;
139}139}
140140
...@@ -766,7 +766,7 @@ static TypeTableEntryId container_to_type(ContainerKind kind) {...@@ -766,7 +766,7 @@ static TypeTableEntryId container_to_type(ContainerKind kind) {
766 zig_unreachable();766 zig_unreachable();
767}767}
768768
769TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, BlockContext *context,769TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, Scope *context,
770 ContainerKind kind, AstNode *decl_node, const char *name)770 ContainerKind kind, AstNode *decl_node, const char *name)
771{771{
772 TypeTableEntryId type_id = container_to_type(kind);772 TypeTableEntryId type_id = container_to_type(kind);
...@@ -805,7 +805,7 @@ TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry) {...@@ -805,7 +805,7 @@ TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry) {
805 }805 }
806}806}
807807
808static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNode *node,808static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node,
809 TypeTableEntry *expected_type)809 TypeTableEntry *expected_type)
810{810{
811 IrExecutable ir_executable = {0};811 IrExecutable ir_executable = {0};
...@@ -844,7 +844,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo...@@ -844,7 +844,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo
844 return result;844 return result;
845}845}
846846
847static TypeTableEntry *analyze_type_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,847static TypeTableEntry *analyze_type_expr(CodeGen *g, ImportTableEntry *import, Scope *context,
848 AstNode *node)848 AstNode *node)
849{849{
850 IrInstruction *result = analyze_const_value(g, context, node, g->builtin_types.entry_type);850 IrInstruction *result = analyze_const_value(g, context, node, g->builtin_types.entry_type);
...@@ -861,7 +861,7 @@ static bool fn_wants_full_static_eval(FnTableEntry *fn_table_entry) {...@@ -861,7 +861,7 @@ static bool fn_wants_full_static_eval(FnTableEntry *fn_table_entry) {
861}861}
862862
863// fn_table_entry is populated if and only if there is a function definition for this prototype863// fn_table_entry is populated if and only if there is a function definition for this prototype
864static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *import, BlockContext *context,864static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *import, Scope *context,
865 TypeTableEntry *expected_type, AstNode *node, bool is_naked, bool is_cold, FnTableEntry *fn_table_entry)865 TypeTableEntry *expected_type, AstNode *node, bool is_naked, bool is_cold, FnTableEntry *fn_table_entry)
866{866{
867 assert(node->type == NodeTypeFnProto);867 assert(node->type == NodeTypeFnProto);
...@@ -1022,7 +1022,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -1022,7 +1022,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
1022}1022}
10231023
1024static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_table_entry,1024static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_table_entry,
1025 ImportTableEntry *import, BlockContext *containing_context)1025 ImportTableEntry *import, Scope *containing_context)
1026{1026{
1027 assert(node->type == NodeTypeFnProto);1027 assert(node->type == NodeTypeFnProto);
1028 AstNodeFnProto *fn_proto = &node->data.fn_proto;1028 AstNodeFnProto *fn_proto = &node->data.fn_proto;
...@@ -1060,8 +1060,8 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t...@@ -1060,8 +1060,8 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
1060 }1060 }
10611061
1062 if (fn_table_entry->fn_def_node) {1062 if (fn_table_entry->fn_def_node) {
1063 BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context);1063 Scope *context = new_scope(fn_table_entry->fn_def_node, containing_context);
1064 fn_table_entry->fn_def_node->data.fn_def.block_context = context;1064 fn_table_entry->fn_def_node->data.fn_def.scope = context;
1065 }1065 }
10661066
1067 if (!fn_wants_full_static_eval(fn_table_entry)) {1067 if (!fn_wants_full_static_eval(fn_table_entry)) {
...@@ -1109,7 +1109,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t...@@ -1109,7 +1109,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
1109 fn_type->di_type, fn_table_entry->internal_linkage,1109 fn_type->di_type, fn_table_entry->internal_linkage,
1110 is_definition, scope_line, flags, is_optimized, nullptr);1110 is_definition, scope_line, flags, is_optimized, nullptr);
11111111
1112 fn_table_entry->fn_def_node->data.fn_def.block_context->di_scope = ZigLLVMSubprogramToScope(subprogram);1112 fn_table_entry->fn_def_node->data.fn_def.scope->di_scope = ZigLLVMSubprogramToScope(subprogram);
1113 ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram);1113 ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram);
1114 }1114 }
1115 }1115 }
...@@ -1151,7 +1151,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt...@@ -1151,7 +1151,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt
1151 uint64_t biggest_align_in_bits = 0;1151 uint64_t biggest_align_in_bits = 0;
1152 uint64_t biggest_union_member_size_in_bits = 0;1152 uint64_t biggest_union_member_size_in_bits = 0;
11531153
1154 BlockContext *context = enum_type->data.enumeration.block_context;1154 Scope *context = enum_type->data.enumeration.scope;
11551155
1156 // set temporary flag1156 // set temporary flag
1157 enum_type->data.enumeration.embedded_in_current = true;1157 enum_type->data.enumeration.embedded_in_current = true;
...@@ -1337,7 +1337,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE...@@ -1337,7 +1337,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
1337 // this field should be set to true only during the recursive calls to resolve_struct_type1337 // this field should be set to true only during the recursive calls to resolve_struct_type
1338 struct_type->data.structure.embedded_in_current = true;1338 struct_type->data.structure.embedded_in_current = true;
13391339
1340 BlockContext *context = struct_type->data.structure.block_context;1340 Scope *context = struct_type->data.structure.scope;
13411341
1342 size_t gen_field_index = 0;1342 size_t gen_field_index = 0;
1343 for (size_t i = 0; i < field_count; i += 1) {1343 for (size_t i = 0; i < field_count; i += 1) {
...@@ -1463,7 +1463,7 @@ static bool get_is_generic_fn(AstNode *proto_node) {...@@ -1463,7 +1463,7 @@ static bool get_is_generic_fn(AstNode *proto_node) {
1463}1463}
14641464
1465static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstNode *proto_node,1465static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstNode *proto_node,
1466 BlockContext *containing_context)1466 Scope *containing_context)
1467{1467{
1468 assert(proto_node->type == NodeTypeFnProto);1468 assert(proto_node->type == NodeTypeFnProto);
14691469
...@@ -1546,7 +1546,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN...@@ -1546,7 +1546,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN
1546 }1546 }
1547}1547}
15481548
1549static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContext *block_context,1549static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, Scope *scope,
1550 AstNode *node, Buf *name)1550 AstNode *node, Buf *name)
1551{1551{
1552 assert(import);1552 assert(import);
...@@ -1562,19 +1562,19 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex...@@ -1562,19 +1562,19 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex
1562 g->resolve_queue.append(node);1562 g->resolve_queue.append(node);
1563 }1563 }
15641564
1565 node->block_context = block_context;1565 node->scope = scope;
15661566
1567 auto entry = block_context->decl_table.maybe_get(name);1567 auto entry = scope->decl_table.maybe_get(name);
1568 if (entry) {1568 if (entry) {
1569 AstNode *other_decl_node = entry->value;1569 AstNode *other_decl_node = entry->value;
1570 ErrorMsg *msg = add_node_error(g, node, buf_sprintf("redefinition of '%s'", buf_ptr(name)));1570 ErrorMsg *msg = add_node_error(g, node, buf_sprintf("redefinition of '%s'", buf_ptr(name)));
1571 add_error_note(g, msg, other_decl_node, buf_sprintf("previous definition is here"));1571 add_error_note(g, msg, other_decl_node, buf_sprintf("previous definition is here"));
1572 } else {1572 } else {
1573 block_context->decl_table.put(name, node);1573 scope->decl_table.put(name, node);
1574 }1574 }
1575}1575}
15761576
1577static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {1577static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, Scope *context, AstNode *node) {
1578 assert(node->type == NodeTypeContainerDecl);1578 assert(node->type == NodeTypeContainerDecl);
15791579
1580 if (node->data.struct_decl.type_entry) {1580 if (node->data.struct_decl.type_entry) {
...@@ -1591,7 +1591,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext...@@ -1591,7 +1591,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext
1591 for (size_t i = 0; i < node->data.struct_decl.decls.length; i += 1) {1591 for (size_t i = 0; i < node->data.struct_decl.decls.length; i += 1) {
1592 AstNode *child_node = node->data.struct_decl.decls.at(i);1592 AstNode *child_node = node->data.struct_decl.decls.at(i);
1593 get_as_top_level_decl(child_node)->parent_decl = node;1593 get_as_top_level_decl(child_node)->parent_decl = node;
1594 BlockContext *child_context = get_container_block_context(container_type);1594 Scope *child_context = get_container_block_context(container_type);
1595 scan_decls(g, import, child_context, child_node);1595 scan_decls(g, import, child_context, child_node);
1596 }1596 }
1597}1597}
...@@ -1644,7 +1644,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {...@@ -1644,7 +1644,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {
1644 node->data.error_value_decl.top_level_decl.resolution = TldResolutionOk;1644 node->data.error_value_decl.top_level_decl.resolution = TldResolutionOk;
1645}1645}
16461646
1647void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {1647void scan_decls(CodeGen *g, ImportTableEntry *import, Scope *context, AstNode *node) {
1648 switch (node->type) {1648 switch (node->type) {
1649 case NodeTypeRoot:1649 case NodeTypeRoot:
1650 for (size_t i = 0; i < import->root->data.root.top_level_decls.length; i += 1) {1650 for (size_t i = 0; i < import->root->data.root.top_level_decls.length; i += 1) {
...@@ -1695,7 +1695,7 @@ void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, Ast...@@ -1695,7 +1695,7 @@ void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, Ast
1695 {1695 {
1696 TopLevelDecl *tld = get_as_top_level_decl(node);1696 TopLevelDecl *tld = get_as_top_level_decl(node);
1697 tld->import = import;1697 tld->import = import;
1698 node->block_context = context;1698 node->scope = context;
1699 g->use_queue.append(node);1699 g->use_queue.append(node);
1700 tld->import->use_decls.append(node);1700 tld->import->use_decls.append(node);
1701 break;1701 break;
...@@ -1817,12 +1817,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt...@@ -1817,12 +1817,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
1817// Set name to nullptr to make the variable anonymous (not visible to programmer).1817// Set name to nullptr to make the variable anonymous (not visible to programmer).
1818// TODO merge with definition of add_local_var in ir.cpp1818// TODO merge with definition of add_local_var in ir.cpp
1819static VariableTableEntry *add_local_var_shadowable(CodeGen *g, AstNode *source_node, ImportTableEntry *import,1819static VariableTableEntry *add_local_var_shadowable(CodeGen *g, AstNode *source_node, ImportTableEntry *import,
1820 BlockContext *context, Buf *name, TypeTableEntry *type_entry, bool is_const, AstNode *val_node,1820 Scope *context, Buf *name, TypeTableEntry *type_entry, bool is_const, AstNode *val_node,
1821 bool shadowable)1821 bool shadowable)
1822{1822{
1823 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);1823 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
1824 variable_entry->type = type_entry;1824 variable_entry->type = type_entry;
1825 variable_entry->block_context = context;1825 variable_entry->scope = context;
1826 variable_entry->import = import;1826 variable_entry->import = import;
1827 variable_entry->shadowable = shadowable;1827 variable_entry->shadowable = shadowable;
1828 variable_entry->mem_slot_index = SIZE_MAX;1828 variable_entry->mem_slot_index = SIZE_MAX;
...@@ -1875,7 +1875,7 @@ static VariableTableEntry *add_local_var_shadowable(CodeGen *g, AstNode *source_...@@ -1875,7 +1875,7 @@ static VariableTableEntry *add_local_var_shadowable(CodeGen *g, AstNode *source_
1875}1875}
18761876
1877static VariableTableEntry *add_local_var(CodeGen *g, AstNode *source_node, ImportTableEntry *import,1877static VariableTableEntry *add_local_var(CodeGen *g, AstNode *source_node, ImportTableEntry *import,
1878 BlockContext *context, Buf *name, TypeTableEntry *type_entry, bool is_const, AstNode *val_node)1878 Scope *context, Buf *name, TypeTableEntry *type_entry, bool is_const, AstNode *val_node)
1879{1879{
1880 return add_local_var_shadowable(g, source_node, import, context, name, type_entry, is_const, val_node, false);1880 return add_local_var_shadowable(g, source_node, import, context, name, type_entry, is_const, val_node, false);
1881}1881}
...@@ -1884,7 +1884,7 @@ static void resolve_var_decl(CodeGen *g, ImportTableEntry *import, AstNode *node...@@ -1884,7 +1884,7 @@ static void resolve_var_decl(CodeGen *g, ImportTableEntry *import, AstNode *node
1884 assert(node->type == NodeTypeVariableDeclaration);1884 assert(node->type == NodeTypeVariableDeclaration);
18851885
1886 AstNodeVariableDeclaration *var_decl = &node->data.variable_declaration;1886 AstNodeVariableDeclaration *var_decl = &node->data.variable_declaration;
1887 BlockContext *scope = node->block_context;1887 Scope *scope = node->scope;
1888 bool is_const = var_decl->is_const;1888 bool is_const = var_decl->is_const;
1889 bool is_export = (var_decl->top_level_decl.visib_mod == VisibModExport);1889 bool is_export = (var_decl->top_level_decl.visib_mod == VisibModExport);
1890 bool is_extern = var_decl->is_extern;1890 bool is_extern = var_decl->is_extern;
...@@ -1963,7 +1963,7 @@ void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only) {...@@ -1963,7 +1963,7 @@ void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only) {
19631963
1964 switch (node->type) {1964 switch (node->type) {
1965 case NodeTypeFnProto:1965 case NodeTypeFnProto:
1966 preview_fn_proto_instance(g, import, node, node->block_context);1966 preview_fn_proto_instance(g, import, node, node->scope);
1967 break;1967 break;
1968 case NodeTypeContainerDecl:1968 case NodeTypeContainerDecl:
1969 resolve_struct_decl(g, import, node);1969 resolve_struct_decl(g, import, node);
...@@ -1980,7 +1980,7 @@ void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only) {...@@ -1980,7 +1980,7 @@ void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only) {
1980 if (node->data.type_decl.override_type) {1980 if (node->data.type_decl.override_type) {
1981 entry = node->data.type_decl.override_type;1981 entry = node->data.type_decl.override_type;
1982 } else {1982 } else {
1983 TypeTableEntry *child_type = analyze_type_expr(g, import, import->block_context, type_node);1983 TypeTableEntry *child_type = analyze_type_expr(g, import, import->scope, type_node);
1984 if (child_type->id == TypeTableEntryIdInvalid) {1984 if (child_type->id == TypeTableEntryIdInvalid) {
1985 entry = child_type;1985 entry = child_type;
1986 } else {1986 } else {
...@@ -2170,8 +2170,8 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *...@@ -2170,8 +2170,8 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
2170 return false;2170 return false;
2171}2171}
21722172
2173BlockContext *new_block_context(AstNode *node, BlockContext *parent) {2173Scope *new_scope(AstNode *node, Scope *parent) {
2174 BlockContext *context = allocate<BlockContext>(1);2174 Scope *context = allocate<Scope>(1);
2175 context->node = node;2175 context->node = node;
2176 context->parent = parent;2176 context->parent = parent;
2177 context->decl_table.init(1);2177 context->decl_table.init(1);
...@@ -2197,7 +2197,7 @@ BlockContext *new_block_context(AstNode *node, BlockContext *parent) {...@@ -2197,7 +2197,7 @@ BlockContext *new_block_context(AstNode *node, BlockContext *parent) {
2197 return context;2197 return context;
2198}2198}
21992199
2200AstNode *find_decl(BlockContext *context, Buf *name) {2200AstNode *find_decl(Scope *context, Buf *name) {
2201 while (context) {2201 while (context) {
2202 auto entry = context->decl_table.maybe_get(name);2202 auto entry = context->decl_table.maybe_get(name);
2203 if (entry) {2203 if (entry) {
...@@ -2208,8 +2208,8 @@ AstNode *find_decl(BlockContext *context, Buf *name) {...@@ -2208,8 +2208,8 @@ AstNode *find_decl(BlockContext *context, Buf *name) {
2208 return nullptr;2208 return nullptr;
2209}2209}
22102210
2211VariableTableEntry *find_variable(CodeGen *g, BlockContext *orig_context, Buf *name) {2211VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name) {
2212 BlockContext *context = orig_context;2212 Scope *context = orig_context;
2213 while (context) {2213 while (context) {
2214 auto entry = context->var_table.maybe_get(name);2214 auto entry = context->var_table.maybe_get(name);
2215 if (entry) {2215 if (entry) {
...@@ -2355,7 +2355,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -2355,7 +2355,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
2355 }2355 }
2356 fn_table_entry->anal_state = FnAnalStateProbing;2356 fn_table_entry->anal_state = FnAnalStateProbing;
23572357
2358 BlockContext *context = node->data.fn_def.block_context;2358 Scope *context = node->data.fn_def.scope;
23592359
2360 TypeTableEntry *fn_type = fn_table_entry->type_entry;2360 TypeTableEntry *fn_type = fn_table_entry->type_entry;
2361 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;2361 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
...@@ -2456,7 +2456,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -2456,7 +2456,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
2456 continue;2456 continue;
2457 }2457 }
2458 if (target_tld->visib_mod != VisibModPrivate) {2458 if (target_tld->visib_mod != VisibModPrivate) {
2459 auto existing_entry = tld->import->block_context->decl_table.maybe_get(target_tld->name);2459 auto existing_entry = tld->import->scope->decl_table.maybe_get(target_tld->name);
2460 if (existing_entry) {2460 if (existing_entry) {
2461 AstNode *existing_decl = existing_entry->value;2461 AstNode *existing_decl = existing_entry->value;
2462 if (existing_decl != decl_node) {2462 if (existing_decl != decl_node) {
...@@ -2467,7 +2467,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -2467,7 +2467,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
2467 add_error_note(g, msg, decl_node, buf_sprintf("imported definition here"));2467 add_error_note(g, msg, decl_node, buf_sprintf("imported definition here"));
2468 }2468 }
2469 } else {2469 } else {
2470 tld->import->block_context->decl_table.put(target_tld->name, decl_node);2470 tld->import->scope->decl_table.put(target_tld->name, decl_node);
2471 }2471 }
2472 }2472 }
2473 }2473 }
...@@ -2494,7 +2494,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {...@@ -2494,7 +2494,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
2494 assert(node->type == NodeTypeUse);2494 assert(node->type == NodeTypeUse);
2495 TopLevelDecl *tld = get_as_top_level_decl(node);2495 TopLevelDecl *tld = get_as_top_level_decl(node);
24962496
2497 IrInstruction *result = analyze_const_value(g, tld->import->block_context, node->data.use.expr,2497 IrInstruction *result = analyze_const_value(g, tld->import->scope, node->data.use.expr,
2498 g->builtin_types.entry_namespace);2498 g->builtin_types.entry_namespace);
2499 if (result->type_entry->id == TypeTableEntryIdInvalid)2499 if (result->type_entry->id == TypeTableEntryIdInvalid)
2500 tld->import->any_imports_failed = true;2500 tld->import->any_imports_failed = true;
...@@ -2553,8 +2553,8 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,...@@ -2553,8 +2553,8 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
2553 g->import_table.put(abs_full_path, import_entry);2553 g->import_table.put(abs_full_path, import_entry);
2554 g->import_queue.append(import_entry);2554 g->import_queue.append(import_entry);
25552555
2556 import_entry->block_context = new_block_context(import_entry->root, nullptr);2556 import_entry->scope = new_scope(import_entry->root, nullptr);
2557 import_entry->block_context->di_scope = ZigLLVMFileToScope(import_entry->di_file);2557 import_entry->scope->di_scope = ZigLLVMFileToScope(import_entry->di_file);
25582558
25592559
2560 assert(import_entry->root->type == NodeTypeRoot);2560 assert(import_entry->root->type == NodeTypeRoot);
...@@ -2581,7 +2581,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,...@@ -2581,7 +2581,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
2581void semantic_analyze(CodeGen *g) {2581void semantic_analyze(CodeGen *g) {
2582 for (; g->import_queue_index < g->import_queue.length; g->import_queue_index += 1) {2582 for (; g->import_queue_index < g->import_queue.length; g->import_queue_index += 1) {
2583 ImportTableEntry *import = g->import_queue.at(g->import_queue_index);2583 ImportTableEntry *import = g->import_queue.at(g->import_queue_index);
2584 scan_decls(g, import, import->block_context, import->root);2584 scan_decls(g, import, import->scope, import->root);
2585 }2585 }
25862586
2587 for (; g->use_queue_index < g->use_queue.length; g->use_queue_index += 1) {2587 for (; g->use_queue_index < g->use_queue.length; g->use_queue_index += 1) {
src/analyze.hpp+6-6
...@@ -15,7 +15,7 @@ ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);...@@ -15,7 +15,7 @@ ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
15ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);15ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
16TypeTableEntry *new_type_table_entry(TypeTableEntryId id);16TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
17TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);17TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
18BlockContext *new_block_context(AstNode *node, BlockContext *parent);18Scope *new_scope(AstNode *node, Scope *parent);
19bool is_node_void_expr(AstNode *node);19bool is_node_void_expr(AstNode *node);
20uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);20uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
21TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits);21TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits);
...@@ -27,7 +27,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf...@@ -27,7 +27,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
27TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type);27TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type);
28TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);28TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);
29TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);29TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
30TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, BlockContext *context,30TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, Scope *context,
31 ContainerKind kind, AstNode *decl_node, const char *name);31 ContainerKind kind, AstNode *decl_node, const char *name);
32TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);32TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
33TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type);33TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type);
...@@ -49,8 +49,8 @@ AstNode *first_executing_node(AstNode *node);...@@ -49,8 +49,8 @@ AstNode *first_executing_node(AstNode *node);
4949
50// TODO move these over, these used to be static50// TODO move these over, these used to be static
51bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);51bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);
52VariableTableEntry *find_variable(CodeGen *g, BlockContext *orig_context, Buf *name);52VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
53AstNode *find_decl(BlockContext *context, Buf *name);53AstNode *find_decl(Scope *context, Buf *name);
54void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only);54void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only);
55TopLevelDecl *get_as_top_level_decl(AstNode *node);55TopLevelDecl *get_as_top_level_decl(AstNode *node);
56bool type_is_codegen_pointer(TypeTableEntry *type);56bool type_is_codegen_pointer(TypeTableEntry *type);
...@@ -59,10 +59,10 @@ TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);...@@ -59,10 +59,10 @@ TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
59bool type_is_complete(TypeTableEntry *type_entry);59bool type_is_complete(TypeTableEntry *type_entry);
60void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);60void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
61TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);61TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
62BlockContext *get_container_block_context(TypeTableEntry *type_entry);62Scope *get_container_block_context(TypeTableEntry *type_entry);
63TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);63TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);
64bool is_container_ref(TypeTableEntry *type_entry);64bool is_container_ref(TypeTableEntry *type_entry);
65void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node);65void scan_decls(CodeGen *g, ImportTableEntry *import, Scope *context, AstNode *node);
66void preview_use_decl(CodeGen *g, AstNode *node);66void preview_use_decl(CodeGen *g, AstNode *node);
67void resolve_use_decl(CodeGen *g, AstNode *node);67void resolve_use_decl(CodeGen *g, AstNode *node);
6868
src/codegen.cpp+16-16
...@@ -228,8 +228,8 @@ static void render_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstExprVa...@@ -228,8 +228,8 @@ static void render_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstExprVa
228static void render_const_val_global(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val);228static void render_const_val_global(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val);
229229
230static void set_debug_source_node(CodeGen *g, AstNode *node) {230static void set_debug_source_node(CodeGen *g, AstNode *node) {
231 assert(node->block_context);231 assert(node->scope);
232 ZigLLVMSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, node->block_context->di_scope);232 ZigLLVMSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, node->scope->di_scope);
233}233}
234234
235static void clear_debug_source_node(CodeGen *g) {235static void clear_debug_source_node(CodeGen *g) {
...@@ -312,7 +312,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntr...@@ -312,7 +312,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntr
312 }312 }
313}313}
314314
315static bool want_debug_safety_recursive(CodeGen *g, BlockContext *context) {315static bool want_debug_safety_recursive(CodeGen *g, Scope *context) {
316 if (context->safety_set_node || !context->parent) {316 if (context->safety_set_node || !context->parent) {
317 return !context->safety_off;317 return !context->safety_off;
318 }318 }
...@@ -325,7 +325,7 @@ static bool want_debug_safety(CodeGen *g, AstNode *node) {...@@ -325,7 +325,7 @@ static bool want_debug_safety(CodeGen *g, AstNode *node) {
325 if (g->is_release_build) {325 if (g->is_release_build) {
326 return false;326 return false;
327 }327 }
328 return want_debug_safety_recursive(g, node->block_context);328 return want_debug_safety_recursive(g, node->scope);
329}329}
330330
331static bool ir_want_debug_safety(CodeGen *g, IrInstruction *instruction) {331static bool ir_want_debug_safety(CodeGen *g, IrInstruction *instruction) {
...@@ -558,10 +558,10 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, AstNode *source_node,...@@ -558,10 +558,10 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, AstNode *source_node,
558}558}
559559
560static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {560static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
561 BlockContext *block_context = var->block_context;561 Scope *scope = var->scope;
562 AstNode *source_node = var->decl_node;562 AstNode *source_node = var->decl_node;
563 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc(source_node->line + 1, source_node->column + 1,563 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc(source_node->line + 1, source_node->column + 1,
564 block_context->di_scope);564 scope->di_scope);
565 ZigLLVMInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc,565 ZigLLVMInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc,
566 LLVMGetInsertBlock(g->builder));566 LLVMGetInsertBlock(g->builder));
567}567}
...@@ -2134,7 +2134,7 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini...@@ -2134,7 +2134,7 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
2134 assert(type_entry);2134 assert(type_entry);
2135 bool is_local_to_unit = true;2135 bool is_local_to_unit = true;
2136 ZigLLVMCreateGlobalVariable(g->dbuilder,2136 ZigLLVMCreateGlobalVariable(g->dbuilder,
2137 var->block_context->di_scope, buf_ptr(&var->name),2137 var->scope->di_scope, buf_ptr(&var->name),
2138 buf_ptr(&var->name), var->import->di_file, var->decl_node->line + 1,2138 buf_ptr(&var->name), var->import->di_file, var->decl_node->line + 1,
2139 type_entry->di_type, is_local_to_unit, init_val);2139 type_entry->di_type, is_local_to_unit, init_val);
2140}2140}
...@@ -2332,15 +2332,15 @@ static void do_code_gen(CodeGen *g) {...@@ -2332,15 +2332,15 @@ static void do_code_gen(CodeGen *g) {
23322332
2333 // Set up debug info for blocks2333 // Set up debug info for blocks
2334 for (size_t bc_i = 0; bc_i < fn_table_entry->all_block_contexts.length; bc_i += 1) {2334 for (size_t bc_i = 0; bc_i < fn_table_entry->all_block_contexts.length; bc_i += 1) {
2335 BlockContext *block_context = fn_table_entry->all_block_contexts.at(bc_i);2335 Scope *scope = fn_table_entry->all_block_contexts.at(bc_i);
23362336
2337 if (!block_context->di_scope) {2337 if (!scope->di_scope) {
2338 ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,2338 ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
2339 block_context->parent->di_scope,2339 scope->parent->di_scope,
2340 import->di_file,2340 import->di_file,
2341 block_context->node->line + 1,2341 scope->node->line + 1,
2342 block_context->node->column + 1);2342 scope->node->column + 1);
2343 block_context->di_scope = ZigLLVMLexicalBlockToScope(di_block);2343 scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
2344 }2344 }
23452345
23462346
...@@ -2383,7 +2383,7 @@ static void do_code_gen(CodeGen *g) {...@@ -2383,7 +2383,7 @@ static void do_code_gen(CodeGen *g) {
2383 if (var->is_inline)2383 if (var->is_inline)
2384 continue;2384 continue;
23852385
2386 if (var->block_context->node->type == NodeTypeFnDef) {2386 if (var->scope->node->type == NodeTypeFnDef) {
2387 assert(var->gen_arg_index != SIZE_MAX);2387 assert(var->gen_arg_index != SIZE_MAX);
2388 TypeTableEntry *gen_type;2388 TypeTableEntry *gen_type;
2389 if (handle_is_ptr(var->type)) {2389 if (handle_is_ptr(var->type)) {
...@@ -2395,7 +2395,7 @@ static void do_code_gen(CodeGen *g) {...@@ -2395,7 +2395,7 @@ static void do_code_gen(CodeGen *g) {
2395 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);2395 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);
2396 LLVMSetAlignment(var->value_ref, align_bytes);2396 LLVMSetAlignment(var->value_ref, align_bytes);
2397 }2397 }
2398 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, var->block_context->di_scope,2398 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, var->scope->di_scope,
2399 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,2399 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
2400 gen_type->di_type, !g->strip_debug_symbols, 0, var->gen_arg_index + 1);2400 gen_type->di_type, !g->strip_debug_symbols, 0, var->gen_arg_index + 1);
24012401
...@@ -2406,7 +2406,7 @@ static void do_code_gen(CodeGen *g) {...@@ -2406,7 +2406,7 @@ static void do_code_gen(CodeGen *g) {
2406 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);2406 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);
2407 LLVMSetAlignment(var->value_ref, align_bytes);2407 LLVMSetAlignment(var->value_ref, align_bytes);
24082408
2409 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, var->block_context->di_scope,2409 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, var->scope->di_scope,
2410 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,2410 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
2411 var->type->di_type, !g->strip_debug_symbols, 0);2411 var->type->di_type, !g->strip_debug_symbols, 0);
2412 }2412 }
src/ir.cpp+114-114
...@@ -31,8 +31,8 @@ struct IrAnalyze {...@@ -31,8 +31,8 @@ struct IrAnalyze {
31 IrBasicBlock *const_predecessor_bb;31 IrBasicBlock *const_predecessor_bb;
32};32};
3333
34static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope);34static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
35static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,35static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope,
36 LValPurpose lval);36 LValPurpose lval);
37static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);37static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
3838
...@@ -451,7 +451,7 @@ static IrInstruction *ir_build_const_import(IrBuilder *irb, AstNode *source_node...@@ -451,7 +451,7 @@ static IrInstruction *ir_build_const_import(IrBuilder *irb, AstNode *source_node
451 return &const_instruction->base;451 return &const_instruction->base;
452}452}
453453
454static IrInstruction *ir_build_const_scope(IrBuilder *irb, AstNode *source_node, BlockContext *scope) {454static IrInstruction *ir_build_const_scope(IrBuilder *irb, AstNode *source_node, Scope *scope) {
455 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node);455 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node);
456 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block;456 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block;
457 const_instruction->base.static_value.special = ConstValSpecialStatic;457 const_instruction->base.static_value.special = ConstValSpecialStatic;
...@@ -1211,7 +1211,7 @@ static IrInstruction *ir_build_ref_from(IrBuilder *irb, IrInstruction *old_instr...@@ -1211,7 +1211,7 @@ static IrInstruction *ir_build_ref_from(IrBuilder *irb, IrInstruction *old_instr
1211 return new_instruction;1211 return new_instruction;
1212}1212}
12131213
1214static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, BlockContext *outer_block,1214static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_block, Scope *outer_block,
1215 bool gen_error_defers, bool gen_maybe_defers)1215 bool gen_error_defers, bool gen_maybe_defers)
1216{1216{
1217 while (inner_block != outer_block) {1217 while (inner_block != outer_block) {
...@@ -1221,7 +1221,7 @@ static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, B...@@ -1221,7 +1221,7 @@ static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, B
1221 (gen_maybe_defers && inner_block->node->data.defer.kind == ReturnKindMaybe)))1221 (gen_maybe_defers && inner_block->node->data.defer.kind == ReturnKindMaybe)))
1222 {1222 {
1223 AstNode *defer_expr_node = inner_block->node->data.defer.expr;1223 AstNode *defer_expr_node = inner_block->node->data.defer.expr;
1224 ir_gen_node(irb, defer_expr_node, defer_expr_node->block_context);1224 ir_gen_node(irb, defer_expr_node, defer_expr_node->scope);
1225 }1225 }
1226 inner_block = inner_block->parent;1226 inner_block = inner_block->parent;
1227 }1227 }
...@@ -1230,7 +1230,7 @@ static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, B...@@ -1230,7 +1230,7 @@ static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, B
1230static IrInstruction *ir_gen_return(IrBuilder *irb, AstNode *node) {1230static IrInstruction *ir_gen_return(IrBuilder *irb, AstNode *node) {
1231 assert(node->type == NodeTypeReturnExpr);1231 assert(node->type == NodeTypeReturnExpr);
12321232
1233 BlockContext *scope = node->block_context;1233 Scope *scope = node->scope;
12341234
1235 if (!scope->fn_entry) {1235 if (!scope->fn_entry) {
1236 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));1236 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
...@@ -1264,11 +1264,11 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) {...@@ -1264,11 +1264,11 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) {
1264 irb->current_basic_block = basic_block;1264 irb->current_basic_block = basic_block;
1265}1265}
12661266
1267static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, BlockContext *scope,1267static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope *scope,
1268 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline)1268 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline)
1269{1269{
1270 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);1270 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
1271 variable_entry->block_context = scope;1271 variable_entry->scope = scope;
1272 variable_entry->import = node->owner;1272 variable_entry->import = node->owner;
1273 variable_entry->shadowable = is_shadowable;1273 variable_entry->shadowable = is_shadowable;
1274 variable_entry->mem_slot_index = SIZE_MAX;1274 variable_entry->mem_slot_index = SIZE_MAX;
...@@ -1316,7 +1316,7 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, BlockC...@@ -1316,7 +1316,7 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, BlockC
1316}1316}
13171317
1318// Set name to nullptr to make the variable anonymous (not visible to programmer).1318// Set name to nullptr to make the variable anonymous (not visible to programmer).
1319static VariableTableEntry *ir_add_local_var(IrBuilder *irb, AstNode *node, BlockContext *scope, Buf *name,1319static VariableTableEntry *ir_add_local_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
1320 bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline)1320 bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline)
1321{1321{
1322 VariableTableEntry *var = add_local_var(irb->codegen, node, scope, name,1322 VariableTableEntry *var = add_local_var(irb->codegen, node, scope, name,
...@@ -1329,41 +1329,41 @@ static VariableTableEntry *ir_add_local_var(IrBuilder *irb, AstNode *node, Block...@@ -1329,41 +1329,41 @@ static VariableTableEntry *ir_add_local_var(IrBuilder *irb, AstNode *node, Block
1329static IrInstruction *ir_gen_block(IrBuilder *irb, AstNode *block_node) {1329static IrInstruction *ir_gen_block(IrBuilder *irb, AstNode *block_node) {
1330 assert(block_node->type == NodeTypeBlock);1330 assert(block_node->type == NodeTypeBlock);
13311331
1332 BlockContext *parent_context = block_node->block_context;1332 Scope *parent_scope = block_node->scope;
1333 BlockContext *outer_block_context = new_block_context(block_node, parent_context);1333 Scope *outer_block_scope = new_scope(block_node, parent_scope);
1334 BlockContext *child_context = outer_block_context;1334 Scope *child_scope = outer_block_scope;
13351335
1336 IrInstruction *return_value = nullptr;1336 IrInstruction *return_value = nullptr;
1337 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {1337 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
1338 AstNode *statement_node = block_node->data.block.statements.at(i);1338 AstNode *statement_node = block_node->data.block.statements.at(i);
1339 return_value = ir_gen_node(irb, statement_node, child_context);1339 return_value = ir_gen_node(irb, statement_node, child_scope);
1340 if (statement_node->type == NodeTypeDefer && return_value != irb->codegen->invalid_instruction) {1340 if (statement_node->type == NodeTypeDefer && return_value != irb->codegen->invalid_instruction) {
1341 // defer starts a new block context1341 // defer starts a new block context
1342 child_context = statement_node->data.defer.child_block;1342 child_scope = statement_node->data.defer.child_block;
1343 assert(child_context);1343 assert(child_scope);
1344 }1344 }
1345 }1345 }
13461346
1347 if (!return_value)1347 if (!return_value)
1348 return_value = ir_build_const_void(irb, block_node);1348 return_value = ir_build_const_void(irb, block_node);
13491349
1350 ir_gen_defers_for_block(irb, child_context, outer_block_context, false, false);1350 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false, false);
13511351
1352 return return_value;1352 return return_value;
1353}1353}
13541354
1355static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, AstNode *node, IrBinOp op_id) {1355static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, AstNode *node, IrBinOp op_id) {
1356 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, node->block_context);1356 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, node->scope);
1357 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, node->block_context);1357 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, node->scope);
1358 return ir_build_bin_op(irb, node, op_id, op1, op2);1358 return ir_build_bin_op(irb, node, op_id, op1, op2);
1359}1359}
13601360
1361static IrInstruction *ir_gen_assign(IrBuilder *irb, AstNode *node) {1361static IrInstruction *ir_gen_assign(IrBuilder *irb, AstNode *node) {
1362 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, node->block_context, LValPurposeAssign);1362 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, node->scope, LValPurposeAssign);
1363 if (lvalue == irb->codegen->invalid_instruction)1363 if (lvalue == irb->codegen->invalid_instruction)
1364 return lvalue;1364 return lvalue;
13651365
1366 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, node->block_context);1366 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, node->scope);
1367 if (rvalue == irb->codegen->invalid_instruction)1367 if (rvalue == irb->codegen->invalid_instruction)
1368 return rvalue;1368 return rvalue;
13691369
...@@ -1372,11 +1372,11 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, AstNode *node) {...@@ -1372,11 +1372,11 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, AstNode *node) {
1372}1372}
13731373
1374static IrInstruction *ir_gen_assign_op(IrBuilder *irb, AstNode *node, IrBinOp op_id) {1374static IrInstruction *ir_gen_assign_op(IrBuilder *irb, AstNode *node, IrBinOp op_id) {
1375 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, node->block_context, LValPurposeAssign);1375 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, node->scope, LValPurposeAssign);
1376 if (lvalue == irb->codegen->invalid_instruction)1376 if (lvalue == irb->codegen->invalid_instruction)
1377 return lvalue;1377 return lvalue;
1378 IrInstruction *op1 = ir_build_load_ptr(irb, node->data.bin_op_expr.op1, lvalue);1378 IrInstruction *op1 = ir_build_load_ptr(irb, node->data.bin_op_expr.op1, lvalue);
1379 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, node->block_context);1379 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, node->scope);
1380 if (op2 == irb->codegen->invalid_instruction)1380 if (op2 == irb->codegen->invalid_instruction)
1381 return op2;1381 return op2;
1382 IrInstruction *result = ir_build_bin_op(irb, node, op_id, op1, op2);1382 IrInstruction *result = ir_build_bin_op(irb, node, op_id, op1, op2);
...@@ -1498,7 +1498,7 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, AstNode *node) {...@@ -1498,7 +1498,7 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, AstNode *node) {
1498}1498}
14991499
1500static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstNode *decl_node,1500static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstNode *decl_node,
1501 LValPurpose lval, BlockContext *scope)1501 LValPurpose lval, Scope *scope)
1502{1502{
1503 resolve_top_level_decl(irb->codegen, decl_node, lval != LValPurposeNone);1503 resolve_top_level_decl(irb->codegen, decl_node, lval != LValPurposeNone);
1504 TopLevelDecl *tld = get_as_top_level_decl(decl_node);1504 TopLevelDecl *tld = get_as_top_level_decl(decl_node);
...@@ -1565,7 +1565,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l...@@ -1565,7 +1565,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l
1565 }1565 }
1566 }1566 }
15671567
1568 VariableTableEntry *var = find_variable(irb->codegen, node->block_context, variable_name);1568 VariableTableEntry *var = find_variable(irb->codegen, node->scope, variable_name);
1569 if (var) {1569 if (var) {
1570 IrInstruction *var_ptr = ir_build_var_ptr(irb, node, var);1570 IrInstruction *var_ptr = ir_build_var_ptr(irb, node, var);
1571 if (lval != LValPurposeNone)1571 if (lval != LValPurposeNone)
...@@ -1574,9 +1574,9 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l...@@ -1574,9 +1574,9 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l
1574 return ir_build_load_ptr(irb, node, var_ptr);1574 return ir_build_load_ptr(irb, node, var_ptr);
1575 }1575 }
15761576
1577 AstNode *decl_node = find_decl(node->block_context, variable_name);1577 AstNode *decl_node = find_decl(node->scope, variable_name);
1578 if (decl_node)1578 if (decl_node)
1579 return ir_gen_decl_ref(irb, node, decl_node, lval, node->block_context);1579 return ir_gen_decl_ref(irb, node, decl_node, lval, node->scope);
15801580
1581 if (node->owner->any_imports_failed) {1581 if (node->owner->any_imports_failed) {
1582 // skip the error message since we had a failing import in this file1582 // skip the error message since we had a failing import in this file
...@@ -1592,13 +1592,13 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, AstNode *node, LValPur...@@ -1592,13 +1592,13 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, AstNode *node, LValPur
1592 assert(node->type == NodeTypeArrayAccessExpr);1592 assert(node->type == NodeTypeArrayAccessExpr);
15931593
1594 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;1594 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;
1595 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, node->block_context,1595 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, node->scope,
1596 LValPurposeAddressOf);1596 LValPurposeAddressOf);
1597 if (array_ref_instruction == irb->codegen->invalid_instruction)1597 if (array_ref_instruction == irb->codegen->invalid_instruction)
1598 return array_ref_instruction;1598 return array_ref_instruction;
15991599
1600 AstNode *subscript_node = node->data.array_access_expr.subscript;1600 AstNode *subscript_node = node->data.array_access_expr.subscript;
1601 IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, node->block_context);1601 IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, node->scope);
1602 if (subscript_instruction == irb->codegen->invalid_instruction)1602 if (subscript_instruction == irb->codegen->invalid_instruction)
1603 return subscript_instruction;1603 return subscript_instruction;
16041604
...@@ -1616,7 +1616,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, AstNode *node, LValPur...@@ -1616,7 +1616,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, AstNode *node, LValPur
1616 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;1616 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
1617 Buf *field_name = node->data.field_access_expr.field_name;1617 Buf *field_name = node->data.field_access_expr.field_name;
16181618
1619 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, node->block_context,1619 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, node->scope,
1620 LValPurposeAddressOf);1620 LValPurposeAddressOf);
1621 if (container_ref_instruction == irb->codegen->invalid_instruction)1621 if (container_ref_instruction == irb->codegen->invalid_instruction)
1622 return container_ref_instruction;1622 return container_ref_instruction;
...@@ -1661,7 +1661,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1661,7 +1661,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1661 case BuiltinFnIdTypeof:1661 case BuiltinFnIdTypeof:
1662 {1662 {
1663 AstNode *arg_node = node->data.fn_call_expr.params.at(0);1663 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
1664 IrInstruction *arg = ir_gen_node(irb, arg_node, node->block_context);1664 IrInstruction *arg = ir_gen_node(irb, arg_node, node->scope);
1665 if (arg == irb->codegen->invalid_instruction)1665 if (arg == irb->codegen->invalid_instruction)
1666 return arg;1666 return arg;
1667 return ir_build_typeof(irb, node, arg);1667 return ir_build_typeof(irb, node, arg);
...@@ -1669,12 +1669,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1669,12 +1669,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1669 case BuiltinFnIdSetFnTest:1669 case BuiltinFnIdSetFnTest:
1670 {1670 {
1671 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1671 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1672 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1672 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1673 if (arg0_value == irb->codegen->invalid_instruction)1673 if (arg0_value == irb->codegen->invalid_instruction)
1674 return arg0_value;1674 return arg0_value;
16751675
1676 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);1676 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
1677 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->block_context);1677 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->scope);
1678 if (arg1_value == irb->codegen->invalid_instruction)1678 if (arg1_value == irb->codegen->invalid_instruction)
1679 return arg1_value;1679 return arg1_value;
16801680
...@@ -1683,12 +1683,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1683,12 +1683,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1683 case BuiltinFnIdSetFnVisible:1683 case BuiltinFnIdSetFnVisible:
1684 {1684 {
1685 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1685 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1686 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1686 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1687 if (arg0_value == irb->codegen->invalid_instruction)1687 if (arg0_value == irb->codegen->invalid_instruction)
1688 return arg0_value;1688 return arg0_value;
16891689
1690 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);1690 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
1691 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->block_context);1691 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->scope);
1692 if (arg1_value == irb->codegen->invalid_instruction)1692 if (arg1_value == irb->codegen->invalid_instruction)
1693 return arg1_value;1693 return arg1_value;
16941694
...@@ -1697,12 +1697,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1697,12 +1697,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1697 case BuiltinFnIdSetDebugSafety:1697 case BuiltinFnIdSetDebugSafety:
1698 {1698 {
1699 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1699 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1700 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1700 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1701 if (arg0_value == irb->codegen->invalid_instruction)1701 if (arg0_value == irb->codegen->invalid_instruction)
1702 return arg0_value;1702 return arg0_value;
17031703
1704 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);1704 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
1705 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->block_context);1705 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->scope);
1706 if (arg1_value == irb->codegen->invalid_instruction)1706 if (arg1_value == irb->codegen->invalid_instruction)
1707 return arg1_value;1707 return arg1_value;
17081708
...@@ -1711,7 +1711,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1711,7 +1711,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1711 case BuiltinFnIdCompileVar:1711 case BuiltinFnIdCompileVar:
1712 {1712 {
1713 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1713 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1714 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1714 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1715 if (arg0_value == irb->codegen->invalid_instruction)1715 if (arg0_value == irb->codegen->invalid_instruction)
1716 return arg0_value;1716 return arg0_value;
17171717
...@@ -1720,7 +1720,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1720,7 +1720,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1720 case BuiltinFnIdSizeof:1720 case BuiltinFnIdSizeof:
1721 {1721 {
1722 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1722 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1723 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1723 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1724 if (arg0_value == irb->codegen->invalid_instruction)1724 if (arg0_value == irb->codegen->invalid_instruction)
1725 return arg0_value;1725 return arg0_value;
17261726
...@@ -1729,7 +1729,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1729,7 +1729,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1729 case BuiltinFnIdCtz:1729 case BuiltinFnIdCtz:
1730 {1730 {
1731 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1731 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1732 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1732 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1733 if (arg0_value == irb->codegen->invalid_instruction)1733 if (arg0_value == irb->codegen->invalid_instruction)
1734 return arg0_value;1734 return arg0_value;
17351735
...@@ -1738,7 +1738,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1738,7 +1738,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1738 case BuiltinFnIdClz:1738 case BuiltinFnIdClz:
1739 {1739 {
1740 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1740 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1741 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1741 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1742 if (arg0_value == irb->codegen->invalid_instruction)1742 if (arg0_value == irb->codegen->invalid_instruction)
1743 return arg0_value;1743 return arg0_value;
17441744
...@@ -1747,7 +1747,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1747,7 +1747,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1747 case BuiltinFnIdStaticEval:1747 case BuiltinFnIdStaticEval:
1748 {1748 {
1749 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1749 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1750 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1750 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1751 if (arg0_value == irb->codegen->invalid_instruction)1751 if (arg0_value == irb->codegen->invalid_instruction)
1752 return arg0_value;1752 return arg0_value;
17531753
...@@ -1756,11 +1756,11 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1756,11 +1756,11 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
1756 case BuiltinFnIdImport:1756 case BuiltinFnIdImport:
1757 {1757 {
1758 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);1758 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
1759 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->block_context);1759 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope);
1760 if (arg0_value == irb->codegen->invalid_instruction)1760 if (arg0_value == irb->codegen->invalid_instruction)
1761 return arg0_value;1761 return arg0_value;
17621762
1763 if (node->block_context->fn_entry) {1763 if (node->scope->fn_entry) {
1764 add_node_error(irb->codegen, node, buf_sprintf("import valid only at top level scope"));1764 add_node_error(irb->codegen, node, buf_sprintf("import valid only at top level scope"));
1765 return irb->codegen->invalid_instruction;1765 return irb->codegen->invalid_instruction;
1766 }1766 }
...@@ -1805,7 +1805,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1805,7 +1805,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {
1805 return ir_gen_builtin_fn_call(irb, node);1805 return ir_gen_builtin_fn_call(irb, node);
18061806
1807 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;1807 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
1808 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, node->block_context);1808 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, node->scope);
1809 if (fn_ref == irb->codegen->invalid_instruction)1809 if (fn_ref == irb->codegen->invalid_instruction)
1810 return fn_ref;1810 return fn_ref;
18111811
...@@ -1813,7 +1813,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1813,7 +1813,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {
1813 IrInstruction **args = allocate<IrInstruction*>(arg_count);1813 IrInstruction **args = allocate<IrInstruction*>(arg_count);
1814 for (size_t i = 0; i < arg_count; i += 1) {1814 for (size_t i = 0; i < arg_count; i += 1) {
1815 AstNode *arg_node = node->data.fn_call_expr.params.at(i);1815 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
1816 args[i] = ir_gen_node(irb, arg_node, node->block_context);1816 args[i] = ir_gen_node(irb, arg_node, node->scope);
1817 }1817 }
18181818
1819 return ir_build_call(irb, node, nullptr, fn_ref, arg_count, args);1819 return ir_build_call(irb, node, nullptr, fn_ref, arg_count, args);
...@@ -1822,7 +1822,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {...@@ -1822,7 +1822,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {
1822static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {1822static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {
1823 assert(node->type == NodeTypeIfBoolExpr);1823 assert(node->type == NodeTypeIfBoolExpr);
18241824
1825 IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, node->block_context);1825 IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, node->scope);
1826 if (condition == irb->codegen->invalid_instruction)1826 if (condition == irb->codegen->invalid_instruction)
1827 return condition;1827 return condition;
18281828
...@@ -1837,7 +1837,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {...@@ -1837,7 +1837,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {
1837 ir_build_cond_br(irb, condition->source_node, condition, then_block, else_block, is_inline);1837 ir_build_cond_br(irb, condition->source_node, condition, then_block, else_block, is_inline);
18381838
1839 ir_set_cursor_at_end(irb, then_block);1839 ir_set_cursor_at_end(irb, then_block);
1840 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, node->block_context);1840 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, node->scope);
1841 if (then_expr_result == irb->codegen->invalid_instruction)1841 if (then_expr_result == irb->codegen->invalid_instruction)
1842 return then_expr_result;1842 return then_expr_result;
1843 IrBasicBlock *after_then_block = irb->current_basic_block;1843 IrBasicBlock *after_then_block = irb->current_basic_block;
...@@ -1846,7 +1846,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {...@@ -1846,7 +1846,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {
1846 ir_set_cursor_at_end(irb, else_block);1846 ir_set_cursor_at_end(irb, else_block);
1847 IrInstruction *else_expr_result;1847 IrInstruction *else_expr_result;
1848 if (else_node) {1848 if (else_node) {
1849 else_expr_result = ir_gen_node(irb, else_node, node->block_context);1849 else_expr_result = ir_gen_node(irb, else_node, node->scope);
1850 if (else_expr_result == irb->codegen->invalid_instruction)1850 if (else_expr_result == irb->codegen->invalid_instruction)
1851 return else_expr_result;1851 return else_expr_result;
1852 } else {1852 } else {
...@@ -1870,7 +1870,7 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, AstNode *node, Ir...@@ -1870,7 +1870,7 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, AstNode *node, Ir
1870 assert(node->type == NodeTypePrefixOpExpr);1870 assert(node->type == NodeTypePrefixOpExpr);
1871 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;1871 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
18721872
1873 IrInstruction *value = ir_gen_node_extra(irb, expr_node, node->block_context, lval);1873 IrInstruction *value = ir_gen_node_extra(irb, expr_node, node->scope, lval);
1874 if (value == irb->codegen->invalid_instruction)1874 if (value == irb->codegen->invalid_instruction)
1875 return value;1875 return value;
18761876
...@@ -1887,7 +1887,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, AstNode *node, IrUnOp...@@ -1887,7 +1887,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, AstNode *node, IrUnOp
18871887
1888static IrInstruction *ir_gen_prefix_op_unwrap_maybe(IrBuilder *irb, AstNode *node, LValPurpose lval) {1888static IrInstruction *ir_gen_prefix_op_unwrap_maybe(IrBuilder *irb, AstNode *node, LValPurpose lval) {
1889 AstNode *expr = node->data.prefix_op_expr.primary_expr;1889 AstNode *expr = node->data.prefix_op_expr.primary_expr;
1890 IrInstruction *value = ir_gen_node_extra(irb, expr, node->block_context, LValPurposeAddressOf);1890 IrInstruction *value = ir_gen_node_extra(irb, expr, node->scope, LValPurposeAddressOf);
1891 if (value == irb->codegen->invalid_instruction)1891 if (value == irb->codegen->invalid_instruction)
1892 return value;1892 return value;
18931893
...@@ -1938,7 +1938,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)...@@ -1938,7 +1938,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)
1938 AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;1938 AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;
1939 ContainerInitKind kind = container_init_expr->kind;1939 ContainerInitKind kind = container_init_expr->kind;
19401940
1941 IrInstruction *container_type = ir_gen_node(irb, container_init_expr->type, node->block_context);1941 IrInstruction *container_type = ir_gen_node(irb, container_init_expr->type, node->scope);
1942 if (container_type == irb->codegen->invalid_instruction)1942 if (container_type == irb->codegen->invalid_instruction)
1943 return container_type;1943 return container_type;
19441944
...@@ -1951,7 +1951,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)...@@ -1951,7 +1951,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)
19511951
1952 Buf *name = entry_node->data.struct_val_field.name;1952 Buf *name = entry_node->data.struct_val_field.name;
1953 AstNode *expr_node = entry_node->data.struct_val_field.expr;1953 AstNode *expr_node = entry_node->data.struct_val_field.expr;
1954 IrInstruction *expr_value = ir_gen_node(irb, expr_node, node->block_context);1954 IrInstruction *expr_value = ir_gen_node(irb, expr_node, node->scope);
1955 if (expr_value == irb->codegen->invalid_instruction)1955 if (expr_value == irb->codegen->invalid_instruction)
1956 return expr_value;1956 return expr_value;
19571957
...@@ -1965,7 +1965,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)...@@ -1965,7 +1965,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)
1965 IrInstruction **values = allocate<IrInstruction *>(item_count);1965 IrInstruction **values = allocate<IrInstruction *>(item_count);
1966 for (size_t i = 0; i < item_count; i += 1) {1966 for (size_t i = 0; i < item_count; i += 1) {
1967 AstNode *expr_node = container_init_expr->entries.at(i);1967 AstNode *expr_node = container_init_expr->entries.at(i);
1968 IrInstruction *expr_value = ir_gen_node(irb, expr_node, node->block_context);1968 IrInstruction *expr_value = ir_gen_node(irb, expr_node, node->scope);
1969 if (expr_value == irb->codegen->invalid_instruction)1969 if (expr_value == irb->codegen->invalid_instruction)
1970 return expr_value;1970 return expr_value;
19711971
...@@ -1984,14 +1984,14 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) {...@@ -1984,14 +1984,14 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) {
19841984
1985 IrInstruction *type_instruction;1985 IrInstruction *type_instruction;
1986 if (variable_declaration->type != nullptr) {1986 if (variable_declaration->type != nullptr) {
1987 type_instruction = ir_gen_node(irb, variable_declaration->type, node->block_context);1987 type_instruction = ir_gen_node(irb, variable_declaration->type, node->scope);
1988 if (type_instruction == irb->codegen->invalid_instruction)1988 if (type_instruction == irb->codegen->invalid_instruction)
1989 return type_instruction;1989 return type_instruction;
1990 } else {1990 } else {
1991 type_instruction = nullptr;1991 type_instruction = nullptr;
1992 }1992 }
19931993
1994 IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, node->block_context);1994 IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, node->scope);
1995 if (init_value == irb->codegen->invalid_instruction)1995 if (init_value == irb->codegen->invalid_instruction)
1996 return init_value;1996 return init_value;
19971997
...@@ -1999,7 +1999,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) {...@@ -1999,7 +1999,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) {
1999 bool is_const = variable_declaration->is_const;1999 bool is_const = variable_declaration->is_const;
2000 bool is_extern = variable_declaration->is_extern;2000 bool is_extern = variable_declaration->is_extern;
2001 bool is_inline = ir_should_inline(irb) || variable_declaration->is_inline;2001 bool is_inline = ir_should_inline(irb) || variable_declaration->is_inline;
2002 VariableTableEntry *var = ir_add_local_var(irb, node, node->block_context,2002 VariableTableEntry *var = ir_add_local_var(irb, node, node->scope,
2003 variable_declaration->symbol, is_const, is_const, is_shadowable, is_inline);2003 variable_declaration->symbol, is_const, is_const, is_shadowable, is_inline);
20042004
2005 if (!is_extern && !variable_declaration->expr) {2005 if (!is_extern && !variable_declaration->expr) {
...@@ -2027,19 +2027,19 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) {...@@ -2027,19 +2027,19 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) {
20272027
2028 if (continue_expr_node) {2028 if (continue_expr_node) {
2029 ir_set_cursor_at_end(irb, continue_block);2029 ir_set_cursor_at_end(irb, continue_block);
2030 ir_gen_node(irb, continue_expr_node, node->block_context);2030 ir_gen_node(irb, continue_expr_node, node->scope);
2031 ir_build_br(irb, node, cond_block, is_inline);2031 ir_build_br(irb, node, cond_block, is_inline);
2032 }2032 }
20332033
2034 ir_set_cursor_at_end(irb, cond_block);2034 ir_set_cursor_at_end(irb, cond_block);
2035 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, node->block_context);2035 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, node->scope);
2036 ir_build_cond_br(irb, node->data.while_expr.condition, cond_val, body_block, end_block, is_inline);2036 ir_build_cond_br(irb, node->data.while_expr.condition, cond_val, body_block, end_block, is_inline);
20372037
2038 ir_set_cursor_at_end(irb, body_block);2038 ir_set_cursor_at_end(irb, body_block);
20392039
2040 irb->break_block_stack.append(end_block);2040 irb->break_block_stack.append(end_block);
2041 irb->continue_block_stack.append(continue_block);2041 irb->continue_block_stack.append(continue_block);
2042 ir_gen_node(irb, node->data.while_expr.body, node->block_context);2042 ir_gen_node(irb, node->data.while_expr.body, node->scope);
2043 irb->break_block_stack.pop();2043 irb->break_block_stack.pop();
2044 irb->continue_block_stack.pop();2044 irb->continue_block_stack.pop();
20452045
...@@ -2052,7 +2052,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) {...@@ -2052,7 +2052,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) {
2052static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {2052static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
2053 assert(node->type == NodeTypeForExpr);2053 assert(node->type == NodeTypeForExpr);
20542054
2055 BlockContext *parent_scope = node->block_context;2055 Scope *parent_scope = node->scope;
20562056
2057 AstNode *array_node = node->data.for_expr.array_expr;2057 AstNode *array_node = node->data.for_expr.array_expr;
2058 AstNode *elem_node = node->data.for_expr.elem_node;2058 AstNode *elem_node = node->data.for_expr.elem_node;
...@@ -2079,9 +2079,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {...@@ -2079,9 +2079,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
2079 }2079 }
2080 bool is_inline = ir_should_inline(irb) || node->data.for_expr.is_inline;2080 bool is_inline = ir_should_inline(irb) || node->data.for_expr.is_inline;
20812081
2082 BlockContext *child_scope = new_block_context(node, parent_scope);2082 Scope *child_scope = new_scope(node, parent_scope);
2083 child_scope->parent_loop_node = node;2083 child_scope->parent_loop_node = node;
2084 elem_node->block_context = child_scope;2084 elem_node->scope = child_scope;
20852085
2086 // TODO make it an error to write to element variable or i variable.2086 // TODO make it an error to write to element variable or i variable.
2087 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;2087 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
...@@ -2095,7 +2095,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {...@@ -2095,7 +2095,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
2095 if (index_node) {2095 if (index_node) {
2096 index_var_source_node = index_node;2096 index_var_source_node = index_node;
2097 Buf *index_var_name = index_node->data.symbol_expr.symbol;2097 Buf *index_var_name = index_node->data.symbol_expr.symbol;
2098 index_node->block_context = child_scope;2098 index_node->scope = child_scope;
2099 node->data.for_expr.index_var = ir_add_local_var(irb, index_node, child_scope, index_var_name,2099 node->data.for_expr.index_var = ir_add_local_var(irb, index_node, child_scope, index_var_name,
2100 true, false, false, is_inline);2100 true, false, false, is_inline);
2101 } else {2101 } else {
...@@ -2154,7 +2154,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {...@@ -2154,7 +2154,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
2154static IrInstruction *ir_gen_this_literal(IrBuilder *irb, AstNode *node) {2154static IrInstruction *ir_gen_this_literal(IrBuilder *irb, AstNode *node) {
2155 assert(node->type == NodeTypeThisLiteral);2155 assert(node->type == NodeTypeThisLiteral);
21562156
2157 BlockContext *scope = node->block_context;2157 Scope *scope = node->scope;
21582158
2159 if (!scope->parent)2159 if (!scope->parent)
2160 return ir_build_const_import(irb, node, node->owner);2160 return ir_build_const_import(irb, node, node->owner);
...@@ -2205,18 +2205,18 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {...@@ -2205,18 +2205,18 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {
2205 return irb->codegen->invalid_instruction;2205 return irb->codegen->invalid_instruction;
2206 }2206 }
22072207
2208 IrInstruction *size_value = ir_gen_node(irb, size_node, node->block_context);2208 IrInstruction *size_value = ir_gen_node(irb, size_node, node->scope);
2209 if (size_value == irb->codegen->invalid_instruction)2209 if (size_value == irb->codegen->invalid_instruction)
2210 return size_value;2210 return size_value;
22112211
2212 IrInstruction *child_type = ir_gen_node(irb, child_type_node, node->block_context);2212 IrInstruction *child_type = ir_gen_node(irb, child_type_node, node->scope);
2213 if (child_type == irb->codegen->invalid_instruction)2213 if (child_type == irb->codegen->invalid_instruction)
2214 return child_type;2214 return child_type;
22152215
2216 return ir_build_array_type(irb, node, size_value, child_type);2216 return ir_build_array_type(irb, node, size_value, child_type);
2217 } else {2217 } else {
2218 IrInstruction *child_type = ir_gen_node_extra(irb, child_type_node,2218 IrInstruction *child_type = ir_gen_node_extra(irb, child_type_node,
2219 node->block_context, LValPurposeAddressOf);2219 node->scope, LValPurposeAddressOf);
2220 if (child_type == irb->codegen->invalid_instruction)2220 if (child_type == irb->codegen->invalid_instruction)
2221 return child_type;2221 return child_type;
22222222
...@@ -2246,7 +2246,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {...@@ -2246,7 +2246,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {
2246 if (asm_output->return_type) {2246 if (asm_output->return_type) {
2247 return_count += 1;2247 return_count += 1;
22482248
2249 IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, node->block_context);2249 IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, node->scope);
2250 if (return_type == irb->codegen->invalid_instruction)2250 if (return_type == irb->codegen->invalid_instruction)
2251 return irb->codegen->invalid_instruction;2251 return irb->codegen->invalid_instruction;
2252 if (return_count > 1) {2252 if (return_count > 1) {
...@@ -2257,7 +2257,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {...@@ -2257,7 +2257,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {
2257 output_types[i] = return_type;2257 output_types[i] = return_type;
2258 } else {2258 } else {
2259 Buf *variable_name = asm_output->variable_name;2259 Buf *variable_name = asm_output->variable_name;
2260 VariableTableEntry *var = find_variable(irb->codegen, node->block_context, variable_name);2260 VariableTableEntry *var = find_variable(irb->codegen, node->scope, variable_name);
2261 if (var) {2261 if (var) {
2262 asm_output->variable = var;2262 asm_output->variable = var;
2263 } else {2263 } else {
...@@ -2269,7 +2269,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {...@@ -2269,7 +2269,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {
2269 }2269 }
2270 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {2270 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
2271 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);2271 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
2272 IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, node->block_context);2272 IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, node->scope);
2273 if (input_value == irb->codegen->invalid_instruction)2273 if (input_value == irb->codegen->invalid_instruction)
2274 return irb->codegen->invalid_instruction;2274 return irb->codegen->invalid_instruction;
22752275
...@@ -2288,7 +2288,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {...@@ -2288,7 +2288,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
2288 AstNode *else_node = node->data.if_var_expr.else_node;2288 AstNode *else_node = node->data.if_var_expr.else_node;
2289 bool var_is_ptr = node->data.if_var_expr.var_is_ptr;2289 bool var_is_ptr = node->data.if_var_expr.var_is_ptr;
22902290
2291 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, node->block_context, LValPurposeAddressOf);2291 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, node->scope, LValPurposeAddressOf);
2292 if (expr_value == irb->codegen->invalid_instruction)2292 if (expr_value == irb->codegen->invalid_instruction)
2293 return expr_value;2293 return expr_value;
22942294
...@@ -2304,11 +2304,11 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {...@@ -2304,11 +2304,11 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
2304 ir_set_cursor_at_end(irb, then_block);2304 ir_set_cursor_at_end(irb, then_block);
2305 IrInstruction *var_type = nullptr;2305 IrInstruction *var_type = nullptr;
2306 if (var_decl->type) {2306 if (var_decl->type) {
2307 var_type = ir_gen_node(irb, var_decl->type, node->block_context);2307 var_type = ir_gen_node(irb, var_decl->type, node->scope);
2308 if (var_type == irb->codegen->invalid_instruction)2308 if (var_type == irb->codegen->invalid_instruction)
2309 return irb->codegen->invalid_instruction;2309 return irb->codegen->invalid_instruction;
2310 }2310 }
2311 BlockContext *child_scope = new_block_context(node, node->block_context);2311 Scope *child_scope = new_scope(node, node->scope);
2312 bool is_shadowable = false;2312 bool is_shadowable = false;
2313 bool is_const = var_decl->is_const;2313 bool is_const = var_decl->is_const;
2314 VariableTableEntry *var = ir_add_local_var(irb, node, child_scope,2314 VariableTableEntry *var = ir_add_local_var(irb, node, child_scope,
...@@ -2325,7 +2325,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {...@@ -2325,7 +2325,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
2325 ir_set_cursor_at_end(irb, else_block);2325 ir_set_cursor_at_end(irb, else_block);
2326 IrInstruction *else_expr_result;2326 IrInstruction *else_expr_result;
2327 if (else_node) {2327 if (else_node) {
2328 else_expr_result = ir_gen_node(irb, else_node, node->block_context);2328 else_expr_result = ir_gen_node(irb, else_node, node->scope);
2329 if (else_expr_result == irb->codegen->invalid_instruction)2329 if (else_expr_result == irb->codegen->invalid_instruction)
2330 return else_expr_result;2330 return else_expr_result;
2331 } else {2331 } else {
...@@ -2354,13 +2354,13 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo...@@ -2354,13 +2354,13 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo
23542354
2355 AstNode *expr_node = prong_node->data.switch_prong.expr;2355 AstNode *expr_node = prong_node->data.switch_prong.expr;
2356 AstNode *var_symbol_node = prong_node->data.switch_prong.var_symbol;2356 AstNode *var_symbol_node = prong_node->data.switch_prong.var_symbol;
2357 BlockContext *child_scope;2357 Scope *child_scope;
2358 if (var_symbol_node) {2358 if (var_symbol_node) {
2359 assert(var_symbol_node->type == NodeTypeSymbol);2359 assert(var_symbol_node->type == NodeTypeSymbol);
2360 Buf *var_name = var_symbol_node->data.symbol_expr.symbol;2360 Buf *var_name = var_symbol_node->data.symbol_expr.symbol;
2361 bool var_is_ptr = prong_node->data.switch_prong.var_is_ptr;2361 bool var_is_ptr = prong_node->data.switch_prong.var_is_ptr;
23622362
2363 child_scope = new_block_context(switch_node, switch_node->block_context);2363 child_scope = new_scope(switch_node, switch_node->scope);
2364 bool is_shadowable = false;2364 bool is_shadowable = false;
2365 bool is_const = true;2365 bool is_const = true;
2366 VariableTableEntry *var = ir_add_local_var(irb, var_symbol_node, child_scope,2366 VariableTableEntry *var = ir_add_local_var(irb, var_symbol_node, child_scope,
...@@ -2375,7 +2375,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo...@@ -2375,7 +2375,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo
2375 IrInstruction *var_type = nullptr; // infer the type2375 IrInstruction *var_type = nullptr; // infer the type
2376 ir_build_var_decl(irb, var_symbol_node, var, var_type, var_value); 2376 ir_build_var_decl(irb, var_symbol_node, var, var_type, var_value);
2377 } else {2377 } else {
2378 child_scope = switch_node->block_context;2378 child_scope = switch_node->scope;
2379 }2379 }
23802380
2381 IrInstruction *expr_result = ir_gen_node(irb, expr_node, child_scope);2381 IrInstruction *expr_result = ir_gen_node(irb, expr_node, child_scope);
...@@ -2391,7 +2391,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {...@@ -2391,7 +2391,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
2391 assert(node->type == NodeTypeSwitchExpr);2391 assert(node->type == NodeTypeSwitchExpr);
23922392
2393 AstNode *target_node = node->data.switch_expr.expr;2393 AstNode *target_node = node->data.switch_expr.expr;
2394 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, node->block_context, LValPurposeAddressOf);2394 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, node->scope, LValPurposeAddressOf);
2395 if (target_value_ptr == irb->codegen->invalid_instruction)2395 if (target_value_ptr == irb->codegen->invalid_instruction)
2396 return target_value_ptr;2396 return target_value_ptr;
2397 IrInstruction *target_value = ir_build_switch_target(irb, node, target_value_ptr);2397 IrInstruction *target_value = ir_build_switch_target(irb, node, target_value_ptr);
...@@ -2436,15 +2436,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {...@@ -2436,15 +2436,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
2436 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);2436 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
2437 last_item_node = item_node;2437 last_item_node = item_node;
2438 if (item_node->type == NodeTypeSwitchRange) {2438 if (item_node->type == NodeTypeSwitchRange) {
2439 item_node->block_context = node->block_context;2439 item_node->scope = node->scope;
2440 AstNode *start_node = item_node->data.switch_range.start;2440 AstNode *start_node = item_node->data.switch_range.start;
2441 AstNode *end_node = item_node->data.switch_range.end;2441 AstNode *end_node = item_node->data.switch_range.end;
24422442
2443 IrInstruction *start_value = ir_gen_node(irb, start_node, node->block_context);2443 IrInstruction *start_value = ir_gen_node(irb, start_node, node->scope);
2444 if (start_value == irb->codegen->invalid_instruction)2444 if (start_value == irb->codegen->invalid_instruction)
2445 return irb->codegen->invalid_instruction;2445 return irb->codegen->invalid_instruction;
24462446
2447 IrInstruction *end_value = ir_gen_node(irb, end_node, node->block_context);2447 IrInstruction *end_value = ir_gen_node(irb, end_node, node->scope);
2448 if (end_value == irb->codegen->invalid_instruction)2448 if (end_value == irb->codegen->invalid_instruction)
2449 return irb->codegen->invalid_instruction;2449 return irb->codegen->invalid_instruction;
24502450
...@@ -2463,7 +2463,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {...@@ -2463,7 +2463,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
2463 ok_bit = both_ok;2463 ok_bit = both_ok;
2464 }2464 }
2465 } else {2465 } else {
2466 IrInstruction *item_value = ir_gen_node(irb, item_node, node->block_context);2466 IrInstruction *item_value = ir_gen_node(irb, item_node, node->scope);
2467 if (item_value == irb->codegen->invalid_instruction)2467 if (item_value == irb->codegen->invalid_instruction)
2468 return irb->codegen->invalid_instruction;2468 return irb->codegen->invalid_instruction;
24692469
...@@ -2500,7 +2500,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {...@@ -2500,7 +2500,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
2500 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);2500 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
2501 assert(item_node->type != NodeTypeSwitchRange);2501 assert(item_node->type != NodeTypeSwitchRange);
25022502
2503 IrInstruction *item_value = ir_gen_node(irb, item_node, node->block_context);2503 IrInstruction *item_value = ir_gen_node(irb, item_node, node->scope);
2504 if (item_value == irb->codegen->invalid_instruction)2504 if (item_value == irb->codegen->invalid_instruction)
2505 return irb->codegen->invalid_instruction;2505 return irb->codegen->invalid_instruction;
25062506
...@@ -2542,8 +2542,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {...@@ -2542,8 +2542,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
2542 return ir_build_phi(irb, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);2542 return ir_build_phi(irb, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
2543}2543}
25442544
2545static LabelTableEntry *find_label(IrExecutable *exec, BlockContext *orig_context, Buf *name) {2545static LabelTableEntry *find_label(IrExecutable *exec, Scope *orig_context, Buf *name) {
2546 BlockContext *context = orig_context;2546 Scope *context = orig_context;
2547 while (context) {2547 while (context) {
2548 auto entry = context->label_table.maybe_get(name);2548 auto entry = context->label_table.maybe_get(name);
2549 if (entry) {2549 if (entry) {
...@@ -2564,14 +2564,14 @@ static IrInstruction *ir_gen_label(IrBuilder *irb, AstNode *node) {...@@ -2564,14 +2564,14 @@ static IrInstruction *ir_gen_label(IrBuilder *irb, AstNode *node) {
2564 label->bb = label_block;2564 label->bb = label_block;
2565 irb->exec->all_labels.append(label);2565 irb->exec->all_labels.append(label);
25662566
2567 LabelTableEntry *existing_label = find_label(irb->exec, node->block_context, label_name);2567 LabelTableEntry *existing_label = find_label(irb->exec, node->scope, label_name);
2568 if (existing_label) {2568 if (existing_label) {
2569 ErrorMsg *msg = add_node_error(irb->codegen, node,2569 ErrorMsg *msg = add_node_error(irb->codegen, node,
2570 buf_sprintf("duplicate label name '%s'", buf_ptr(label_name)));2570 buf_sprintf("duplicate label name '%s'", buf_ptr(label_name)));
2571 add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here"));2571 add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here"));
2572 return irb->codegen->invalid_instruction;2572 return irb->codegen->invalid_instruction;
2573 } else {2573 } else {
2574 node->block_context->label_table.put(label_name, label);2574 node->scope->label_table.put(label_name, label);
2575 }2575 }
25762576
2577 bool is_inline = ir_should_inline(irb);2577 bool is_inline = ir_should_inline(irb);
...@@ -2607,11 +2607,11 @@ static IrInstruction *ir_gen_type_literal(IrBuilder *irb, AstNode *node) {...@@ -2607,11 +2607,11 @@ static IrInstruction *ir_gen_type_literal(IrBuilder *irb, AstNode *node) {
2607 return ir_build_const_type(irb, node, irb->codegen->builtin_types.entry_type);2607 return ir_build_const_type(irb, node, irb->codegen->builtin_types.entry_type);
2608}2608}
26092609
2610static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContext *block_context,2610static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,
2611 LValPurpose lval)2611 LValPurpose lval)
2612{2612{
2613 assert(block_context);2613 assert(scope);
2614 node->block_context = block_context;2614 node->scope = scope;
26152615
2616 switch (node->type) {2616 switch (node->type) {
2617 case NodeTypeStructValueField:2617 case NodeTypeStructValueField:
...@@ -2694,15 +2694,15 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex...@@ -2694,15 +2694,15 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex
2694 zig_unreachable();2694 zig_unreachable();
2695}2695}
26962696
2697static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,2697static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope,
2698 LValPurpose lval)2698 LValPurpose lval)
2699{2699{
2700 IrInstruction *result = ir_gen_node_raw(irb, node, block_context, lval);2700 IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval);
2701 irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);2701 irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);
2702 return result;2702 return result;
2703}2703}
27042704
2705static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope) {2705static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {
2706 return ir_gen_node_extra(irb, node, scope, LValPurposeNone);2706 return ir_gen_node_extra(irb, node, scope, LValPurposeNone);
2707}2707}
27082708
...@@ -2714,7 +2714,7 @@ static bool ir_goto_pass2(IrBuilder *irb) {...@@ -2714,7 +2714,7 @@ static bool ir_goto_pass2(IrBuilder *irb) {
2714 IrInstruction *old_instruction = *slot;2714 IrInstruction *old_instruction = *slot;
27152715
2716 Buf *label_name = goto_node->data.goto_expr.name;2716 Buf *label_name = goto_node->data.goto_expr.name;
2717 LabelTableEntry *label = find_label(irb->exec, goto_node->block_context, label_name);2717 LabelTableEntry *label = find_label(irb->exec, goto_node->scope, label_name);
2718 if (!label) {2718 if (!label) {
2719 add_node_error(irb->codegen, goto_node,2719 add_node_error(irb->codegen, goto_node,
2720 buf_sprintf("no label in scope named '%s'", buf_ptr(label_name)));2720 buf_sprintf("no label in scope named '%s'", buf_ptr(label_name)));
...@@ -2741,7 +2741,7 @@ static bool ir_goto_pass2(IrBuilder *irb) {...@@ -2741,7 +2741,7 @@ static bool ir_goto_pass2(IrBuilder *irb) {
2741 return true;2741 return true;
2742}2742}
27432743
2744IrInstruction *ir_gen(CodeGen *codegen, AstNode *node, BlockContext *scope, IrExecutable *ir_executable) {2744IrInstruction *ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) {
2745 assert(node->owner);2745 assert(node->owner);
27462746
2747 IrBuilder ir_builder = {0};2747 IrBuilder ir_builder = {0};
...@@ -2778,7 +2778,7 @@ IrInstruction *ir_gen_fn(CodeGen *codegn, FnTableEntry *fn_entry) {...@@ -2778,7 +2778,7 @@ IrInstruction *ir_gen_fn(CodeGen *codegn, FnTableEntry *fn_entry) {
2778 assert(fn_def_node->type == NodeTypeFnDef);2778 assert(fn_def_node->type == NodeTypeFnDef);
27792779
2780 AstNode *body_node = fn_def_node->data.fn_def.body;2780 AstNode *body_node = fn_def_node->data.fn_def.body;
2781 BlockContext *scope = fn_def_node->data.fn_def.block_context;2781 Scope *scope = fn_def_node->data.fn_def.scope;
27822782
2783 return ir_gen(codegn, body_node, scope, ir_executable);2783 return ir_gen(codegn, body_node, scope, ir_executable);
2784}2784}
...@@ -3023,8 +3023,8 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -3023,8 +3023,8 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
3023 } else {3023 } else {
3024 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->source_node, wanted_type, value, cast_op);3024 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->source_node, wanted_type, value, cast_op);
3025 result->type_entry = wanted_type;3025 result->type_entry = wanted_type;
3026 if (need_alloca && source_instr->source_node->block_context->fn_entry) {3026 if (need_alloca && source_instr->source_node->scope->fn_entry) {
3027 source_instr->source_node->block_context->fn_entry->alloca_list.append(result);3027 source_instr->source_node->scope->fn_entry->alloca_list.append(result);
3028 }3028 }
3029 return result;3029 return result;
3030 }3030 }
...@@ -3550,7 +3550,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst...@@ -3550,7 +3550,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
3550 ir_link_new_instruction(value, source_instruction);3550 ir_link_new_instruction(value, source_instruction);
3551 return ptr_type;3551 return ptr_type;
3552 } else {3552 } else {
3553 FnTableEntry *fn_entry = source_instruction->source_node->block_context->fn_entry;3553 FnTableEntry *fn_entry = source_instruction->source_node->scope->fn_entry;
3554 IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value);3554 IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value);
3555 fn_entry->alloca_list.append(new_instruction);3555 fn_entry->alloca_list.append(new_instruction);
3556 return ptr_type;3556 return ptr_type;
...@@ -4097,7 +4097,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -4097,7 +4097,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
40974097
4098 ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, casted_init_value);4098 ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, casted_init_value);
40994099
4100 BlockContext *scope = decl_var_instruction->base.source_node->block_context;4100 Scope *scope = decl_var_instruction->base.source_node->scope;
4101 if (scope->fn_entry)4101 if (scope->fn_entry)
4102 scope->fn_entry->variable_list.append(var);4102 scope->fn_entry->variable_list.append(var);
41034103
...@@ -4201,7 +4201,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -4201,7 +4201,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
4201 fn_entry, fn_ref, call_param_count, casted_args);4201 fn_entry, fn_ref, call_param_count, casted_args);
42024202
4203 if (type_has_bits(return_type) && handle_is_ptr(return_type))4203 if (type_has_bits(return_type) && handle_is_ptr(return_type))
4204 call_instruction->base.source_node->block_context->fn_entry->alloca_list.append(new_call_instruction);4204 call_instruction->base.source_node->scope->fn_entry->alloca_list.append(new_call_instruction);
42054205
4206 return ir_finish_anal(ira, return_type);4206 return ir_finish_anal(ira, return_type);
4207}4207}
...@@ -4732,7 +4732,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc...@@ -4732,7 +4732,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
4732 return var->type;4732 return var->type;
47334733
4734 ConstExprValue *mem_slot = nullptr;4734 ConstExprValue *mem_slot = nullptr;
4735 if (var->block_context->fn_entry) {4735 if (var->scope->fn_entry) {
4736 // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing.4736 // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing.
4737 if (var->mem_slot_index != SIZE_MAX)4737 if (var->mem_slot_index != SIZE_MAX)
4738 mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];4738 mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];
...@@ -4879,7 +4879,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -4879,7 +4879,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
4879 IrInstruction *container_ptr, TypeTableEntry *container_type)4879 IrInstruction *container_ptr, TypeTableEntry *container_type)
4880{4880{
4881 if (!is_slice(bare_struct_type)) {4881 if (!is_slice(bare_struct_type)) {
4882 BlockContext *container_block_context = get_container_block_context(bare_struct_type);4882 Scope *container_block_context = get_container_block_context(bare_struct_type);
4883 assert(container_block_context);4883 assert(container_block_context);
4884 auto entry = container_block_context->decl_table.maybe_get(field_name);4884 auto entry = container_block_context->decl_table.maybe_get(field_name);
4885 AstNode *fn_decl_node = entry ? entry->value : nullptr;4885 AstNode *fn_decl_node = entry ? entry->value : nullptr;
...@@ -5023,7 +5023,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -5023,7 +5023,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
5023 } else if (child_type->id == TypeTableEntryIdEnum) {5023 } else if (child_type->id == TypeTableEntryIdEnum) {
5024 zig_panic("TODO enum type field");5024 zig_panic("TODO enum type field");
5025 } else if (child_type->id == TypeTableEntryIdStruct) {5025 } else if (child_type->id == TypeTableEntryIdStruct) {
5026 BlockContext *container_block_context = get_container_block_context(child_type);5026 Scope *container_block_context = get_container_block_context(child_type);
5027 auto entry = container_block_context->decl_table.maybe_get(field_name);5027 auto entry = container_block_context->decl_table.maybe_get(field_name);
5028 AstNode *decl_node = entry ? entry->value : nullptr;5028 AstNode *decl_node = entry ? entry->value : nullptr;
5029 if (decl_node) {5029 if (decl_node) {
...@@ -5055,7 +5055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -5055,7 +5055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
5055 ImportTableEntry *namespace_import = namespace_val->data.x_import;5055 ImportTableEntry *namespace_import = namespace_val->data.x_import;
50565056
5057 bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var;5057 bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var;
5058 AstNode *decl_node = find_decl(namespace_import->block_context, field_name);5058 AstNode *decl_node = find_decl(namespace_import->scope, field_name);
5059 if (!decl_node) {5059 if (!decl_node) {
5060 // we must now resolve all the use decls5060 // we must now resolve all the use decls
5061 for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) {5061 for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) {
...@@ -5066,7 +5066,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -5066,7 +5066,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
5066 }5066 }
5067 resolve_use_decl(ira->codegen, use_decl_node);5067 resolve_use_decl(ira->codegen, use_decl_node);
5068 }5068 }
5069 decl_node = find_decl(namespace_import->block_context, field_name);5069 decl_node = find_decl(namespace_import->scope, field_name);
5070 }5070 }
5071 if (decl_node) {5071 if (decl_node) {
5072 TopLevelDecl *tld = get_as_top_level_decl(decl_node);5072 TopLevelDecl *tld = get_as_top_level_decl(decl_node);
...@@ -5323,19 +5323,19 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -5323,19 +5323,19 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
5323 if (!target_val)5323 if (!target_val)
5324 return ira->codegen->builtin_types.entry_invalid;5324 return ira->codegen->builtin_types.entry_invalid;
53255325
5326 BlockContext *target_context;5326 Scope *target_context;
5327 if (target_type->id == TypeTableEntryIdBlock) {5327 if (target_type->id == TypeTableEntryIdBlock) {
5328 target_context = target_val->data.x_block;5328 target_context = target_val->data.x_block;
5329 } else if (target_type->id == TypeTableEntryIdFn) {5329 } else if (target_type->id == TypeTableEntryIdFn) {
5330 target_context = target_val->data.x_fn->fn_def_node->data.fn_def.block_context;5330 target_context = target_val->data.x_fn->fn_def_node->data.fn_def.scope;
5331 } else if (target_type->id == TypeTableEntryIdMetaType) {5331 } else if (target_type->id == TypeTableEntryIdMetaType) {
5332 TypeTableEntry *type_arg = target_val->data.x_type;5332 TypeTableEntry *type_arg = target_val->data.x_type;
5333 if (type_arg->id == TypeTableEntryIdStruct) {5333 if (type_arg->id == TypeTableEntryIdStruct) {
5334 target_context = type_arg->data.structure.block_context;5334 target_context = type_arg->data.structure.scope;
5335 } else if (type_arg->id == TypeTableEntryIdEnum) {5335 } else if (type_arg->id == TypeTableEntryIdEnum) {
5336 target_context = type_arg->data.enumeration.block_context;5336 target_context = type_arg->data.enumeration.scope;
5337 } else if (type_arg->id == TypeTableEntryIdUnion) {5337 } else if (type_arg->id == TypeTableEntryIdUnion) {
5338 target_context = type_arg->data.unionation.block_context;5338 target_context = type_arg->data.unionation.scope;
5339 } else {5339 } else {
5340 add_node_error(ira->codegen, target_instruction->source_node,5340 add_node_error(ira->codegen, target_instruction->source_node,
5341 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));5341 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
...@@ -5966,7 +5966,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -5966,7 +5966,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
5966 ImportTableEntry *target_import = add_source_file(ira->codegen, target_package,5966 ImportTableEntry *target_import = add_source_file(ira->codegen, target_package,
5967 abs_full_path, search_dir, import_target_path, import_code);5967 abs_full_path, search_dir, import_target_path, import_code);
59685968
5969 scan_decls(ira->codegen, target_import, target_import->block_context, target_import->root);5969 scan_decls(ira->codegen, target_import, target_import->scope, target_import->root);
59705970
5971 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var);5971 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var);
5972 out_val->data.x_import = target_import;5972 out_val->data.x_import = target_import;
...@@ -6021,7 +6021,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -6021,7 +6021,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
60216021
6022 IrInstructionStructInitField *new_fields = allocate<IrInstructionStructInitField>(actual_field_count);6022 IrInstructionStructInitField *new_fields = allocate<IrInstructionStructInitField>(actual_field_count);
60236023
6024 FnTableEntry *fn_entry = instruction->source_node->block_context->fn_entry;6024 FnTableEntry *fn_entry = instruction->source_node->scope->fn_entry;
6025 bool outside_fn = (fn_entry == nullptr);6025 bool outside_fn = (fn_entry == nullptr);
60266026
6027 ConstExprValue const_val = {};6027 ConstExprValue const_val = {};
...@@ -6124,7 +6124,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -6124,7 +6124,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
6124 const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count);6124 const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count);
6125 const_val.data.x_array.size = elem_count;6125 const_val.data.x_array.size = elem_count;
61266126
6127 FnTableEntry *fn_entry = instruction->base.source_node->block_context->fn_entry;6127 FnTableEntry *fn_entry = instruction->base.source_node->scope->fn_entry;
6128 bool outside_fn = (fn_entry == nullptr);6128 bool outside_fn = (fn_entry == nullptr);
61296129
6130 IrInstruction **new_items = allocate<IrInstruction *>(elem_count);6130 IrInstruction **new_items = allocate<IrInstruction *>(elem_count);
src/ir.hpp+1-1
...@@ -10,7 +10,7 @@...@@ -10,7 +10,7 @@
1010
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13IrInstruction *ir_gen(CodeGen *g, AstNode *node, BlockContext *scope, IrExecutable *ir_executable);13IrInstruction *ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
14IrInstruction *ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);14IrInstruction *ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);
1515
16TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,16TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
src/parseh.cpp+3-3
...@@ -817,7 +817,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl)...@@ -817,7 +817,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl)
817 const EnumDecl *enum_def = enum_decl->getDefinition();817 const EnumDecl *enum_def = enum_decl->getDefinition();
818 if (!enum_def) {818 if (!enum_def) {
819 TypeTableEntry *enum_type = get_partial_container_type(c->codegen, c->import,819 TypeTableEntry *enum_type = get_partial_container_type(c->codegen, c->import,
820 c->import->block_context,820 c->import->scope,
821 ContainerKindEnum, c->source_node, buf_ptr(full_type_name));821 ContainerKindEnum, c->source_node, buf_ptr(full_type_name));
822 c->enum_type_table.put(bare_name, enum_type);822 c->enum_type_table.put(bare_name, enum_type);
823 c->decl_table.put(enum_decl, enum_type);823 c->decl_table.put(enum_decl, enum_type);
...@@ -842,7 +842,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl)...@@ -842,7 +842,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl)
842842
843 if (pure_enum) {843 if (pure_enum) {
844 TypeTableEntry *enum_type = get_partial_container_type(c->codegen, c->import,844 TypeTableEntry *enum_type = get_partial_container_type(c->codegen, c->import,
845 c->import->block_context,845 c->import->scope,
846 ContainerKindEnum, c->source_node, buf_ptr(full_type_name));846 ContainerKindEnum, c->source_node, buf_ptr(full_type_name));
847 c->enum_type_table.put(bare_name, enum_type);847 c->enum_type_table.put(bare_name, enum_type);
848 c->decl_table.put(enum_decl, enum_type);848 c->decl_table.put(enum_decl, enum_type);
...@@ -1002,7 +1002,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_...@@ -1002,7 +1002,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
10021002
10031003
1004 TypeTableEntry *struct_type = get_partial_container_type(c->codegen, c->import,1004 TypeTableEntry *struct_type = get_partial_container_type(c->codegen, c->import,
1005 c->import->block_context, ContainerKindStruct, c->source_node, buf_ptr(full_type_name));1005 c->import->scope, ContainerKindStruct, c->source_node, buf_ptr(full_type_name));
10061006
1007 c->struct_type_table.put(bare_name, struct_type);1007 c->struct_type_table.put(bare_name, struct_type);
1008 c->decl_table.put(record_decl, struct_type);1008 c->decl_table.put(record_decl, struct_type);