Reputation: 526
I am confused with the clang ast-dump outout, what does the line and col mean? Thanks
`-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 used an 'class Anmimal' 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 'class Anmimal' lvalue Var 0xa853fb8 'an' 'class Anmimal'
| -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 used 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 0xa87ef38 'struct Cat' lvalue Var 0xa87ea28 'cat' 'struct Cat'
| -IntegerLiteral 0xa87ef98 <col:16> 'int' 20
-ReturnStmt 0xa87f000
`-IntegerLiteral 0xa87efe0 'int' 0
Upvotes: 1
Views: 788
Reputation: 1111
They are source locations associated with each node of the AST: file, line, and column. Clang typically reports either the start of the node or the range covered by the node. To save space, Clang does not repeat the file name when it is the same as the preceding node's. The same is true with line numbers. The algorithm is
if(filename != old_filename)
print filename:line:column
old_filename = filename
elseif(line != old_line)
print line:column
old_line = line
else
print column
So the function declaration for main()
spans lines 33-44. It seems that main's declaration starts at col. 5 of line 33. And so on.
Source locations can be accessed programmatically through getLocStart()
, getLocEnd()
, and getSourceRange()
methods on various AST objects, permitting one to make precise changes to source code.
Upvotes: 3