I am working on a Windows 10 server, and I have clang 7.0.0 install on (from llvm), and I'm attempting to get the abstract syntax trees (ast) of several programs that use templates in c++, however, I don't seem to be able to get the full ast. The command below is what I use on both my windows server and on my personal laptop which is running linux and has clang 7.0.0.
clang++ -c -fno-color-diagnostics -Xclang -ast-dump input.cpp > output.txt
The file, "input.cpp", is a simple mock template class:
template <class T>
class Thing {
private:
T a_ {};
public:
Thing() = default;
void set_thing(T a) { a_ = a; }
T& get_thing() { return a_; }
};
On my windows server, the output of template class is seen below:
`-ClassTemplateDecl 0x21dcd03f4c8 <input.cpp:1:1, line:12:1> line:2:7 Thing
|-TemplateTypeParmDecl 0x21dcd03f378 <line:1:11, col:17> col:17 referenced class depth 0 index 0 T
`-CXXRecordDecl 0x21dcd03f430 <line:2:1, line:12:1> line:2:7 class Thing definition
|-DefinitionData standard_layout trivially_copyable has_user_declared_ctor can_const_default_init
| |-DefaultConstructor exists
| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
|-CXXRecordDecl 0x21dcd03f730 <col:1, col:7> col:7 implicit referenced class Thing
|-AccessSpecDecl 0x21dcd03f7c8 <line:4:1, col:8> col:1 private
|-FieldDecl 0x21dcd03f800 <line:5:2, col:8> col:4 a_ 'T'
| `-InitListExpr 0x21dcd03fd30 <col:7, col:8> 'void'
|-AccessSpecDecl 0x21dcd03f850 <line:6:1, col:7> col:1 public
|-CXXConstructorDecl 0x21dcd03f920 <line:7:2, col:18> col:2 Thing<T> 'void ()' default
|-CXXMethodDecl 0x21dcd03fae0 <line:8:2, col:20> col:7 set_thing 'void (T)'
| |-ParmVarDecl 0x21dcd03f9e0 <col:17, col:19> col:19 a 'T'
| `-<<<NULL>>>
`-CXXMethodDecl 0x21dcd03fc70 <line:11:2, col:15> col:5 get_thing 'T &()'
`-<<<NULL>>>
On my personal laptop, the output is shown below:
`-ClassTemplateDecl 0x64dfc38 <input.cpp:1:1, line:12:1> line:2:7 Thing
|-TemplateTypeParmDecl 0x64dfae8 <line:1:11, col:17> col:17 referenced class depth 0 index 0 T
`-CXXRecordDecl 0x64dfba0 <line:2:1, line:12:1> line:2:7 class Thing definition
|-DefinitionData standard_layout trivially_copyable has_user_declared_ctor can_const_default_init
| |-DefaultConstructor exists
| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
|-CXXRecordDecl 0x64dfea0 <col:1, col:7> col:7 implicit referenced class Thing
|-AccessSpecDecl 0x64dff38 <line:4:1, col:8> col:1 private
|-FieldDecl 0x64dff70 <line:5:2, col:8> col:4 referenced a_ 'T'
| `-InitListExpr 0x64e0490 <col:7, col:8> 'void'
|-AccessSpecDecl 0x64dffb8 <line:6:1, col:7> col:1 public
|-CXXConstructorDecl 0x64e0080 <line:7:2, col:18> col:2 Thing<T> 'void ()' default
|-CXXMethodDecl 0x64e0240 <line:8:2, line:10:2> line:8:7 set_thing 'void (T)'
| |-ParmVarDecl 0x64e0140 <col:17, col:19> col:19 referenced a 'T'
| `-CompoundStmt 0x64e0570 <col:22, line:10:2>
| `-BinaryOperator 0x64e0548 <line:9:3, col:8> '<dependent type>' '='
| |-MemberExpr 0x64e04e8 <col:3> 'T' lvalue ->a_ 0x64dff70
| | `-CXXThisExpr 0x64e04d0 <col:3> 'Thing<T> *' this
| `-DeclRefExpr 0x64e0520 <col:8> 'T' lvalue ParmVar 0x64e0140 'a' 'T'
`-CXXMethodDecl 0x64e03d0 <line:11:2, col:30> col:5 get_thing 'T &()'
`-CompoundStmt 0x64e05f0 <col:17, col:30>
`-ReturnStmt 0x64e05d8 <col:19, col:26>
`-MemberExpr 0x64e05a0 <col:26> 'T' lvalue ->a_ 0x64dff70
`-CXXThisExpr 0x64e0588 <col:26> 'Thing<T> *' this
My focus is on the "NULL" nodes of the tree when I run the command on windows, and is not seen on my laptop. I was wondering what actions I could take to get the latter output on windows. I've attempted other versions like clang 6.0.0 with no luck. I have also attempt to use the command clang++ -cc1 -ast-dump input.cpp, however, it has problems with includes as cited here.
Note: I use html code snippet to format the ast tree because it was able to format it the best.