<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi,<br>
<br>
I am parsing some very simple C-header file with libclang. My program parses the translation unit and visits all nodes in the AST:<br>
<br>
<pre><code>int main(int argc, char *argv[]) {<br>    CXIndex index = clang_createIndex(0, 0);<br><br>    const char *filename = "Node.h";<br><br>    CXTranslationUnit TU = clang_parseTranslationUnit(index, filename, NULL, 0, NULL, 0, CXTranslationUnit_None);<br><br>    CXCursor rootCursor = clang_getTranslationUnitCursor(TU);<br><br>    clang_visitChildren(rootCursor, printVisitor, NULL);<br><br>    clang_disposeTranslationUnit(TU);<br>    clang_disposeIndex(index);<br>    return 0;<br>}<br><br style="font-family: Tahoma;"><span style="font-family: Tahoma;">And the visitor:</span><br></code><code>CXChildVisitResult printVisitor(CXCursor cursor, CXCursor parent, CXClientData client_data) {<br><br>    CXSourceRange range = clang_getCursorExtent(cursor);<br>    CXSourceLocation startLocation = clang_getRangeStart(range);<br>    CXSourceLocation endLocation = clang_getRangeEnd(range);<br><br>    CXFile file;<br>    unsigned int line, column, offset;<br>    clang_getInstantiationLocation(startLocation, &file, &line, &column, &offset);<br>    printf("Start: Line: %u Column: %u Offset: %u\n", line, column, offset);<br>    clang_getInstantiationLocation(endLocation, &file, &line, &column, &offset);<br>    printf("End: Line: %u Column: %u Offset: %u\n", line, column, offset); <br><br>    return CXChildVisit_Recurse;<br>}<br></code><span style="font-family: Tahoma;">When I run this code with an empty header file I get lots of weird output like this:<br>Parsing: empty.h<br>Kind: A typedef.<br>Start: Line: 0 Column: 0 Offset: 0<br>End: Line: 0 Column: 0 Offset: 0<br>Filename: (null)<br>or <br>Kind: A field (in C) or non-static data member (in C++) in a struct, union or C++ class.<br>Start: Line: 99 Column: 81 Offset: 3243<br>End: Line: 99 Column: 98 Offset: 3260<br>Filename: (null)<br><br>The very last output is a "First Expression" - so I assume I have to ignore everything until the first expression is found and start working from there?<br><br>Any help appreciated.<br><br>Thanks,<br>Enrico<br></span></pre>
<br>
</div>
</body>
</html>