Commit 22c52f1eb6

Andrew Kelley <superjoe30@gmail.com>
2016-01-05 01:14:53
member functions get a namespaced symbol
1 parent 4514661
src/analyze.cpp
@@ -506,6 +506,16 @@ static void preview_fn_def(CodeGen *g, ImportTableEntry *import, AstNode *node,
         fn_table_entry->internal_linkage = is_internal;
         fn_table_entry->calling_convention = is_internal ? LLVMFastCallConv : LLVMCCallConv;
         fn_table_entry->label_table.init(8);
+        fn_table_entry->member_of_struct = struct_type;
+
+        if (struct_type) {
+            buf_resize(&fn_table_entry->symbol_name, 0);
+            buf_appendf(&fn_table_entry->symbol_name, "%s_%s",
+                    buf_ptr(&struct_type->name),
+                    buf_ptr(proto_name));
+        } else {
+            buf_init_from_buf(&fn_table_entry->symbol_name, proto_name);
+        }
 
         g->fn_protos.append(fn_table_entry);
         g->fn_defs.append(fn_table_entry);
@@ -556,6 +566,8 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
                 fn_table_entry->import_entry = import;
                 fn_table_entry->label_table.init(8);
 
+                buf_init_from_buf(&fn_table_entry->symbol_name, &fn_proto->data.fn_proto.name);
+
                 resolve_function_proto(g, fn_proto, fn_table_entry, import);
 
                 Buf *name = &fn_proto->data.fn_proto.name;
src/analyze.hpp
@@ -138,6 +138,8 @@ struct FnTableEntry {
     ZigList<FnAttrId> fn_attr_list;
     // Required to be a pre-order traversal of the AST. (parents must come before children)
     ZigList<BlockContext *> all_block_contexts;
+    TypeTableEntry *member_of_struct;
+    Buf symbol_name;
 
     // reminder: hash tables must be initialized before use
     HashMap<Buf *, LabelTableEntry *, buf_hash, buf_eql_buf> label_table;
src/codegen.cpp
@@ -1503,7 +1503,8 @@ static void do_code_gen(CodeGen *g) {
             gen_param_index += 1;
         }
         LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, param_count, fn_proto->is_var_args);
-        LLVMValueRef fn = LLVMAddFunction(g->module, buf_ptr(&fn_proto->name), function_type);
+
+        LLVMValueRef fn = LLVMAddFunction(g->module, buf_ptr(&fn_table_entry->symbol_name), function_type);
 
         for (int attr_i = 0; attr_i < fn_table_entry->fn_attr_list.length; attr_i += 1) {
             FnAttrId attr_id = fn_table_entry->fn_attr_list.at(attr_i);
@@ -1542,7 +1543,8 @@ static void do_code_gen(CodeGen *g) {
         unsigned flags = 0;
         bool is_optimized = g->build_type == CodeGenBuildTypeRelease;
         LLVMZigDISubprogram *subprogram = LLVMZigCreateFunction(g->dbuilder,
-            import->block_context->di_scope, buf_ptr(&fn_proto->name), "", import->di_file, line_number,
+            import->block_context->di_scope, buf_ptr(&fn_table_entry->symbol_name), "",
+            import->di_file, line_number,
             create_di_function_type(g, fn_proto, import->di_file), fn_table_entry->internal_linkage, 
             is_definition, scope_line, flags, is_optimized, fn);