TestClangImport: Fix tests

This commit is contained in:
Daniel Marjamäki 2020-11-01 11:33:01 +01:00
parent 5aab1f9692
commit 4094274723
2 changed files with 40 additions and 67 deletions

View File

@ -1186,10 +1186,7 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
className = mExtTokens[mExtTokens.size() - 2];
className += getTemplateParameters();
/*Token *nameToken =*/ addtoken(tokenList, className);
if (!isDefinition()) {
addtoken(tokenList, ";");
return;
}
if (isDefinition()) {
std::vector<AstNodePtr> children2;
for (AstNodePtr child: children) {
if (child->nodeType == CXXConstructorDecl ||
@ -1202,6 +1199,8 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
scope->className = className;
mData->mSymbolDatabase->typeList.push_back(Type(classToken, scope, classToken->scope()));
scope->definedType = &mData->mSymbolDatabase->typeList.back();
}
addtoken(tokenList, ";");
}
Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList)

View File

@ -60,6 +60,7 @@ private:
TEST_CASE(cxxNullPtrLiteralExpr);
TEST_CASE(cxxOperatorCallExpr);
TEST_CASE(cxxRecordDecl1);
TEST_CASE(cxxRecordDecl2);
TEST_CASE(cxxStaticCastExpr1);
TEST_CASE(cxxStaticCastExpr2);
TEST_CASE(cxxStdInitializerListExpr);
@ -115,7 +116,7 @@ private:
Tokenizer tokenizer(&settings, this);
std::istringstream istr(clang);
clangimport::parseClangAstDump(&tokenizer, istr);
return tokenizer.tokens()->stringifyList(true, false, false, true, false);
return tokenizer.tokens()->stringifyList(true, false, false, false, false);
}
void breakStmt() {
@ -164,14 +165,7 @@ private:
" | |-DeclRefExpr 0x2444d68 <col:13> 'int' lvalue ParmVar 0x2444aa0 'x' 'int'\n"
" | `-IntegerLiteral 0x2444d90 <col:15> 'int' 123\n"
" `-BreakStmt 0x2444dd8 <line:6:13>";
ASSERT_EQUALS("void foo ( int x@1 ) {\n"
"switch ( x@1 ) {\n"
"case 16 :\n"
"case 32 :\n"
"x@1 = 123 ;\n"
"\n"
"\n"
"break ; } }", parse(clang));
ASSERT_EQUALS("void foo ( int x@1 ) { switch ( x@1 ) { case 16 : case 32 : x@1 = 123 ; break ; } }", parse(clang));
}
void characterLiteral() {
@ -192,7 +186,7 @@ private:
" |-CXXRecordDecl 0x274c758 <col:1, col:7> col:7 implicit class C\n"
" `-CXXMethodDecl 0x274c870 <col:11, col:23> col:16 foo 'void ()'\n"
" `-CompoundStmt 0x274c930 <col:22, col:23>";
ASSERT_EQUALS("class C { void foo ( ) { } }", parse(clang));
ASSERT_EQUALS("class C { void foo ( ) { } } ;", parse(clang));
}
void classTemplateDecl1() {
@ -253,7 +247,7 @@ private:
"| | `-ParmVarDecl 0x247c790 <col:25> col:25 'const C<int> &'\n"
"| `-CXXConstructorDecl 0x247c828 <col:25> col:25 implicit constexpr C 'void (C<int> &&)' inline default trivial noexcept-unevaluated 0x247c828\n"
"| `-ParmVarDecl 0x247c960 <col:25> col:25 'C<int> &&'\n";
ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } default ( ) { } noexcept-unevaluated ( const C<int> & ) ; noexcept-unevaluated ( C<int> && ) ; }", parse(clang));
ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } default ( ) { } noexcept-unevaluated ( const C<int> & ) ; noexcept-unevaluated ( C<int> && ) ; } ;", parse(clang));
}
void conditionalExpr() {
@ -360,7 +354,7 @@ private:
const char clang[] = "`-CXXRecordDecl 0x8ecd60 <1.cpp:1:1, line:4:1> line:1:8 struct S definition\n"
" `-CXXDestructorDecl 0x8ed088 <line:3:3, col:9> col:3 ~S 'void () noexcept'\n"
" `-CompoundStmt 0x8ed1a8 <col:8, col:9>";
ASSERT_EQUALS("struct S\n\n{ ~S ( ) { } }", parse(clang));
ASSERT_EQUALS("struct S { ~S ( ) { } } ;", parse(clang));
}
void cxxForRangeStmt1() {
@ -394,8 +388,7 @@ private:
" | `-ImplicitCastExpr 0x4281040 <col:15> 'const char *':'const char *' <LValueToRValue>\n"
" | `-DeclRefExpr 0x4281018 <col:15> 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n"
" `-CompoundStmt 0x42810e0 <col:24, line:7:3>";
ASSERT_EQUALS("void foo ( ) {\n"
"for ( char c1@1 : hello ) { } }",
ASSERT_EQUALS("void foo ( ) { for ( char c1@1 : hello ) { } }",
parse(clang));
}
@ -449,8 +442,7 @@ private:
" | `-CXXFunctionalCastExpr 0x1592b40 <line:2:15, line:3:28> 'MyVar<int>':'MyVar<int>' functional cast to MyVar<int> <ConstructorConversion>\n"
" | `-CXXConstructExpr 0x15929f0 <line:2:15, line:3:28> 'MyVar<int>':'MyVar<int>' 'void (int)'\n"
" | `-IntegerLiteral 0x1570248 <col:27> 'int' 5\n";
ASSERT_EQUALS("int main ( int argc@1 , char ** argv@2 ) {\n"
"MyVar<int> setCode@3 = MyVar<int> ( 5 ) ; }",
ASSERT_EQUALS("int main ( int argc@1 , char ** argv@2 ) { MyVar<int> setCode@3 = MyVar<int> ( 5 ) ; }",
parse(clang));
}
@ -498,11 +490,7 @@ private:
"| `-CXXMethodDecl 0x21ccc68 <line:3:1, col:10> col:6 foo 'void ()'\n"
"`-CXXMethodDecl 0x21ccd60 parent 0x21cca40 prev 0x21ccc68 <line:6:1, col:19> col:12 foo 'void ()'\n"
" `-CompoundStmt 0x21cce50 <col:18, col:19>";
ASSERT_EQUALS("class Fred\n"
"{ void foo ( ) ; }\n"
"\n"
"\n"
"void foo ( ) { }", parse(clang));
ASSERT_EQUALS("class Fred { void foo ( ) ; } ; void foo ( ) { }", parse(clang));
}
void cxxNewExpr1() {
@ -512,8 +500,7 @@ private:
" `-CXXNewExpr 0x3a97e68 <col:10, col:21> 'int *' array Function 0x3a978c0 'operator new[]' 'void *(unsigned long)'\n"
" `-ImplicitCastExpr 0x3a97e18 <col:18> 'unsigned long' <IntegralCast>\n"
" `-IntegerLiteral 0x3a97de0 <col:18> 'int' 100";
ASSERT_EQUALS("int * i@1 = new int ;\n"
"int * j@2 = new int [ 100 ] ;",
ASSERT_EQUALS("int * i@1 = new int ; int * j@2 = new int [ 100 ] ;",
parse(clang));
}
@ -523,8 +510,7 @@ private:
"| `-ReturnStmt 0x5c4308 <line:8:3, col:14>\n"
"| `-CXXNewExpr 0x5c42c8 <col:10, col:14> 'S *' Function 0x59a378 'operator new' 'void *(unsigned long)'\n"
"| `-CXXConstructExpr 0x5c42a0 <col:14> 'S' 'void () noexcept'";
ASSERT_EQUALS("struct S * f ( ) {\n"
"return new S ( ) ; }",
ASSERT_EQUALS("struct S * f ( ) { return new S ( ) ; }",
parse(clang));
}
@ -554,6 +540,11 @@ private:
ASSERT_EQUALS("class Foo ;", parse(clang));
}
void cxxRecordDecl2() {
const char clang[] = "`-CXXRecordDecl 0x34cc5f8 <1.cpp:2:1, col:7> col:7 struct Foo definition";
ASSERT_EQUALS("struct Foo { } ;", parse(clang));
}
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"
@ -601,7 +592,7 @@ private:
" `-DefaultStmt 0x1847830 <line:6:3, line:7:12>\n"
" `-ReturnStmt 0x1847820 <col:5, col:12>\n"
" `-IntegerLiteral 0x1847800 <col:12> 'int' 1";
ASSERT_EQUALS("int foo ( int rc@1 ) {\n\nswitch ( rc@1 ) {\ndefault : return 1 ; } }", parse(clang));
ASSERT_EQUALS("int foo ( int rc@1 ) { switch ( rc@1 ) { default : return 1 ; } }", parse(clang));
}
void doStmt() {
@ -661,8 +652,7 @@ private:
" | `-DeclRefExpr 0x24b2d28 <col:12> 'int' lvalue ParmVar 0x24b2ae0 'x' 'int'\n"
" `-ImplicitCastExpr 0x24b2d90 <col:16> 'int' <LValueToRValue>\n"
" `-DeclRefExpr 0x24b2d50 <col:16> 'int' lvalue ParmVar 0x24b2b58 'y' 'int'";
ASSERT_EQUALS("int foo ( int x@1 , int y@2 ) {\n\n"
"return x@1 / y@2 ; }", parse(clang));
ASSERT_EQUALS("int foo ( int x@1 , int y@2 ) { return x@1 / y@2 ; }", parse(clang));
}
void funcdecl3() {
@ -711,8 +701,7 @@ private:
" |-ImplicitCastExpr 0x333afc8 <col:9, col:16> 'int (*)(int)' <FunctionToPointerDecay>\n"
" | `-DeclRefExpr 0x333af00 <col:9, col:16> 'int (int)' lvalue Function 0x333ae00 'foo' 'int (int)' (FunctionTemplate 0x333a860 'foo')\n"
" `-IntegerLiteral 0x333ab48 <col:18> 'int' 1";
ASSERT_EQUALS("int foo<int> ( int t@1 ) { return t@1 + 1 ; }\n"
"int bar ( ) { foo ( 1 ) ; }", parse(clang));
ASSERT_EQUALS("int foo<int> ( int t@1 ) { return t@1 + 1 ; } int bar ( ) { foo ( 1 ) ; }", parse(clang));
}
void ifelse() {
@ -728,9 +717,7 @@ private:
" | `-IntegerLiteral 0x2637cb8 <col:13> 'int' 10\n"
" |-CompoundStmt 0x2637d18 <col:17, col:18>\n"
" `-CompoundStmt 0x2637d28 <line:3:10, col:11>";
ASSERT_EQUALS("int foo ( int x@1 ) {\n"
"if ( x@1 > 10 ) { }\n"
"else { } }", parse(clang));
ASSERT_EQUALS("int foo ( int x@1 ) { if ( x@1 > 10 ) { } else { } }", parse(clang));
}
void ifStmt() {
@ -774,8 +761,7 @@ private:
" `-ImplicitCastExpr 0x2441e40 <col:30, col:32> 'int' <LValueToRValue>\n"
" `-MemberExpr 0x2441e08 <col:30, col:32> 'int' lvalue .x 0x2441b48\n"
" `-DeclRefExpr 0x2441de0 <col:30> 'struct S':'struct S' lvalue ParmVar 0x2441be8 's' 'struct S':'struct S'";
ASSERT_EQUALS("struct S { int x@1 ; } ;\n"
"int foo ( struct S s@2 ) { return s@2 . x@1 ; }",
ASSERT_EQUALS("struct S { int x@1 ; } ; int foo ( struct S s@2 ) { return s@2 . x@1 ; }",
parse(clang));
}
@ -790,9 +776,7 @@ private:
const char clang[] = "`-RecordDecl 0x354eac8 <1.c:1:1, line:4:1> line:1:8 struct S definition\n"
" |-FieldDecl 0x354eb88 <line:2:3, col:7> col:7 x 'int'\n"
" `-FieldDecl 0x354ebe8 <line:3:3, col:7> col:7 y 'int'";
ASSERT_EQUALS("struct S\n"
"{ int x@1 ;\n"
"int y@2 ; } ;",
ASSERT_EQUALS("struct S { int x@1 ; int y@2 ; } ;",
parse(clang));
}
@ -868,8 +852,7 @@ private:
" `-ImplicitCastExpr 0x32b8c00 <col:9> 'int' <LValueToRValue>\n"
" `-DeclRefExpr 0x32b8bd8 <col:9> 'int' lvalue Var 0x32b8aa0 'a' 'int'";
ASSERT_EQUALS("int a@1 = 1 ;\n"
"int b@2 = a@1 ;",
ASSERT_EQUALS("int a@1 = 1 ; int b@2 = a@1 ;",
parse(clang));
}
@ -884,11 +867,7 @@ private:
" | `-IntegerLiteral 0x3873d00 <col:5> 'int' 0\n"
" `-IntegerLiteral 0x3873d88 <col:10> 'int' 0\n";
ASSERT_EQUALS("int [10] a@1 ;\n" // <- TODO
"\n"
"void foo ( ) {\n"
"\n"
"a@1 [ 0 ] = 0 ; }",
ASSERT_EQUALS("int [10] a@1 ; void foo ( ) { a@1 [ 0 ] = 0 ; }",
parse(clang));
}
@ -920,8 +899,7 @@ private:
" |-<<<NULL>>>\n"
" |-IntegerLiteral 0x3d45bf8 <col:12> 'int' 0\n"
" `-NullStmt 0x3d45c18 <col:14>";
ASSERT_EQUALS("void foo ( ) {\n"
"while ( 0 ) { ; } }",
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { ; } }",
parse(clang));
}
@ -957,11 +935,7 @@ private:
"`-VarDecl 0x29ad898 <line:5:1, col:22> col:9 x 'ns::abc':'ns::abc' cinit\n"
" `-DeclRefExpr 0x29ad998 <col:13, col:22> 'ns::abc' EnumConstant 0x29ad7b0 'c' 'ns::abc'\n";
ASSERT_EQUALS("namespace ns\n"
"{ enum abc { a , b , c } }\n"
"\n"
"\n"
"ns::abc x@1 = c ;", parse(clang));
ASSERT_EQUALS("namespace ns { enum abc { a , b , c } } ns::abc x@1 = c ;", parse(clang));
GET_SYMBOL_DB(clang);