我试图将一个参数的类名提取到objective-C中的方法调用.我正在解析的代码是:
- (void)testAddConcreteDataModel:(DFDemoDataModelOne*)helpmeh { [self.dataModels addobject:helpmeh]; }
我需要的结果是helpmeh类的类型,即“DFDemoDataModelOne”.
到目前为止,我有以下代码,输出:“[(DFDataModelContainer).dataModels addobject:helpmeh]”
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,CXCursor parent) { // test if ([param isEqualToString:@"helpmeh"] && cursor.kind == CXCursor_DeclRefExpr) { // found the interesting part.. what Now? } return CXChildVisit_Recurse; } } } return CXChildVisit_Continue; } }
关于如何从游标中提取信息,我只是有点迷失 – 当我转储我的类时,我可以看到我需要的信息就在那里(参见最后一行):
|-ObjcmethodDecl 0x112790f90 <line:32:1,line:34:1> - testAddConcreteDataModel: 'void' | |-ImplicitParamDecl 0x112791960 <<invalid sloc>> self 'DFDataModelContainer *const __strong' | |-ImplicitParamDecl 0x1127919c0 <<invalid sloc>> _cmd 'SEL':'SEL *' | |-ParmVarDecl 0x112791040 <line:32:35,col:55> helpmeh 'DFDemoDataModelOne *__strong' | `-CompoundStmt 0x112791bf0 <col:63,line:34:1> | `-ExprWithCleanups 0x112791bd8 <line:33:5,col:39> 'void' | `-ObjcmessageExpr 0x112791ba0 <col:5,col:39> 'void' selector=addobject: | |-PseudoObjectExpr 0x112791b48 <col:6,col:11> 'NSMutableArray *' | | |-ObjCPropertyRefExpr 0x112791ad0 <col:6,col:11> '<pseudo-object type>' lvalue objcproperty Kind=PropertyRef Property="dataModels" Messaging=Getter | | | `-OpaqueValueExpr 0x112791ab0 <col:6> 'DFDataModelContainer *' | | | `-ImplicitCastExpr 0x112791a40 <col:6> 'DFDataModelContainer *' <LValuetoRValue> | | | `-DeclRefExpr 0x112791a18 <col:6> 'DFDataModelContainer *const __strong' lvalue ImplicitParam 0x112791960 'self' 'DFDataModelContainer *const __strong' | | |-OpaqueValueExpr 0x112791ab0 <col:6> 'DFDataModelContainer *' | | | `-ImplicitCastExpr 0x112791a40 <col:6> 'DFDataModelContainer *' <LValuetoRValue> | | | `-DeclRefExpr 0x112791a18 <col:6> 'DFDataModelContainer *const __strong' lvalue ImplicitParam 0x112791960 'self' 'DFDataModelContainer *const __strong' | | `-ImplicitCastExpr 0x112791b30 <col:11> 'NSMutableArray *' <ARCReclaimReturnedobject> | | `-ObjcmessageExpr 0x112791b00 <col:11> 'NSMutableArray *' selector=dataModels | | `-OpaqueValueExpr 0x112791ab0 <col:6> 'DFDataModelContainer *' | | `-ImplicitCastExpr 0x112791a40 <col:6> 'DFDataModelContainer *' <LValuetoRValue> | | `-DeclRefExpr 0x112791a18 <col:6> 'DFDataModelContainer *const __strong' lvalue ImplicitParam 0x112791960 'self' 'DFDataModelContainer *const __strong' | `-ImplicitCastExpr 0x112791b88 <col:32> 'id':'id' <BitCast> | `-ImplicitCastExpr 0x112791b70 <col:32> 'DFDemoDataModelOne *' <LValuetoRValue> | `-DeclRefExpr 0x112791a88 <col:32> 'DFDemoDataModelOne *__strong' lvalue ParmVar 0x112791040 'helpmeh' 'DFDemoDataModelOne *__strong'
任何指针非常感谢!