Clang import: CharacterLiteral

This commit is contained in:
Daniel Marjamäki 2020-01-09 16:54:45 +01:00
parent fea981211e
commit 7daa1bc11d
2 changed files with 25 additions and 0 deletions

View File

@ -30,6 +30,7 @@ static const std::string ArraySubscriptExpr = "ArraySubscriptExpr";
static const std::string BinaryOperator = "BinaryOperator";
static const std::string BreakStmt = "BreakStmt";
static const std::string CallExpr = "CallExpr";
static const std::string CharacterLiteral = "CharacterLiteral";
static const std::string ClassTemplateDecl = "ClassTemplateDecl";
static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl";
static const std::string CompoundStmt = "CompoundStmt";
@ -355,6 +356,23 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
}
if (nodeType == BreakStmt)
return addtoken(tokenList, "break");
if (nodeType == CharacterLiteral) {
int c = MathLib::toLongNumber(mExtTokens.back());
if (c == 0)
return addtoken(tokenList, "\'\\0\'");
if (c == '\r')
return addtoken(tokenList, "\'\\r\'");
if (c == '\n')
return addtoken(tokenList, "\'\\n\'");
if (c == '\t')
return addtoken(tokenList, "\'\\t\'");
if (c < ' ' || c >= 0x80) {
std::ostringstream hex;
hex << std::hex << ((c>>4) & 0xf) << (c&0xf);
return addtoken(tokenList, "\'\\x" + hex.str() + "\'");
}
return addtoken(tokenList, std::string("\'") + char(c) + std::string("\'"));
}
if (nodeType == CallExpr)
return createTokensCall(tokenList);
if (nodeType == ClassTemplateDecl) {

View File

@ -30,6 +30,7 @@ public:
private:
void run() OVERRIDE {
TEST_CASE(breakStmt);
TEST_CASE(characterLiteral);
TEST_CASE(class1);
TEST_CASE(classTemplateDecl1);
TEST_CASE(classTemplateDecl2);
@ -78,6 +79,12 @@ private:
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { break ; } }", parse(clang));
}
void characterLiteral() {
const char clang[] = "`-VarDecl 0x3df8608 <a.cpp:1:1, col:10> col:6 c 'char' cinit\n"
" `-CharacterLiteral 0x3df86a8 <col:10> 'char' 120";
ASSERT_EQUALS("char c@1 = 'x' ;", parse(clang));
}
void class1() {
const char clang[] = "`-CXXRecordDecl 0x274c638 <a.cpp:1:1, col:25> col:7 class C definition\n"
" |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init\n"