title: clang can't parse my .h file standalone
body: <p>I'm using python binding of libclang but I think this problem is caused by libclang not by python binding.</p>
  
  <p>I have a header <code>object.h</code></p>
  
  <pre><code>#ifndef OBJECT_H
  #define OBJECT_H
  
  class Object {
  public:
    int run();
  };
  
  #endif
  </code></pre>
  
  <p>And a implementation <code>object.cpp</code></p>
  
  <pre><code>#include "object.h"
  
  int Object::run() {
    int a = 0;
    return a*a;
  }
  </code></pre>
  
  <p>If I visit AST of the translation unit of <code>object.h</code>, the last AST node is <code>VAR_DECL</code> <code>class Object</code> and that's it. It won't visit <code>public:...</code> part. If I use clang to check syntax directly is would complain about my header file is wrong.</p>
  
  <pre><code>$ clang -Xclang -ast-dump -fsyntax-only object/object.h
  object/object.h:4:1: error: unknown type name 'class'
  class Object {
  ^
  object/object.h:4:13: error: expected ';' after top level declarator
  class Object {
              ^
              ;
  TranslationUnitDecl 0x7f816102d2d0 &lt;&lt;invalid sloc&gt;&gt;
  |-TypedefDecl 0x7f816102d7d0 &lt;&lt;invalid sloc&gt;&gt; __int128_t '__int128'
  |-TypedefDecl 0x7f816102d830 &lt;&lt;invalid sloc&gt;&gt; __uint128_t 'unsigned __int128'
  |-TypedefDecl 0x7f816102db80 &lt;&lt;invalid sloc&gt;&gt; __builtin_va_list '__va_list_tag [1]'
  `-VarDecl 0x7f816102dbf0 &lt;object/object.h:4:1, col:7&gt; Object 'int' invalid
  2 errors generated.
  </code></pre>
  
  <p>If I use clang to dump ast of <code>object.cpp</code>, I won't have that error.</p>
  
  <pre><code>$ clang -Xclang -ast-dump -fsyntax-only object/object.cpp
  TranslationUnitDecl 0x7fc6230302d0 &lt;&lt;invalid sloc&gt;&gt;
  |-TypedefDecl 0x7fc623030810 &lt;&lt;invalid sloc&gt;&gt; __int128_t '__int128'
  |-TypedefDecl 0x7fc623030870 &lt;&lt;invalid sloc&gt;&gt; __uint128_t 'unsigned __int128'
  |-TypedefDecl 0x7fc623030c30 &lt;&lt;invalid sloc&gt;&gt; __builtin_va_list '__va_list_tag [1]'
  |-CXXRecordDecl 0x7fc623030c80 &lt;object/object.h:4:1, line:7:1&gt; class Object definition
  | |-CXXRecordDecl 0x7fc623030d90 &lt;line:4:1, col:7&gt; class Object
  | |-AccessSpecDecl 0x7fc623030e20 &lt;line:5:1, col:7&gt; public
  | `-CXXMethodDecl 0x7fc623030ea0 &lt;line:6:3, col:11&gt; run 'int (void)'
  `-CXXMethodDecl 0x7fc62307be10 parent 0x7fc623030c80 prev 0x7fc623030ea0 &lt;object/object.cpp:3:1, line:6:1&gt; run 'int (void)'
    `-CompoundStmt 0x7fc62307c058 &lt;line:3:19, line:6:1&gt;
      |-DeclStmt 0x7fc62307bf78 &lt;line:4:3, col:12&gt;
      | `-VarDecl 0x7fc62307bf00 &lt;col:3, col:11&gt; a 'int'
      |   `-IntegerLiteral 0x7fc62307bf58 &lt;col:11&gt; 'int' 0
      `-ReturnStmt 0x7fc62307c038 &lt;line:5:3, col:12&gt;
        `-BinaryOperator 0x7fc62307c010 &lt;col:10, col:12&gt; 'int' '*'
          |-ImplicitCastExpr 0x7fc62307bfe0 &lt;col:10&gt; 'int' &lt;LValueToRValue&gt;
          | `-DeclRefExpr 0x7fc62307bf90 &lt;col:10&gt; 'int' lvalue Var 0x7fc62307bf00 'a' 'int'
          `-ImplicitCastExpr 0x7fc62307bff8 &lt;col:12&gt; 'int' &lt;LValueToRValue&gt;
            `-DeclRefExpr 0x7fc62307bfb8 &lt;col:12&gt; 'int' lvalue Var 0x7fc62307bf00 'a' 'int'
  </code></pre>
  
  <p>It seems like clang combine <code>object.h</code> <code>object.cpp</code> together then do the parsing.
  If that's so, how do I get the ast node of <code>Object</code> in thrid line of <code>object.cpp</code> <code>int Object::run() {</code>? Is there a ast node for that?</p>
  
  <p>It also confuses me a lot like when I visit the <code>run()</code> method in <code>object.cpp</code>, it will say current location is in <code>object.cpp</code> but the extent is in <code>object.h</code>. What does the extent mean exactly? Any easier tutorial documents other than libclang API document?</p>