authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-05 03:11:59-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-05 03:11:59-04:00
logc3362c1cb63ff8d8e79a16c76a574bbbd488967c
tree47e5c4e90947056a5b5c3e42c87cad1d664dd443
parent87970920c493de2f2d4606dfef92bb847e07105f

fix void return node and param name nodes, fix dupe macros

all tests passing

3 files changed, 11 insertions(+), 15 deletions(-)

src/analyze.cpp+7-3
......@@ -1180,7 +1180,8 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
11801180 }
11811181 }
11821182
1183 fn_type_id.return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
1183 fn_type_id.return_type = (fn_proto->return_type == nullptr) ?
1184 g->builtin_types.entry_void : analyze_type_expr(g, child_scope, fn_proto->return_type);
11841185
11851186 switch (fn_type_id.return_type->id) {
11861187 case TypeTableEntryIdInvalid:
......@@ -2056,7 +2057,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
20562057 for (size_t i = 0; i < fn_proto->params.length; i += 1) {
20572058 AstNode *param_node = fn_proto->params.at(i);
20582059 assert(param_node->type == NodeTypeParamDecl);
2059 if (buf_len(param_node->data.param_decl.name) == 0) {
2060 if (param_node->data.param_decl.name == nullptr) {
20602061 add_node_error(g, param_node, buf_sprintf("missing parameter name"));
20612062 }
20622063 }
......@@ -2268,7 +2269,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
22682269 {
22692270 // if the name is missing, we immediately announce an error
22702271 Buf *fn_name = node->data.fn_proto.name;
2271 if (buf_len(fn_name) == 0) {
2272 if (fn_name == nullptr) {
22722273 add_node_error(g, node, buf_sprintf("missing function name"));
22732274 break;
22742275 }
......@@ -2950,6 +2951,9 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari
29502951 } else {
29512952 param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i);
29522953 }
2954 if (param_name == nullptr) {
2955 continue;
2956 }
29532957
29542958 TypeTableEntry *param_type = param_info->type;
29552959 bool is_noalias = param_info->is_noalias;
src/ir.cpp+1-1
......@@ -6116,7 +6116,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
61166116
61176117 IrInstruction *return_type;
61186118 if (node->data.fn_proto.return_type == nullptr) {
6119 return_type = ir_build_const_void(irb, parent_scope, node);
6119 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
61206120 } else {
61216121 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
61226122 if (return_type == irb->codegen->invalid_instruction)
src/parseh.cpp+3-11
......@@ -1620,9 +1620,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
16201620 return;
16211621 }
16221622
1623 const FunctionProtoType *fn_proto_ty = (const FunctionProtoType *) fn_decl->getType().getTypePtr();
1624 size_t arg_count = fn_proto_ty->getNumParams();
1625 for (size_t i = 0; i < arg_count; i += 1) {
1623 for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
16261624 AstNode *param_node = proto_node->data.fn_proto.params.at(i);
16271625 const ParmVarDecl *param = fn_decl->getParamDecl(i);
16281626 const char *name = decl_name(param);
......@@ -2036,13 +2034,7 @@ static bool decl_visitor(void *context, const Decl *decl) {
20362034}
20372035
20382036static bool name_exists(Context *c, Buf *name) {
2039 if (get_global(c, name)) {
2040 return true;
2041 }
2042 if (c->macro_table.maybe_get(name)) {
2043 return true;
2044 }
2045 return false;
2037 return get_global(c, name) != nullptr;
20462038}
20472039
20482040static void render_aliases(Context *c) {
......@@ -2162,7 +2154,7 @@ static void process_symbol_macros(Context *c) {
21622154
21632155 // Check if this macro aliases another top level declaration
21642156 AstNode *existing_node = get_global(c, ms.value);
2165 if (!existing_node)
2157 if (!existing_node || name_exists(c, ms.name))
21662158 continue;
21672159
21682160 // If a macro aliases a global variable which is a function pointer, we conclude that