diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-04-16 04:32:26 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-04-16 04:32:48 -0400 |
| commit | 3226b5315e4caa8fc8aaffaa258b07b212f230b1 (patch) | |
| tree | 690be370579aa290d345a85aa61e26cb6602e8d9 /src/zig_clang.cpp | |
| parent | f488f3fd03d12ea02240855d4784cc2e283af7ed (diff) | |
| download | zig-3226b5315e4caa8fc8aaffaa258b07b212f230b1.tar.gz zig-3226b5315e4caa8fc8aaffaa258b07b212f230b1.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 | 131 |
1 files changed, 126 insertions, 5 deletions
diff --git a/src/zig_clang.cpp b/src/zig_clang.cpp index 49385ae35b..6142c808ad 100644 --- a/src/zig_clang.cpp +++ b/src/zig_clang.cpp @@ -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); +} |
