Clang import; cxxStaticCastExpr2

This commit is contained in:
Daniel Marjamäki 2020-01-10 11:04:37 +01:00
parent 9afeef01c6
commit a0a2eae1d2
2 changed files with 32 additions and 4 deletions

View File

@ -84,8 +84,27 @@ static std::vector<std::string> splitString(const std::string &line)
pos2 = line.find("\'", pos1+1);
if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
pos2 = line.find("\'", pos2 + 3);
} else
} else {
pos2 = line.find(" ", pos1) - 1;
if (std::isalpha(line[pos1]) && line.find("<", pos1) < pos2 && line.find(">", pos1) > pos2) {
int level = 0;
pos2 = pos1;
for (pos2 = pos1; pos2 < line.size(); ++pos2) {
if (line[pos2] == '<')
++level;
else if (line[pos2] == '>') {
if (level <= 1)
break;
--level;
}
}
if (level != 1 || pos2 + 1 >= line.size())
return std::vector<std::string> {};
pos2 = line.find(" ", pos2);
if (pos2 != std::string::npos)
--pos2;
}
}
ret.push_back(line.substr(pos1, pos2+1-pos1));
if (pos2 == std::string::npos)
break;
@ -479,7 +498,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
return children[0]->createTokens(tokenList);
if (nodeType == DeclRefExpr) {
const std::string addr = mExtTokens[mExtTokens.size() - 3];
Token *reftok = addtoken(tokenList, unquote(mExtTokens[mExtTokens.size() - 2]));
std::string name = unquote(getSpelling());
Token *reftok = addtoken(tokenList, name.empty() ? "<NoName>" : name);
mData->ref(addr, reftok);
return reftok;
}

View File

@ -39,7 +39,8 @@ private:
TEST_CASE(cxxConstructorDecl);
TEST_CASE(cxxMemberCall);
TEST_CASE(cxxOperatorCallExpr);
TEST_CASE(cxxStaticCastExpr);
TEST_CASE(cxxStaticCastExpr1);
TEST_CASE(cxxStaticCastExpr2);
TEST_CASE(forStmt);
TEST_CASE(funcdecl1);
TEST_CASE(funcdecl2);
@ -217,13 +218,20 @@ private:
ASSERT_EQUALS("void foo ( ) { C c@1 ; c@1 . operator= ( 4 ) ; }", parse(clang));
}
void cxxStaticCastExpr() {
void cxxStaticCastExpr1() {
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 cxxStaticCastExpr2() {
const char clang[] = "`-VarDecl 0x2e0e650 <a.cpp:2:1, col:27> col:5 a 'int' cinit\n"
" `-CXXStaticCastExpr 0x3e453e8 <col:12> 'std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, Library::AllocFunc> >' xvalue static_cast<struct std::_Rb_tree_iterator<struct std::pair<const class std::__cxx11::basic_string<char>, struct Library::AllocFunc> > &&> <NoOp>\n"
" `-DeclRefExpr 0x3e453b0 <col:12> 'std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, Library::AllocFunc> >' lvalue ParmVar 0x3e45250 '' 'std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, Library::AllocFunc> > &&'";
ASSERT_EQUALS("int a@1 = static_cast<structstd::_Rb_tree_iterator<structstd::pair<constclassstd::__cxx11::basic_string<char>,structLibrary::AllocFunc>>&&> ( <NoName> ) ;", parse(clang));
}
void forStmt() {
const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n"
" `-CompoundStmt 0x2f93dc0 <col:12, col:56>\n"