Clang import: better handling of CXXMethodDecl in getSpelling

This commit is contained in:
Daniel Marjamäki 2020-11-24 19:20:16 +01:00
parent 43ce1607c7
commit 788abfa8a4
2 changed files with 16 additions and 1 deletions

View File

@ -347,7 +347,7 @@ std::string clangimport::AstNode::getSpelling() const
}
int typeIndex = mExtTokens.size() - 1;
if (nodeType == FunctionDecl || nodeType == CXXConstructorDecl) {
if (nodeType == FunctionDecl || nodeType == CXXConstructorDecl || nodeType == CXXMethodDecl) {
while (typeIndex >= 0 && mExtTokens[typeIndex][0] != '\'')
typeIndex--;
if (typeIndex <= 0)

View File

@ -56,6 +56,7 @@ private:
TEST_CASE(cxxMethodDecl1);
TEST_CASE(cxxMethodDecl2);
TEST_CASE(cxxMethodDecl3);
TEST_CASE(cxxMethodDecl4);
TEST_CASE(cxxNewExpr1);
TEST_CASE(cxxNewExpr2);
TEST_CASE(cxxNullPtrLiteralExpr);
@ -508,6 +509,20 @@ private:
ASSERT_EQUALS("class Fred { void foo ( ) ; } ; void Fred :: foo ( ) { }", parse(clang));
}
void cxxMethodDecl4() {
const char clang[] = "|-ClassTemplateSpecializationDecl 0x15d82f8 <line:7:3, line:18:3> line:8:12 struct char_traits definition\n"
"| |-TemplateArgument type 'char'\n"
"| | `-BuiltinType 0x15984c0 'char'\n"
"| |-CXXRecordDecl 0x15d8520 <col:5, col:12> col:12 implicit struct char_traits\n"
"| |-TypedefDecl 0x15d85c0 <line:10:7, col:20> col:20 referenced char_type 'char'\n"
"| | `-BuiltinType 0x15984c0 'char'\n"
"| |-CXXMethodDecl 0x15d8738 <line:12:7, line:16:7> line:13:7 move 'char *(char *)' static\n"
"| | |-ParmVarDecl 0x15d8630 <col:12, col:18> col:18 used __s1 'char *'\n"
"| | `-CompoundStmt 0x15d88e8 <line:14:7, line:16:7>\n";
ASSERT_EQUALS("struct char_traits<char> { static char * move ( char * __s1@1 ) { } } ;",
parse(clang));
}
void cxxNewExpr1() {
const char clang[] = "|-VarDecl 0x3a97680 <1.cpp:2:1, col:14> col:6 i 'int *' cinit\n"
"| `-CXXNewExpr 0x3a97d18 <col:10, col:14> 'int *' Function 0x3a97778 'operator new' 'void *(unsigned long)'\n"