translate-c: move some code to the C API

See #1964
This commit is contained in:
Andrew Kelley
2019-04-16 04:32:26 -04:00
parent f488f3fd03
commit 3226b5315e
3 changed files with 218 additions and 70 deletions

View File

@@ -28,7 +28,7 @@
#endif
// Detect additions to the enum
void zig2clang_BO(clang::BinaryOperatorKind op) {
void ZigClang_detect_enum_BO(clang::BinaryOperatorKind op) {
switch (op) {
case clang::BO_PtrMemD:
case clang::BO_PtrMemI:
@@ -102,7 +102,7 @@ static_assert((clang::BinaryOperatorKind)ZigClangBO_Xor == clang::BO_Xor, "");
static_assert((clang::BinaryOperatorKind)ZigClangBO_XorAssign == clang::BO_XorAssign, "");
// Detect additions to the enum
void zig2clang_UO(clang::UnaryOperatorKind op) {
void ZigClang_detect_enum_UO(clang::UnaryOperatorKind op) {
switch (op) {
case clang::UO_AddrOf:
case clang::UO_Coawait:
@@ -138,7 +138,7 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, "
static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, "");
// Detect additions to the enum
void zig2clang_CK(clang::CastKind x) {
void ZigClang_detect_enum_CK(clang::CastKind x) {
switch (x) {
case clang::CK_ARCConsumeObject:
case clang::CK_ARCExtendBlockObject:
@@ -264,7 +264,7 @@ static_assert((clang::CastKind)ZigClangCK_AddressSpaceConversion == clang::CK_Ad
static_assert((clang::CastKind)ZigClangCK_IntToOCLSampler == clang::CK_IntToOCLSampler, "");
// Detect additions to the enum
void zig2clang_TypeClass(clang::Type::TypeClass ty) {
void ZigClang_detect_enum_TypeClass(clang::Type::TypeClass ty) {
switch (ty) {
case clang::Type::Builtin:
case clang::Type::Complex:
@@ -366,7 +366,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_Pipe == clang::Type::Pipe, ""
static_assert((clang::Type::TypeClass)ZigClangType_Atomic == clang::Type::Atomic, "");
// Detect additions to the enum
void zig2clang_StmtClass(clang::Stmt::StmtClass x) {
void ZigClang_detect_enum_StmtClass(clang::Stmt::StmtClass x) {
switch (x) {
case clang::Stmt::NoStmtClass:
case clang::Stmt::NullStmtClass:
@@ -767,6 +767,37 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeParal
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeParallelForSimdDirectiveClass == clang::Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeSimdDirectiveClass == clang::Stmt::OMPTargetTeamsDistributeSimdDirectiveClass, "");
void ZigClang_detect_enum_APValueKind(clang::APValue::ValueKind x) {
switch (x) {
case clang::APValue::Uninitialized:
case clang::APValue::Int:
case clang::APValue::Float:
case clang::APValue::ComplexInt:
case clang::APValue::ComplexFloat:
case clang::APValue::LValue:
case clang::APValue::Vector:
case clang::APValue::Array:
case clang::APValue::Struct:
case clang::APValue::Union:
case clang::APValue::MemberPointer:
case clang::APValue::AddrLabelDiff:
break;
}
}
static_assert((clang::APValue::ValueKind)ZigClangAPValueUninitialized == clang::APValue::Uninitialized, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueInt == clang::APValue::Int, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueFloat == clang::APValue::Float, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueComplexInt == clang::APValue::ComplexInt, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueComplexFloat == clang::APValue::ComplexFloat, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueLValue == clang::APValue::LValue, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueVector == clang::APValue::Vector, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueArray == clang::APValue::Array, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueStruct == clang::APValue::Struct, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueUnion == clang::APValue::Union, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueMemberPointer == clang::APValue::MemberPointer, "");
static_assert((clang::APValue::ValueKind)ZigClangAPValueAddrLabelDiff == clang::APValue::AddrLabelDiff, "");
static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), "");
static ZigClangSourceLocation bitcast(clang::SourceLocation src) {
@@ -792,6 +823,18 @@ static clang::QualType bitcast(ZigClangQualType src) {
return dest;
}
static_assert(sizeof(ZigClangAPValueLValueBase) == sizeof(clang::APValue::LValueBase), "");
static ZigClangAPValueLValueBase bitcast(clang::APValue::LValueBase src) {
ZigClangAPValueLValueBase dest;
memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangAPValueLValueBase));
return dest;
}
static clang::APValue::LValueBase bitcast(ZigClangAPValueLValueBase src) {
clang::APValue::LValueBase dest;
memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangAPValueLValueBase));
return dest;
}
ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self,
ZigClangSourceLocation Loc)
{
@@ -1026,3 +1069,81 @@ ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self) {
auto casted = reinterpret_cast<const clang::Expr *>(self);
return bitcast(casted->getBeginLoc());
}
ZigClangAPValueKind ZigClangAPValue_getKind(const ZigClangAPValue *self) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
return (ZigClangAPValueKind)casted->getKind();
}
const ZigClangAPSInt *ZigClangAPValue_getInt(const ZigClangAPValue *self) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
const llvm::APSInt *result = &casted->getInt();
return reinterpret_cast<const ZigClangAPSInt *>(result);
}
unsigned ZigClangAPValue_getArrayInitializedElts(const ZigClangAPValue *self) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
return casted->getArrayInitializedElts();
}
const ZigClangAPValue *ZigClangAPValue_getArrayInitializedElt(const ZigClangAPValue *self, unsigned i) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
const clang::APValue *result = &casted->getArrayInitializedElt(i);
return reinterpret_cast<const ZigClangAPValue *>(result);
}
const ZigClangAPValue *ZigClangAPValue_getArrayFiller(const ZigClangAPValue *self) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
const clang::APValue *result = &casted->getArrayFiller();
return reinterpret_cast<const ZigClangAPValue *>(result);
}
unsigned ZigClangAPValue_getArraySize(const ZigClangAPValue *self) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
return casted->getArraySize();
}
const ZigClangAPSInt *ZigClangAPSInt_negate(const ZigClangAPSInt *self) {
auto casted = reinterpret_cast<const llvm::APSInt *>(self);
llvm::APSInt *result = new llvm::APSInt();
*result = *casted;
*result = -*result;
return reinterpret_cast<const ZigClangAPSInt *>(result);
}
void ZigClangAPSInt_free(const ZigClangAPSInt *self) {
auto casted = reinterpret_cast<const llvm::APSInt *>(self);
delete casted;
}
bool ZigClangAPSInt_isSigned(const ZigClangAPSInt *self) {
auto casted = reinterpret_cast<const llvm::APSInt *>(self);
return casted->isSigned();
}
bool ZigClangAPSInt_isNegative(const ZigClangAPSInt *self) {
auto casted = reinterpret_cast<const llvm::APSInt *>(self);
return casted->isNegative();
}
const uint64_t *ZigClangAPSInt_getRawData(const ZigClangAPSInt *self) {
auto casted = reinterpret_cast<const llvm::APSInt *>(self);
return casted->getRawData();
}
unsigned ZigClangAPSInt_getNumWords(const ZigClangAPSInt *self) {
auto casted = reinterpret_cast<const llvm::APSInt *>(self);
return casted->getNumWords();
}
const ZigClangExpr *ZigClangAPValueLValueBase_dyn_cast_Expr(ZigClangAPValueLValueBase self) {
clang::APValue::LValueBase casted = bitcast(self);
const clang::Expr *expr = casted.dyn_cast<const clang::Expr *>();
return reinterpret_cast<const ZigClangExpr *>(expr);
}
ZigClangAPValueLValueBase ZigClangAPValue_getLValueBase(const ZigClangAPValue *self) {
auto casted = reinterpret_cast<const clang::APValue *>(self);
clang::APValue::LValueBase lval_base = casted->getLValueBase();
return bitcast(lval_base);
}