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

all tests passing
This commit is contained in:
Andrew Kelley 2017-09-05 03:11:59 -04:00
parent 87970920c4
commit c3362c1cb6
3 changed files with 11 additions and 15 deletions

View File

@ -1180,7 +1180,8 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
}
}
fn_type_id.return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
fn_type_id.return_type = (fn_proto->return_type == nullptr) ?
g->builtin_types.entry_void : analyze_type_expr(g, child_scope, fn_proto->return_type);
switch (fn_type_id.return_type->id) {
case TypeTableEntryIdInvalid:
@ -2056,7 +2057,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
for (size_t i = 0; i < fn_proto->params.length; i += 1) {
AstNode *param_node = fn_proto->params.at(i);
assert(param_node->type == NodeTypeParamDecl);
if (buf_len(param_node->data.param_decl.name) == 0) {
if (param_node->data.param_decl.name == nullptr) {
add_node_error(g, param_node, buf_sprintf("missing parameter name"));
}
}
@ -2268,7 +2269,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
{
// if the name is missing, we immediately announce an error
Buf *fn_name = node->data.fn_proto.name;
if (buf_len(fn_name) == 0) {
if (fn_name == nullptr) {
add_node_error(g, node, buf_sprintf("missing function name"));
break;
}
@ -2950,6 +2951,9 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari
} else {
param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i);
}
if (param_name == nullptr) {
continue;
}
TypeTableEntry *param_type = param_info->type;
bool is_noalias = param_info->is_noalias;

View File

@ -6116,7 +6116,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
IrInstruction *return_type;
if (node->data.fn_proto.return_type == nullptr) {
return_type = ir_build_const_void(irb, parent_scope, node);
return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
} else {
return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
if (return_type == irb->codegen->invalid_instruction)

View File

@ -1620,9 +1620,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
return;
}
const FunctionProtoType *fn_proto_ty = (const FunctionProtoType *) fn_decl->getType().getTypePtr();
size_t arg_count = fn_proto_ty->getNumParams();
for (size_t i = 0; i < arg_count; i += 1) {
for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
AstNode *param_node = proto_node->data.fn_proto.params.at(i);
const ParmVarDecl *param = fn_decl->getParamDecl(i);
const char *name = decl_name(param);
@ -2036,13 +2034,7 @@ static bool decl_visitor(void *context, const Decl *decl) {
}
static bool name_exists(Context *c, Buf *name) {
if (get_global(c, name)) {
return true;
}
if (c->macro_table.maybe_get(name)) {
return true;
}
return false;
return get_global(c, name) != nullptr;
}
static void render_aliases(Context *c) {
@ -2162,7 +2154,7 @@ static void process_symbol_macros(Context *c) {
// Check if this macro aliases another top level declaration
AstNode *existing_node = get_global(c, ms.value);
if (!existing_node)
if (!existing_node || name_exists(c, ms.name))
continue;
// If a macro aliases a global variable which is a function pointer, we conclude that