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...@@ -1180,7 +1180,8 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1180 }1180 }
1181 }1181 }
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
1185 switch (fn_type_id.return_type->id) {1186 switch (fn_type_id.return_type->id) {
1186 case TypeTableEntryIdInvalid:1187 case TypeTableEntryIdInvalid:
...@@ -2056,7 +2057,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -2056,7 +2057,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
2056 for (size_t i = 0; i < fn_proto->params.length; i += 1) {2057 for (size_t i = 0; i < fn_proto->params.length; i += 1) {
2057 AstNode *param_node = fn_proto->params.at(i);2058 AstNode *param_node = fn_proto->params.at(i);
2058 assert(param_node->type == NodeTypeParamDecl);2059 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) {
2060 add_node_error(g, param_node, buf_sprintf("missing parameter name"));2061 add_node_error(g, param_node, buf_sprintf("missing parameter name"));
2061 }2062 }
2062 }2063 }
...@@ -2268,7 +2269,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -2268,7 +2269,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
2268 {2269 {
2269 // if the name is missing, we immediately announce an error2270 // if the name is missing, we immediately announce an error
2270 Buf *fn_name = node->data.fn_proto.name;2271 Buf *fn_name = node->data.fn_proto.name;
2271 if (buf_len(fn_name) == 0) {2272 if (fn_name == nullptr) {
2272 add_node_error(g, node, buf_sprintf("missing function name"));2273 add_node_error(g, node, buf_sprintf("missing function name"));
2273 break;2274 break;
2274 }2275 }
...@@ -2950,6 +2951,9 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari...@@ -2950,6 +2951,9 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari
2950 } else {2951 } else {
2951 param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i);2952 param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i);
2952 }2953 }
2954 if (param_name == nullptr) {
2955 continue;
2956 }
29532957
2954 TypeTableEntry *param_type = param_info->type;2958 TypeTableEntry *param_type = param_info->type;
2955 bool is_noalias = param_info->is_noalias;2959 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...@@ -6116,7 +6116,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
61166116
6117 IrInstruction *return_type;6117 IrInstruction *return_type;
6118 if (node->data.fn_proto.return_type == nullptr) {6118 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);
6120 } else {6120 } else {
6121 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);6121 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
6122 if (return_type == irb->codegen->invalid_instruction)6122 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) {...@@ -1620,9 +1620,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
1620 return;1620 return;
1621 }1621 }
16221622
1623 const FunctionProtoType *fn_proto_ty = (const FunctionProtoType *) fn_decl->getType().getTypePtr();1623 for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
1624 size_t arg_count = fn_proto_ty->getNumParams();
1625 for (size_t i = 0; i < arg_count; i += 1) {
1626 AstNode *param_node = proto_node->data.fn_proto.params.at(i);1624 AstNode *param_node = proto_node->data.fn_proto.params.at(i);
1627 const ParmVarDecl *param = fn_decl->getParamDecl(i);1625 const ParmVarDecl *param = fn_decl->getParamDecl(i);
1628 const char *name = decl_name(param);1626 const char *name = decl_name(param);
...@@ -2036,13 +2034,7 @@ static bool decl_visitor(void *context, const Decl *decl) {...@@ -2036,13 +2034,7 @@ static bool decl_visitor(void *context, const Decl *decl) {
2036}2034}
20372035
2038static bool name_exists(Context *c, Buf *name) {2036static bool name_exists(Context *c, Buf *name) {
2039 if (get_global(c, name)) {2037 return get_global(c, name) != nullptr;
2040 return true;
2041 }
2042 if (c->macro_table.maybe_get(name)) {
2043 return true;
2044 }
2045 return false;
2046}2038}
20472039
2048static void render_aliases(Context *c) {2040static void render_aliases(Context *c) {
...@@ -2162,7 +2154,7 @@ static void process_symbol_macros(Context *c) {...@@ -2162,7 +2154,7 @@ static void process_symbol_macros(Context *c) {
21622154
2163 // Check if this macro aliases another top level declaration2155 // Check if this macro aliases another top level declaration
2164 AstNode *existing_node = get_global(c, ms.value);2156 AstNode *existing_node = get_global(c, ms.value);
2165 if (!existing_node)2157 if (!existing_node || name_exists(c, ms.name))
2166 continue;2158 continue;
21672159
2168 // If a macro aliases a global variable which is a function pointer, we conclude that2160 // If a macro aliases a global variable which is a function pointer, we conclude that