authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-27 01:45:29-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-27 01:45:29-05:00
log9e7c47597985a4a35912d2b1f800d3af05597a3a
treed95fe1f12b383d8be481c8c1fe444e2bb6bbf7c0
parente5325c7ef3c5b0fe9afbcba59cd269608d65dda0

IR: silence irrelevant function prototype errors


2 files changed, 35 insertions(+), 14 deletions(-)

src/analyze.cpp+28-13
...@@ -907,14 +907,18 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -907,14 +907,18 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
907 fn_type_id.param_info = allocate_nonzero<FnTypeParamInfo>(fn_type_id.param_count);907 fn_type_id.param_info = allocate_nonzero<FnTypeParamInfo>(fn_type_id.param_count);
908908
909 fn_type_id.is_var_args = fn_proto->is_var_args;909 fn_type_id.is_var_args = fn_proto->is_var_args;
910 fn_type_id.return_type = analyze_type_expr(g, import, context, fn_proto->return_type);
911910
912 for (size_t i = 0; i < fn_type_id.param_count; i += 1) {911 for (size_t i = 0; i < fn_type_id.param_count; i += 1) {
913 AstNode *child = fn_proto->params.at(i);912 AstNode *child = fn_proto->params.at(i);
914 assert(child->type == NodeTypeParamDecl);913 assert(child->type == NodeTypeParamDecl);
915914
916 TypeTableEntry *type_entry = analyze_type_expr(g, import, context,915 TypeTableEntry *type_entry;
917 child->data.param_decl.type);916 if (fn_proto->skip) {
917 type_entry = g->builtin_types.entry_invalid;
918 } else {
919 type_entry = analyze_type_expr(g, import, context, child->data.param_decl.type);
920 }
921
918 switch (type_entry->id) {922 switch (type_entry->id) {
919 case TypeTableEntryIdInvalid:923 case TypeTableEntryIdInvalid:
920 fn_proto->skip = true;924 fn_proto->skip = true;
...@@ -927,16 +931,20 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -927,16 +931,20 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
927 case TypeTableEntryIdNamespace:931 case TypeTableEntryIdNamespace:
928 case TypeTableEntryIdBlock:932 case TypeTableEntryIdBlock:
929 case TypeTableEntryIdGenericFn:933 case TypeTableEntryIdGenericFn:
930 fn_proto->skip = true;934 if (!fn_proto->skip) {
931 add_node_error(g, child->data.param_decl.type,935 fn_proto->skip = true;
932 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));936 add_node_error(g, child->data.param_decl.type,
937 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
938 }
933 break;939 break;
934 case TypeTableEntryIdMetaType:940 case TypeTableEntryIdMetaType:
935 if (!child->data.param_decl.is_inline) {941 if (!child->data.param_decl.is_inline) {
936 fn_proto->skip = true;942 if (!fn_proto->skip) {
937 add_node_error(g, child->data.param_decl.type,943 fn_proto->skip = true;
938 buf_sprintf("parameter of type '%s' must be declared inline",944 add_node_error(g, child->data.param_decl.type,
939 buf_ptr(&type_entry->name)));945 buf_sprintf("parameter of type '%s' must be declared inline",
946 buf_ptr(&type_entry->name)));
947 }
940 }948 }
941 break;949 break;
942 case TypeTableEntryIdVoid:950 case TypeTableEntryIdVoid:
...@@ -967,6 +975,11 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -967,6 +975,11 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
967 param_info->is_noalias = child->data.param_decl.is_noalias;975 param_info->is_noalias = child->data.param_decl.is_noalias;
968 }976 }
969977
978 if (fn_proto->skip) {
979 fn_type_id.return_type = g->builtin_types.entry_invalid;
980 } else {
981 fn_type_id.return_type = analyze_type_expr(g, import, context, fn_proto->return_type);
982 }
970 switch (fn_type_id.return_type->id) {983 switch (fn_type_id.return_type->id) {
971 case TypeTableEntryIdInvalid:984 case TypeTableEntryIdInvalid:
972 fn_proto->skip = true;985 fn_proto->skip = true;
...@@ -979,9 +992,11 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -979,9 +992,11 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
979 case TypeTableEntryIdBlock:992 case TypeTableEntryIdBlock:
980 case TypeTableEntryIdGenericFn:993 case TypeTableEntryIdGenericFn:
981 case TypeTableEntryIdVar:994 case TypeTableEntryIdVar:
982 fn_proto->skip = true;995 if (!fn_proto->skip) {
983 add_node_error(g, fn_proto->return_type,996 fn_proto->skip = true;
984 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));997 add_node_error(g, fn_proto->return_type,
998 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
999 }
985 break;1000 break;
986 case TypeTableEntryIdMetaType:1001 case TypeTableEntryIdMetaType:
987 case TypeTableEntryIdUnreachable:1002 case TypeTableEntryIdUnreachable:
src/ir.cpp+7-1
...@@ -2523,6 +2523,11 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, IrInstruction *value, LValPur...@@ -2523,6 +2523,11 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, IrInstruction *value, LValPur
2523 return ir_build_ref(irb, value->source_node, value);2523 return ir_build_ref(irb, value->source_node, value);
2524}2524}
25252525
2526static IrInstruction *ir_gen_type_literal(IrBuilder *irb, AstNode *node) {
2527 assert(node->type == NodeTypeTypeLiteral);
2528 return ir_build_const_type(irb, node, irb->codegen->builtin_types.entry_type);
2529}
2530
2526static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContext *block_context,2531static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContext *block_context,
2527 LValPurpose lval)2532 LValPurpose lval)
2528{2533{
...@@ -2580,6 +2585,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex...@@ -2580,6 +2585,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex
2580 return ir_gen_label(irb, node);2585 return ir_gen_label(irb, node);
2581 case NodeTypeGoto:2586 case NodeTypeGoto:
2582 return ir_gen_goto(irb, node);2587 return ir_gen_goto(irb, node);
2588 case NodeTypeTypeLiteral:
2589 return ir_lval_wrap(irb, ir_gen_type_literal(irb, node), lval);
2583 case NodeTypeUnwrapErrorExpr:2590 case NodeTypeUnwrapErrorExpr:
2584 case NodeTypeDefer:2591 case NodeTypeDefer:
2585 case NodeTypeSliceExpr:2592 case NodeTypeSliceExpr:
...@@ -2588,7 +2595,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex...@@ -2588,7 +2595,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex
2588 case NodeTypeCharLiteral:2595 case NodeTypeCharLiteral:
2589 case NodeTypeZeroesLiteral:2596 case NodeTypeZeroesLiteral:
2590 case NodeTypeErrorType:2597 case NodeTypeErrorType:
2591 case NodeTypeTypeLiteral:
2592 case NodeTypeVarLiteral:2598 case NodeTypeVarLiteral:
2593 case NodeTypeRoot:2599 case NodeTypeRoot:
2594 case NodeTypeFnProto:2600 case NodeTypeFnProto: