diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-04-11 03:57:53 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-04-11 03:59:12 -0400 |
| commit | dff201540f91bb41b44d7f73a11f4082f928cff7 (patch) | |
| tree | f5ec4c9f617cecb7a88e92f125a1382f8ef5827d /src/zig_clang.cpp | |
| parent | 8f5753ba9f1fd43f14628e143d33d6e8a64847f0 (diff) | |
| download | zig-dff201540f91bb41b44d7f73a11f4082f928cff7.tar.gz zig-dff201540f91bb41b44d7f73a11f4082f928cff7.zip | |
translate-c: move some code to the C API
See #1964
Diffstat (limited to 'src/zig_clang.cpp')
| -rw-r--r-- | src/zig_clang.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/zig_clang.cpp b/src/zig_clang.cpp index 230c3c3116..7c0c787e43 100644 --- a/src/zig_clang.cpp +++ b/src/zig_clang.cpp @@ -212,3 +212,48 @@ bool ZigClangASTUnit_visitLocalTopLevelDecls(ZigClangASTUnit *self, void *contex return reinterpret_cast<clang::ASTUnit *>(self)->visitLocalTopLevelDecls(context, reinterpret_cast<bool (*)(void *, const clang::Decl *)>(Fn)); } + +const ZigClangRecordDecl *ZigClangRecordType_getDecl(const ZigClangRecordType *record_ty) { + const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordType *>(record_ty)->getDecl(); + return reinterpret_cast<const ZigClangRecordDecl *>(record_decl); +} + +const ZigClangTagDecl *ZigClangRecordDecl_getCanonicalDecl(const ZigClangRecordDecl *record_decl) { + const clang::TagDecl *tag_decl = reinterpret_cast<const clang::RecordDecl*>(record_decl)->getCanonicalDecl(); + return reinterpret_cast<const ZigClangTagDecl *>(tag_decl); +} + +const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *zig_record_decl) { + const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl); + const clang::RecordDecl *definition = record_decl->getDefinition(); + return reinterpret_cast<const ZigClangRecordDecl *>(definition); +} + +bool ZigClangRecordDecl_isUnion(const ZigClangRecordDecl *record_decl) { + return reinterpret_cast<const clang::RecordDecl*>(record_decl)->isUnion(); +} + +bool ZigClangRecordDecl_isStruct(const ZigClangRecordDecl *record_decl) { + return reinterpret_cast<const clang::RecordDecl*>(record_decl)->isStruct(); +} + +bool ZigClangRecordDecl_isAnonymousStructOrUnion(const ZigClangRecordDecl *record_decl) { + return reinterpret_cast<const clang::RecordDecl*>(record_decl)->isAnonymousStructOrUnion(); +} + +const char *ZigClangDecl_getName_bytes_begin(const ZigClangDecl *zig_decl) { + const clang::Decl *decl = reinterpret_cast<const clang::Decl *>(zig_decl); + const clang::NamedDecl *named_decl = static_cast<const clang::NamedDecl *>(decl); + return (const char *)named_decl->getName().bytes_begin(); +} + +ZigClangSourceLocation ZigClangRecordDecl_getLocation(const ZigClangRecordDecl *zig_record_decl) { + const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl); + return bitcast(record_decl->getLocation()); +} + +bool ZigClangSourceLocation_eq(ZigClangSourceLocation zig_a, ZigClangSourceLocation zig_b) { + clang::SourceLocation a = bitcast(zig_a); + clang::SourceLocation b = bitcast(zig_b); + return a == b; +} |
