Clang import; CXXStaticCast
This commit is contained in:
parent
bf62138237
commit
b8aa71bc87
|
@ -41,6 +41,7 @@ static const std::string CXXMemberCallExpr = "CXXMemberCallExpr";
|
||||||
static const std::string CXXMethodDecl = "CXXMethodDecl";
|
static const std::string CXXMethodDecl = "CXXMethodDecl";
|
||||||
static const std::string CXXOperatorCallExpr = "CXXOperatorCallExpr";
|
static const std::string CXXOperatorCallExpr = "CXXOperatorCallExpr";
|
||||||
static const std::string CXXRecordDecl = "CXXRecordDecl";
|
static const std::string CXXRecordDecl = "CXXRecordDecl";
|
||||||
|
static const std::string CXXStaticCastExpr = "CXXStaticCastExpr";
|
||||||
static const std::string CXXThisExpr = "CXXThisExpr";
|
static const std::string CXXThisExpr = "CXXThisExpr";
|
||||||
static const std::string DeclRefExpr = "DeclRefExpr";
|
static const std::string DeclRefExpr = "DeclRefExpr";
|
||||||
static const std::string DeclStmt = "DeclStmt";
|
static const std::string DeclStmt = "DeclStmt";
|
||||||
|
@ -322,7 +323,9 @@ const Scope *clangastdump::AstNode::getNestedInScope(TokenList *tokenList)
|
||||||
void clangastdump::AstNode::setValueType(Token *tok)
|
void clangastdump::AstNode::setValueType(Token *tok)
|
||||||
{
|
{
|
||||||
int typeIndex = -1;
|
int typeIndex = -1;
|
||||||
if (nodeType == UnaryExprOrTypeTraitExpr)
|
if (nodeType == CXXStaticCastExpr)
|
||||||
|
typeIndex = mExtTokens.size() - 3;
|
||||||
|
else if (nodeType == UnaryExprOrTypeTraitExpr)
|
||||||
typeIndex = mExtTokens.size() - 3;
|
typeIndex = mExtTokens.size() - 3;
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
@ -330,7 +333,9 @@ void clangastdump::AstNode::setValueType(Token *tok)
|
||||||
TokenList decl(nullptr);
|
TokenList decl(nullptr);
|
||||||
addTypeTokens(&decl, mExtTokens[typeIndex]);
|
addTypeTokens(&decl, mExtTokens[typeIndex]);
|
||||||
|
|
||||||
if (Token::simpleMatch(decl.front(), "unsigned long"))
|
if (Token::simpleMatch(decl.front(), "int"))
|
||||||
|
tok->setValueType(new ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0));
|
||||||
|
else if (Token::simpleMatch(decl.front(), "unsigned long"))
|
||||||
tok->setValueType(new ValueType(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0));
|
tok->setValueType(new ValueType(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,6 +461,18 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
||||||
createTokensForCXXRecord(tokenList);
|
createTokensForCXXRecord(tokenList);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (nodeType == CXXStaticCastExpr) {
|
||||||
|
Token *cast = addtoken(tokenList, getSpelling());
|
||||||
|
Token *par1 = addtoken(tokenList, "(");
|
||||||
|
Token *expr = children[0]->createTokens(tokenList);
|
||||||
|
Token *par2 = addtoken(tokenList, ")");
|
||||||
|
par1->link(par2);
|
||||||
|
par2->link(par1);
|
||||||
|
par1->astOperand1(cast);
|
||||||
|
par1->astOperand2(expr);
|
||||||
|
setValueType(par1);
|
||||||
|
return par1;
|
||||||
|
}
|
||||||
if (nodeType == CXXThisExpr)
|
if (nodeType == CXXThisExpr)
|
||||||
return addtoken(tokenList, "this");
|
return addtoken(tokenList, "this");
|
||||||
if (nodeType == DeclStmt)
|
if (nodeType == DeclStmt)
|
||||||
|
|
|
@ -39,6 +39,7 @@ private:
|
||||||
TEST_CASE(cxxConstructorDecl);
|
TEST_CASE(cxxConstructorDecl);
|
||||||
TEST_CASE(cxxMemberCall);
|
TEST_CASE(cxxMemberCall);
|
||||||
TEST_CASE(cxxOperatorCallExpr);
|
TEST_CASE(cxxOperatorCallExpr);
|
||||||
|
TEST_CASE(cxxStaticCastExpr);
|
||||||
TEST_CASE(forStmt);
|
TEST_CASE(forStmt);
|
||||||
TEST_CASE(funcdecl1);
|
TEST_CASE(funcdecl1);
|
||||||
TEST_CASE(funcdecl2);
|
TEST_CASE(funcdecl2);
|
||||||
|
@ -216,6 +217,13 @@ private:
|
||||||
ASSERT_EQUALS("void foo ( ) { C c@1 ; c@1 . operator= ( 4 ) ; }", parse(clang));
|
ASSERT_EQUALS("void foo ( ) { C c@1 ; c@1 . operator= ( 4 ) ; }", parse(clang));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cxxStaticCastExpr() {
|
||||||
|
const char clang[] = "`-VarDecl 0x2e0e650 <a.cpp:2:1, col:27> col:5 a 'int' cinit\n"
|
||||||
|
" `-CXXStaticCastExpr 0x2e0e728 <col:9, col:27> 'int' static_cast<int> <NoOp>\n"
|
||||||
|
" `-IntegerLiteral 0x2e0e6f0 <col:26> 'int' 0";
|
||||||
|
ASSERT_EQUALS("int a@1 = static_cast<int> ( 0 ) ;", parse(clang));
|
||||||
|
}
|
||||||
|
|
||||||
void forStmt() {
|
void forStmt() {
|
||||||
const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n"
|
const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n"
|
||||||
" `-CompoundStmt 0x2f93dc0 <col:12, col:56>\n"
|
" `-CompoundStmt 0x2f93dc0 <col:12, col:56>\n"
|
||||||
|
|
Loading…
Reference in New Issue