authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-29 21:50:38-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-29 21:50:38-05:00
log7729f6cf4edd7c8eda935b1c7c8b4276d73b6e69
tree07304cd09fd9a3c99b6070b584adf0ebf219f3ef
parent716b0b8655610a3a64818c51a91254c6e4715e49

translate-c: support static incomplete array inside function


2 files changed, 24 insertions(+), 2 deletions(-)

src/translate_c.cpp+14-2
...@@ -976,11 +976,23 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou...@@ -976,11 +976,23 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
976 const AttributedType *attributed_ty = static_cast<const AttributedType *>(ty);976 const AttributedType *attributed_ty = static_cast<const AttributedType *>(ty);
977 return trans_qual_type(c, attributed_ty->getEquivalentType(), source_loc);977 return trans_qual_type(c, attributed_ty->getEquivalentType(), source_loc);
978 }978 }
979 case Type::IncompleteArray:
980 {
981 const IncompleteArrayType *incomplete_array_ty = static_cast<const IncompleteArrayType *>(ty);
982 QualType child_qt = incomplete_array_ty->getElementType();
983 AstNode *child_type_node = trans_qual_type(c, child_qt, source_loc);
984 if (child_type_node == nullptr) {
985 emit_warning(c, source_loc, "unresolved array element type");
986 return nullptr;
987 }
988 AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(),
989 child_qt.isVolatileQualified(), child_type_node);
990 return pointer_node;
991 }
979 case Type::BlockPointer:992 case Type::BlockPointer:
980 case Type::LValueReference:993 case Type::LValueReference:
981 case Type::RValueReference:994 case Type::RValueReference:
982 case Type::MemberPointer:995 case Type::MemberPointer:
983 case Type::IncompleteArray:
984 case Type::VariableArray:996 case Type::VariableArray:
985 case Type::DependentSizedArray:997 case Type::DependentSizedArray:
986 case Type::DependentSizedExtVector:998 case Type::DependentSizedExtVector:
...@@ -4301,7 +4313,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch...@@ -4301,7 +4313,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
4301 }4313 }
4302 }4314 }
43034315
4304 return 0;4316 return ErrorUnexpected;
4305 }4317 }
43064318
4307 c->ctx = &ast_unit->getASTContext();4319 c->ctx = &ast_unit->getASTContext();
test/translate_c.zig+10
...@@ -1178,4 +1178,14 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -1178,4 +1178,14 @@ pub fn addCases(cases: &tests.TranslateCContext) {
1178 ,1178 ,
1179 \\pub var v0: ?&const u8 = c"0.0.0";1179 \\pub var v0: ?&const u8 = c"0.0.0";
1180 );1180 );
1181
1182 cases.add("static incomplete array inside function",
1183 \\void foo(void) {
1184 \\ static const char v2[] = "2.2.2";
1185 \\}
1186 ,
1187 \\pub fn foo() {
1188 \\ const v2: &const u8 = c"2.2.2";
1189 \\}
1190 );
1181}1191}