Skip to content

Commit bad7991

Browse files
committed
exprForRange
1 parent add14be commit bad7991

1 file changed

Lines changed: 43 additions & 73 deletions

File tree

test/testclangimport.cpp

Lines changed: 43 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ class TestClangImport : public TestFixture {
6060
/*
6161
TEST_CASE(cxxDeleteExpr);
6262
TEST_CASE(cxxDestructorDecl);
63-
TEST_CASE(cxxForRangeStmt1);
64-
TEST_CASE(cxxForRangeStmt2);
63+
*/
64+
TEST_CASE(cxxForRangeStmt1);
65+
/*
6566
TEST_CASE(cxxFunctionalCastExpr);
6667
TEST_CASE(cxxMemberCall);
6768
TEST_CASE(cxxMethodDecl1);
@@ -433,79 +434,48 @@ class TestClangImport : public TestFixture {
433434
" `-CompoundStmt 0x8ed1a8 <col:8, col:9>";
434435
ASSERT_EQUALS("struct S { ~S ( ) { } } ;", parse(clang));
435436
}
436-
437+
*/
437438
void cxxForRangeStmt1() {
438-
const char clang[] = "`-FunctionDecl 0x4280820 <a.cpp:4:1, line:8:1> line:4:6 foo 'void ()'\n"
439-
" `-CompoundStmt 0x42810f0 <col:12, line:8:1>\n"
440-
" `-CXXForRangeStmt 0x4281090 <line:5:3, line:7:3>\n"
441-
" |-DeclStmt 0x4280c30 <line:5:17>\n"
442-
" | `-VarDecl 0x42809c8 <col:17> col:17 implicit referenced __range1 'char const (&)[6]' cinit\n"
443-
" | `-DeclRefExpr 0x42808c0 <col:17> 'const char [6]' lvalue Var 0x4280678 'hello' 'const char [6]'\n"
444-
" |-DeclStmt 0x4280ef8 <col:15>\n"
445-
" | `-VarDecl 0x4280ca8 <col:15> col:15 implicit used __begin1 'const char *':'const char *' cinit\n"
446-
" | `-ImplicitCastExpr 0x4280e10 <col:15> 'const char *' <ArrayToPointerDecay>\n"
447-
" | `-DeclRefExpr 0x4280c48 <col:15> 'char const[6]' lvalue Var 0x42809c8 '__range1' 'char const (&)[6]'\n"
448-
" |-DeclStmt 0x4280f10 <col:15>\n"
449-
" | `-VarDecl 0x4280d18 <col:15, col:17> col:15 implicit used __end1 'const char *':'const char *' cinit\n"
450-
" | `-BinaryOperator 0x4280e60 <col:15, col:17> 'const char *' '+'\n"
451-
" | |-ImplicitCastExpr 0x4280e48 <col:15> 'const char *' <ArrayToPointerDecay>\n"
452-
" | | `-DeclRefExpr 0x4280c70 <col:15> 'char const[6]' lvalue Var 0x42809c8 '__range1' 'char const (&)[6]'\n"
453-
" | `-IntegerLiteral 0x4280e28 <col:17> 'long' 6\n"
454-
" |-BinaryOperator 0x4280fa8 <col:15> 'bool' '!='\n"
455-
" | |-ImplicitCastExpr 0x4280f78 <col:15> 'const char *':'const char *' <LValueToRValue>\n"
456-
" | | `-DeclRefExpr 0x4280f28 <col:15> 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n"
457-
" | `-ImplicitCastExpr 0x4280f90 <col:15> 'const char *':'const char *' <LValueToRValue>\n"
458-
" | `-DeclRefExpr 0x4280f50 <col:15> 'const char *':'const char *' lvalue Var 0x4280d18 '__end1' 'const char *':'const char *'\n"
459-
" |-UnaryOperator 0x4280ff8 <col:15> 'const char *':'const char *' lvalue prefix '++'\n"
460-
" | `-DeclRefExpr 0x4280fd0 <col:15> 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n"
461-
" |-DeclStmt 0x4280958 <col:8, col:22>\n"
462-
" | `-VarDecl 0x42808f8 <col:8, col:15> col:13 c1 'char' cinit\n"
463-
" | `-ImplicitCastExpr 0x4281078 <col:15> 'char' <LValueToRValue>\n"
464-
" | `-UnaryOperator 0x4281058 <col:15> 'const char' lvalue prefix '*' cannot overflow\n"
465-
" | `-ImplicitCastExpr 0x4281040 <col:15> 'const char *':'const char *' <LValueToRValue>\n"
466-
" | `-DeclRefExpr 0x4281018 <col:15> 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n"
467-
" `-CompoundStmt 0x42810e0 <col:24, line:7:3>";
468-
ASSERT_EQUALS("void foo ( ) { for ( char c1@1 : hello ) { } }",
469-
parse(clang));
470-
}
471-
472-
void cxxForRangeStmt2() {
473-
// clang 9
474-
const char clang[] = "`-FunctionDecl 0xc15d98 <a.cpp:3:1, col:36> col:6 foo 'void ()'\n"
475-
" `-CompoundStmt 0xc16668 <col:12, col:36>\n"
476-
" `-CXXForRangeStmt 0xc165f8 <col:14, col:34>\n"
477-
" |-<<<NULL>>>\n"
478-
" |-DeclStmt 0xc161c0 <col:25>\n"
479-
" | `-VarDecl 0xc15f48 <col:25> col:25 implicit referenced __range1 'int const (&)[4]' cinit\n"
480-
" | `-DeclRefExpr 0xc15e38 <col:25> 'const int [4]' lvalue Var 0xc15ac0 'values' 'const int [4]'\n"
481-
" |-DeclStmt 0xc16498 <col:24>\n"
482-
" | `-VarDecl 0xc16228 <col:24> col:24 implicit used __begin1 'const int *':'const int *' cinit\n"
483-
" | `-ImplicitCastExpr 0xc163b0 <col:24> 'const int *' <ArrayToPointerDecay>\n"
484-
" | `-DeclRefExpr 0xc161d8 <col:24> 'int const[4]' lvalue Var 0xc15f48 '__range1' 'int const (&)[4]' non_odr_use_constant\n"
485-
" |-DeclStmt 0xc164b0 <col:24>\n"
486-
" | `-VarDecl 0xc162a0 <col:24, col:25> col:24 implicit used __end1 'const int *':'const int *' cinit\n"
487-
" | `-BinaryOperator 0xc16400 <col:24, col:25> 'const int *' '+'\n"
488-
" | |-ImplicitCastExpr 0xc163e8 <col:24> 'const int *' <ArrayToPointerDecay>\n"
489-
" | | `-DeclRefExpr 0xc161f8 <col:24> 'int const[4]' lvalue Var 0xc15f48 '__range1' 'int const (&)[4]' non_odr_use_constant\n"
490-
" | `-IntegerLiteral 0xc163c8 <col:25> 'long' 4\n"
491-
" |-BinaryOperator 0xc16538 <col:24> 'bool' '!='\n"
492-
" | |-ImplicitCastExpr 0xc16508 <col:24> 'const int *':'const int *' <LValueToRValue>\n"
493-
" | | `-DeclRefExpr 0xc164c8 <col:24> 'const int *':'const int *' lvalue Var 0xc16228 '__begin1' 'const int *':'const int *'\n"
494-
" | `-ImplicitCastExpr 0xc16520 <col:24> 'const int *':'const int *' <LValueToRValue>\n"
495-
" | `-DeclRefExpr 0xc164e8 <col:24> 'const int *':'const int *' lvalue Var 0xc162a0 '__end1' 'const int *':'const int *'\n"
496-
" |-UnaryOperator 0xc16578 <col:24> 'const int *':'const int *' lvalue prefix '++'\n"
497-
" | `-DeclRefExpr 0xc16558 <col:24> 'const int *':'const int *' lvalue Var 0xc16228 '__begin1' 'const int *':'const int *'\n"
498-
" |-DeclStmt 0xc15ed8 <col:19, col:31>\n"
499-
" | `-VarDecl 0xc15e70 <col:19, col:24> col:23 v 'int' cinit\n"
500-
" | `-ImplicitCastExpr 0xc165e0 <col:24> 'int' <LValueToRValue>\n"
501-
" | `-UnaryOperator 0xc165c8 <col:24> 'const int' lvalue prefix '*' cannot overflow\n"
502-
" | `-ImplicitCastExpr 0xc165b0 <col:24> 'const int *':'const int *' <LValueToRValue>\n"
503-
" | `-DeclRefExpr 0xc16590 <col:24> 'const int *':'const int *' lvalue Var 0xc16228 '__begin1' 'const int *':'const int *'\n"
504-
" `-CompoundStmt 0xc16658 <col:33, col:34>";
505-
ASSERT_EQUALS("void foo ( ) { for ( int v@1 : values ) { } }",
506-
parse(clang));
439+
// This json dump was generated by tools/testclangimport.py
440+
// code: int x[2]; void f () { for (int i: x) {} }
441+
const char clang_json[] = R"C(
442+
{"kind": "TranslationUnitDecl", "id": "0x1", "inner": [
443+
{"kind": "VarDecl", "name": "x", "id": "0x2", "type": {"qualType": "int[2]"}},
444+
{"kind": "FunctionDecl", "name": "f", "id": "0x3", "type": {"qualType": "void ()"}, "inner": [
445+
{"kind": "CompoundStmt", "id": "0x4", "inner": [
446+
{"kind": "CXXForRangeStmt", "id": "0x5", "inner": [{},
447+
{"kind": "DeclStmt", "id": "0x6", "inner": [
448+
{"kind": "VarDecl", "name": "__range1", "init": "c", "id": "0x7", "type": {"qualType": "int (&)[2]"}, "inner": [
449+
{"kind": "DeclRefExpr", "id": "0x8", "type": {"qualType": "int[2]"}, "referencedDecl": {"name": "x", "id": "0x2"}}]}]},
450+
{"kind": "DeclStmt", "id": "0x9", "inner": [
451+
{"kind": "VarDecl", "name": "__begin1", "init": "c", "id": "0xa", "type": {"qualType": "int *"}, "inner": [
452+
{"kind": "ImplicitCastExpr", "id": "0xb", "type": {"qualType": "int *"}, "inner": [
453+
{"kind": "DeclRefExpr", "id": "0xc", "type": {"qualType": "int[2]"}, "referencedDecl": {"name": "__range1", "id": "0x7"}}]}]}]},
454+
{"kind": "DeclStmt", "id": "0xd", "inner": [
455+
{"kind": "VarDecl", "name": "__end1", "init": "c", "id": "0xe", "type": {"qualType": "int *"}, "inner": [
456+
{"kind": "BinaryOperator", "opcode": "+", "id": "0xf", "type": {"qualType": "int *"}, "inner": [
457+
{"kind": "ImplicitCastExpr", "id": "0x10", "type": {"qualType": "int *"}, "inner": [
458+
{"kind": "DeclRefExpr", "id": "0x11", "type": {"qualType": "int[2]"}, "referencedDecl": {"name": "__range1", "id": "0x7"}}]},
459+
{"kind": "IntegerLiteral", "value": "2", "id": "0x12", "type": {"qualType": "long"}}]}]}]},
460+
{"kind": "BinaryOperator", "opcode": "!=", "id": "0x13", "type": {"qualType": "bool"}, "inner": [
461+
{"kind": "ImplicitCastExpr", "id": "0x14", "type": {"qualType": "int *"}, "inner": [
462+
{"kind": "DeclRefExpr", "id": "0x15", "type": {"qualType": "int *"}, "referencedDecl": {"name": "__begin1", "id": "0xa"}}]},
463+
{"kind": "ImplicitCastExpr", "id": "0x16", "type": {"qualType": "int *"}, "inner": [
464+
{"kind": "DeclRefExpr", "id": "0x17", "type": {"qualType": "int *"}, "referencedDecl": {"name": "__end1", "id": "0xe"}}]}]},
465+
{"kind": "UnaryOperator", "opcode": "++", "id": "0x18", "type": {"qualType": "int *"}, "inner": [
466+
{"kind": "DeclRefExpr", "id": "0x19", "type": {"qualType": "int *"}, "referencedDecl": {"name": "__begin1", "id": "0xa"}}]},
467+
{"kind": "DeclStmt", "id": "0x1a", "inner": [
468+
{"kind": "VarDecl", "name": "i", "init": "c", "id": "0x1b", "type": {"qualType": "int"}, "inner": [
469+
{"kind": "ImplicitCastExpr", "id": "0x1c", "type": {"qualType": "int"}, "inner": [
470+
{"kind": "UnaryOperator", "opcode": "*", "id": "0x1d", "type": {"qualType": "int"}, "inner": [
471+
{"kind": "ImplicitCastExpr", "id": "0x1e", "type": {"qualType": "int *"}, "inner": [
472+
{"kind": "DeclRefExpr", "id": "0x1f", "type": {"qualType": "int *"}, "referencedDecl": {"name": "__begin1", "id": "0xa"}}]}]}]}]}]},
473+
{"kind": "CompoundStmt", "id": "0x20"}]}]}]}]})C";
474+
475+
ASSERT_EQUALS("int x@1 [ 2 ] ; void f ( ) { for ( int i@2 : x@1 ) { } }",
476+
parse(clang_json));
507477
}
508-
478+
/*
509479
void cxxFunctionalCastExpr() {
510480
const char clang[] = "`-FunctionDecl 0x156fe98 <a.cpp:1:1, line:3:1> line:1:5 main 'int (int, char **)'\n"
511481
" |-ParmVarDecl 0x156fd00 <col:10, col:14> col:14 argc 'int'\n"

0 commit comments

Comments
 (0)