From a20b3a9e2e331daefab8ec8a601b0eb4e36ec864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 21 Jan 2020 17:47:45 +0100 Subject: [PATCH] Clang import; better handling of string literals --- lib/clangimport.cpp | 2 ++ test/testclangimport.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index e008d3314..9edc84c06 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -101,6 +101,8 @@ static std::vector splitString(const std::string &line) std::string::size_type pos2; if (line[pos1] == '<') pos2 = line.find(">", pos1); + else if (line[pos1] == '\"') + pos2 = line.find("\"", pos1+1); else if (line[pos1] == '\'') { pos2 = line.find("\'", pos1+1); if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 34c48b409..d2fe681da 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -31,6 +31,7 @@ public: private: void run() OVERRIDE { TEST_CASE(breakStmt); + TEST_CASE(callExpr); TEST_CASE(caseStmt1); TEST_CASE(characterLiteral); TEST_CASE(class1); @@ -110,6 +111,22 @@ private: 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:14 used x 'int'\n" + " `-CompoundStmt 0x2444e00 \n" + " `-CallExpr 0x7f5a6c04b158 'bool'\n" + " |-ImplicitCastExpr 0x7f5a6c04b140 'bool (*)(const Token *, const char *, int)' \n" + " | `-DeclRefExpr 0x7f5a6c04b0a8 'bool (const Token *, const char *, int)' lvalue CXXMethod 0x43e5600 'Match' 'bool (const Token *, const char *, int)'\n" + " |-ImplicitCastExpr 0x7f5a6c04b1c8 'const Token *' \n" + " | `-ImplicitCastExpr 0x7f5a6c04b1b0 'Token *' \n" + " | `-DeclRefExpr 0x7f5a6c04b0e0 'Token *' lvalue Var 0x7f5a6c045968 'tokAfterCondition' 'Token *'\n" + " |-ImplicitCastExpr 0x7f5a6c04b1e0 'const char *' \n" + " | `-StringLiteral 0x7f5a6c04b108 'const char [11]' lvalue \"%name% : {\"\n" + " `-CXXDefaultArgExpr 0x7f5a6c04b1f8 <> 'int'\n"; + ASSERT_EQUALS("void foo ( int x@1 ) { Match ( tokAfterCondition , \"%name% : {\" ) ; }", parse(clang)); + } + void caseStmt1() { const char clang[] = "`-FunctionDecl 0x2444b60 <1.c:1:1, line:8:1> line:1:6 foo 'void (int)'\n" " |-ParmVarDecl 0x2444aa0 col:14 used x 'int'\n"