authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-04 17:14:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-04 17:14:53-07:00
log22c52f1eb67a46e60be876fda332ad7d2f338ee7
tree8aad02e3a9116d450dfc0350e5c1bb3feb8a1d6e
parent4514661cfef1cd0090ba9888b69037af3ef9805a

member functions get a namespaced symbol


3 files changed, 18 insertions(+), 2 deletions(-)

src/analyze.cpp+12
...@@ -506,6 +506,16 @@ static void preview_fn_def(CodeGen *g, ImportTableEntry *import, AstNode *node,...@@ -506,6 +506,16 @@ static void preview_fn_def(CodeGen *g, ImportTableEntry *import, AstNode *node,
506 fn_table_entry->internal_linkage = is_internal;506 fn_table_entry->internal_linkage = is_internal;
507 fn_table_entry->calling_convention = is_internal ? LLVMFastCallConv : LLVMCCallConv;507 fn_table_entry->calling_convention = is_internal ? LLVMFastCallConv : LLVMCCallConv;
508 fn_table_entry->label_table.init(8);508 fn_table_entry->label_table.init(8);
509 fn_table_entry->member_of_struct = struct_type;
510
511 if (struct_type) {
512 buf_resize(&fn_table_entry->symbol_name, 0);
513 buf_appendf(&fn_table_entry->symbol_name, "%s_%s",
514 buf_ptr(&struct_type->name),
515 buf_ptr(proto_name));
516 } else {
517 buf_init_from_buf(&fn_table_entry->symbol_name, proto_name);
518 }
509519
510 g->fn_protos.append(fn_table_entry);520 g->fn_protos.append(fn_table_entry);
511 g->fn_defs.append(fn_table_entry);521 g->fn_defs.append(fn_table_entry);
...@@ -556,6 +566,8 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,...@@ -556,6 +566,8 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
556 fn_table_entry->import_entry = import;566 fn_table_entry->import_entry = import;
557 fn_table_entry->label_table.init(8);567 fn_table_entry->label_table.init(8);
558568
569 buf_init_from_buf(&fn_table_entry->symbol_name, &fn_proto->data.fn_proto.name);
570
559 resolve_function_proto(g, fn_proto, fn_table_entry, import);571 resolve_function_proto(g, fn_proto, fn_table_entry, import);
560572
561 Buf *name = &fn_proto->data.fn_proto.name;573 Buf *name = &fn_proto->data.fn_proto.name;
src/analyze.hpp+2
...@@ -138,6 +138,8 @@ struct FnTableEntry {...@@ -138,6 +138,8 @@ struct FnTableEntry {
138 ZigList<FnAttrId> fn_attr_list;138 ZigList<FnAttrId> fn_attr_list;
139 // Required to be a pre-order traversal of the AST. (parents must come before children)139 // Required to be a pre-order traversal of the AST. (parents must come before children)
140 ZigList<BlockContext *> all_block_contexts;140 ZigList<BlockContext *> all_block_contexts;
141 TypeTableEntry *member_of_struct;
142 Buf symbol_name;
141143
142 // reminder: hash tables must be initialized before use144 // reminder: hash tables must be initialized before use
143 HashMap<Buf *, LabelTableEntry *, buf_hash, buf_eql_buf> label_table;145 HashMap<Buf *, LabelTableEntry *, buf_hash, buf_eql_buf> label_table;
src/codegen.cpp+4-2
...@@ -1503,7 +1503,8 @@ static void do_code_gen(CodeGen *g) {...@@ -1503,7 +1503,8 @@ static void do_code_gen(CodeGen *g) {
1503 gen_param_index += 1;1503 gen_param_index += 1;
1504 }1504 }
1505 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, param_count, fn_proto->is_var_args);1505 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, param_count, fn_proto->is_var_args);
1506 LLVMValueRef fn = LLVMAddFunction(g->module, buf_ptr(&fn_proto->name), function_type);1506
1507 LLVMValueRef fn = LLVMAddFunction(g->module, buf_ptr(&fn_table_entry->symbol_name), function_type);
15071508
1508 for (int attr_i = 0; attr_i < fn_table_entry->fn_attr_list.length; attr_i += 1) {1509 for (int attr_i = 0; attr_i < fn_table_entry->fn_attr_list.length; attr_i += 1) {
1509 FnAttrId attr_id = fn_table_entry->fn_attr_list.at(attr_i);1510 FnAttrId attr_id = fn_table_entry->fn_attr_list.at(attr_i);
...@@ -1542,7 +1543,8 @@ static void do_code_gen(CodeGen *g) {...@@ -1542,7 +1543,8 @@ static void do_code_gen(CodeGen *g) {
1542 unsigned flags = 0;1543 unsigned flags = 0;
1543 bool is_optimized = g->build_type == CodeGenBuildTypeRelease;1544 bool is_optimized = g->build_type == CodeGenBuildTypeRelease;
1544 LLVMZigDISubprogram *subprogram = LLVMZigCreateFunction(g->dbuilder,1545 LLVMZigDISubprogram *subprogram = LLVMZigCreateFunction(g->dbuilder,
1545 import->block_context->di_scope, buf_ptr(&fn_proto->name), "", import->di_file, line_number,1546 import->block_context->di_scope, buf_ptr(&fn_table_entry->symbol_name), "",
1547 import->di_file, line_number,
1546 create_di_function_type(g, fn_proto, import->di_file), fn_table_entry->internal_linkage, 1548 create_di_function_type(g, fn_proto, import->di_file), fn_table_entry->internal_linkage,
1547 is_definition, scope_line, flags, is_optimized, fn);1549 is_definition, scope_line, flags, is_optimized, fn);
15481550