Clang import; CStyleCastExpr

This commit is contained in:
Daniel Marjamäki 2020-01-10 16:19:01 +01:00
parent 75fd4809e6
commit 8f1a50ffc0
2 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,7 @@ static const std::string ClassTemplateDecl = "ClassTemplateDecl";
static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl";
static const std::string CompoundStmt = "CompoundStmt";
static const std::string ContinueStmt = "ContinueStmt";
static const std::string CStyleCastExpr = "CStyleCastExpr";
static const std::string CXXBoolLiteralExpr = "CXXBoolLiteralExpr";
static const std::string CXXConstructorDecl = "CXXConstructorDecl";
static const std::string CXXMemberCallExpr = "CXXMemberCallExpr";
@ -248,6 +249,10 @@ std::string clangastdump::AstNode::getType() const
{
if (nodeType == BinaryOperator)
return unquote(mExtTokens[mExtTokens.size() - 2]);
if (nodeType == CStyleCastExpr)
return unquote((mExtTokens.back() == "<NoOp>") ?
mExtTokens[mExtTokens.size() - 2] :
mExtTokens.back());
if (nodeType == CXXStaticCastExpr)
return unquote(mExtTokens[mExtTokens.size() - 3]);
if (nodeType == DeclRefExpr)
@ -497,6 +502,15 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
createTokensFunctionDecl(tokenList);
return nullptr;
}
if (nodeType == CStyleCastExpr) {
Token *par1 = addtoken(tokenList, "(");
addTypeTokens(tokenList, '\'' + getType() + '\'');
Token *par2 = addtoken(tokenList, ")");
par1->link(par2);
par2->link(par1);
par1->astOperand1(children[0]->createTokens(tokenList));
return par1;
}
if (nodeType == CXXBoolLiteralExpr) {
addtoken(tokenList, mExtTokens.back());
tokenList->back()->setValueType(new ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0));

View File

@ -35,6 +35,7 @@ private:
TEST_CASE(classTemplateDecl1);
TEST_CASE(classTemplateDecl2);
TEST_CASE(continueStmt);
TEST_CASE(cstyleCastExpr);
TEST_CASE(cxxBoolLiteralExpr);
TEST_CASE(cxxConstructorDecl);
TEST_CASE(cxxMemberCall);
@ -175,6 +176,13 @@ private:
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { continue ; } }", parse(clang));
}
void cstyleCastExpr() {
const char clang[] = "`-VarDecl 0x2336aa0 <1.c:1:1, col:14> col:5 x 'int' cinit\n"
" `-CStyleCastExpr 0x2336b70 <col:9, col:14> 'int' <NoOp>\n"
" `-CharacterLiteral 0x2336b40 <col:14> 'int' 97";
ASSERT_EQUALS("int x@1 = ( int ) 'a' ;", parse(clang));
}
void cxxBoolLiteralExpr() {
const char clang[] = "`-VarDecl 0x3940608 <a.cpp:1:1, col:10> col:6 x 'bool' cinit\n"
" `-CXXBoolLiteralExpr 0x39406a8 <col:10> 'bool' true";