Clang import; better handling of string literals

This commit is contained in:
Daniel Marjamäki 2020-01-21 17:47:45 +01:00
parent 6386f0e633
commit a20b3a9e2e
2 changed files with 19 additions and 0 deletions

View File

@ -101,6 +101,8 @@ static std::vector<std::string> splitString(const std::string &line)
std::string::size_type pos2; std::string::size_type pos2;
if (line[pos1] == '<') if (line[pos1] == '<')
pos2 = line.find(">", pos1); pos2 = line.find(">", pos1);
else if (line[pos1] == '\"')
pos2 = line.find("\"", pos1+1);
else if (line[pos1] == '\'') { else if (line[pos1] == '\'') {
pos2 = line.find("\'", pos1+1); pos2 = line.find("\'", pos1+1);
if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)

View File

@ -31,6 +31,7 @@ public:
private: private:
void run() OVERRIDE { void run() OVERRIDE {
TEST_CASE(breakStmt); TEST_CASE(breakStmt);
TEST_CASE(callExpr);
TEST_CASE(caseStmt1); TEST_CASE(caseStmt1);
TEST_CASE(characterLiteral); TEST_CASE(characterLiteral);
TEST_CASE(class1); TEST_CASE(class1);
@ -110,6 +111,22 @@ private:
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { break ; } }", parse(clang)); ASSERT_EQUALS("void foo ( ) { while ( 0 ) { break ; } }", parse(clang));
} }
void callExpr() {
const char clang[] = "`-FunctionDecl 0x2444b60 <1.c:1:1, line:8:1> line:1:6 foo 'void (int)'\n"
" |-ParmVarDecl 0x2444aa0 <col:10, col:14> col:14 used x 'int'\n"
" `-CompoundStmt 0x2444e00 <col:17, line:8:1>\n"
" `-CallExpr 0x7f5a6c04b158 <line:1:16, col:60> 'bool'\n"
" |-ImplicitCastExpr 0x7f5a6c04b140 <col:16, col:23> 'bool (*)(const Token *, const char *, int)' <FunctionToPointerDecay>\n"
" | `-DeclRefExpr 0x7f5a6c04b0a8 <col:16, col:23> 'bool (const Token *, const char *, int)' lvalue CXXMethod 0x43e5600 'Match' 'bool (const Token *, const char *, int)'\n"
" |-ImplicitCastExpr 0x7f5a6c04b1c8 <col:29> 'const Token *' <NoOp>\n"
" | `-ImplicitCastExpr 0x7f5a6c04b1b0 <col:29> 'Token *' <LValueToRValue>\n"
" | `-DeclRefExpr 0x7f5a6c04b0e0 <col:29> 'Token *' lvalue Var 0x7f5a6c045968 'tokAfterCondition' 'Token *'\n"
" |-ImplicitCastExpr 0x7f5a6c04b1e0 <col:48> 'const char *' <ArrayToPointerDecay>\n"
" | `-StringLiteral 0x7f5a6c04b108 <col:48> 'const char [11]' lvalue \"%name% : {\"\n"
" `-CXXDefaultArgExpr 0x7f5a6c04b1f8 <<invalid sloc>> 'int'\n";
ASSERT_EQUALS("void foo ( int x@1 ) { Match ( tokAfterCondition , \"%name% : {\" ) ; }", parse(clang));
}
void caseStmt1() { void caseStmt1() {
const char clang[] = "`-FunctionDecl 0x2444b60 <1.c:1:1, line:8:1> line:1:6 foo 'void (int)'\n" const char clang[] = "`-FunctionDecl 0x2444b60 <1.c:1:1, line:8:1> line:1:6 foo 'void (int)'\n"
" |-ParmVarDecl 0x2444aa0 <col:10, col:14> col:14 used x 'int'\n" " |-ParmVarDecl 0x2444aa0 <col:10, col:14> col:14 used x 'int'\n"