我正在Windows 10服务器上工作,并且在llvm上安装了clang 7.0.0,并且我试图获取使用模板的多个程序的抽象语法树(ast)但是,在c ++中,我似乎无法完全理解。下面的命令是我在Windows服务器和运行linux并且具有clang 7.0.0的个人笔记本电脑上使用的命令。
clang++ -c -fno-color-diagnostics -Xclang -ast-dump input.cpp > output.txt
文件“ input.cpp”是一个简单的模拟模板类:
template <class T>
class Thing {
private:
T a_ {};
public:
Thing() = default;
void set_thing(T a) { a_ = a; }
T& get_thing() { return a_; }
};
在我的Windows服务器上,模板类的输出如下所示:
`-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>>>
在我的个人笔记本电脑上,输出如下所示:
`-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
当我在Windows上运行命令时,我的注意力集中在树的“ NULL”节点上,而在笔记本电脑上却看不到。我想知道我可以采取什么措施将后者输出到Windows上。我尝试了其他版本,例如clang 6.0.0,但没有运气。我也尝试使用命令clang ++ -cc1 -ast-dump input.cpp,但是,包含引号here时存在问题。
注意:我使用html代码段来格式化ast树,因为它能够最好地对其进行格式化。
答案 0 :(得分:0)
clang ++ -c -fno-delayed-template-parsing -fno-color-diagnostics -Xclang -ast-dump input.cpp