title: libclang get class name from cursor
body: <p>I am trying to extract the class name of a parameter to a method call in objective-C.  The code I am parsing is:</p>
  
  <pre><code>- (void)testAddConcreteDataModel:(DFDemoDataModelOne*)helpmeh {
      [self.dataModels addObject:helpmeh];
  }
  </code></pre>
  
  <p>And the result I need is the type of class of helpmeh, which is "DFDemoDataModelOne".</p>
  
  <p>So far I have the following code, which outputs: <code>"[(DFDataModelContainer).dataModels addObject:helpmeh]"</code></p>
  
  <pre><code>    if (cursor.kind == CXCursor_ObjCMessageExpr) {
          __block NSString* memberName = nil;
          __block NSString* ownerClassName = nil;
          __block NSString* methodName = [NSString stringWithUTF8String:clang_getCString(clang_getCursorDisplayName(cursor))];
  
          clang_visitChildrenWithBlock(cursor, ^enum CXChildVisitResult(CXCursor cursor, CXCursor parent) {
              if (cursor.kind == CXCursor_MemberRefExpr) {
                  memberName = [NSString stringWithUTF8String:clang_getCString(clang_getCursorDisplayName(cursor))];
                  ownerClassName = [NSString stringWithUTF8String:clang_getCString(clang_getCursorDisplayName(clang_getCursorSemanticParent(clang_getCursorReferenced(cursor))))];
              } else {
                  if (memberName) {
                      NSString* param = [NSString stringWithUTF8String:clang_getCString(clang_getCursorDisplayName(cursor))];
                      NSLog(@"[(%@).%@ %@%@]", ownerClassName, memberName, methodName, param);
                      clang_visitChildrenWithBlock(cursor, ^enum CXChildVisitResult(CXCursor cursor, CXCursor parent) {
  
                           // test
                           if ([param isEqualToString:@"helpmeh"] &amp;&amp; cursor.kind == CXCursor_DeclRefExpr) {
                              // found the interesting part.. what now?
                           }
                           return CXChildVisit_Recurse;
                       }
                  }
              }
              return CXChildVisit_Continue;
          }
      }
  </code></pre>
  
  <p>I'm just a bit lost as to how to extract information from cursors- when I AST dump my class I can see the information I need is all there (see the last line):</p>
  
  <pre><code>|-ObjCMethodDecl 0x112790f90 &lt;line:32:1, line:34:1&gt; - testAddConcreteDataModel: 'void'
    | |-ImplicitParamDecl 0x112791960 &lt;&lt;invalid sloc&gt;&gt; self 'DFDataModelContainer *const __strong'
    | |-ImplicitParamDecl 0x1127919c0 &lt;&lt;invalid sloc&gt;&gt; _cmd 'SEL':'SEL *'
    | |-ParmVarDecl 0x112791040 &lt;line:32:35, col:55&gt; helpmeh 'DFDemoDataModelOne *__strong'
    | `-CompoundStmt 0x112791bf0 &lt;col:63, line:34:1&gt;
    |   `-ExprWithCleanups 0x112791bd8 &lt;line:33:5, col:39&gt; 'void'
    |     `-ObjCMessageExpr 0x112791ba0 &lt;col:5, col:39&gt; 'void' selector=addObject:
    |       |-PseudoObjectExpr 0x112791b48 &lt;col:6, col:11&gt; 'NSMutableArray *'
    |       | |-ObjCPropertyRefExpr 0x112791ad0 &lt;col:6, col:11&gt; '&lt;pseudo-object type&gt;' lvalue objcproperty Kind=PropertyRef Property="dataModels" Messaging=Getter
    |       | | `-OpaqueValueExpr 0x112791ab0 &lt;col:6&gt; 'DFDataModelContainer *'
    |       | |   `-ImplicitCastExpr 0x112791a40 &lt;col:6&gt; 'DFDataModelContainer *' &lt;LValueToRValue&gt;
    |       | |     `-DeclRefExpr 0x112791a18 &lt;col:6&gt; 'DFDataModelContainer *const __strong' lvalue ImplicitParam 0x112791960 'self' 'DFDataModelContainer *const __strong'
    |       | |-OpaqueValueExpr 0x112791ab0 &lt;col:6&gt; 'DFDataModelContainer *'
    |       | | `-ImplicitCastExpr 0x112791a40 &lt;col:6&gt; 'DFDataModelContainer *' &lt;LValueToRValue&gt;
    |       | |   `-DeclRefExpr 0x112791a18 &lt;col:6&gt; 'DFDataModelContainer *const __strong' lvalue ImplicitParam 0x112791960 'self' 'DFDataModelContainer *const __strong'
    |       | `-ImplicitCastExpr 0x112791b30 &lt;col:11&gt; 'NSMutableArray *' &lt;ARCReclaimReturnedObject&gt;
    |       |   `-ObjCMessageExpr 0x112791b00 &lt;col:11&gt; 'NSMutableArray *' selector=dataModels
    |       |     `-OpaqueValueExpr 0x112791ab0 &lt;col:6&gt; 'DFDataModelContainer *'
    |       |       `-ImplicitCastExpr 0x112791a40 &lt;col:6&gt; 'DFDataModelContainer *' &lt;LValueToRValue&gt;
    |       |         `-DeclRefExpr 0x112791a18 &lt;col:6&gt; 'DFDataModelContainer *const __strong' lvalue ImplicitParam 0x112791960 'self' 'DFDataModelContainer *const __strong'
    |       `-ImplicitCastExpr 0x112791b88 &lt;col:32&gt; 'id':'id' &lt;BitCast&gt;
    |         `-ImplicitCastExpr 0x112791b70 &lt;col:32&gt; 'DFDemoDataModelOne *' &lt;LValueToRValue&gt;
    |           `-DeclRefExpr 0x112791a88 &lt;col:32&gt; 'DFDemoDataModelOne *__strong' lvalue ParmVar 0x112791040 'helpmeh' 'DFDemoDataModelOne *__strong'
  </code></pre>
  
  <p>Any pointers greatly appreciated!</p>