8

我需要分析Objective-C的静态代码,主要是AST,寻找到我发现从LLVM锵工具可以转储AST可能的工具后,所以我使用的终端使用这个命令来测试它:如何从Objective-C代码中提取AST?

clang -cc1 -ast-dump ~/SomeTest.m 

,但我得到这个错误:

In file included from /Users/myusername/SomeTest.m:9: 
/Users/myusername/SomeTest.h:9:9: fatal error: 'UIKit/UIKit.h' file not found 
#import <UIKit/UIKit.h> 
     ^
typedef __int128_t __int128_t; 
typedef __uint128_t __uint128_t; 
typedef SEL *SEL; 
typedef id id; 
typedef Class *Class; 
struct __va_list_tag { 
    unsigned int gp_offset; 
    unsigned int fp_offset; 
    void *overflow_arg_area; 
    void *reg_save_area; 
}; 
typedef struct __va_list_tag __va_list_tag; 
typedef __va_list_tag __builtin_va_list[1]; 
@interface [email protected] 
@implementation just4testViewController 
- (void) dealloc (CompoundStmt 0x7f86b183b110 </Users/myusername/SomeTest.m:14:1, line:16:1>) 


- (void) didReceiveMemoryWarning (CompoundStmt 0x7f86b183b2a0 </Users/myusername/SomeTest.m:19:1, line:24:1>) 


- (void) viewDidUnload (CompoundStmt 0x7f86b183b430 </Users/myusername/SomeTest.m:37:1, line:41:1>) 


- (id) shouldAutorotateToInterfaceOrientation:(id)interfaceOrientation (CompoundStmt 0x7f86b183b648 </Users/myusername/SomeTest.m:44:1, line:47:1>) 


@end 
1 error generated. 

任何想法,为什么我得到这个?我不介意使用任何工具从Objective-C代码中提取AST,只要它是可靠的并提供输出文档

+0

嗨,你有没有设法找到解析器从Objective-C源代码中提取AST?谢谢! – ramo

回答

2

编译器找不到UIKit框架。你必须告诉它使用它:

clang -framework UIKit -cc1 -ast-dump ~/SomeTest.m 
+0

仍然得到这个 编译时警告:参数未使用:'-cc1' clang:warning:参数在编译过程中未使用:'-ast-dump' 从/Users/myusername/SomeTest.m:9: /Users/myusername/SomeTest.h:9:9:致命错误:未找到'UIKit/UIKit.h'文件 #import ^ 生成1个错误。 –

0

尝试-Xclang -ast-dump而不是-cc1 -ast-dump。 (标准免责声明:任何使用-Xclang-cc1使用不稳定的界面编译器。)

+0

