Clang import: CharacterLiteral
This commit is contained in:
parent
fea981211e
commit
7daa1bc11d
@ -30,6 +30,7 @@ static const std::string ArraySubscriptExpr = "ArraySubscriptExpr";
|
|||||||
static const std::string BinaryOperator = "BinaryOperator";
|
static const std::string BinaryOperator = "BinaryOperator";
|
||||||
static const std::string BreakStmt = "BreakStmt";
|
static const std::string BreakStmt = "BreakStmt";
|
||||||
static const std::string CallExpr = "CallExpr";
|
static const std::string CallExpr = "CallExpr";
|
||||||
|
static const std::string CharacterLiteral = "CharacterLiteral";
|
||||||
static const std::string ClassTemplateDecl = "ClassTemplateDecl";
|
static const std::string ClassTemplateDecl = "ClassTemplateDecl";
|
||||||
static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl";
|
static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl";
|
||||||
static const std::string CompoundStmt = "CompoundStmt";
|
static const std::string CompoundStmt = "CompoundStmt";
|
||||||
@ -355,6 +356,23 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
|||||||
}
|
}
|
||||||
if (nodeType == BreakStmt)
|
if (nodeType == BreakStmt)
|
||||||
return addtoken(tokenList, "break");
|
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)
|
if (nodeType == CallExpr)
|
||||||
return createTokensCall(tokenList);
|
return createTokensCall(tokenList);
|
||||||
if (nodeType == ClassTemplateDecl) {
|
if (nodeType == ClassTemplateDecl) {
|
||||||
|
@ -30,6 +30,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void run() OVERRIDE {
|
void run() OVERRIDE {
|
||||||
TEST_CASE(breakStmt);
|
TEST_CASE(breakStmt);
|
||||||
|
TEST_CASE(characterLiteral);
|
||||||
TEST_CASE(class1);
|
TEST_CASE(class1);
|
||||||
TEST_CASE(classTemplateDecl1);
|
TEST_CASE(classTemplateDecl1);
|
||||||
TEST_CASE(classTemplateDecl2);
|
TEST_CASE(classTemplateDecl2);
|
||||||
@ -78,6 +79,12 @@ private:
|
|||||||
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { break ; } }", parse(clang));
|
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() {
|
void class1() {
|
||||||
const char clang[] = "`-CXXRecordDecl 0x274c638 <a.cpp:1:1, col:25> col:7 class C definition\n"
|
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"
|
" |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user