| author | |
| committer | |
| log | 3226b5315e4caa8fc8aaffaa258b07b212f230b1 |
| tree | 690be370579aa290d345a85aa61e26cb6602e8d9 |
| parent | f488f3fd03d12ea02240855d4784cc2e283af7ed |
| signature |
See #19643 files changed, 218 insertions(+), 70 deletions(-)
src/translate_c.cpp+51-34| ... | @@ -125,7 +125,16 @@ static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope | ... | @@ -125,7 +125,16 @@ static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope |
| 125 | static AstNode *trans_qual_type(Context *c, ZigClangQualType qt, ZigClangSourceLocation source_loc); | 125 | static AstNode *trans_qual_type(Context *c, ZigClangQualType qt, ZigClangSourceLocation source_loc); |
| 126 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, | 126 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, |
| 127 | const ZigClangExpr *expr, TransLRValue lrval); | 127 | const ZigClangExpr *expr, TransLRValue lrval); |
| 128 | static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQualType qt, ZigClangSourceLocation source_loc); | 128 | static AstNode *trans_ap_value(Context *c, const ZigClangAPValue *ap_value, ZigClangQualType qt, |
| 129 | ZigClangSourceLocation source_loc); | ||
| 130 | |||
| 131 | static const ZigClangAPSInt *bitcast(const llvm::APSInt *src) { | ||
| 132 | return reinterpret_cast<const ZigClangAPSInt *>(src); | ||
| 133 | } | ||
| 134 | |||
| 135 | static const ZigClangAPValue *bitcast(const clang::APValue *src) { | ||
| 136 | return reinterpret_cast<const ZigClangAPValue *>(src); | ||
| 137 | } | ||
| 129 | 138 | ||
| 130 | static const ZigClangStmt *bitcast(const clang::Stmt *src) { | 139 | static const ZigClangStmt *bitcast(const clang::Stmt *src) { |
| 131 | return reinterpret_cast<const ZigClangStmt *>(src); | 140 | return reinterpret_cast<const ZigClangStmt *>(src); |
| ... | @@ -497,16 +506,21 @@ static Buf *string_ref_to_buf(llvm::StringRef string_ref) { | ... | @@ -497,16 +506,21 @@ static Buf *string_ref_to_buf(llvm::StringRef string_ref) { |
| 497 | return buf_create_from_mem((const char *)string_ref.bytes_begin(), string_ref.size()); | 506 | return buf_create_from_mem((const char *)string_ref.bytes_begin(), string_ref.size()); |
| 498 | } | 507 | } |
| 499 | 508 | ||
| 500 | static AstNode *trans_create_node_apint(Context *c, const llvm::APSInt &aps_int) { | 509 | static AstNode *trans_create_node_apint(Context *c, const ZigClangAPSInt *aps_int) { |
| 501 | AstNode *node = trans_create_node(c, NodeTypeIntLiteral); | 510 | AstNode *node = trans_create_node(c, NodeTypeIntLiteral); |
| 502 | node->data.int_literal.bigint = allocate<BigInt>(1); | 511 | node->data.int_literal.bigint = allocate<BigInt>(1); |
| 503 | bool is_negative = aps_int.isSigned() && aps_int.isNegative(); | 512 | bool is_negative = ZigClangAPSInt_isSigned(aps_int) && ZigClangAPSInt_isNegative(aps_int); |
| 504 | if (!is_negative) { | 513 | if (!is_negative) { |
| 505 | bigint_init_data(node->data.int_literal.bigint, aps_int.getRawData(), aps_int.getNumWords(), false); | 514 | bigint_init_data(node->data.int_literal.bigint, |
| 515 | ZigClangAPSInt_getRawData(aps_int), | ||
| 516 | ZigClangAPSInt_getNumWords(aps_int), | ||
| 517 | false); | ||
| 506 | return node; | 518 | return node; |
| 507 | } | 519 | } |
| 508 | llvm::APSInt negated = -aps_int; | 520 | const ZigClangAPSInt *negated = ZigClangAPSInt_negate(aps_int); |
| 509 | bigint_init_data(node->data.int_literal.bigint, negated.getRawData(), negated.getNumWords(), true); | 521 | bigint_init_data(node->data.int_literal.bigint, ZigClangAPSInt_getRawData(negated), |
| 522 | ZigClangAPSInt_getNumWords(negated), true); | ||
| 523 | ZigClangAPSInt_free(negated); | ||
| 510 | return node; | 524 | return node; |
| 511 | 525 | ||
| 512 | } | 526 | } |
| ... | @@ -1295,7 +1309,7 @@ static AstNode *trans_integer_literal(Context *c, ResultUsed result_used, const | ... | @@ -1295,7 +1309,7 @@ static AstNode *trans_integer_literal(Context *c, ResultUsed result_used, const |
| 1295 | emit_warning(c, bitcast(stmt->getBeginLoc()), "invalid integer literal"); | 1309 | emit_warning(c, bitcast(stmt->getBeginLoc()), "invalid integer literal"); |
| 1296 | return nullptr; | 1310 | return nullptr; |
| 1297 | } | 1311 | } |
| 1298 | AstNode *node = trans_create_node_apint(c, result.Val.getInt()); | 1312 | AstNode *node = trans_create_node_apint(c, bitcast(&result.Val.getInt())); |
| 1299 | return maybe_suppress_result(c, result_used, node); | 1313 | return maybe_suppress_result(c, result_used, node); |
| 1300 | } | 1314 | } |
| 1301 | 1315 | ||
| ... | @@ -1307,7 +1321,7 @@ static AstNode *trans_constant_expr(Context *c, ResultUsed result_used, const cl | ... | @@ -1307,7 +1321,7 @@ static AstNode *trans_constant_expr(Context *c, ResultUsed result_used, const cl |
| 1307 | emit_warning(c, bitcast(expr->getBeginLoc()), "invalid constant expression"); | 1321 | emit_warning(c, bitcast(expr->getBeginLoc()), "invalid constant expression"); |
| 1308 | return nullptr; | 1322 | return nullptr; |
| 1309 | } | 1323 | } |
| 1310 | AstNode *node = trans_ap_value(c, &result.Val, bitcast(expr->getType()), bitcast(expr->getBeginLoc())); | 1324 | AstNode *node = trans_ap_value(c, bitcast(&result.Val), bitcast(expr->getType()), bitcast(expr->getBeginLoc())); |
| 1311 | return maybe_suppress_result(c, result_used, node); | 1325 | return maybe_suppress_result(c, result_used, node); |
| 1312 | } | 1326 | } |
| 1313 | 1327 | ||
| ... | @@ -4103,7 +4117,8 @@ static AstNode *resolve_enum_decl(Context *c, const ZigClangEnumDecl *enum_decl) | ... | @@ -4103,7 +4117,8 @@ static AstNode *resolve_enum_decl(Context *c, const ZigClangEnumDecl *enum_decl) |
| 4103 | field_name = enum_val_name; | 4117 | field_name = enum_val_name; |
| 4104 | } | 4118 | } |
| 4105 | 4119 | ||
| 4106 | AstNode *int_node = pure_enum && !is_anonymous ? nullptr : trans_create_node_apint(c, enum_const->getInitVal()); | 4120 | AstNode *int_node = pure_enum && !is_anonymous ? |
| 4121 | nullptr : trans_create_node_apint(c, bitcast(&enum_const->getInitVal())); | ||
| 4107 | AstNode *field_node = trans_create_node(c, NodeTypeStructField); | 4122 | AstNode *field_node = trans_create_node(c, NodeTypeStructField); |
| 4108 | field_node->data.struct_field.name = field_name; | 4123 | field_node->data.struct_field.name = field_name; |
| 4109 | field_node->data.struct_field.type = nullptr; | 4124 | field_node->data.struct_field.type = nullptr; |
| ... | @@ -4245,17 +4260,19 @@ static AstNode *resolve_record_decl(Context *c, const ZigClangRecordDecl *record | ... | @@ -4245,17 +4260,19 @@ static AstNode *resolve_record_decl(Context *c, const ZigClangRecordDecl *record |
| 4245 | } | 4260 | } |
| 4246 | } | 4261 | } |
| 4247 | 4262 | ||
| 4248 | static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQualType qt, ZigClangSourceLocation source_loc) { | 4263 | static AstNode *trans_ap_value(Context *c, const ZigClangAPValue *ap_value, ZigClangQualType qt, |
| 4249 | switch (ap_value->getKind()) { | 4264 | ZigClangSourceLocation source_loc) |
| 4250 | case clang::APValue::Int: | 4265 | { |
| 4251 | return trans_create_node_apint(c, ap_value->getInt()); | 4266 | switch (ZigClangAPValue_getKind(ap_value)) { |
| 4252 | case clang::APValue::Uninitialized: | 4267 | case ZigClangAPValueInt: |
| 4268 | return trans_create_node_apint(c, ZigClangAPValue_getInt(ap_value)); | ||
| 4269 | case ZigClangAPValueUninitialized: | ||
| 4253 | return trans_create_node(c, NodeTypeUndefinedLiteral); | 4270 | return trans_create_node(c, NodeTypeUndefinedLiteral); |
| 4254 | case clang::APValue::Array: { | 4271 | case ZigClangAPValueArray: { |
| 4255 | emit_warning(c, source_loc, "TODO add a test case for this code"); | 4272 | emit_warning(c, source_loc, "TODO add a test case for this code"); |
| 4256 | 4273 | ||
| 4257 | unsigned init_count = ap_value->getArrayInitializedElts(); | 4274 | unsigned init_count = ZigClangAPValue_getArrayInitializedElts(ap_value); |
| 4258 | unsigned all_count = ap_value->getArraySize(); | 4275 | unsigned all_count = ZigClangAPValue_getArraySize(ap_value); |
| 4259 | unsigned leftover_count = all_count - init_count; | 4276 | unsigned leftover_count = all_count - init_count; |
| 4260 | AstNode *init_node = trans_create_node(c, NodeTypeContainerInitExpr); | 4277 | AstNode *init_node = trans_create_node(c, NodeTypeContainerInitExpr); |
| 4261 | AstNode *arr_type_node = trans_qual_type(c, qt, source_loc); | 4278 | AstNode *arr_type_node = trans_qual_type(c, qt, source_loc); |
| ... | @@ -4269,8 +4286,8 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua | ... | @@ -4269,8 +4286,8 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua |
| 4269 | ZigClangQualType child_qt = bitcast(qt_type->getAsArrayTypeUnsafe()->getElementType()); | 4286 | ZigClangQualType child_qt = bitcast(qt_type->getAsArrayTypeUnsafe()->getElementType()); |
| 4270 | 4287 | ||
| 4271 | for (size_t i = 0; i < init_count; i += 1) { | 4288 | for (size_t i = 0; i < init_count; i += 1) { |
| 4272 | clang::APValue &elem_ap_val = ap_value->getArrayInitializedElt(i); | 4289 | const ZigClangAPValue *elem_ap_val = ZigClangAPValue_getArrayInitializedElt(ap_value, i); |
| 4273 | AstNode *elem_node = trans_ap_value(c, &elem_ap_val, child_qt, source_loc); | 4290 | AstNode *elem_node = trans_ap_value(c, elem_ap_val, child_qt, source_loc); |
| 4274 | if (elem_node == nullptr) | 4291 | if (elem_node == nullptr) |
| 4275 | return nullptr; | 4292 | return nullptr; |
| 4276 | init_node->data.container_init_expr.entries.append(elem_node); | 4293 | init_node->data.container_init_expr.entries.append(elem_node); |
| ... | @@ -4279,8 +4296,8 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua | ... | @@ -4279,8 +4296,8 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua |
| 4279 | return init_node; | 4296 | return init_node; |
| 4280 | } | 4297 | } |
| 4281 | 4298 | ||
| 4282 | clang::APValue &filler_ap_val = ap_value->getArrayFiller(); | 4299 | const ZigClangAPValue *filler_ap_val = ZigClangAPValue_getArrayFiller(ap_value); |
| 4283 | AstNode *filler_node = trans_ap_value(c, &filler_ap_val, child_qt, source_loc); | 4300 | AstNode *filler_node = trans_ap_value(c, filler_ap_val, child_qt, source_loc); |
| 4284 | if (filler_node == nullptr) | 4301 | if (filler_node == nullptr) |
| 4285 | return nullptr; | 4302 | return nullptr; |
| 4286 | 4303 | ||
| ... | @@ -4307,37 +4324,37 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua | ... | @@ -4307,37 +4324,37 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua |
| 4307 | 4324 | ||
| 4308 | return trans_create_node_bin_op(c, init_node, BinOpTypeArrayCat, rhs_node); | 4325 | return trans_create_node_bin_op(c, init_node, BinOpTypeArrayCat, rhs_node); |
| 4309 | } | 4326 | } |
| 4310 | case clang::APValue::LValue: { | 4327 | case ZigClangAPValueLValue: { |
| 4311 | const clang::APValue::LValueBase lval_base = ap_value->getLValueBase(); | 4328 | const ZigClangAPValueLValueBase lval_base = ZigClangAPValue_getLValueBase(ap_value); |
| 4312 | if (const clang::Expr *expr = lval_base.dyn_cast<const clang::Expr *>()) { | 4329 | if (const ZigClangExpr *expr = ZigClangAPValueLValueBase_dyn_cast_Expr(lval_base)) { |
| 4313 | return trans_expr(c, ResultUsedYes, &c->global_scope->base, bitcast(expr), TransRValue); | 4330 | return trans_expr(c, ResultUsedYes, &c->global_scope->base, expr, TransRValue); |
| 4314 | } | 4331 | } |
| 4315 | //const clang::ValueDecl *value_decl = lval_base.get<const clang::ValueDecl *>(); | 4332 | //const clang::ValueDecl *value_decl = lval_base.get<const clang::ValueDecl *>(); |
| 4316 | emit_warning(c, source_loc, "TODO handle initializer LValue clang::ValueDecl"); | 4333 | emit_warning(c, source_loc, "TODO handle initializer LValue clang::ValueDecl"); |
| 4317 | return nullptr; | 4334 | return nullptr; |
| 4318 | } | 4335 | } |
| 4319 | case clang::APValue::Float: | 4336 | case ZigClangAPValueFloat: |
| 4320 | emit_warning(c, source_loc, "unsupported initializer value kind: Float"); | 4337 | emit_warning(c, source_loc, "unsupported initializer value kind: Float"); |
| 4321 | return nullptr; | 4338 | return nullptr; |
| 4322 | case clang::APValue::ComplexInt: | 4339 | case ZigClangAPValueComplexInt: |
| 4323 | emit_warning(c, source_loc, "unsupported initializer value kind: ComplexInt"); | 4340 | emit_warning(c, source_loc, "unsupported initializer value kind: ComplexInt"); |
| 4324 | return nullptr; | 4341 | return nullptr; |
| 4325 | case clang::APValue::ComplexFloat: | 4342 | case ZigClangAPValueComplexFloat: |
| 4326 | emit_warning(c, source_loc, "unsupported initializer value kind: ComplexFloat"); | 4343 | emit_warning(c, source_loc, "unsupported initializer value kind: ComplexFloat"); |
| 4327 | return nullptr; | 4344 | return nullptr; |
| 4328 | case clang::APValue::Vector: | 4345 | case ZigClangAPValueVector: |
| 4329 | emit_warning(c, source_loc, "unsupported initializer value kind: Vector"); | 4346 | emit_warning(c, source_loc, "unsupported initializer value kind: Vector"); |
| 4330 | return nullptr; | 4347 | return nullptr; |
| 4331 | case clang::APValue::Struct: | 4348 | case ZigClangAPValueStruct: |
| 4332 | emit_warning(c, source_loc, "unsupported initializer value kind: Struct"); | 4349 | emit_warning(c, source_loc, "unsupported initializer value kind: Struct"); |
| 4333 | return nullptr; | 4350 | return nullptr; |
| 4334 | case clang::APValue::Union: | 4351 | case ZigClangAPValueUnion: |
| 4335 | emit_warning(c, source_loc, "unsupported initializer value kind: Union"); | 4352 | emit_warning(c, source_loc, "unsupported initializer value kind: Union"); |
| 4336 | return nullptr; | 4353 | return nullptr; |
| 4337 | case clang::APValue::MemberPointer: | 4354 | case ZigClangAPValueMemberPointer: |
| 4338 | emit_warning(c, source_loc, "unsupported initializer value kind: MemberPointer"); | 4355 | emit_warning(c, source_loc, "unsupported initializer value kind: MemberPointer"); |
| 4339 | return nullptr; | 4356 | return nullptr; |
| 4340 | case clang::APValue::AddrLabelDiff: | 4357 | case ZigClangAPValueAddrLabelDiff: |
| 4341 | emit_warning(c, source_loc, "unsupported initializer value kind: AddrLabelDiff"); | 4358 | emit_warning(c, source_loc, "unsupported initializer value kind: AddrLabelDiff"); |
| 4342 | return nullptr; | 4359 | return nullptr; |
| 4343 | } | 4360 | } |
| ... | @@ -4374,7 +4391,7 @@ static void visit_var_decl(Context *c, const clang::VarDecl *var_decl) { | ... | @@ -4374,7 +4391,7 @@ static void visit_var_decl(Context *c, const clang::VarDecl *var_decl) { |
| 4374 | if (is_static && !is_extern) { | 4391 | if (is_static && !is_extern) { |
| 4375 | AstNode *init_node; | 4392 | AstNode *init_node; |
| 4376 | if (var_decl->hasInit()) { | 4393 | if (var_decl->hasInit()) { |
| 4377 | clang::APValue *ap_value = var_decl->evaluateValue(); | 4394 | const ZigClangAPValue *ap_value = bitcast(var_decl->evaluateValue()); |
| 4378 | if (ap_value == nullptr) { | 4395 | if (ap_value == nullptr) { |
| 4379 | emit_warning(c, bitcast(var_decl->getLocation()), | 4396 | emit_warning(c, bitcast(var_decl->getLocation()), |
| 4380 | "ignoring variable '%s' - unable to evaluate initializer", buf_ptr(name)); | 4397 | "ignoring variable '%s' - unable to evaluate initializer", buf_ptr(name)); |
src/zig_clang.cpp+126-5| ... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | // Detect additions to the enum | 30 | // Detect additions to the enum |
| 31 | void zig2clang_BO(clang::BinaryOperatorKind op) { | 31 | void ZigClang_detect_enum_BO(clang::BinaryOperatorKind op) { |
| 32 | switch (op) { | 32 | switch (op) { |
| 33 | case clang::BO_PtrMemD: | 33 | case clang::BO_PtrMemD: |
| 34 | case clang::BO_PtrMemI: | 34 | case clang::BO_PtrMemI: |
| ... | @@ -102,7 +102,7 @@ static_assert((clang::BinaryOperatorKind)ZigClangBO_Xor == clang::BO_Xor, ""); | ... | @@ -102,7 +102,7 @@ static_assert((clang::BinaryOperatorKind)ZigClangBO_Xor == clang::BO_Xor, ""); |
| 102 | static_assert((clang::BinaryOperatorKind)ZigClangBO_XorAssign == clang::BO_XorAssign, ""); | 102 | static_assert((clang::BinaryOperatorKind)ZigClangBO_XorAssign == clang::BO_XorAssign, ""); |
| 103 | 103 | ||
| 104 | // Detect additions to the enum | 104 | // Detect additions to the enum |
| 105 | void zig2clang_UO(clang::UnaryOperatorKind op) { | 105 | void ZigClang_detect_enum_UO(clang::UnaryOperatorKind op) { |
| 106 | switch (op) { | 106 | switch (op) { |
| 107 | case clang::UO_AddrOf: | 107 | case clang::UO_AddrOf: |
| 108 | case clang::UO_Coawait: | 108 | case clang::UO_Coawait: |
| ... | @@ -138,7 +138,7 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, " | ... | @@ -138,7 +138,7 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, " |
| 138 | static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, ""); | 138 | static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, ""); |
| 139 | 139 | ||
| 140 | // Detect additions to the enum | 140 | // Detect additions to the enum |
| 141 | void zig2clang_CK(clang::CastKind x) { | 141 | void ZigClang_detect_enum_CK(clang::CastKind x) { |
| 142 | switch (x) { | 142 | switch (x) { |
| 143 | case clang::CK_ARCConsumeObject: | 143 | case clang::CK_ARCConsumeObject: |
| 144 | case clang::CK_ARCExtendBlockObject: | 144 | case clang::CK_ARCExtendBlockObject: |
| ... | @@ -264,7 +264,7 @@ static_assert((clang::CastKind)ZigClangCK_AddressSpaceConversion == clang::CK_Ad | ... | @@ -264,7 +264,7 @@ static_assert((clang::CastKind)ZigClangCK_AddressSpaceConversion == clang::CK_Ad |
| 264 | static_assert((clang::CastKind)ZigClangCK_IntToOCLSampler == clang::CK_IntToOCLSampler, ""); | 264 | static_assert((clang::CastKind)ZigClangCK_IntToOCLSampler == clang::CK_IntToOCLSampler, ""); |
| 265 | 265 | ||
| 266 | // Detect additions to the enum | 266 | // Detect additions to the enum |
| 267 | void zig2clang_TypeClass(clang::Type::TypeClass ty) { | 267 | void ZigClang_detect_enum_TypeClass(clang::Type::TypeClass ty) { |
| 268 | switch (ty) { | 268 | switch (ty) { |
| 269 | case clang::Type::Builtin: | 269 | case clang::Type::Builtin: |
| 270 | case clang::Type::Complex: | 270 | case clang::Type::Complex: |
| ... | @@ -366,7 +366,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_Pipe == clang::Type::Pipe, "" | ... | @@ -366,7 +366,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_Pipe == clang::Type::Pipe, "" |
| 366 | static_assert((clang::Type::TypeClass)ZigClangType_Atomic == clang::Type::Atomic, ""); | 366 | static_assert((clang::Type::TypeClass)ZigClangType_Atomic == clang::Type::Atomic, ""); |
| 367 | 367 | ||
| 368 | // Detect additions to the enum | 368 | // Detect additions to the enum |
| 369 | void zig2clang_StmtClass(clang::Stmt::StmtClass x) { | 369 | void ZigClang_detect_enum_StmtClass(clang::Stmt::StmtClass x) { |
| 370 | switch (x) { | 370 | switch (x) { |
| 371 | case clang::Stmt::NoStmtClass: | 371 | case clang::Stmt::NoStmtClass: |
| 372 | case clang::Stmt::NullStmtClass: | 372 | case clang::Stmt::NullStmtClass: |
| ... | @@ -767,6 +767,37 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeParal | ... | @@ -767,6 +767,37 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeParal |
| 767 | static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeParallelForSimdDirectiveClass == clang::Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass, ""); | 767 | static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeParallelForSimdDirectiveClass == clang::Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass, ""); |
| 768 | static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeSimdDirectiveClass == clang::Stmt::OMPTargetTeamsDistributeSimdDirectiveClass, ""); | 768 | static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTargetTeamsDistributeSimdDirectiveClass == clang::Stmt::OMPTargetTeamsDistributeSimdDirectiveClass, ""); |
| 769 | 769 | ||
| 770 | void ZigClang_detect_enum_APValueKind(clang::APValue::ValueKind x) { | ||
| 771 | switch (x) { | ||
| 772 | case clang::APValue::Uninitialized: | ||
| 773 | case clang::APValue::Int: | ||
| 774 | case clang::APValue::Float: | ||
| 775 | case clang::APValue::ComplexInt: | ||
| 776 | case clang::APValue::ComplexFloat: | ||
| 777 | case clang::APValue::LValue: | ||
| 778 | case clang::APValue::Vector: | ||
| 779 | case clang::APValue::Array: | ||
| 780 | case clang::APValue::Struct: | ||
| 781 | case clang::APValue::Union: | ||
| 782 | case clang::APValue::MemberPointer: | ||
| 783 | case clang::APValue::AddrLabelDiff: | ||
| 784 | break; | ||
| 785 | } | ||
| 786 | } | ||
| 787 | |||
| 788 | static_assert((clang::APValue::ValueKind)ZigClangAPValueUninitialized == clang::APValue::Uninitialized, ""); | ||
| 789 | static_assert((clang::APValue::ValueKind)ZigClangAPValueInt == clang::APValue::Int, ""); | ||
| 790 | static_assert((clang::APValue::ValueKind)ZigClangAPValueFloat == clang::APValue::Float, ""); | ||
| 791 | static_assert((clang::APValue::ValueKind)ZigClangAPValueComplexInt == clang::APValue::ComplexInt, ""); | ||
| 792 | static_assert((clang::APValue::ValueKind)ZigClangAPValueComplexFloat == clang::APValue::ComplexFloat, ""); | ||
| 793 | static_assert((clang::APValue::ValueKind)ZigClangAPValueLValue == clang::APValue::LValue, ""); | ||
| 794 | static_assert((clang::APValue::ValueKind)ZigClangAPValueVector == clang::APValue::Vector, ""); | ||
| 795 | static_assert((clang::APValue::ValueKind)ZigClangAPValueArray == clang::APValue::Array, ""); | ||
| 796 | static_assert((clang::APValue::ValueKind)ZigClangAPValueStruct == clang::APValue::Struct, ""); | ||
| 797 | static_assert((clang::APValue::ValueKind)ZigClangAPValueUnion == clang::APValue::Union, ""); | ||
| 798 | static_assert((clang::APValue::ValueKind)ZigClangAPValueMemberPointer == clang::APValue::MemberPointer, ""); | ||
| 799 | static_assert((clang::APValue::ValueKind)ZigClangAPValueAddrLabelDiff == clang::APValue::AddrLabelDiff, ""); | ||
| 800 | |||
| 770 | 801 | ||
| 771 | static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), ""); | 802 | static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), ""); |
| 772 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { | 803 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { |
| ... | @@ -792,6 +823,18 @@ static clang::QualType bitcast(ZigClangQualType src) { | ... | @@ -792,6 +823,18 @@ static clang::QualType bitcast(ZigClangQualType src) { |
| 792 | return dest; | 823 | return dest; |
| 793 | } | 824 | } |
| 794 | 825 | ||
| 826 | static_assert(sizeof(ZigClangAPValueLValueBase) == sizeof(clang::APValue::LValueBase), ""); | ||
| 827 | static ZigClangAPValueLValueBase bitcast(clang::APValue::LValueBase src) { | ||
| 828 | ZigClangAPValueLValueBase dest; | ||
| 829 | memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangAPValueLValueBase)); | ||
| 830 | return dest; | ||
| 831 | } | ||
| 832 | static clang::APValue::LValueBase bitcast(ZigClangAPValueLValueBase src) { | ||
| 833 | clang::APValue::LValueBase dest; | ||
| 834 | memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangAPValueLValueBase)); | ||
| 835 | return dest; | ||
| 836 | } | ||
| 837 | |||
| 795 | ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self, | 838 | ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self, |
| 796 | ZigClangSourceLocation Loc) | 839 | ZigClangSourceLocation Loc) |
| 797 | { | 840 | { |
| ... | @@ -1026,3 +1069,81 @@ ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self) { | ... | @@ -1026,3 +1069,81 @@ ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self) { |
| 1026 | auto casted = reinterpret_cast<const clang::Expr *>(self); | 1069 | auto casted = reinterpret_cast<const clang::Expr *>(self); |
| 1027 | return bitcast(casted->getBeginLoc()); | 1070 | return bitcast(casted->getBeginLoc()); |
| 1028 | } | 1071 | } |
| 1072 | |||
| 1073 | ZigClangAPValueKind ZigClangAPValue_getKind(const ZigClangAPValue *self) { | ||
| 1074 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1075 | return (ZigClangAPValueKind)casted->getKind(); | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | const ZigClangAPSInt *ZigClangAPValue_getInt(const ZigClangAPValue *self) { | ||
| 1079 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1080 | const llvm::APSInt *result = &casted->getInt(); | ||
| 1081 | return reinterpret_cast<const ZigClangAPSInt *>(result); | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | unsigned ZigClangAPValue_getArrayInitializedElts(const ZigClangAPValue *self) { | ||
| 1085 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1086 | return casted->getArrayInitializedElts(); | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | const ZigClangAPValue *ZigClangAPValue_getArrayInitializedElt(const ZigClangAPValue *self, unsigned i) { | ||
| 1090 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1091 | const clang::APValue *result = &casted->getArrayInitializedElt(i); | ||
| 1092 | return reinterpret_cast<const ZigClangAPValue *>(result); | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | const ZigClangAPValue *ZigClangAPValue_getArrayFiller(const ZigClangAPValue *self) { | ||
| 1096 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1097 | const clang::APValue *result = &casted->getArrayFiller(); | ||
| 1098 | return reinterpret_cast<const ZigClangAPValue *>(result); | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | unsigned ZigClangAPValue_getArraySize(const ZigClangAPValue *self) { | ||
| 1102 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1103 | return casted->getArraySize(); | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | const ZigClangAPSInt *ZigClangAPSInt_negate(const ZigClangAPSInt *self) { | ||
| 1107 | auto casted = reinterpret_cast<const llvm::APSInt *>(self); | ||
| 1108 | llvm::APSInt *result = new llvm::APSInt(); | ||
| 1109 | *result = *casted; | ||
| 1110 | *result = -*result; | ||
| 1111 | return reinterpret_cast<const ZigClangAPSInt *>(result); | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | void ZigClangAPSInt_free(const ZigClangAPSInt *self) { | ||
| 1115 | auto casted = reinterpret_cast<const llvm::APSInt *>(self); | ||
| 1116 | delete casted; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | bool ZigClangAPSInt_isSigned(const ZigClangAPSInt *self) { | ||
| 1120 | auto casted = reinterpret_cast<const llvm::APSInt *>(self); | ||
| 1121 | return casted->isSigned(); | ||
| 1122 | } | ||
| 1123 | |||
| 1124 | bool ZigClangAPSInt_isNegative(const ZigClangAPSInt *self) { | ||
| 1125 | auto casted = reinterpret_cast<const llvm::APSInt *>(self); | ||
| 1126 | return casted->isNegative(); | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | const uint64_t *ZigClangAPSInt_getRawData(const ZigClangAPSInt *self) { | ||
| 1130 | auto casted = reinterpret_cast<const llvm::APSInt *>(self); | ||
| 1131 | return casted->getRawData(); | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | unsigned ZigClangAPSInt_getNumWords(const ZigClangAPSInt *self) { | ||
| 1135 | auto casted = reinterpret_cast<const llvm::APSInt *>(self); | ||
| 1136 | return casted->getNumWords(); | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | const ZigClangExpr *ZigClangAPValueLValueBase_dyn_cast_Expr(ZigClangAPValueLValueBase self) { | ||
| 1140 | clang::APValue::LValueBase casted = bitcast(self); | ||
| 1141 | const clang::Expr *expr = casted.dyn_cast<const clang::Expr *>(); | ||
| 1142 | return reinterpret_cast<const ZigClangExpr *>(expr); | ||
| 1143 | } | ||
| 1144 | |||
| 1145 | ZigClangAPValueLValueBase ZigClangAPValue_getLValueBase(const ZigClangAPValue *self) { | ||
| 1146 | auto casted = reinterpret_cast<const clang::APValue *>(self); | ||
| 1147 | clang::APValue::LValueBase lval_base = casted->getLValueBase(); | ||
| 1148 | return bitcast(lval_base); | ||
| 1149 | } |
src/zig_clang.h+41-31| ... | @@ -8,6 +8,8 @@ | ... | @@ -8,6 +8,8 @@ |
| 8 | #ifndef ZIG_ZIG_CLANG_H | 8 | #ifndef ZIG_ZIG_CLANG_H |
| 9 | #define ZIG_ZIG_CLANG_H | 9 | #define ZIG_ZIG_CLANG_H |
| 10 | 10 | ||
| 11 | #include <inttypes.h> | ||
| 12 | |||
| 11 | #ifdef __cplusplus | 13 | #ifdef __cplusplus |
| 12 | #define ZIG_EXTERN_C extern "C" | 14 | #define ZIG_EXTERN_C extern "C" |
| 13 | #else | 15 | #else |
| ... | @@ -26,7 +28,14 @@ struct ZigClangQualType { | ... | @@ -26,7 +28,14 @@ struct ZigClangQualType { |
| 26 | void *ptr; | 28 | void *ptr; |
| 27 | }; | 29 | }; |
| 28 | 30 | ||
| 31 | struct ZigClangAPValueLValueBase { | ||
| 32 | void *Ptr; | ||
| 33 | unsigned CallIndex; | ||
| 34 | unsigned Version; | ||
| 35 | }; | ||
| 36 | |||
| 29 | struct ZigClangAPValue; | 37 | struct ZigClangAPValue; |
| 38 | struct ZigClangAPSInt; | ||
| 30 | struct ZigClangASTContext; | 39 | struct ZigClangASTContext; |
| 31 | struct ZigClangASTUnit; | 40 | struct ZigClangASTUnit; |
| 32 | struct ZigClangArraySubscriptExpr; | 41 | struct ZigClangArraySubscriptExpr; |
| ... | @@ -400,24 +409,6 @@ enum ZigClangStmtClass { | ... | @@ -400,24 +409,6 @@ enum ZigClangStmtClass { |
| 400 | ZigClangStmt_WhileStmtClass, | 409 | ZigClangStmt_WhileStmtClass, |
| 401 | }; | 410 | }; |
| 402 | 411 | ||
| 403 | //struct ZigClangCC_AAPCS; | ||
| 404 | //struct ZigClangCC_AAPCS_VFP; | ||
| 405 | //struct ZigClangCC_C; | ||
| 406 | //struct ZigClangCC_IntelOclBicc; | ||
| 407 | //struct ZigClangCC_OpenCLKernel; | ||
| 408 | //struct ZigClangCC_PreserveAll; | ||
| 409 | //struct ZigClangCC_PreserveMost; | ||
| 410 | //struct ZigClangCC_SpirFunction; | ||
| 411 | //struct ZigClangCC_Swift; | ||
| 412 | //struct ZigClangCC_Win64; | ||
| 413 | //struct ZigClangCC_X86FastCall; | ||
| 414 | //struct ZigClangCC_X86Pascal; | ||
| 415 | //struct ZigClangCC_X86RegCall; | ||
| 416 | //struct ZigClangCC_X86StdCall; | ||
| 417 | //struct ZigClangCC_X86ThisCall; | ||
| 418 | //struct ZigClangCC_X86VectorCall; | ||
| 419 | //struct ZigClangCC_X86_64SysV; | ||
| 420 | |||
| 421 | enum ZigClangCK { | 412 | enum ZigClangCK { |
| 422 | ZigClangCK_Dependent, | 413 | ZigClangCK_Dependent, |
| 423 | ZigClangCK_BitCast, | 414 | ZigClangCK_BitCast, |
| ... | @@ -480,19 +471,20 @@ enum ZigClangCK { | ... | @@ -480,19 +471,20 @@ enum ZigClangCK { |
| 480 | ZigClangCK_IntToOCLSampler, | 471 | ZigClangCK_IntToOCLSampler, |
| 481 | }; | 472 | }; |
| 482 | 473 | ||
| 483 | //struct ZigClangETK_Class; | 474 | enum ZigClangAPValueKind { |
| 484 | //struct ZigClangETK_Enum; | 475 | ZigClangAPValueUninitialized, |
| 485 | //struct ZigClangETK_Interface; | 476 | ZigClangAPValueInt, |
| 486 | //struct ZigClangETK_None; | 477 | ZigClangAPValueFloat, |
| 487 | //struct ZigClangETK_Struct; | 478 | ZigClangAPValueComplexInt, |
| 488 | //struct ZigClangETK_Typename; | 479 | ZigClangAPValueComplexFloat, |
| 489 | //struct ZigClangETK_Union; | 480 | ZigClangAPValueLValue, |
| 490 | 481 | ZigClangAPValueVector, | |
| 491 | //struct ZigClangSC_None; | 482 | ZigClangAPValueArray, |
| 492 | //struct ZigClangSC_PrivateExtern; | 483 | ZigClangAPValueStruct, |
| 493 | //struct ZigClangSC_Static; | 484 | ZigClangAPValueUnion, |
| 494 | 485 | ZigClangAPValueMemberPointer, | |
| 495 | //struct ZigClangTU_Complete; | 486 | ZigClangAPValueAddrLabelDiff, |
| 487 | }; | ||
| 496 | 488 | ||
| 497 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *, | 489 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *, |
| 498 | ZigClangSourceLocation Loc); | 490 | ZigClangSourceLocation Loc); |
| ... | @@ -558,4 +550,22 @@ ZIG_EXTERN_C bool ZigClangStmt_classof_Expr(const ZigClangStmt *self); | ... | @@ -558,4 +550,22 @@ ZIG_EXTERN_C bool ZigClangStmt_classof_Expr(const ZigClangStmt *self); |
| 558 | ZIG_EXTERN_C ZigClangStmtClass ZigClangExpr_getStmtClass(const ZigClangExpr *self); | 550 | ZIG_EXTERN_C ZigClangStmtClass ZigClangExpr_getStmtClass(const ZigClangExpr *self); |
| 559 | ZIG_EXTERN_C ZigClangQualType ZigClangExpr_getType(const ZigClangExpr *self); | 551 | ZIG_EXTERN_C ZigClangQualType ZigClangExpr_getType(const ZigClangExpr *self); |
| 560 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self); | 552 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self); |
| 553 | |||
| 554 | ZIG_EXTERN_C ZigClangAPValueKind ZigClangAPValue_getKind(const ZigClangAPValue *self); | ||
| 555 | ZIG_EXTERN_C const ZigClangAPSInt *ZigClangAPValue_getInt(const ZigClangAPValue *self); | ||
| 556 | ZIG_EXTERN_C unsigned ZigClangAPValue_getArrayInitializedElts(const ZigClangAPValue *self); | ||
| 557 | ZIG_EXTERN_C const ZigClangAPValue *ZigClangAPValue_getArrayInitializedElt(const ZigClangAPValue *self, unsigned i); | ||
| 558 | ZIG_EXTERN_C const ZigClangAPValue *ZigClangAPValue_getArrayFiller(const ZigClangAPValue *self); | ||
| 559 | ZIG_EXTERN_C unsigned ZigClangAPValue_getArraySize(const ZigClangAPValue *self); | ||
| 560 | ZIG_EXTERN_C ZigClangAPValueLValueBase ZigClangAPValue_getLValueBase(const ZigClangAPValue *self); | ||
| 561 | |||
| 562 | ZIG_EXTERN_C bool ZigClangAPSInt_isSigned(const ZigClangAPSInt *self); | ||
| 563 | ZIG_EXTERN_C bool ZigClangAPSInt_isNegative(const ZigClangAPSInt *self); | ||
| 564 | ZIG_EXTERN_C const ZigClangAPSInt *ZigClangAPSInt_negate(const ZigClangAPSInt *self); | ||
| 565 | ZIG_EXTERN_C void ZigClangAPSInt_free(const ZigClangAPSInt *self); | ||
| 566 | ZIG_EXTERN_C const uint64_t *ZigClangAPSInt_getRawData(const ZigClangAPSInt *self); | ||
| 567 | ZIG_EXTERN_C unsigned ZigClangAPSInt_getNumWords(const ZigClangAPSInt *self); | ||
| 568 | |||
| 569 | ZIG_EXTERN_C const ZigClangExpr *ZigClangAPValueLValueBase_dyn_cast_Expr(ZigClangAPValueLValueBase self); | ||
| 570 | |||
| 561 | #endif | 571 | #endif |