From 3e14f86f9e703a4d189aab5e2f27c1029927c9e9 Mon Sep 17 00:00:00 2001 From: hryx Date: Wed, 29 May 2019 15:33:44 -0700 Subject: [PATCH] Implement missing clang functions from last commit --- src-self-hosted/clang.zig | 7 +++++++ src-self-hosted/translate_c.zig | 4 ++-- src/zig_clang.cpp | 20 ++++++++++++++++++++ src/zig_clang.h | 7 +++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src-self-hosted/clang.zig b/src-self-hosted/clang.zig index 108204d401..4bc027dfa8 100644 --- a/src-self-hosted/clang.zig +++ b/src-self-hosted/clang.zig @@ -479,6 +479,7 @@ pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: str pub extern fn ZigClangTypedefType_getDecl(arg0: ?*const struct_ZigClangTypedefType) ?*const struct_ZigClangTypedefNameDecl; pub extern fn ZigClangTypedefNameDecl_getUnderlyingType(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangQualType; pub extern fn ZigClangQualType_getCanonicalType(arg0: struct_ZigClangQualType) struct_ZigClangQualType; +pub extern fn ZigClangQualType_getTypeClass(self: struct_ZigClangQualType) ZigClangTypeClass; pub extern fn ZigClangQualType_getTypePtr(self: struct_ZigClangQualType) *const struct_ZigClangType; pub extern fn ZigClangQualType_addConst(arg0: [*c]struct_ZigClangQualType) void; pub extern fn ZigClangQualType_eq(arg0: struct_ZigClangQualType, arg1: struct_ZigClangQualType) bool; @@ -887,3 +888,9 @@ pub extern fn ZigClangImplicitCastExpr_getSubExpr(*const ZigClangImplicitCastExp pub extern fn ZigClangArrayType_getElementType(*const ZigClangArrayType) ZigClangQualType; pub extern fn ZigClangDeclRefExpr_getDecl(*const ZigClangDeclRefExpr) *const ZigClangValueDecl; + +pub extern fn ZigClangParenType_getInnerType(*const ZigClangParenType) ZigClangQualType; + +pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType) ZigClangQualType; + +pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType; diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 017b861458..a7818de67c 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -638,12 +638,12 @@ fn qualTypeChildIsFnProto(qt: ZigClangQualType) bool { const ty = ZigClangQualType_getTypePtr(qt); if (ZigClangType_getTypeClass(ty) == .Paren) { const paren_type = @ptrCast(*const ZigClangParenType, ty); - const inner_type = ZigClangParenType_getInnerType(ty); + const inner_type = ZigClangParenType_getInnerType(paren_type); return ZigClangQualType_getTypeClass(inner_type) == .FunctionProto; } if (ZigClangType_getTypeClass(ty) == .Attributed) { const attr_type = @ptrCast(*const ZigClangAttributedType, ty); - return qualTypeChildIsFnProto(bitcast(ZigClangAttributedType_getEquivalentType(attr_type))); + return qualTypeChildIsFnProto(ZigClangAttributedType_getEquivalentType(attr_type)); } return false; } diff --git a/src/zig_clang.cpp b/src/zig_clang.cpp index 251c50ae73..a4c5dfe058 100644 --- a/src/zig_clang.cpp +++ b/src/zig_clang.cpp @@ -1546,6 +1546,11 @@ const ZigClangType *ZigClangQualType_getTypePtr(ZigClangQualType self) { return reinterpret_cast(ty); } +ZigClangTypeClass ZigClangQualType_getTypeClass(ZigClangQualType self) { + clang::QualType ty = bitcast(self); + return (ZigClangTypeClass)(ty->getTypeClass()); +} + void ZigClangQualType_addConst(ZigClangQualType *self) { reinterpret_cast(self)->addConst(); } @@ -1944,3 +1949,18 @@ const struct ZigClangValueDecl *ZigClangDeclRefExpr_getDecl(const struct ZigClan auto casted = reinterpret_cast(self); return reinterpret_cast(casted->getDecl()); } + +struct ZigClangQualType ZigClangParenType_getInnerType(const struct ZigClangParenType *self) { + auto casted = reinterpret_cast(self); + return bitcast(casted->getInnerType()); +} + +struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct ZigClangAttributedType *self) { + auto casted = reinterpret_cast(self); + return bitcast(casted->getEquivalentType()); +} + +struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *self) { + auto casted = reinterpret_cast(self); + return bitcast(casted->getNamedType()); +} diff --git a/src/zig_clang.h b/src/zig_clang.h index 086fd7a029..21cc25eb24 100644 --- a/src/zig_clang.h +++ b/src/zig_clang.h @@ -807,6 +807,7 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangTypedefNameDecl_getUnderlyingType(c ZIG_EXTERN_C struct ZigClangQualType ZigClangQualType_getCanonicalType(struct ZigClangQualType); ZIG_EXTERN_C const struct ZigClangType *ZigClangQualType_getTypePtr(struct ZigClangQualType); +ZIG_EXTERN_C enum ZigClangTypeClass ZigClangQualType_getTypeClass(struct ZigClangQualType); ZIG_EXTERN_C void ZigClangQualType_addConst(struct ZigClangQualType *); ZIG_EXTERN_C bool ZigClangQualType_eq(struct ZigClangQualType, struct ZigClangQualType); ZIG_EXTERN_C bool ZigClangQualType_isConstQualified(struct ZigClangQualType); @@ -878,4 +879,10 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangArrayType_getElementType(const stru ZIG_EXTERN_C const struct ZigClangValueDecl *ZigClangDeclRefExpr_getDecl(const struct ZigClangDeclRefExpr *); +ZIG_EXTERN_C struct ZigClangQualType ZigClangParenType_getInnerType(const struct ZigClangParenType *); + +ZIG_EXTERN_C struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct ZigClangAttributedType *); + +ZIG_EXTERN_C struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *); + #endif