translate-c: move some code to the C API

See #1964
This commit is contained in:
Andrew Kelley
2019-04-11 15:33:05 -04:00
parent 4172fe986e
commit b960f1d922
3 changed files with 60 additions and 24 deletions

View File

@@ -218,17 +218,33 @@ const ZigClangRecordDecl *ZigClangRecordType_getDecl(const ZigClangRecordType *r
return reinterpret_cast<const ZigClangRecordDecl *>(record_decl);
}
const ZigClangEnumDecl *ZigClangEnumType_getDecl(const ZigClangEnumType *enum_ty) {
const clang::EnumDecl *enum_decl = reinterpret_cast<const clang::EnumType *>(enum_ty)->getDecl();
return reinterpret_cast<const ZigClangEnumDecl *>(enum_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 ZigClangTagDecl *ZigClangEnumDecl_getCanonicalDecl(const ZigClangEnumDecl *enum_decl) {
const clang::TagDecl *tag_decl = reinterpret_cast<const clang::EnumDecl*>(enum_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);
}
const ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const ZigClangEnumDecl *zig_enum_decl) {
const clang::EnumDecl *enum_decl = reinterpret_cast<const clang::EnumDecl *>(zig_enum_decl);
const clang::EnumDecl *definition = enum_decl->getDefinition();
return reinterpret_cast<const ZigClangEnumDecl *>(definition);
}
bool ZigClangRecordDecl_isUnion(const ZigClangRecordDecl *record_decl) {
return reinterpret_cast<const clang::RecordDecl*>(record_decl)->isUnion();
}
@@ -252,8 +268,17 @@ ZigClangSourceLocation ZigClangRecordDecl_getLocation(const ZigClangRecordDecl *
return bitcast(record_decl->getLocation());
}
ZigClangSourceLocation ZigClangEnumDecl_getLocation(const ZigClangEnumDecl *self) {
auto casted = reinterpret_cast<const clang::EnumDecl *>(self);
return bitcast(casted->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;
}
ZigClangQualType ZigClangEnumDecl_getIntegerType(const ZigClangEnumDecl *self) {
return bitcast(reinterpret_cast<const clang::EnumDecl *>(self)->getIntegerType());
}