| ... | ... | @@ -1335,14 +1335,33 @@ static AstNode *trans_floating_literal(Context *c, ResultUsed result_used, const |
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | static AstNode *trans_character_literal(Context *c, ResultUsed result_used, const clang::CharacterLiteral *stmt) { |
| 1338 | | clang::Expr::EvalResult result; |
| 1339 | | if (!stmt->EvaluateAsInt(result, *reinterpret_cast<clang::ASTContext *>(c->ctx))) { |
| 1340 | | emit_warning(c, bitcast(stmt->getBeginLoc()), "invalid character literal"); |
| 1341 | | return nullptr; |
| 1338 | switch (stmt->getKind()) { |
| 1339 | case clang::CharacterLiteral::CharacterKind::Ascii: |
| 1340 | { |
| 1341 | unsigned val = stmt->getValue(); |
| 1342 | // C has a somewhat obscure feature called multi-character character |
| 1343 | // constant |
| 1344 | if (val > 255) |
| 1345 | return trans_create_node_unsigned(c, val); |
| 1346 | } |
| 1347 | // fallthrough |
| 1348 | case clang::CharacterLiteral::CharacterKind::UTF8: |
| 1349 | { |
| 1350 | AstNode *node = trans_create_node(c, NodeTypeCharLiteral); |
| 1351 | node->data.char_literal.value = stmt->getValue(); |
| 1352 | return maybe_suppress_result(c, result_used, node); |
| 1353 | } |
| 1354 | case clang::CharacterLiteral::CharacterKind::UTF16: |
| 1355 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO support UTF16 character literals"); |
| 1356 | return nullptr; |
| 1357 | case clang::CharacterLiteral::CharacterKind::UTF32: |
| 1358 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO support UTF32 character literals"); |
| 1359 | return nullptr; |
| 1360 | case clang::CharacterLiteral::CharacterKind::Wide: |
| 1361 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO support wide character literals"); |
| 1362 | return nullptr; |
| 1342 | 1363 | } |
| 1343 | | AstNode *node = trans_create_node(c, NodeTypeCharLiteral); |
| 1344 | | node->data.char_literal.value = result.Val.getInt().getExtValue(); |
| 1345 | | return maybe_suppress_result(c, result_used, node); |
| 1364 | zig_unreachable(); |
| 1346 | 1365 | } |
| 1347 | 1366 | |
| 1348 | 1367 | static AstNode *trans_constant_expr(Context *c, ResultUsed result_used, const clang::ConstantExpr *expr) { |