<div dir="ltr">I found that if I call `TraverseDecl()` or `TraverseAST()` on a visitor, the AST will expand, I dumped the context of the TranslateUnitDecl before and after `TraverseDecl()` is called:<div>before:</div><div><br></div><div>TranslationUnitDecl 0x5577ffd893a8 <<invalid sloc>> <invalid sloc> <undeserialized declarations><br>|-CXXMethodDecl 0x5577ffdb4670 parent 0x5577ffdb40a8 prev 0x5577ffdb4280 </home/liu/source/helloworld/main.cpp:1:1, line:3:1> line:1:11 used test 'void ()'<br>| |-Overrides: [ 0x5577ffdb43c8 Foo::test 'void ()' ]<br>| |-CompoundStmt 0x5577ffdb47e0 <col:18, line:3:1><br>| |-OverrideAttr 0x5577ffdb4790 </home/liu/source/helloworld/test.h:11:15> Inherited<br>| `-FinalAttr 0x5577ffdb47b8 <col:24> Inherited final<br>`-FunctionDecl 0x5577ffdb4840 </home/liu/source/helloworld/main.cpp:5:1, line:6:1> line:5:5 main 'int ()'<br>  `-CompoundStmt 0x5577ffdb4968 <col:12, line:6:1><br></div><div><br></div><div>As you can see, this is a method definition, pretty simple, it is indeed what I write in a cpp file.</div><div><br></div><div>but after calling `TraverseAST()`, the result of of the TranslateUnitDecl:</div><div><br></div><div>TranslationUnitDecl 0x5577ffd893a8 <<invalid sloc>> <invalid sloc><br>|-TypedefDecl 0x5577ffd8a048 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'<br>| `-BuiltinType 0x5577ffd89940 '__int128'<br>|-TypedefDecl 0x5577ffd8a0b8 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'<br>| `-BuiltinType 0x5577ffd89960 'unsigned __int128'<br>|-TypedefDecl 0x5577ffd89fb8 <<invalid sloc>> <invalid sloc> implicit __NSConstantString '__NSConstantString_tag'<br>| `-RecordType 0x5577ffd89d30 '__NSConstantString_tag' imported<br>|   `-CXXRecord 0x5577ffd89c88 '__NSConstantString_tag'<br>|-TypedefDecl 0x5577ffd8a150 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'<br>| `-PointerType 0x5577ffd8a110 'char *'<br>|   `-BuiltinType 0x5577ffd89440 'char'<br>|-TypedefDecl 0x5577ffdb4048 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'<br>| `-ConstantArrayType 0x5577ffdb3ff0 '__va_list_tag [1]' 1 <br>|   `-RecordType 0x5577ffd8a250 '__va_list_tag'<br>|     `-CXXRecord 0x5577ffd8a1a8 '__va_list_tag'<br>|-CXXRecordDecl 0x5577ffdb4470 </home/liu/source/helloworld/test.h:3:1, line:8:1> line:3:8 imported referenced struct Foo definition<br>| |-DefinitionData polymorphic literal has_constexpr_non_copy_move_ctor can_const_default_init<br>| | |-DefaultConstructor exists non_trivial constexpr needs_implicit defaulted_is_constexpr<br>| | |-CopyConstructor simple non_trivial has_const_param needs_implicit implicit_has_const_param<br>| | |-MoveConstructor exists simple non_trivial needs_implicit<br>| | |-CopyAssignment simple non_trivial has_const_param implicit_has_const_param<br>| | |-MoveAssignment exists simple non_trivial<br>| | `-Destructor simple irrelevant trivial<br>| |-CXXRecordDecl 0x5577ffdb49a8 <col:1, col:8> col:8 imported implicit struct Foo<br>| |-CXXMethodDecl 0x5577ffdb43c8 <line:5:3, col:24> col:16 imported test 'void ()' virtual<br>| | |-CompoundStmt 0x5577ffdb7e68 <col:23, col:24><br>| | `-AnnotateAttr 0x5577ffdb45a0 <line:4:5, col:12> "call_super"<br>| |-CXXMethodDecl 0x5577ffdb4a58 <line:7:3, col:31> col:16 imported used test2 'void ()' virtual<br>| | |-CompoundStmt 0x5577ffdb7e58 <col:30, col:31><br>| | |-AnnotateAttr 0x5577ffdb4af8 <line:6:5, col:12> "call_super"<br>| | `-FinalAttr 0x5577ffdb4b50 <line:7:24> final<br>| |-CXXMethodDecl 0x5577ffdb4bd0 <line:3:8> col:8 imported implicit constexpr operator= 'Foo &(const Foo &)' inline default noexcept-unevaluated 0x5577ffdb4bd0<br>| | `-ParmVarDecl 0x5577ffdb4d40 <col:8> col:8 imported 'const Foo &'<br>| |-CXXMethodDecl 0x5577ffdb4db8 <col:8> col:8 imported implicit constexpr operator= 'Foo &(Foo &&)' inline default noexcept-unevaluated 0x5577ffdb4db8<br>| | `-ParmVarDecl 0x5577ffdb7678 <col:8> col:8 imported 'Foo &&'<br>| `-CXXDestructorDecl 0x5577ffdb76f0 <col:8> col:8 imported implicit ~Foo 'void ()' inline default trivial noexcept-unevaluated 0x5577ffdb76f0<br>|-CXXRecordDecl 0x5577ffdb40a8 <line:10:1, line:12:1> line:10:8 imported struct Bar definition<br>| |-DefinitionData polymorphic literal has_constexpr_non_copy_move_ctor can_const_default_init<br>| | |-DefaultConstructor exists non_trivial constexpr needs_implicit defaulted_is_constexpr<br>| | |-CopyConstructor simple non_trivial has_const_param needs_implicit implicit_has_const_param<br>| | |-MoveConstructor exists simple non_trivial needs_implicit<br>| | |-CopyAssignment simple non_trivial has_const_param implicit_has_const_param<br>| | |-MoveAssignment exists simple non_trivial<br>| | `-Destructor simple irrelevant trivial<br>| |-public 'Foo'<br>| |-CXXRecordDecl 0x5577ffdb7888 <col:1, col:8> col:8 imported implicit struct Bar<br>| |-CXXMethodDecl 0x5577ffdb4280 <line:11:3, col:24> col:8 imported used test 'void ()'<br>| | |-Overrides: [ 0x5577ffdb43c8 Foo::test 'void ()' ]<br>| | |-OverrideAttr 0x5577ffdb4320 <col:15><br>| | `-FinalAttr 0x5577ffdb4348 <col:24> final<br>| |-CXXMethodDecl 0x5577ffdb7938 <line:10:8> col:8 imported implicit constexpr operator= 'Bar &(const Bar &)' inline default noexcept-unevaluated 0x5577ffdb7938<br>| | `-ParmVarDecl 0x5577ffdb7ab0 <col:8> col:8 imported 'const Bar &'<br>| |-CXXMethodDecl 0x5577ffdb7b28 <col:8> col:8 imported implicit constexpr operator= 'Bar &(Bar &&)' inline default noexcept-unevaluated 0x5577ffdb7b28<br>| | `-ParmVarDecl 0x5577ffdb7c70 <col:8> col:8 imported 'Bar &&'<br>| `-CXXDestructorDecl 0x5577ffdb7ce8 <col:8> col:8 imported implicit ~Bar 'void ()' inline default trivial noexcept-unevaluated 0x5577ffdb7ce8<br>|-CXXMethodDecl 0x5577ffdb4670 parent 0x5577ffdb40a8 prev 0x5577ffdb4280 </home/liu/source/helloworld/main.cpp:1:1, line:3:1> line:1:11 used test 'void ()'<br>| |-Overrides: [ 0x5577ffdb43c8 Foo::test 'void ()' ]<br>| |-CompoundStmt 0x5577ffdb47e0 <col:18, line:3:1><br>| |-OverrideAttr 0x5577ffdb4790 </home/liu/source/helloworld/test.h:11:15> Inherited<br>| `-FinalAttr 0x5577ffdb47b8 <col:24> Inherited final<br>`-FunctionDecl 0x5577ffdb4840 </home/liu/source/helloworld/main.cpp:5:1, line:6:1> line:5:5 main 'int ()'<br>  `-CompoundStmt 0x5577ffdb4968 <col:12, line:6:1><br><br></div><div>And this will 100% happen even if I implemented nothing in a visitor.</div><div><br></div><div>Since the code of the traverse highly depends on macros, it hard for me to debug what's going on.</div><div><br></div><div>So can anyone help:</div><div>1. Why does the AST expand?</div><div>2. Can I prevent it from expanding if I don't need the information of the PCH? Less traverse means better performance.</div><div>3. If the expansion is not the common case, are there any good break points for me to debug?</div><div><br></div><div><br></div></div>