| ... | ... | @@ -129,6 +129,7 @@ static TransScope *trans_stmt(Context *c, TransScope *scope, const Stmt *stmt, A |
| 129 | 129 | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval); |
| 130 | 130 | static AstNode *trans_qual_type(Context *c, QualType qt, const SourceLocation &source_loc); |
| 131 | 131 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval); |
| 132 | static AstNode *trans_ap_value(Context *c, APValue *ap_value, QualType qt, const SourceLocation &source_loc); |
| 132 | 133 | |
| 133 | 134 | ATTRIBUTE_PRINTF(3, 4) |
| 134 | 135 | static void emit_warning(Context *c, const SourceLocation &sl, const char *format, ...) { |
| ... | ... | @@ -1225,6 +1226,15 @@ static AstNode *trans_integer_literal(Context *c, const IntegerLiteral *stmt) { |
| 1225 | 1226 | return trans_create_node_apint(c, result.Val.getInt()); |
| 1226 | 1227 | } |
| 1227 | 1228 | |
| 1229 | static AstNode *trans_constant_expr(Context *c, const ConstantExpr *expr) { |
| 1230 | Expr::EvalResult result; |
| 1231 | if (!expr->EvaluateAsConstantExpr(result, Expr::EvaluateForCodeGen, *c->ctx)) { |
| 1232 | emit_warning(c, expr->getBeginLoc(), "invalid constant expression"); |
| 1233 | return nullptr; |
| 1234 | } |
| 1235 | return trans_ap_value(c, &result.Val, expr->getType(), expr->getBeginLoc()); |
| 1236 | } |
| 1237 | |
| 1228 | 1238 | static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, TransScope *scope, |
| 1229 | 1239 | const ConditionalOperator *stmt) |
| 1230 | 1240 | { |
| ... | ... | @@ -3183,6 +3193,9 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, |
| 3183 | 3193 | return trans_switch_case(c, scope, (const CaseStmt *)stmt, out_node, out_child_scope); |
| 3184 | 3194 | case Stmt::DefaultStmtClass: |
| 3185 | 3195 | return trans_switch_default(c, scope, (const DefaultStmt *)stmt, out_node, out_child_scope); |
| 3196 | case Stmt::ConstantExprClass: |
| 3197 | return wrap_stmt(out_node, out_child_scope, scope, |
| 3198 | trans_constant_expr(c, (const ConstantExpr *)stmt)); |
| 3186 | 3199 | case Stmt::NoStmtClass: |
| 3187 | 3200 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C NoStmtClass"); |
| 3188 | 3201 | return ErrorUnexpected; |
| ... | ... | @@ -3690,9 +3703,6 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, |
| 3690 | 3703 | case Stmt::FixedPointLiteralClass: |
| 3691 | 3704 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C FixedPointLiteralClass"); |
| 3692 | 3705 | return ErrorUnexpected; |
| 3693 | | case Stmt::ConstantExprClass: |
| 3694 | | emit_warning(c, stmt->getBeginLoc(), "TODO handle C ConstantExprClass"); |
| 3695 | | return ErrorUnexpected; |
| 3696 | 3706 | } |
| 3697 | 3707 | zig_unreachable(); |
| 3698 | 3708 | } |