我与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使用了"类anmamal" 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'类anmimal'lvalue var 0xa853fb8'an an'''''''''' | -IntegerLiteral 0xa87e880 <col:10> 'int' 100
|-CXXMemberCallExpr 0xa87e9f0 <line:38:1, col:12> 'int'
|
-memberexpr 0xa87e9b8''.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'struct Cat'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'struct cat'lvalue var 0xa87ea28'cat'struct cat' |-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 0xa877ef38'struct cat'lvalue var 0xa87ea28'cat'struct cat' |-IntegerLiteral 0xa87ef98 <col:16> 'int' 20
-RETURNSTMT 0XA87F000 `-integerliteral 0xa87efe0'Int'0
它们是与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的函数声明。Main的声明似乎始于Col。第33行的第5条等。
可以通过各种AST对象上的getLocStart()
,getLocEnd()
和getSourceRange()
方法以编程方式访问源位置,从而允许一个对源代码进行精确更改。