仍然得到完全相同的错误发布在问题:( –

+0

采取一个命令,编译有问题的文件,然后添加-Xclang -ast-dump到该命令。否则,你会最终得到奇怪的结果; ObjC文件的AST依赖于命令行选项 – servn

+0

我没有明白你的意思,请你替我解释一下吧 –

0

OP说:我不介意使用任何工具来提取Objective-C代码AST ...

我们的DMS Software Reengingineering Toolkit可以为Objective-C做到这一点。

对于该命令行到DMS生成的解析器 “domainparser”:

run \DMS\Domains\C\ObjectiveCv2\Tools\Parser\domainparser ++AST "C:\temp\test.m" 

此目标C文件 “test.m”:

@implementation GTLClientLoginAuthorizationArgs 

@synthesize request = request_, 
    delegate = delegate_, 
    selector = sel_, 
    completionHandler = completionHandler_, 
    thread = thread_, 
    error = error_; 

+ (GTLClientLoginAuthorizationArgs *)argsWithRequest:(NSMutableURLRequest *)req 
        delegate:(id)delegate 
        selector:(SEL)sel 
       completionHandler:(id)completionHandler 
         thread:(NSThread *)thread { 
    GTLClientLoginAuthorizationArgs *obj; 
    obj = [[[GTLClientLoginAuthorizationArgs alloc] init] autorelease]; 
    obj.request = req; 
    obj.delegate = delegate; 
    obj.selector = sel; 
    obj.completionHandler = completionHandler; 
    obj.thread = thread; 
    return obj; 
} 

- (void)dealloc { 
    self.request = nil; 
    self.delegate = nil; 
    self.selector = NULL; 
    self.completionHandler = nil; 
    self.thread = nil; 
    self.error = nil; 
    [super dealloc]; 
} 
@end 

产生与AST这个输出:

Domain Parser for C~ObjectiveCv2 2.4.4 
Copyright (C) Semantic Designs 1996-2012; All Rights Reserved 
([email protected]~ObjectiveCv2=2#422f080^0 Line 1 Column 1 File C:/temp/test.m 
([email protected]~ObjectiveCv2=1048#422f140 Line 1 Column 1 File C:/temp/test.m 
    ([email protected]~ObjectiveCv2=1270#4228b40[`GTLClientLoginAuthorizationArgs'] Line 1 Column 17 File C:/temp/test.m)IDENTIFIER 
    ([email protected]~ObjectiveCv2=1046#4228b80 Line 3 Column 1 File C:/temp/test.m)super_class_option 
    ([email protected]~ObjectiveCv2=1061#4228bc0 Line 3 Column 1 File C:/temp/test.m)instance_variables 
    ([email protected]~ObjectiveCv2=1079#422f0a0 Line 3 Column 1 File C:/temp/test.m 
    ([email protected]~ObjectiveCv2=1079#422e8c0 Line 3 Column 1 File C:/temp/test.m 
    |([email protected]~ObjectiveCv2=1079#42290a0 Line 3 Column 1 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1078#4228c00 Line 3 Column 1 File C:/temp/test.m)implementation_definition_list 
    | ([email protected]~ObjectiveCv2=1131#4229080 Line 3 Column 1 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1134#4229060 Line 3 Column 13 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1134#4228fc0 Line 3 Column 13 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1134#4228f40 Line 3 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1134#4228e80 Line 3 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1134#4228de0 Line 3 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1133#4228d00 Line 3 Column 13 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1136#4228cc0 Line 3 Column 13 File C:/temp/test.m 
    | | | ([email protected]~ObjectiveCv2=1270#4228c40[`request'] Line 3 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | | ([email protected]~ObjectiveCv2=1270#4228c80[`request_'] Line 3 Column 23 File C:/temp/test.m)IDENTIFIER 
    | | |)property_synthesize_item 
    | | )property_synthesize_list 
    | | ([email protected]~ObjectiveCv2=1136#4228dc0 Line 4 Column 13 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1270#4228d80[`delegate'] Line 4 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | |([email protected]~ObjectiveCv2=1270#4228da0[`delegate_'] Line 4 Column 24 File C:/temp/test.m)IDENTIFIER 
    | | )property_synthesize_item 
    | | )property_synthesize_list 
    | | ([email protected]~ObjectiveCv2=1136#4228e60 Line 5 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4228e20[`selector'] Line 5 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4228e40[`sel_'] Line 5 Column 24 File C:/temp/test.m)IDENTIFIER 
    | | )property_synthesize_item 
    | |)property_synthesize_list 
    | | ([email protected]~ObjectiveCv2=1136#4228f20 Line 6 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4228ea0[`completionHandler'] Line 6 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4228f00[`completionHandler_'] Line 6 Column 33 File C:/temp/test.m)IDENTIFIER 
    | |)property_synthesize_item 
    | |)property_synthesize_list 
    | |([email protected]~ObjectiveCv2=1136#4228fa0 Line 7 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4228f60[`thread'] Line 7 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4228f80[`thread_'] Line 7 Column 22 File C:/temp/test.m)IDENTIFIER 
    | |)property_synthesize_item 
    | )property_synthesize_list 
    | ([email protected]~ObjectiveCv2=1136#4229040 Line 8 Column 13 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1270#4228fe0[`error'] Line 8 Column 13 File C:/temp/test.m)IDENTIFIER 
    | |([email protected]~ObjectiveCv2=1270#4229020[`error_'] Line 8 Column 21 File C:/temp/test.m)IDENTIFIER 
    | )property_synthesize_item 
    | )property_synthesize_list 
    |)property_implementation 
    |)implementation_definition_list 
    |([email protected]~ObjectiveCv2=1087#422ea00 Line 10 Column 1 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1103#4229200 Line 10 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=647#42291c0 Line 10 Column 4 File C:/temp/test.m 
    | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#4228ca0{2} Line 10 Column 4 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1144#4229100 Line 10 Column 4 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42290c0^2#4228ca0:2#4229100:1[`GTLClientLoginAuthorizationArgs'] Line 10 Column 4 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1057#42290e0 Line 10 Column 36 File C:/temp/test.m)protocol_option 
    | |)type_specifier 
    | |([email protected]~ObjectiveCv2=1270#42290c0^2#4228ca0:2#4229100:1... [ALREADY PRINTED] ...) 
    | )AMBIGUITY 
    | ([email protected]~ObjectiveCv2=640#4229120 Line 10 Column 36 File C:/temp/test.m)ptr_operator 
    | )type_id 
    |)method_type 
    | ([email protected]~ObjectiveCv2=1095#4229940 Line 10 Column 38 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1095#4229720 Line 10 Column 38 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1095#42296a0 Line 10 Column 38 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1095#4229580 Line 10 Column 38 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1094#42294a0 Line 10 Column 38 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1099#4229480 Line 10 Column 38 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42291e0[`argsWithRequest'] Line 10 Column 38 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1103#4229440 Line 10 Column 54 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=647#42293c0 Line 10 Column 55 File C:/temp/test.m 
    | | | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#4229300{2} Line 10 Column 55 File C:/temp/test.m 
    | | | ([email protected]~ObjectiveCv2=1144#42292a0 Line 10 Column 55 File C:/temp/test.m 
    | | | ([email protected]~ObjectiveCv2=1270#4229220^2#4229300:2#42292a0:1[`NSMutableURLRequest'] Line 10 Column 55 File C:/temp/test.m)IDENTIFIER 
    | | | ([email protected]~ObjectiveCv2=1057#4229260 Line 10 Column 75 File C:/temp/test.m)protocol_option 
    | | | )type_specifier 
    | | | ([email protected]~ObjectiveCv2=1270#4229220^2#4229300:2#42292a0:1... [ALREADY PRINTED] ...) 
    | | |)AMBIGUITY 
    | | | ([email protected]~ObjectiveCv2=640#42293a0 Line 10 Column 75 File C:/temp/test.m)ptr_operator 
    | | |)type_id 
    | | )method_type 
    | | ([email protected]~ObjectiveCv2=1270#42293e0[`req'] Line 10 Column 77 File C:/temp/test.m)IDENTIFIER 
    | | )keyword_declarator 
    | |)keyword_selector 
    | | ([email protected]~ObjectiveCv2=1099#4229600 Line 11 Column 45 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4229460[`delegate'] Line 11 Column 45 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1103#4228d40 Line 11 Column 54 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1143#42294e0 Line 11 Column 55 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1057#4229500 Line 11 Column 57 File C:/temp/test.m)protocol_option 
    | | )type_specifier 
    | | )method_type 
    | | ([email protected]~ObjectiveCv2=1270#4228d20[`delegate'] Line 11 Column 58 File C:/temp/test.m)IDENTIFIER 
    | |)keyword_declarator 
    | |)keyword_selector 
    | |([email protected]~ObjectiveCv2=1099#4229680 Line 12 Column 45 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42295a0[`selector'] Line 12 Column 45 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1103#4229280 Line 12 Column 54 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1141#42295c0 Line 12 Column 55 File C:/temp/test.m)simple_type_specifier 
    | |)method_type 
    | | ([email protected]~ObjectiveCv2=1270#4229560[`sel'] Line 12 Column 59 File C:/temp/test.m)IDENTIFIER 
    | |)keyword_declarator 
    | )keyword_selector 
    | ([email protected]~ObjectiveCv2=1099#4229700 Line 13 Column 36 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1270#4229520[`completionHandler'] Line 13 Column 36 File C:/temp/test.m)IDENTIFIER 
    | |([email protected]~ObjectiveCv2=1103#42294c0 Line 13 Column 54 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1143#42296c0 Line 13 Column 55 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1057#42296e0 Line 13 Column 57 File C:/temp/test.m)protocol_option 
    | |)type_specifier 
    | |)method_type 
    | |([email protected]~ObjectiveCv2=1270#4228c60[`completionHandler'] Line 13 Column 58 File C:/temp/test.m)IDENTIFIER 
    | )keyword_declarator 
    | )keyword_selector 
    | ([email protected]~ObjectiveCv2=1099#4229920 Line 14 Column 47 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1270#4229760[`thread'] Line 14 Column 47 File C:/temp/test.m)IDENTIFIER 
    | ([email protected]~ObjectiveCv2=1103#4229900 Line 14 Column 54 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=647#4229860 Line 14 Column 55 File C:/temp/test.m 
    | | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#4229320{2} Line 14 Column 55 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1144#42297e0 Line 14 Column 55 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42297c0^2#4229320:2#42297e0:1[`NSThread'] Line 14 Column 55 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1057#4229740 Line 14 Column 64 File C:/temp/test.m)protocol_option 
    | | )type_specifier 
    | | ([email protected]~ObjectiveCv2=1270#42297c0^2#4229320:2#42297e0:1... [ALREADY PRINTED] ...) 
    | |)AMBIGUITY 
    | | ([email protected]~ObjectiveCv2=640#4229840 Line 14 Column 64 File C:/temp/test.m)ptr_operator 
    | |)type_id 
    | )method_type 
    | ([email protected]~ObjectiveCv2=1270#42298c0[`thread'] Line 14 Column 66 File C:/temp/test.m)IDENTIFIER 
    | )keyword_declarator 
    |)keyword_selector 
    | ([email protected]~ObjectiveCv2=1085#4229980 Line 14 Column 73 File C:/temp/test.m)declaration_star 
    | ([email protected]~ObjectiveCv2=403#422e920 Line 14 Column 73 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=405#422e3e0 {8} Line 15 Column 3 File C:/temp/test.m 
    | (AMBIGUITY<statement=332>@C~ObjectiveCv2=1390#4229780{2} Line 15 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=400#422e200 Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=209#4229e60 Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42299e0^3#42297a0:1#4229a80:1#4229e60:1[`GTLClientLoginAuthorizationArgs'] Line 15 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4229ca0^2#4229d60:2#4229e60:2[`obj'] Line 15 Column 36 File C:/temp/test.m)IDENTIFIER 
    | |)multiplicative_expression 
    | |)expression_statement 
    | |([email protected]~ObjectiveCv2=515#422e1e0 Line 15 Column 3 File C:/temp/test.m 
    | | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#42297a0{2} Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42299e0^3#42297a0:1#4229a80:1#4229e60:1... [ALREADY PRINTED] ...) 
    | | ([email protected]~ObjectiveCv2=1144#4229a80 Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42299e0^3#42297a0:1#4229a80:1#4229e60:1... [ALREADY PRINTED] ...) 
    | | ([email protected]~ObjectiveCv2=1057#4229a20 Line 15 Column 35 File C:/temp/test.m)protocol_option 
    | | )type_specifier 
    | |)AMBIGUITY 
    | | ([email protected]~ObjectiveCv2=624#4229d60 Line 15 Column 35 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=640#4229cc0 Line 15 Column 35 File C:/temp/test.m)ptr_operator 
    | | ([email protected]~ObjectiveCv2=1270#4229ca0^2#4229d60:2#4229e60:2... [ALREADY PRINTED] ...) 
    | |)declarator 
    | |)simple_declaration 
    | )AMBIGUITY 
    | ([email protected]~ObjectiveCv2=400#422e3c0 Line 16 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e360 Line 16 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e1c0[`obj'] Line 16 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1158#422e340 Line 16 Column 9 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1158#422e320 Line 16 Column 10 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1158#422e2e0 Line 16 Column 11 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1270#422e220[`GTLClientLoginAuthorizationArgs'] Line 16 Column 12 File C:/temp/test.m)IDENTIFIER 
    | | |([email protected]~ObjectiveCv2=1270#422e2a0[`alloc'] Line 16 Column 44 File C:/temp/test.m)IDENTIFIER 
    | | )primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e2c0[`init'] Line 16 Column 51 File C:/temp/test.m)IDENTIFIER 
    | | )primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e300[`autorelease'] Line 16 Column 57 File C:/temp/test.m)IDENTIFIER 
    | |)primary_expression 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e540 Line 17 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e500 Line 17 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e480 Line 17 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e380[`obj'] Line 17 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e440[`request'] Line 17 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e4a0[`req'] Line 17 Column 17 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e680 Line 18 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e640 Line 18 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e600 Line 18 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e520[`obj'] Line 18 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e5c0[`delegate'] Line 18 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e620[`delegate'] Line 18 Column 18 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e780 Line 19 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e720 Line 19 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e740 Line 19 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e660[`obj'] Line 19 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e560[`selector'] Line 19 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e760[`sel'] Line 19 Column 18 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e6e0 Line 20 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e800 Line 20 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e840 Line 20 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e580[`obj'] Line 20 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e6a0[`completionHandler'] Line 20 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e860[`completionHandler'] Line 20 Column 27 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e900 Line 21 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e960 Line 21 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e8a0 Line 21 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e820[`obj'] Line 21 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e7a0[`thread'] Line 21 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e940[`thread'] Line 21 Column 16 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=487#422e9c0 Line 22 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1270#422e880[`obj'] Line 22 Column 10 File C:/temp/test.m)IDENTIFIER 
    | )jump_statement 
    | )statement_seq 
    |)compound_statement 
    |)class_method_definition 
    )implementation_definition_list 
    ([email protected]~ObjectiveCv2=1088#422f280 Line 25 Column 1 File C:/temp/test.m 
    |(AMBIGUITY<method_result_option=527>@C~ObjectiveCv2=1390#4229f40{2} Line 25 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1101#422ea60 Line 25 Column 3 File C:/temp/test.m)method_result_option 
    | ([email protected]~ObjectiveCv2=1103#422e7c0 Line 25 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=545#422e9e0 Line 25 Column 4 File C:/temp/test.m)simple_type_specifier 
    |)method_type 
    |)AMBIGUITY 
    |([email protected]~ObjectiveCv2=1270#422e8e0[`dealloc'] Line 25 Column 9 File C:/temp/test.m)IDENTIFIER 
    |([email protected]~ObjectiveCv2=1085#422e7e0 Line 25 Column 17 File C:/temp/test.m)declaration_star 
    |([email protected]~ObjectiveCv2=403#422efa0 Line 25 Column 17 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=405#422ecc0 {7} Line 26 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=400#422eb40 Line 26 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422eb20 Line 26 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422eae0 Line 26 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ea80 Line 26 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422eaa0[`request'] Line 26 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422eb00 Line 26 Column 18 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422eca0 Line 27 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422ec40 Line 27 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422ec00 Line 27 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422eba0 Line 27 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422ebc0[`delegate'] Line 27 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422ec20 Line 27 Column 19 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ee20 Line 28 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422ee00 Line 28 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422ed60 Line 28 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ece0 Line 28 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422ed40[`selector'] Line 28 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1270#422edc0[`NULL'] Line 28 Column 19 File C:/temp/test.m)IDENTIFIER 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ef40 Line 29 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422ef20 Line 29 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422eee0 Line 29 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ee60 Line 29 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422eec0[`completionHandler'] Line 29 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422ef00 Line 29 Column 28 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ee80 Line 30 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422efe0 Line 30 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422f020 Line 30 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ee40 Line 30 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422f000[`thread'] Line 30 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422efc0 Line 30 Column 17 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ef80 Line 31 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422f0c0 Line 31 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422f100 Line 31 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ef60 Line 31 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422f060[`error'] Line 31 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422f120 Line 31 Column 16 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422f1a0 Line 32 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1158#422f180 Line 32 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1156#422f1e0 Line 32 Column 4 File C:/temp/test.m)primary_expression 
    | |([email protected]~ObjectiveCv2=1270#422f040[`dealloc'] Line 32 Column 10 File C:/temp/test.m)IDENTIFIER 
    | )primary_expression 
    | )expression_statement 
    |)statement_seq 
    |)compound_statement 
    )instance_method_definition 
)implementation_definition_list 
)class_implementation 
)translation_unit 
Exiting with final status 0 

因为树的形状与我们使用的语法是同构的,所以语法i s的文档。查看how we do this and yet produce an AST以前的答案。

这是从流行的图书馆取得的代码片段;它只是一个片段,否则树会很大。我也通过忽略#imports,让我运行一个易于配置的解析器,而欺骗了一点点。 DMS将解析包含#includes的文件并保留指令或保留包含文本,具体取决于解析器的配置方式。

这是针对ObjectiveC,而不是ObjectiveC++。我们正在研究: - }

DMS为程序分析提供了很多额外的支持,这些程序分析对其生成的AST进行操作。

+0

谢谢downvoter。这个答案提供了OP的请求的具体回应,并显示如何做他想做的事情。 –