Skip to content

Commit 7729f6c

Browse files
committedNov 30, 2017
translate-c: support static incomplete array inside function
1 parent 716b0b8 commit 7729f6c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
 

‎src/translate_c.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,23 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
976976
const AttributedType *attributed_ty = static_cast<const AttributedType *>(ty);
977977
return trans_qual_type(c, attributed_ty->getEquivalentType(), source_loc);
978978
}
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+
}
979992
case Type::BlockPointer:
980993
case Type::LValueReference:
981994
case Type::RValueReference:
982995
case Type::MemberPointer:
983-
case Type::IncompleteArray:
984996
case Type::VariableArray:
985997
case Type::DependentSizedArray:
986998
case Type::DependentSizedExtVector:
@@ -4301,7 +4313,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
43014313
}
43024314
}
43034315

4304-
return 0;
4316+
return ErrorUnexpected;
43054317
}
43064318

43074319
c->ctx = &ast_unit->getASTContext();

‎test/translate_c.zig

+10
Original file line numberDiff line numberDiff line change
@@ -1178,4 +1178,14 @@ pub fn addCases(cases: &tests.TranslateCContext) {
11781178
,
11791179
\\pub var v0: ?&const u8 = c"0.0.0";
11801180
);
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+
);
11811191
}

0 commit comments

Comments
 (0)
Please sign in to comment.