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
907907 fn_type_id.param_info = allocate_nonzero<FnTypeParamInfo>(fn_type_id.param_count);
908908
909909 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
912911 for (size_t i = 0; i < fn_type_id.param_count; i += 1) {
913912 AstNode *child = fn_proto->params.at(i);
914913 assert(child->type == NodeTypeParamDecl);
915914
916 TypeTableEntry *type_entry = analyze_type_expr(g, import, context,
917 child->data.param_decl.type);
915 TypeTableEntry *type_entry;
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
918922 switch (type_entry->id) {
919923 case TypeTableEntryIdInvalid:
920924 fn_proto->skip = true;
......@@ -927,16 +931,20 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
927931 case TypeTableEntryIdNamespace:
928932 case TypeTableEntryIdBlock:
929933 case TypeTableEntryIdGenericFn:
930 fn_proto->skip = true;
931 add_node_error(g, child->data.param_decl.type,
932 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
934 if (!fn_proto->skip) {
935 fn_proto->skip = true;
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 }
933939 break;
934940 case TypeTableEntryIdMetaType:
935941 if (!child->data.param_decl.is_inline) {
936 fn_proto->skip = true;
937 add_node_error(g, child->data.param_decl.type,
938 buf_sprintf("parameter of type '%s' must be declared inline",
939 buf_ptr(&type_entry->name)));
942 if (!fn_proto->skip) {
943 fn_proto->skip = true;
944 add_node_error(g, child->data.param_decl.type,
945 buf_sprintf("parameter of type '%s' must be declared inline",
946 buf_ptr(&type_entry->name)));
947 }
940948 }
941949 break;
942950 case TypeTableEntryIdVoid:
......@@ -967,6 +975,11 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
967975 param_info->is_noalias = child->data.param_decl.is_noalias;
968976 }
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 }
970983 switch (fn_type_id.return_type->id) {
971984 case TypeTableEntryIdInvalid:
972985 fn_proto->skip = true;
......@@ -979,9 +992,11 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
979992 case TypeTableEntryIdBlock:
980993 case TypeTableEntryIdGenericFn:
981994 case TypeTableEntryIdVar:
982 fn_proto->skip = true;
983 add_node_error(g, fn_proto->return_type,
984 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
995 if (!fn_proto->skip) {
996 fn_proto->skip = true;
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 }
9851000 break;
9861001 case TypeTableEntryIdMetaType:
9871002 case TypeTableEntryIdUnreachable:
src/ir.cpp+7-1
......@@ -2523,6 +2523,11 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, IrInstruction *value, LValPur
25232523 return ir_build_ref(irb, value->source_node, value);
25242524}
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
25262531static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContext *block_context,
25272532 LValPurpose lval)
25282533{
......@@ -2580,6 +2585,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex
25802585 return ir_gen_label(irb, node);
25812586 case NodeTypeGoto:
25822587 return ir_gen_goto(irb, node);
2588 case NodeTypeTypeLiteral:
2589 return ir_lval_wrap(irb, ir_gen_type_literal(irb, node), lval);
25832590 case NodeTypeUnwrapErrorExpr:
25842591 case NodeTypeDefer:
25852592 case NodeTypeSliceExpr:
......@@ -2588,7 +2595,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContex
25882595 case NodeTypeCharLiteral:
25892596 case NodeTypeZeroesLiteral:
25902597 case NodeTypeErrorType:
2591 case NodeTypeTypeLiteral:
25922598 case NodeTypeVarLiteral:
25932599 case NodeTypeRoot:
25942600 case NodeTypeFnProto: