authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-17 16:18:18+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-19 01:05:17+00:00
loged956b581283824da1f7d39b953f4d716928eee2
tree0379cf03da67cec831bb3b0bd16ebf4cfc385e71
parent0c33ebb38eeb383da62a8af8aa368e8f6cac63a2

translate-c: add support for MacroQualified definitions


5 files changed, 26 insertions(+), 1 deletions(-)

src-self-hosted/clang.zig+4
...@@ -42,6 +42,7 @@ pub const struct_ZigClangImplicitCastExpr = @OpaqueType();...@@ -42,6 +42,7 @@ pub const struct_ZigClangImplicitCastExpr = @OpaqueType();
42pub const struct_ZigClangIncompleteArrayType = @OpaqueType();42pub const struct_ZigClangIncompleteArrayType = @OpaqueType();
43pub const struct_ZigClangIntegerLiteral = @OpaqueType();43pub const struct_ZigClangIntegerLiteral = @OpaqueType();
44pub const struct_ZigClangMacroDefinitionRecord = @OpaqueType();44pub const struct_ZigClangMacroDefinitionRecord = @OpaqueType();
45pub const struct_ZigClangMacroQualifiedType = @OpaqueType();
45pub const struct_ZigClangMemberExpr = @OpaqueType();46pub const struct_ZigClangMemberExpr = @OpaqueType();
46pub const struct_ZigClangNamedDecl = @OpaqueType();47pub const struct_ZigClangNamedDecl = @OpaqueType();
47pub const struct_ZigClangNone = @OpaqueType();48pub const struct_ZigClangNone = @OpaqueType();
...@@ -831,6 +832,7 @@ pub const ZigClangImplicitCastExpr = struct_ZigClangImplicitCastExpr;...@@ -831,6 +832,7 @@ pub const ZigClangImplicitCastExpr = struct_ZigClangImplicitCastExpr;
831pub const ZigClangIncompleteArrayType = struct_ZigClangIncompleteArrayType;832pub const ZigClangIncompleteArrayType = struct_ZigClangIncompleteArrayType;
832pub const ZigClangIntegerLiteral = struct_ZigClangIntegerLiteral;833pub const ZigClangIntegerLiteral = struct_ZigClangIntegerLiteral;
833pub const ZigClangMacroDefinitionRecord = struct_ZigClangMacroDefinitionRecord;834pub const ZigClangMacroDefinitionRecord = struct_ZigClangMacroDefinitionRecord;
835pub const ZigClangMacroQualifiedType = struct_ZigClangMacroQualifiedType;
834pub const ZigClangMemberExpr = struct_ZigClangMemberExpr;836pub const ZigClangMemberExpr = struct_ZigClangMemberExpr;
835pub const ZigClangNamedDecl = struct_ZigClangNamedDecl;837pub const ZigClangNamedDecl = struct_ZigClangNamedDecl;
836pub const ZigClangNone = struct_ZigClangNone;838pub const ZigClangNone = struct_ZigClangNone;
...@@ -937,6 +939,8 @@ pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType)...@@ -937,6 +939,8 @@ pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType)
937939
938pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType;940pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType;
939941
942pub extern fn ZigClangMacroQualifiedType_getModifiedType(*const ZigClangMacroQualifiedType) ZigClangQualType;
943
940pub extern fn ZigClangCStyleCastExpr_getBeginLoc(*const ZigClangCStyleCastExpr) ZigClangSourceLocation;944pub extern fn ZigClangCStyleCastExpr_getBeginLoc(*const ZigClangCStyleCastExpr) ZigClangSourceLocation;
941pub extern fn ZigClangCStyleCastExpr_getSubExpr(*const ZigClangCStyleCastExpr) *const ZigClangExpr;945pub extern fn ZigClangCStyleCastExpr_getSubExpr(*const ZigClangCStyleCastExpr) *const ZigClangExpr;
942pub extern fn ZigClangCStyleCastExpr_getType(*const ZigClangCStyleCastExpr) ZigClangQualType;946pub extern fn ZigClangCStyleCastExpr_getType(*const ZigClangCStyleCastExpr) ZigClangQualType;
src/translate_c.cpp+5-1
...@@ -1213,6 +1213,11 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc...@@ -1213,6 +1213,11 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc
1213 const ZigClangAttributedType *attributed_ty = reinterpret_cast<const ZigClangAttributedType *>(ty);1213 const ZigClangAttributedType *attributed_ty = reinterpret_cast<const ZigClangAttributedType *>(ty);
1214 return trans_qual_type(c, ZigClangAttributedType_getEquivalentType(attributed_ty), source_loc);1214 return trans_qual_type(c, ZigClangAttributedType_getEquivalentType(attributed_ty), source_loc);
1215 }1215 }
1216 case ZigClangType_MacroQualified:
1217 {
1218 const ZigClangMacroQualifiedType *macroqualified_ty = reinterpret_cast<const ZigClangMacroQualifiedType *>(ty);
1219 return trans_qual_type(c, ZigClangMacroQualifiedType_getModifiedType(macroqualified_ty), source_loc);
1220 }
1216 case ZigClangType_IncompleteArray:1221 case ZigClangType_IncompleteArray:
1217 {1222 {
1218 const ZigClangIncompleteArrayType *incomplete_array_ty = reinterpret_cast<const ZigClangIncompleteArrayType *>(ty);1223 const ZigClangIncompleteArrayType *incomplete_array_ty = reinterpret_cast<const ZigClangIncompleteArrayType *>(ty);
...@@ -1262,7 +1267,6 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc...@@ -1262,7 +1267,6 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc
1262 case ZigClangType_DeducedTemplateSpecialization:1267 case ZigClangType_DeducedTemplateSpecialization:
1263 case ZigClangType_DependentAddressSpace:1268 case ZigClangType_DependentAddressSpace:
1264 case ZigClangType_DependentVector:1269 case ZigClangType_DependentVector:
1265 case ZigClangType_MacroQualified:
1266 emit_warning(c, source_loc, "unsupported type: '%s'", ZigClangType_getTypeClassName(ty));1270 emit_warning(c, source_loc, "unsupported type: '%s'", ZigClangType_getTypeClassName(ty));
1267 return nullptr;1271 return nullptr;
1268 }1272 }
src/zig_clang.cpp+5
...@@ -2214,6 +2214,11 @@ struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct Zi...@@ -2214,6 +2214,11 @@ struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct Zi
2214 return bitcast(casted->getEquivalentType());2214 return bitcast(casted->getEquivalentType());
2215}2215}
22162216
2217struct ZigClangQualType ZigClangMacroQualifiedType_getModifiedType(const struct ZigClangMacroQualifiedType *self) {
2218 auto casted = reinterpret_cast<const clang::MacroQualifiedType *>(self);
2219 return bitcast(casted->getModifiedType());
2220}
2221
2217struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *self) {2222struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *self) {
2218 auto casted = reinterpret_cast<const clang::ElaboratedType *>(self);2223 auto casted = reinterpret_cast<const clang::ElaboratedType *>(self);
2219 return bitcast(casted->getNamedType());2224 return bitcast(casted->getNamedType());
src/zig_clang.h+3
...@@ -112,6 +112,7 @@ struct ZigClangImplicitCastExpr;...@@ -112,6 +112,7 @@ struct ZigClangImplicitCastExpr;
112struct ZigClangIncompleteArrayType;112struct ZigClangIncompleteArrayType;
113struct ZigClangIntegerLiteral;113struct ZigClangIntegerLiteral;
114struct ZigClangMacroDefinitionRecord;114struct ZigClangMacroDefinitionRecord;
115struct ZigClangMacroQualifiedType;
115struct ZigClangMemberExpr;116struct ZigClangMemberExpr;
116struct ZigClangNamedDecl;117struct ZigClangNamedDecl;
117struct ZigClangNone;118struct ZigClangNone;
...@@ -1004,6 +1005,8 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangParenType_getInnerType(const struct...@@ -1004,6 +1005,8 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangParenType_getInnerType(const struct
10041005
1005ZIG_EXTERN_C struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct ZigClangAttributedType *);1006ZIG_EXTERN_C struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct ZigClangAttributedType *);
10061007
1008ZIG_EXTERN_C struct ZigClangQualType ZigClangMacroQualifiedType_getModifiedType(const struct ZigClangMacroQualifiedType *);
1009
1007ZIG_EXTERN_C struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *);1010ZIG_EXTERN_C struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *);
1008ZIG_EXTERN_C enum ZigClangElaboratedTypeKeyword ZigClangElaboratedType_getKeyword(const struct ZigClangElaboratedType *);1011ZIG_EXTERN_C enum ZigClangElaboratedTypeKeyword ZigClangElaboratedType_getKeyword(const struct ZigClangElaboratedType *);
10091012
test/translate_c.zig+9
...@@ -1814,6 +1814,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1814,6 +1814,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1814 \\1814 \\
1815 );1815 );
18161816
1817 if (builtin.os != builtin.Os.windows) {
1818 // sysv_abi not currently supported on windows
1819 cases.add("Macro qualified functions",
1820 \\void __attribute__((sysv_abi)) foo(void);
1821 ,
1822 \\pub extern fn foo() void;
1823 );
1824 }
1825
1817 /////////////// Cases for only stage1 because stage2 behavior is better ////////////////1826 /////////////// Cases for only stage1 because stage2 behavior is better ////////////////
1818 cases.addC("Parameterless function prototypes",1827 cases.addC("Parameterless function prototypes",
1819 \\void foo() {}1828 \\void foo() {}