| ... | @@ -522,7 +522,18 @@ static AstNode *trans_create_node_apint(Context *c, const ZigClangAPSInt *aps_in | ... | @@ -522,7 +522,18 @@ static AstNode *trans_create_node_apint(Context *c, const ZigClangAPSInt *aps_in |
| 522 | ZigClangAPSInt_getNumWords(negated), true); | 522 | ZigClangAPSInt_getNumWords(negated), true); |
| 523 | ZigClangAPSInt_free(negated); | 523 | ZigClangAPSInt_free(negated); |
| 524 | return node; | 524 | return node; |
| | 525 | } |
| 525 | | 526 | |
| | 527 | static AstNode *trans_create_node_apfloat(Context *c, const llvm::APFloat &ap_float) { |
| | 528 | uint8_t buf[128]; |
| | 529 | size_t written = ap_float.convertToHexString((char *)buf, 0, false, |
| | 530 | llvm::APFloat::rmNearestTiesToEven); |
| | 531 | AstNode *node = trans_create_node(c, NodeTypeFloatLiteral); |
| | 532 | node->data.float_literal.bigfloat = allocate<BigFloat>(1); |
| | 533 | if (bigfloat_init_buf(node->data.float_literal.bigfloat, buf, written)) { |
| | 534 | node->data.float_literal.overflow = true; |
| | 535 | } |
| | 536 | return node; |
| 526 | } | 537 | } |
| 527 | | 538 | |
| 528 | static const ZigClangType *qual_type_canon(ZigClangQualType qt) { | 539 | static const ZigClangType *qual_type_canon(ZigClangQualType qt) { |
| ... | @@ -1313,6 +1324,16 @@ static AstNode *trans_integer_literal(Context *c, ResultUsed result_used, const | ... | @@ -1313,6 +1324,16 @@ static AstNode *trans_integer_literal(Context *c, ResultUsed result_used, const |
| 1313 | return maybe_suppress_result(c, result_used, node); | 1324 | return maybe_suppress_result(c, result_used, node); |
| 1314 | } | 1325 | } |
| 1315 | | 1326 | |
| | 1327 | static AstNode *trans_floating_literal(Context *c, ResultUsed result_used, const clang::FloatingLiteral *stmt) { |
| | 1328 | llvm::APFloat result{0.0f}; |
| | 1329 | if (!stmt->EvaluateAsFloat(result, *reinterpret_cast<clang::ASTContext *>(c->ctx))) { |
| | 1330 | emit_warning(c, bitcast(stmt->getBeginLoc()), "invalid floating literal"); |
| | 1331 | return nullptr; |
| | 1332 | } |
| | 1333 | AstNode *node = trans_create_node_apfloat(c, result); |
| | 1334 | return maybe_suppress_result(c, result_used, node); |
| | 1335 | } |
| | 1336 | |
| 1316 | static AstNode *trans_constant_expr(Context *c, ResultUsed result_used, const clang::ConstantExpr *expr) { | 1337 | static AstNode *trans_constant_expr(Context *c, ResultUsed result_used, const clang::ConstantExpr *expr) { |
| 1317 | clang::Expr::EvalResult result; | 1338 | clang::Expr::EvalResult result; |
| 1318 | if (!expr->EvaluateAsConstantExpr(result, clang::Expr::EvaluateForCodeGen, | 1339 | if (!expr->EvaluateAsConstantExpr(result, clang::Expr::EvaluateForCodeGen, |
| ... | @@ -3549,8 +3570,8 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s | ... | @@ -3549,8 +3570,8 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s |
| 3549 | emit_warning(c, ZigClangStmt_getBeginLoc(stmt), "TODO handle C FixedPointLiteralClass"); | 3570 | emit_warning(c, ZigClangStmt_getBeginLoc(stmt), "TODO handle C FixedPointLiteralClass"); |
| 3550 | return ErrorUnexpected; | 3571 | return ErrorUnexpected; |
| 3551 | case ZigClangStmt_FloatingLiteralClass: | 3572 | case ZigClangStmt_FloatingLiteralClass: |
| 3552 | emit_warning(c, ZigClangStmt_getBeginLoc(stmt), "TODO handle C FloatingLiteralClass"); | 3573 | return wrap_stmt(out_node, out_child_scope, scope, |
| 3553 | return ErrorUnexpected; | 3574 | trans_floating_literal(c, result_used, (const clang::FloatingLiteral *)stmt)); |
| 3554 | case ZigClangStmt_ExprWithCleanupsClass: | 3575 | case ZigClangStmt_ExprWithCleanupsClass: |
| 3555 | emit_warning(c, ZigClangStmt_getBeginLoc(stmt), "TODO handle C ExprWithCleanupsClass"); | 3576 | emit_warning(c, ZigClangStmt_getBeginLoc(stmt), "TODO handle C ExprWithCleanupsClass"); |
| 3556 | return ErrorUnexpected; | 3577 | return ErrorUnexpected; |