| ... | @@ -129,6 +129,7 @@ static TransScope *trans_stmt(Context *c, TransScope *scope, const Stmt *stmt, A | ... | @@ -129,6 +129,7 @@ static TransScope *trans_stmt(Context *c, TransScope *scope, const Stmt *stmt, A |
| 129 | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval); | 129 | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval); |
| 130 | static AstNode *trans_qual_type(Context *c, QualType qt, const SourceLocation &source_loc); | 130 | static AstNode *trans_qual_type(Context *c, QualType qt, const SourceLocation &source_loc); |
| 131 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval); | 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 | ATTRIBUTE_PRINTF(3, 4) | 134 | ATTRIBUTE_PRINTF(3, 4) |
| 134 | static void emit_warning(Context *c, const SourceLocation &sl, const char *format, ...) { | 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,6 +1226,15 @@ static AstNode *trans_integer_literal(Context *c, const IntegerLiteral *stmt) { |
| 1225 | return trans_create_node_apint(c, result.Val.getInt()); | 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 | static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, TransScope *scope, | 1238 | static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, TransScope *scope, |
| 1229 | const ConditionalOperator *stmt) | 1239 | const ConditionalOperator *stmt) |
| 1230 | { | 1240 | { |
| ... | @@ -3183,6 +3193,9 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, | ... | @@ -3183,6 +3193,9 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, |
| 3183 | return trans_switch_case(c, scope, (const CaseStmt *)stmt, out_node, out_child_scope); | 3193 | return trans_switch_case(c, scope, (const CaseStmt *)stmt, out_node, out_child_scope); |
| 3184 | case Stmt::DefaultStmtClass: | 3194 | case Stmt::DefaultStmtClass: |
| 3185 | return trans_switch_default(c, scope, (const DefaultStmt *)stmt, out_node, out_child_scope); | 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 | case Stmt::NoStmtClass: | 3199 | case Stmt::NoStmtClass: |
| 3187 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C NoStmtClass"); | 3200 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C NoStmtClass"); |
| 3188 | return ErrorUnexpected; | 3201 | return ErrorUnexpected; |
| ... | @@ -3690,9 +3703,6 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, | ... | @@ -3690,9 +3703,6 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt, |
| 3690 | case Stmt::FixedPointLiteralClass: | 3703 | case Stmt::FixedPointLiteralClass: |
| 3691 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C FixedPointLiteralClass"); | 3704 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C FixedPointLiteralClass"); |
| 3692 | return ErrorUnexpected; | 3705 | return ErrorUnexpected; |
| 3693 | case Stmt::ConstantExprClass: | | |
| 3694 | emit_warning(c, stmt->getBeginLoc(), "TODO handle C ConstantExprClass"); | | |
| 3695 | return ErrorUnexpected; | | |
| 3696 | } | 3706 | } |
| 3697 | zig_unreachable(); | 3707 | zig_unreachable(); |
| 3698 | } | 3708 | } |