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 @@
1919struct AstNode;
2020struct ImportTableEntry;
2121struct FnTableEntry;
22struct BlockContext;
22struct Scope;
2323struct TypeTableEntry;
2424struct VariableTableEntry;
2525struct ErrorTableEntry;
......@@ -115,7 +115,7 @@ struct ConstExprValue {
115115 ConstArrayValue x_array;
116116 ConstPtrValue x_ptr;
117117 ImportTableEntry *x_import;
118 BlockContext *x_block;
118 Scope *x_block;
119119 } data;
120120};
121121
......@@ -252,7 +252,7 @@ struct AstNodeFnDef {
252252 // populated by semantic analyzer
253253 TypeTableEntry *implicit_return_type;
254254 // the first child block context
255 BlockContext *block_context;
255 Scope *scope;
256256};
257257
258258struct AstNodeFnDecl {
......@@ -274,11 +274,11 @@ struct AstNodeBlock {
274274
275275 // populated by semantic analyzer
276276 // this one is the scope that the block itself introduces
277 BlockContext *child_block;
277 Scope *child_block;
278278 // this is the innermost scope created by defers and var decls.
279279 // you can follow its parents up to child_block. it will equal
280280 // child_block if there are no defers or var decls in the block.
281 BlockContext *nested_block;
281 Scope *nested_block;
282282};
283283
284284enum ReturnKind {
......@@ -300,7 +300,7 @@ struct AstNodeDefer {
300300 // populated by semantic analyzer:
301301 size_t index_in_block;
302302 LLVMBasicBlockRef basic_block;
303 BlockContext *child_block;
303 Scope *child_block;
304304};
305305
306306struct AstNodeVariableDeclaration {
......@@ -638,7 +638,7 @@ struct AstNodeStructDecl {
638638 ZigList<AstNode *> decls;
639639
640640 // populated by semantic analyzer
641 BlockContext *block_context;
641 Scope *scope;
642642 TypeTableEntry *type_entry;
643643 TypeTableEntry *generic_fn_type;
644644 bool skip;
......@@ -762,7 +762,7 @@ struct AstNode {
762762 ImportTableEntry *owner;
763763 // the context in which this expression/node is evaluated.
764764 // for blocks, this points to the containing scope, not the block's own scope for its children.
765 BlockContext *block_context;
765 Scope *scope;
766766 union {
767767 AstNodeRoot root;
768768 AstNodeFnDef fn_def;
......@@ -884,7 +884,7 @@ struct TypeTableEntryStruct {
884884 uint64_t size_bytes;
885885 bool is_invalid; // true if any fields are invalid
886886 bool is_slice;
887 BlockContext *block_context;
887 Scope *scope;
888888
889889 // set this flag temporarily to detect infinite loops
890890 bool embedded_in_current;
......@@ -910,7 +910,7 @@ struct TypeTableEntryEnum {
910910 TypeTableEntry *tag_type;
911911 TypeTableEntry *union_type;
912912
913 BlockContext *block_context;
913 Scope *scope;
914914
915915 // set this flag temporarily to detect infinite loops
916916 bool embedded_in_current;
......@@ -926,7 +926,7 @@ struct TypeTableEntryUnion {
926926 TypeStructField *fields;
927927 uint64_t size_bytes;
928928 bool is_invalid; // true if any fields are invalid
929 BlockContext *block_context;
929 Scope *scope;
930930
931931 // set this flag temporarily to detect infinite loops
932932 bool embedded_in_current;
......@@ -1044,7 +1044,7 @@ struct ImportTableEntry {
10441044 ZigLLVMDIFile *di_file;
10451045 Buf *source_code;
10461046 ZigList<size_t> *line_offsets;
1047 BlockContext *block_context;
1047 Scope *scope;
10481048 AstNode *c_import_node;
10491049 bool any_imports_failed;
10501050
......@@ -1071,7 +1071,7 @@ struct FnTableEntry {
10711071 AstNode *fn_def_node;
10721072 ImportTableEntry *import_entry;
10731073 // 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;
10751075 Buf symbol_name;
10761076 TypeTableEntry *type_entry; // function type
10771077 bool internal_linkage;
......@@ -1310,7 +1310,7 @@ struct VariableTableEntry {
13101310 ZigLLVMDILocalVariable *di_loc_var;
13111311 size_t src_arg_index;
13121312 size_t gen_arg_index;
1313 BlockContext *block_context;
1313 Scope *scope;
13141314 LLVMValueRef param_value_ref;
13151315 bool force_depends_on_compile_var;
13161316 ImportTableEntry *import;
......@@ -1331,7 +1331,7 @@ struct LabelTableEntry {
13311331 bool used;
13321332};
13331333
1334struct BlockContext {
1334struct Scope {
13351335 AstNode *node;
13361336
13371337 // any variables that are introduced by this scope
......@@ -1343,7 +1343,7 @@ struct BlockContext {
13431343 FnTableEntry *fn_entry;
13441344
13451345 // if the block has a parent, this is it
1346 BlockContext *parent;
1346 Scope *parent;
13471347
13481348 // if break or continue is valid in this context, this is the loop node that
13491349 // it would pertain to
src/analyze.cpp+44-44
......@@ -115,26 +115,26 @@ TypeTableEntry *new_type_table_entry(TypeTableEntryId id) {
115115 return entry;
116116}
117117
118static BlockContext **get_container_block_context_ptr(TypeTableEntry *type_entry) {
118static Scope **get_container_block_context_ptr(TypeTableEntry *type_entry) {
119119 if (type_entry->id == TypeTableEntryIdStruct) {
120 return &type_entry->data.structure.block_context;
120 return &type_entry->data.structure.scope;
121121 } else if (type_entry->id == TypeTableEntryIdEnum) {
122 return &type_entry->data.enumeration.block_context;
122 return &type_entry->data.enumeration.scope;
123123 } else if (type_entry->id == TypeTableEntryIdUnion) {
124 return &type_entry->data.unionation.block_context;
124 return &type_entry->data.unionation.scope;
125125 }
126126 zig_unreachable();
127127}
128128
129BlockContext *get_container_block_context(TypeTableEntry *type_entry) {
129Scope *get_container_block_context(TypeTableEntry *type_entry) {
130130 return *get_container_block_context_ptr(type_entry);
131131}
132132
133133static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node,
134 BlockContext *parent_context)
134 Scope *parent_context)
135135{
136136 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);
138138 return entry;
139139}
140140
......@@ -766,7 +766,7 @@ static TypeTableEntryId container_to_type(ContainerKind kind) {
766766 zig_unreachable();
767767}
768768
769TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, BlockContext *context,
769TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, Scope *context,
770770 ContainerKind kind, AstNode *decl_node, const char *name)
771771{
772772 TypeTableEntryId type_id = container_to_type(kind);
......@@ -805,7 +805,7 @@ TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry) {
805805 }
806806}
807807
808static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNode *node,
808static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node,
809809 TypeTableEntry *expected_type)
810810{
811811 IrExecutable ir_executable = {0};
......@@ -844,7 +844,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo
844844 return result;
845845}
846846
847static TypeTableEntry *analyze_type_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,
847static TypeTableEntry *analyze_type_expr(CodeGen *g, ImportTableEntry *import, Scope *context,
848848 AstNode *node)
849849{
850850 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) {
861861}
862862
863863// 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,
865865 TypeTableEntry *expected_type, AstNode *node, bool is_naked, bool is_cold, FnTableEntry *fn_table_entry)
866866{
867867 assert(node->type == NodeTypeFnProto);
......@@ -1022,7 +1022,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
10221022}
10231023
10241024static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_table_entry,
1025 ImportTableEntry *import, BlockContext *containing_context)
1025 ImportTableEntry *import, Scope *containing_context)
10261026{
10271027 assert(node->type == NodeTypeFnProto);
10281028 AstNodeFnProto *fn_proto = &node->data.fn_proto;
......@@ -1060,8 +1060,8 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
10601060 }
10611061
10621062 if (fn_table_entry->fn_def_node) {
1063 BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context);
1064 fn_table_entry->fn_def_node->data.fn_def.block_context = context;
1063 Scope *context = new_scope(fn_table_entry->fn_def_node, containing_context);
1064 fn_table_entry->fn_def_node->data.fn_def.scope = context;
10651065 }
10661066
10671067 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
11091109 fn_type->di_type, fn_table_entry->internal_linkage,
11101110 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);
11131113 ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram);
11141114 }
11151115 }
......@@ -1151,7 +1151,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt
11511151 uint64_t biggest_align_in_bits = 0;
11521152 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
11561156 // set temporary flag
11571157 enum_type->data.enumeration.embedded_in_current = true;
......@@ -1337,7 +1337,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
13371337 // this field should be set to true only during the recursive calls to resolve_struct_type
13381338 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
13421342 size_t gen_field_index = 0;
13431343 for (size_t i = 0; i < field_count; i += 1) {
......@@ -1463,7 +1463,7 @@ static bool get_is_generic_fn(AstNode *proto_node) {
14631463}
14641464
14651465static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstNode *proto_node,
1466 BlockContext *containing_context)
1466 Scope *containing_context)
14671467{
14681468 assert(proto_node->type == NodeTypeFnProto);
14691469
......@@ -1546,7 +1546,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN
15461546 }
15471547}
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,
15501550 AstNode *node, Buf *name)
15511551{
15521552 assert(import);
......@@ -1562,19 +1562,19 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex
15621562 g->resolve_queue.append(node);
15631563 }
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);
15681568 if (entry) {
15691569 AstNode *other_decl_node = entry->value;
15701570 ErrorMsg *msg = add_node_error(g, node, buf_sprintf("redefinition of '%s'", buf_ptr(name)));
15711571 add_error_note(g, msg, other_decl_node, buf_sprintf("previous definition is here"));
15721572 } else {
1573 block_context->decl_table.put(name, node);
1573 scope->decl_table.put(name, node);
15741574 }
15751575}
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) {
15781578 assert(node->type == NodeTypeContainerDecl);
15791579
15801580 if (node->data.struct_decl.type_entry) {
......@@ -1591,7 +1591,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext
15911591 for (size_t i = 0; i < node->data.struct_decl.decls.length; i += 1) {
15921592 AstNode *child_node = node->data.struct_decl.decls.at(i);
15931593 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);
15951595 scan_decls(g, import, child_context, child_node);
15961596 }
15971597}
......@@ -1644,7 +1644,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {
16441644 node->data.error_value_decl.top_level_decl.resolution = TldResolutionOk;
16451645}
16461646
1647void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {
1647void scan_decls(CodeGen *g, ImportTableEntry *import, Scope *context, AstNode *node) {
16481648 switch (node->type) {
16491649 case NodeTypeRoot:
16501650 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
16951695 {
16961696 TopLevelDecl *tld = get_as_top_level_decl(node);
16971697 tld->import = import;
1698 node->block_context = context;
1698 node->scope = context;
16991699 g->use_queue.append(node);
17001700 tld->import->use_decls.append(node);
17011701 break;
......@@ -1817,12 +1817,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
18171817// Set name to nullptr to make the variable anonymous (not visible to programmer).
18181818// TODO merge with definition of add_local_var in ir.cpp
18191819static 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,
18211821 bool shadowable)
18221822{
18231823 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
18241824 variable_entry->type = type_entry;
1825 variable_entry->block_context = context;
1825 variable_entry->scope = context;
18261826 variable_entry->import = import;
18271827 variable_entry->shadowable = shadowable;
18281828 variable_entry->mem_slot_index = SIZE_MAX;
......@@ -1875,7 +1875,7 @@ static VariableTableEntry *add_local_var_shadowable(CodeGen *g, AstNode *source_
18751875}
18761876
18771877static 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)
18791879{
18801880 return add_local_var_shadowable(g, source_node, import, context, name, type_entry, is_const, val_node, false);
18811881}
......@@ -1884,7 +1884,7 @@ static void resolve_var_decl(CodeGen *g, ImportTableEntry *import, AstNode *node
18841884 assert(node->type == NodeTypeVariableDeclaration);
18851885
18861886 AstNodeVariableDeclaration *var_decl = &node->data.variable_declaration;
1887 BlockContext *scope = node->block_context;
1887 Scope *scope = node->scope;
18881888 bool is_const = var_decl->is_const;
18891889 bool is_export = (var_decl->top_level_decl.visib_mod == VisibModExport);
18901890 bool is_extern = var_decl->is_extern;
......@@ -1963,7 +1963,7 @@ void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only) {
19631963
19641964 switch (node->type) {
19651965 case NodeTypeFnProto:
1966 preview_fn_proto_instance(g, import, node, node->block_context);
1966 preview_fn_proto_instance(g, import, node, node->scope);
19671967 break;
19681968 case NodeTypeContainerDecl:
19691969 resolve_struct_decl(g, import, node);
......@@ -1980,7 +1980,7 @@ void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only) {
19801980 if (node->data.type_decl.override_type) {
19811981 entry = node->data.type_decl.override_type;
19821982 } 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);
19841984 if (child_type->id == TypeTableEntryIdInvalid) {
19851985 entry = child_type;
19861986 } else {
......@@ -2170,8 +2170,8 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
21702170 return false;
21712171}
21722172
2173BlockContext *new_block_context(AstNode *node, BlockContext *parent) {
2174 BlockContext *context = allocate<BlockContext>(1);
2173Scope *new_scope(AstNode *node, Scope *parent) {
2174 Scope *context = allocate<Scope>(1);
21752175 context->node = node;
21762176 context->parent = parent;
21772177 context->decl_table.init(1);
......@@ -2197,7 +2197,7 @@ BlockContext *new_block_context(AstNode *node, BlockContext *parent) {
21972197 return context;
21982198}
21992199
2200AstNode *find_decl(BlockContext *context, Buf *name) {
2200AstNode *find_decl(Scope *context, Buf *name) {
22012201 while (context) {
22022202 auto entry = context->decl_table.maybe_get(name);
22032203 if (entry) {
......@@ -2208,8 +2208,8 @@ AstNode *find_decl(BlockContext *context, Buf *name) {
22082208 return nullptr;
22092209}
22102210
2211VariableTableEntry *find_variable(CodeGen *g, BlockContext *orig_context, Buf *name) {
2212 BlockContext *context = orig_context;
2211VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name) {
2212 Scope *context = orig_context;
22132213 while (context) {
22142214 auto entry = context->var_table.maybe_get(name);
22152215 if (entry) {
......@@ -2355,7 +2355,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
23552355 }
23562356 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
23602360 TypeTableEntry *fn_type = fn_table_entry->type_entry;
23612361 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 *
24562456 continue;
24572457 }
24582458 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);
24602460 if (existing_entry) {
24612461 AstNode *existing_decl = existing_entry->value;
24622462 if (existing_decl != decl_node) {
......@@ -2467,7 +2467,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
24672467 add_error_note(g, msg, decl_node, buf_sprintf("imported definition here"));
24682468 }
24692469 } 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);
24712471 }
24722472 }
24732473 }
......@@ -2494,7 +2494,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
24942494 assert(node->type == NodeTypeUse);
24952495 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,
24982498 g->builtin_types.entry_namespace);
24992499 if (result->type_entry->id == TypeTableEntryIdInvalid)
25002500 tld->import->any_imports_failed = true;
......@@ -2553,8 +2553,8 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
25532553 g->import_table.put(abs_full_path, import_entry);
25542554 g->import_queue.append(import_entry);
25552555
2556 import_entry->block_context = new_block_context(import_entry->root, nullptr);
2557 import_entry->block_context->di_scope = ZigLLVMFileToScope(import_entry->di_file);
2556 import_entry->scope = new_scope(import_entry->root, nullptr);
2557 import_entry->scope->di_scope = ZigLLVMFileToScope(import_entry->di_file);
25582558
25592559
25602560 assert(import_entry->root->type == NodeTypeRoot);
......@@ -2581,7 +2581,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
25812581void semantic_analyze(CodeGen *g) {
25822582 for (; g->import_queue_index < g->import_queue.length; g->import_queue_index += 1) {
25832583 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);
25852585 }
25862586
25872587 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);
1515ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
1616TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
1717TypeTableEntry *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);
1919bool is_node_void_expr(AstNode *node);
2020uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
2121TypeTableEntry **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
2727TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type);
2828TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);
2929TypeTableEntry *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,
3131 ContainerKind kind, AstNode *decl_node, const char *name);
3232TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
3333TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type);
......@@ -49,8 +49,8 @@ AstNode *first_executing_node(AstNode *node);
4949
5050// TODO move these over, these used to be static
5151bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);
52VariableTableEntry *find_variable(CodeGen *g, BlockContext *orig_context, Buf *name);
53AstNode *find_decl(BlockContext *context, Buf *name);
52VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
53AstNode *find_decl(Scope *context, Buf *name);
5454void resolve_top_level_decl(CodeGen *g, AstNode *node, bool pointer_only);
5555TopLevelDecl *get_as_top_level_decl(AstNode *node);
5656bool type_is_codegen_pointer(TypeTableEntry *type);
......@@ -59,10 +59,10 @@ TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
5959bool type_is_complete(TypeTableEntry *type_entry);
6060void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
6161TypeStructField *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);
6363TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);
6464bool 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);
6666void preview_use_decl(CodeGen *g, AstNode *node);
6767void 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
228228static void render_const_val_global(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val);
229229
230230static void set_debug_source_node(CodeGen *g, AstNode *node) {
231 assert(node->block_context);
232 ZigLLVMSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, node->block_context->di_scope);
231 assert(node->scope);
232 ZigLLVMSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, node->scope->di_scope);
233233}
234234
235235static void clear_debug_source_node(CodeGen *g) {
......@@ -312,7 +312,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntr
312312 }
313313}
314314
315static bool want_debug_safety_recursive(CodeGen *g, BlockContext *context) {
315static bool want_debug_safety_recursive(CodeGen *g, Scope *context) {
316316 if (context->safety_set_node || !context->parent) {
317317 return !context->safety_off;
318318 }
......@@ -325,7 +325,7 @@ static bool want_debug_safety(CodeGen *g, AstNode *node) {
325325 if (g->is_release_build) {
326326 return false;
327327 }
328 return want_debug_safety_recursive(g, node->block_context);
328 return want_debug_safety_recursive(g, node->scope);
329329}
330330
331331static bool ir_want_debug_safety(CodeGen *g, IrInstruction *instruction) {
......@@ -558,10 +558,10 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, AstNode *source_node,
558558}
559559
560560static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
561 BlockContext *block_context = var->block_context;
561 Scope *scope = var->scope;
562562 AstNode *source_node = var->decl_node;
563563 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc(source_node->line + 1, source_node->column + 1,
564 block_context->di_scope);
564 scope->di_scope);
565565 ZigLLVMInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc,
566566 LLVMGetInsertBlock(g->builder));
567567}
......@@ -2134,7 +2134,7 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
21342134 assert(type_entry);
21352135 bool is_local_to_unit = true;
21362136 ZigLLVMCreateGlobalVariable(g->dbuilder,
2137 var->block_context->di_scope, buf_ptr(&var->name),
2137 var->scope->di_scope, buf_ptr(&var->name),
21382138 buf_ptr(&var->name), var->import->di_file, var->decl_node->line + 1,
21392139 type_entry->di_type, is_local_to_unit, init_val);
21402140}
......@@ -2332,15 +2332,15 @@ static void do_code_gen(CodeGen *g) {
23322332
23332333 // Set up debug info for blocks
23342334 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) {
23382338 ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
2339 block_context->parent->di_scope,
2339 scope->parent->di_scope,
23402340 import->di_file,
2341 block_context->node->line + 1,
2342 block_context->node->column + 1);
2343 block_context->di_scope = ZigLLVMLexicalBlockToScope(di_block);
2341 scope->node->line + 1,
2342 scope->node->column + 1);
2343 scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
23442344 }
23452345
23462346
......@@ -2383,7 +2383,7 @@ static void do_code_gen(CodeGen *g) {
23832383 if (var->is_inline)
23842384 continue;
23852385
2386 if (var->block_context->node->type == NodeTypeFnDef) {
2386 if (var->scope->node->type == NodeTypeFnDef) {
23872387 assert(var->gen_arg_index != SIZE_MAX);
23882388 TypeTableEntry *gen_type;
23892389 if (handle_is_ptr(var->type)) {
......@@ -2395,7 +2395,7 @@ static void do_code_gen(CodeGen *g) {
23952395 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);
23962396 LLVMSetAlignment(var->value_ref, align_bytes);
23972397 }
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,
23992399 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
24002400 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) {
24062406 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);
24072407 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,
24102410 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
24112411 var->type->di_type, !g->strip_debug_symbols, 0);
24122412 }
src/ir.cpp+114-114
......@@ -31,8 +31,8 @@ struct IrAnalyze {
3131 IrBasicBlock *const_predecessor_bb;
3232};
3333
34static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope);
35static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
34static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
35static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope,
3636 LValPurpose lval);
3737static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
3838
......@@ -451,7 +451,7 @@ static IrInstruction *ir_build_const_import(IrBuilder *irb, AstNode *source_node
451451 return &const_instruction->base;
452452}
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) {
455455 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node);
456456 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block;
457457 const_instruction->base.static_value.special = ConstValSpecialStatic;
......@@ -1211,7 +1211,7 @@ static IrInstruction *ir_build_ref_from(IrBuilder *irb, IrInstruction *old_instr
12111211 return new_instruction;
12121212}
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,
12151215 bool gen_error_defers, bool gen_maybe_defers)
12161216{
12171217 while (inner_block != outer_block) {
......@@ -1221,7 +1221,7 @@ static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, B
12211221 (gen_maybe_defers && inner_block->node->data.defer.kind == ReturnKindMaybe)))
12221222 {
12231223 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);
12251225 }
12261226 inner_block = inner_block->parent;
12271227 }
......@@ -1230,7 +1230,7 @@ static void ir_gen_defers_for_block(IrBuilder *irb, BlockContext *inner_block, B
12301230static IrInstruction *ir_gen_return(IrBuilder *irb, AstNode *node) {
12311231 assert(node->type == NodeTypeReturnExpr);
12321232
1233 BlockContext *scope = node->block_context;
1233 Scope *scope = node->scope;
12341234
12351235 if (!scope->fn_entry) {
12361236 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) {
12641264 irb->current_basic_block = basic_block;
12651265}
12661266
1267static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, BlockContext *scope,
1267static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope *scope,
12681268 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline)
12691269{
12701270 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
1271 variable_entry->block_context = scope;
1271 variable_entry->scope = scope;
12721272 variable_entry->import = node->owner;
12731273 variable_entry->shadowable = is_shadowable;
12741274 variable_entry->mem_slot_index = SIZE_MAX;
......@@ -1316,7 +1316,7 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, BlockC
13161316}
13171317
13181318// 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,
13201320 bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline)
13211321{
13221322 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
13291329static IrInstruction *ir_gen_block(IrBuilder *irb, AstNode *block_node) {
13301330 assert(block_node->type == NodeTypeBlock);
13311331
1332 BlockContext *parent_context = block_node->block_context;
1333 BlockContext *outer_block_context = new_block_context(block_node, parent_context);
1334 BlockContext *child_context = outer_block_context;
1332 Scope *parent_scope = block_node->scope;
1333 Scope *outer_block_scope = new_scope(block_node, parent_scope);
1334 Scope *child_scope = outer_block_scope;
13351335
13361336 IrInstruction *return_value = nullptr;
13371337 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
13381338 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);
13401340 if (statement_node->type == NodeTypeDefer && return_value != irb->codegen->invalid_instruction) {
13411341 // defer starts a new block context
1342 child_context = statement_node->data.defer.child_block;
1343 assert(child_context);
1342 child_scope = statement_node->data.defer.child_block;
1343 assert(child_scope);
13441344 }
13451345 }
13461346
13471347 if (!return_value)
13481348 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
13521352 return return_value;
13531353}
13541354
13551355static 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);
1357 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, 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->scope);
13581358 return ir_build_bin_op(irb, node, op_id, op1, op2);
13591359}
13601360
13611361static 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);
13631363 if (lvalue == irb->codegen->invalid_instruction)
13641364 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);
13671367 if (rvalue == irb->codegen->invalid_instruction)
13681368 return rvalue;
13691369
......@@ -1372,11 +1372,11 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, AstNode *node) {
13721372}
13731373
13741374static 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);
13761376 if (lvalue == irb->codegen->invalid_instruction)
13771377 return lvalue;
13781378 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);
13801380 if (op2 == irb->codegen->invalid_instruction)
13811381 return op2;
13821382 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) {
14981498}
14991499
15001500static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstNode *decl_node,
1501 LValPurpose lval, BlockContext *scope)
1501 LValPurpose lval, Scope *scope)
15021502{
15031503 resolve_top_level_decl(irb->codegen, decl_node, lval != LValPurposeNone);
15041504 TopLevelDecl *tld = get_as_top_level_decl(decl_node);
......@@ -1565,7 +1565,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l
15651565 }
15661566 }
15671567
1568 VariableTableEntry *var = find_variable(irb->codegen, node->block_context, variable_name);
1568 VariableTableEntry *var = find_variable(irb->codegen, node->scope, variable_name);
15691569 if (var) {
15701570 IrInstruction *var_ptr = ir_build_var_ptr(irb, node, var);
15711571 if (lval != LValPurposeNone)
......@@ -1574,9 +1574,9 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l
15741574 return ir_build_load_ptr(irb, node, var_ptr);
15751575 }
15761576
1577 AstNode *decl_node = find_decl(node->block_context, variable_name);
1577 AstNode *decl_node = find_decl(node->scope, variable_name);
15781578 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
15811581 if (node->owner->any_imports_failed) {
15821582 // 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
15921592 assert(node->type == NodeTypeArrayAccessExpr);
15931593
15941594 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,
15961596 LValPurposeAddressOf);
15971597 if (array_ref_instruction == irb->codegen->invalid_instruction)
15981598 return array_ref_instruction;
15991599
16001600 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);
16021602 if (subscript_instruction == irb->codegen->invalid_instruction)
16031603 return subscript_instruction;
16041604
......@@ -1616,7 +1616,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, AstNode *node, LValPur
16161616 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
16171617 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,
16201620 LValPurposeAddressOf);
16211621 if (container_ref_instruction == irb->codegen->invalid_instruction)
16221622 return container_ref_instruction;
......@@ -1661,7 +1661,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
16611661 case BuiltinFnIdTypeof:
16621662 {
16631663 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);
16651665 if (arg == irb->codegen->invalid_instruction)
16661666 return arg;
16671667 return ir_build_typeof(irb, node, arg);
......@@ -1669,12 +1669,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
16691669 case BuiltinFnIdSetFnTest:
16701670 {
16711671 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);
16731673 if (arg0_value == irb->codegen->invalid_instruction)
16741674 return arg0_value;
16751675
16761676 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);
16781678 if (arg1_value == irb->codegen->invalid_instruction)
16791679 return arg1_value;
16801680
......@@ -1683,12 +1683,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
16831683 case BuiltinFnIdSetFnVisible:
16841684 {
16851685 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);
16871687 if (arg0_value == irb->codegen->invalid_instruction)
16881688 return arg0_value;
16891689
16901690 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);
16921692 if (arg1_value == irb->codegen->invalid_instruction)
16931693 return arg1_value;
16941694
......@@ -1697,12 +1697,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
16971697 case BuiltinFnIdSetDebugSafety:
16981698 {
16991699 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);
17011701 if (arg0_value == irb->codegen->invalid_instruction)
17021702 return arg0_value;
17031703
17041704 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);
17061706 if (arg1_value == irb->codegen->invalid_instruction)
17071707 return arg1_value;
17081708
......@@ -1711,7 +1711,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
17111711 case BuiltinFnIdCompileVar:
17121712 {
17131713 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);
17151715 if (arg0_value == irb->codegen->invalid_instruction)
17161716 return arg0_value;
17171717
......@@ -1720,7 +1720,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
17201720 case BuiltinFnIdSizeof:
17211721 {
17221722 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);
17241724 if (arg0_value == irb->codegen->invalid_instruction)
17251725 return arg0_value;
17261726
......@@ -1729,7 +1729,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
17291729 case BuiltinFnIdCtz:
17301730 {
17311731 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);
17331733 if (arg0_value == irb->codegen->invalid_instruction)
17341734 return arg0_value;
17351735
......@@ -1738,7 +1738,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
17381738 case BuiltinFnIdClz:
17391739 {
17401740 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);
17421742 if (arg0_value == irb->codegen->invalid_instruction)
17431743 return arg0_value;
17441744
......@@ -1747,7 +1747,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
17471747 case BuiltinFnIdStaticEval:
17481748 {
17491749 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);
17511751 if (arg0_value == irb->codegen->invalid_instruction)
17521752 return arg0_value;
17531753
......@@ -1756,11 +1756,11 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) {
17561756 case BuiltinFnIdImport:
17571757 {
17581758 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);
17601760 if (arg0_value == irb->codegen->invalid_instruction)
17611761 return arg0_value;
17621762
1763 if (node->block_context->fn_entry) {
1763 if (node->scope->fn_entry) {
17641764 add_node_error(irb->codegen, node, buf_sprintf("import valid only at top level scope"));
17651765 return irb->codegen->invalid_instruction;
17661766 }
......@@ -1805,7 +1805,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {
18051805 return ir_gen_builtin_fn_call(irb, node);
18061806
18071807 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);
18091809 if (fn_ref == irb->codegen->invalid_instruction)
18101810 return fn_ref;
18111811
......@@ -1813,7 +1813,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) {
18131813 IrInstruction **args = allocate<IrInstruction*>(arg_count);
18141814 for (size_t i = 0; i < arg_count; i += 1) {
18151815 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);
18171817 }
18181818
18191819 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) {
18221822static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {
18231823 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);
18261826 if (condition == irb->codegen->invalid_instruction)
18271827 return condition;
18281828
......@@ -1837,7 +1837,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {
18371837 ir_build_cond_br(irb, condition->source_node, condition, then_block, else_block, is_inline);
18381838
18391839 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);
18411841 if (then_expr_result == irb->codegen->invalid_instruction)
18421842 return then_expr_result;
18431843 IrBasicBlock *after_then_block = irb->current_basic_block;
......@@ -1846,7 +1846,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) {
18461846 ir_set_cursor_at_end(irb, else_block);
18471847 IrInstruction *else_expr_result;
18481848 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);
18501850 if (else_expr_result == irb->codegen->invalid_instruction)
18511851 return else_expr_result;
18521852 } else {
......@@ -1870,7 +1870,7 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, AstNode *node, Ir
18701870 assert(node->type == NodeTypePrefixOpExpr);
18711871 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);
18741874 if (value == irb->codegen->invalid_instruction)
18751875 return value;
18761876
......@@ -1887,7 +1887,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, AstNode *node, IrUnOp
18871887
18881888static IrInstruction *ir_gen_prefix_op_unwrap_maybe(IrBuilder *irb, AstNode *node, LValPurpose lval) {
18891889 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);
18911891 if (value == irb->codegen->invalid_instruction)
18921892 return value;
18931893
......@@ -1938,7 +1938,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)
19381938 AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;
19391939 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);
19421942 if (container_type == irb->codegen->invalid_instruction)
19431943 return container_type;
19441944
......@@ -1951,7 +1951,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)
19511951
19521952 Buf *name = entry_node->data.struct_val_field.name;
19531953 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);
19551955 if (expr_value == irb->codegen->invalid_instruction)
19561956 return expr_value;
19571957
......@@ -1965,7 +1965,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node)
19651965 IrInstruction **values = allocate<IrInstruction *>(item_count);
19661966 for (size_t i = 0; i < item_count; i += 1) {
19671967 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);
19691969 if (expr_value == irb->codegen->invalid_instruction)
19701970 return expr_value;
19711971
......@@ -1984,14 +1984,14 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) {
19841984
19851985 IrInstruction *type_instruction;
19861986 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);
19881988 if (type_instruction == irb->codegen->invalid_instruction)
19891989 return type_instruction;
19901990 } else {
19911991 type_instruction = nullptr;
19921992 }
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);
19951995 if (init_value == irb->codegen->invalid_instruction)
19961996 return init_value;
19971997
......@@ -1999,7 +1999,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) {
19991999 bool is_const = variable_declaration->is_const;
20002000 bool is_extern = variable_declaration->is_extern;
20012001 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,
20032003 variable_declaration->symbol, is_const, is_const, is_shadowable, is_inline);
20042004
20052005 if (!is_extern && !variable_declaration->expr) {
......@@ -2027,19 +2027,19 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) {
20272027
20282028 if (continue_expr_node) {
20292029 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);
20312031 ir_build_br(irb, node, cond_block, is_inline);
20322032 }
20332033
20342034 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);
20362036 ir_build_cond_br(irb, node->data.while_expr.condition, cond_val, body_block, end_block, is_inline);
20372037
20382038 ir_set_cursor_at_end(irb, body_block);
20392039
20402040 irb->break_block_stack.append(end_block);
20412041 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);
20432043 irb->break_block_stack.pop();
20442044 irb->continue_block_stack.pop();
20452045
......@@ -2052,7 +2052,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) {
20522052static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
20532053 assert(node->type == NodeTypeForExpr);
20542054
2055 BlockContext *parent_scope = node->block_context;
2055 Scope *parent_scope = node->scope;
20562056
20572057 AstNode *array_node = node->data.for_expr.array_expr;
20582058 AstNode *elem_node = node->data.for_expr.elem_node;
......@@ -2079,9 +2079,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
20792079 }
20802080 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);
20832083 child_scope->parent_loop_node = node;
2084 elem_node->block_context = child_scope;
2084 elem_node->scope = child_scope;
20852085
20862086 // TODO make it an error to write to element variable or i variable.
20872087 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
......@@ -2095,7 +2095,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
20952095 if (index_node) {
20962096 index_var_source_node = index_node;
20972097 Buf *index_var_name = index_node->data.symbol_expr.symbol;
2098 index_node->block_context = child_scope;
2098 index_node->scope = child_scope;
20992099 node->data.for_expr.index_var = ir_add_local_var(irb, index_node, child_scope, index_var_name,
21002100 true, false, false, is_inline);
21012101 } else {
......@@ -2154,7 +2154,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) {
21542154static IrInstruction *ir_gen_this_literal(IrBuilder *irb, AstNode *node) {
21552155 assert(node->type == NodeTypeThisLiteral);
21562156
2157 BlockContext *scope = node->block_context;
2157 Scope *scope = node->scope;
21582158
21592159 if (!scope->parent)
21602160 return ir_build_const_import(irb, node, node->owner);
......@@ -2205,18 +2205,18 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) {
22052205 return irb->codegen->invalid_instruction;
22062206 }
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);
22092209 if (size_value == irb->codegen->invalid_instruction)
22102210 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);
22132213 if (child_type == irb->codegen->invalid_instruction)
22142214 return child_type;
22152215
22162216 return ir_build_array_type(irb, node, size_value, child_type);
22172217 } else {
22182218 IrInstruction *child_type = ir_gen_node_extra(irb, child_type_node,
2219 node->block_context, LValPurposeAddressOf);
2219 node->scope, LValPurposeAddressOf);
22202220 if (child_type == irb->codegen->invalid_instruction)
22212221 return child_type;
22222222
......@@ -2246,7 +2246,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {
22462246 if (asm_output->return_type) {
22472247 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);
22502250 if (return_type == irb->codegen->invalid_instruction)
22512251 return irb->codegen->invalid_instruction;
22522252 if (return_count > 1) {
......@@ -2257,7 +2257,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {
22572257 output_types[i] = return_type;
22582258 } else {
22592259 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);
22612261 if (var) {
22622262 asm_output->variable = var;
22632263 } else {
......@@ -2269,7 +2269,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) {
22692269 }
22702270 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
22712271 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);
22732273 if (input_value == irb->codegen->invalid_instruction)
22742274 return irb->codegen->invalid_instruction;
22752275
......@@ -2288,7 +2288,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
22882288 AstNode *else_node = node->data.if_var_expr.else_node;
22892289 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);
22922292 if (expr_value == irb->codegen->invalid_instruction)
22932293 return expr_value;
22942294
......@@ -2304,11 +2304,11 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
23042304 ir_set_cursor_at_end(irb, then_block);
23052305 IrInstruction *var_type = nullptr;
23062306 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);
23082308 if (var_type == irb->codegen->invalid_instruction)
23092309 return irb->codegen->invalid_instruction;
23102310 }
2311 BlockContext *child_scope = new_block_context(node, node->block_context);
2311 Scope *child_scope = new_scope(node, node->scope);
23122312 bool is_shadowable = false;
23132313 bool is_const = var_decl->is_const;
23142314 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) {
23252325 ir_set_cursor_at_end(irb, else_block);
23262326 IrInstruction *else_expr_result;
23272327 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);
23292329 if (else_expr_result == irb->codegen->invalid_instruction)
23302330 return else_expr_result;
23312331 } else {
......@@ -2354,13 +2354,13 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo
23542354
23552355 AstNode *expr_node = prong_node->data.switch_prong.expr;
23562356 AstNode *var_symbol_node = prong_node->data.switch_prong.var_symbol;
2357 BlockContext *child_scope;
2357 Scope *child_scope;
23582358 if (var_symbol_node) {
23592359 assert(var_symbol_node->type == NodeTypeSymbol);
23602360 Buf *var_name = var_symbol_node->data.symbol_expr.symbol;
23612361 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);
23642364 bool is_shadowable = false;
23652365 bool is_const = true;
23662366 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
23752375 IrInstruction *var_type = nullptr; // infer the type
23762376 ir_build_var_decl(irb, var_symbol_node, var, var_type, var_value);
23772377 } else {
2378 child_scope = switch_node->block_context;
2378 child_scope = switch_node->scope;
23792379 }
23802380
23812381 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) {
23912391 assert(node->type == NodeTypeSwitchExpr);
23922392
23932393 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);
23952395 if (target_value_ptr == irb->codegen->invalid_instruction)
23962396 return target_value_ptr;
23972397 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) {
24362436 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
24372437 last_item_node = item_node;
24382438 if (item_node->type == NodeTypeSwitchRange) {
2439 item_node->block_context = node->block_context;
2439 item_node->scope = node->scope;
24402440 AstNode *start_node = item_node->data.switch_range.start;
24412441 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);
24442444 if (start_value == irb->codegen->invalid_instruction)
24452445 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);
24482448 if (end_value == irb->codegen->invalid_instruction)
24492449 return irb->codegen->invalid_instruction;
24502450
......@@ -2463,7 +2463,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
24632463 ok_bit = both_ok;
24642464 }
24652465 } 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);
24672467 if (item_value == irb->codegen->invalid_instruction)
24682468 return irb->codegen->invalid_instruction;
24692469
......@@ -2500,7 +2500,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
25002500 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
25012501 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);
25042504 if (item_value == irb->codegen->invalid_instruction)
25052505 return irb->codegen->invalid_instruction;
25062506
......@@ -2542,8 +2542,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) {
25422542 return ir_build_phi(irb, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
25432543}
25442544
2545static LabelTableEntry *find_label(IrExecutable *exec, BlockContext *orig_context, Buf *name) {
2546 BlockContext *context = orig_context;
2545static LabelTableEntry *find_label(IrExecutable *exec, Scope *orig_context, Buf *name) {
2546 Scope *context = orig_context;
25472547 while (context) {
25482548 auto entry = context->label_table.maybe_get(name);
25492549 if (entry) {
......@@ -2564,14 +2564,14 @@ static IrInstruction *ir_gen_label(IrBuilder *irb, AstNode *node) {
25642564 label->bb = label_block;
25652565 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);
25682568 if (existing_label) {
25692569 ErrorMsg *msg = add_node_error(irb->codegen, node,
25702570 buf_sprintf("duplicate label name '%s'", buf_ptr(label_name)));
25712571 add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here"));
25722572 return irb->codegen->invalid_instruction;
25732573 } else {
2574 node->block_context->label_table.put(label_name, label);
2574 node->scope->label_table.put(label_name, label);
25752575 }
25762576
25772577 bool is_inline = ir_should_inline(irb);
......@@ -2607,11 +2607,11 @@ static IrInstruction *ir_gen_type_literal(IrBuilder *irb, AstNode *node) {
26072607 return ir_build_const_type(irb, node, irb->codegen->builtin_types.entry_type);
26082608}
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,
26112611 LValPurpose lval)
26122612{
2613 assert(block_context);
2614 node->block_context = block_context;
2613 assert(scope);
2614 node->scope = scope;
26152615
26162616 switch (node->type) {
26172617 case NodeTypeStructValueField:
......@@ -2694,15 +2694,15 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex
26942694 zig_unreachable();
26952695}
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,
26982698 LValPurpose lval)
26992699{
2700 IrInstruction *result = ir_gen_node_raw(irb, node, block_context, lval);
2700 IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval);
27012701 irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);
27022702 return result;
27032703}
27042704
2705static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope) {
2705static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {
27062706 return ir_gen_node_extra(irb, node, scope, LValPurposeNone);
27072707}
27082708
......@@ -2714,7 +2714,7 @@ static bool ir_goto_pass2(IrBuilder *irb) {
27142714 IrInstruction *old_instruction = *slot;
27152715
27162716 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);
27182718 if (!label) {
27192719 add_node_error(irb->codegen, goto_node,
27202720 buf_sprintf("no label in scope named '%s'", buf_ptr(label_name)));
......@@ -2741,7 +2741,7 @@ static bool ir_goto_pass2(IrBuilder *irb) {
27412741 return true;
27422742}
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) {
27452745 assert(node->owner);
27462746
27472747 IrBuilder ir_builder = {0};
......@@ -2778,7 +2778,7 @@ IrInstruction *ir_gen_fn(CodeGen *codegn, FnTableEntry *fn_entry) {
27782778 assert(fn_def_node->type == NodeTypeFnDef);
27792779
27802780 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
27832783 return ir_gen(codegn, body_node, scope, ir_executable);
27842784}
......@@ -3023,8 +3023,8 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
30233023 } else {
30243024 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->source_node, wanted_type, value, cast_op);
30253025 result->type_entry = wanted_type;
3026 if (need_alloca && source_instr->source_node->block_context->fn_entry) {
3027 source_instr->source_node->block_context->fn_entry->alloca_list.append(result);
3026 if (need_alloca && source_instr->source_node->scope->fn_entry) {
3027 source_instr->source_node->scope->fn_entry->alloca_list.append(result);
30283028 }
30293029 return result;
30303030 }
......@@ -3550,7 +3550,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
35503550 ir_link_new_instruction(value, source_instruction);
35513551 return ptr_type;
35523552 } else {
3553 FnTableEntry *fn_entry = source_instruction->source_node->block_context->fn_entry;
3553 FnTableEntry *fn_entry = source_instruction->source_node->scope->fn_entry;
35543554 IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value);
35553555 fn_entry->alloca_list.append(new_instruction);
35563556 return ptr_type;
......@@ -4097,7 +4097,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
40974097
40984098 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;
41014101 if (scope->fn_entry)
41024102 scope->fn_entry->variable_list.append(var);
41034103
......@@ -4201,7 +4201,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
42014201 fn_entry, fn_ref, call_param_count, casted_args);
42024202
42034203 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
42064206 return ir_finish_anal(ira, return_type);
42074207}
......@@ -4732,7 +4732,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
47324732 return var->type;
47334733
47344734 ConstExprValue *mem_slot = nullptr;
4735 if (var->block_context->fn_entry) {
4735 if (var->scope->fn_entry) {
47364736 // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing.
47374737 if (var->mem_slot_index != SIZE_MAX)
47384738 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,
48794879 IrInstruction *container_ptr, TypeTableEntry *container_type)
48804880{
48814881 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);
48834883 assert(container_block_context);
48844884 auto entry = container_block_context->decl_table.maybe_get(field_name);
48854885 AstNode *fn_decl_node = entry ? entry->value : nullptr;
......@@ -5023,7 +5023,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
50235023 } else if (child_type->id == TypeTableEntryIdEnum) {
50245024 zig_panic("TODO enum type field");
50255025 } 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);
50275027 auto entry = container_block_context->decl_table.maybe_get(field_name);
50285028 AstNode *decl_node = entry ? entry->value : nullptr;
50295029 if (decl_node) {
......@@ -5055,7 +5055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
50555055 ImportTableEntry *namespace_import = namespace_val->data.x_import;
50565056
50575057 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);
50595059 if (!decl_node) {
50605060 // we must now resolve all the use decls
50615061 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
50665066 }
50675067 resolve_use_decl(ira->codegen, use_decl_node);
50685068 }
5069 decl_node = find_decl(namespace_import->block_context, field_name);
5069 decl_node = find_decl(namespace_import->scope, field_name);
50705070 }
50715071 if (decl_node) {
50725072 TopLevelDecl *tld = get_as_top_level_decl(decl_node);
......@@ -5323,19 +5323,19 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
53235323 if (!target_val)
53245324 return ira->codegen->builtin_types.entry_invalid;
53255325
5326 BlockContext *target_context;
5326 Scope *target_context;
53275327 if (target_type->id == TypeTableEntryIdBlock) {
53285328 target_context = target_val->data.x_block;
53295329 } 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;
53315331 } else if (target_type->id == TypeTableEntryIdMetaType) {
53325332 TypeTableEntry *type_arg = target_val->data.x_type;
53335333 if (type_arg->id == TypeTableEntryIdStruct) {
5334 target_context = type_arg->data.structure.block_context;
5334 target_context = type_arg->data.structure.scope;
53355335 } else if (type_arg->id == TypeTableEntryIdEnum) {
5336 target_context = type_arg->data.enumeration.block_context;
5336 target_context = type_arg->data.enumeration.scope;
53375337 } else if (type_arg->id == TypeTableEntryIdUnion) {
5338 target_context = type_arg->data.unionation.block_context;
5338 target_context = type_arg->data.unionation.scope;
53395339 } else {
53405340 add_node_error(ira->codegen, target_instruction->source_node,
53415341 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
59665966 ImportTableEntry *target_import = add_source_file(ira->codegen, target_package,
59675967 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
59715971 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var);
59725972 out_val->data.x_import = target_import;
......@@ -6021,7 +6021,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
60216021
60226022 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;
60256025 bool outside_fn = (fn_entry == nullptr);
60266026
60276027 ConstExprValue const_val = {};
......@@ -6124,7 +6124,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
61246124 const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count);
61256125 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;
61286128 bool outside_fn = (fn_entry == nullptr);
61296129
61306130 IrInstruction **new_items = allocate<IrInstruction *>(elem_count);
src/ir.hpp+1-1
......@@ -10,7 +10,7 @@
1010
1111#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);
1414IrInstruction *ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);
1515
1616TypeTableEntry *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)
817817 const EnumDecl *enum_def = enum_decl->getDefinition();
818818 if (!enum_def) {
819819 TypeTableEntry *enum_type = get_partial_container_type(c->codegen, c->import,
820 c->import->block_context,
820 c->import->scope,
821821 ContainerKindEnum, c->source_node, buf_ptr(full_type_name));
822822 c->enum_type_table.put(bare_name, enum_type);
823823 c->decl_table.put(enum_decl, enum_type);
......@@ -842,7 +842,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl)
842842
843843 if (pure_enum) {
844844 TypeTableEntry *enum_type = get_partial_container_type(c->codegen, c->import,
845 c->import->block_context,
845 c->import->scope,
846846 ContainerKindEnum, c->source_node, buf_ptr(full_type_name));
847847 c->enum_type_table.put(bare_name, enum_type);
848848 c->decl_table.put(enum_decl, enum_type);
......@@ -1002,7 +1002,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
10021002
10031003
10041004 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
10071007 c->struct_type_table.put(bare_name, struct_type);
10081008 c->decl_table.put(record_decl, struct_type);