我对clang ast-dump outout感到困惑,线和col是什么意思? 谢谢
`-FunctionDecl 0xa853e98 <line:33:1, line:44:1> line:33:5 main 'int (void)'
-CompoundStmt 0xa87f018 <line:34:1, line:44:1>
|-DeclStmt 0xa87e808 <line:35:1, col:11>
|
- VarDecl 0xa853fb8 col:9使用了&#39;类Anmimal&#39; callinit
| -CXXConstructExpr 0xa87e7d8 <col:9> 'class Anmimal' 'void (void) throw()'
|-BinaryOperator 0xa87e8a0 <line:36:1, col:10> 'int' lvalue '='
| |-MemberExpr 0xa87e848 <col:1, col:4> 'int' lvalue .age 0xa8533b0
| |
- DeclRefExpr 0xa87e820&#39; class Anmimal&#39;左值Var 0xa853fb8&#39;&#39; &#39;类Anmimal&#39;
| -IntegerLiteral 0xa87e880 <col:10> 'int' 100
|-CXXMemberCallExpr 0xa87e9f0 <line:38:1, col:12> 'int'
|
- MemberExpr 0xa87e9b8&#39;&#39; .getSize 0xa853c48
| -DeclRefExpr 0xa87e990 <col:1> 'class Anmimal' lvalue Var 0xa853fb8 'an' 'class Anmimal'
|-DeclStmt 0xa87edb0 <line:40:1, col:8>
|
- VarDecl 0xa87ea28 col:5使用cat&#39; struct Cat&#39; callinit
| -CXXConstructExpr 0xa87ed80 <col:5> 'struct Cat' 'void (void) throw()'
|-BinaryOperator 0xa87ee48 <line:41:1, col:15> 'int' lvalue '='
| |-MemberExpr 0xa87edf0 <col:1, col:5> 'int' lvalue .age_cat 0xa853b38
| |
- DeclRefExpr 0xa87edc8&#39; struct Cat&#39;左值Var 0xa87ea28&#39; cat&#39; &#39; struct Cat&#39;
| -IntegerLiteral 0xa87ee28 <col:15> 'int' 10
|-BinaryOperator 0xa87efb8 <line:42:1, col:16> 'int' lvalue '='
| |-MemberExpr 0xa87ef60 <col:1, col:5> 'int' lvalue .size_cat 0xa853b98
| |
- DeclRefExpr 0xa87ef38&#39; struct Cat&#39;左值Var 0xa87ea28&#39; cat&#39; &#39; struct Cat&#39;
| -IntegerLiteral 0xa87ef98 <col:16> 'int' 20
- ReturnStmt 0xa87f000
`-IntegerLiteral 0xa87efe0&#39; int&#39; 0
答案 0 :(得分:1)
它们是与AST的每个节点关联的源位置:文件,行和列。 Clang通常报告节点的开始或节点覆盖的范围。为了节省空间,当Clang与前面的节点相同时,它不会重复文件名。行号也是如此。算法是
if(filename != old_filename)
print filename:line:column
old_filename = filename
elseif(line != old_line)
print line:column
old_line = line
else
print column
因此main()
的函数声明跨越第33-44行。主要的声明似乎从col开始。第33行中的第5行。依此类推。
可以通过各种AST对象上的getLocStart()
,getLocEnd()
和getSourceRange()
方法以编程方式访问源位置,从而允许对源代码进行精确更改。