-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDocSourceCodeParser.m
207 lines (171 loc) · 4.88 KB
/
DocSourceCodeParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright (C) 2013 Muhammad Hussein Nasrollahpour
Author: Muhammad Hussein Nasrollahpour <[email protected]>
Date: April 2013
License: Modified BSD (see COPYING)
*/
#import "DocSourceCodeParser.h"
#import "DocHeader.h"
#import "DocMethod.h"
#import "DocMacro.h"
#import "DocCDataType.h"
#import "DocIVar.h"
#import "DocProperty.h"
@implementation DocSourceCodeParser
- (id) init
{
return [self initWithSourceFile: nil additionalParserFiles: [NSArray array]];
}
- (id) initWithSourceFile: (NSString *)aSourceCodePath additionalParserFiles: (NSArray *)additionalFiles
{
NILARG_EXCEPTION_TEST(aSourceCodePath);
SUPERINIT;
sourceCollection = [SCKSourceCollection new];
sourceFile = (SCKClangSourceFile *)[sourceCollection sourceFileForPath: aSourceCodePath];
return self;
}
- (void) dealloc
{
sourceCollection = nil;
sourceFile = nil;
}
- (void) parseAndWeave
{
[self parseClassesAndCategories];
[self parseProtocols];
[self parseMacros];
[self parseEnumerations];
[self parseFunctions];
[self parseVariables];
}
- (void) parseClassesAndCategories
{
DocHeader *header = nil;
for (SCKClass *class in [[sourceCollection classes] objectEnumerator])
{
header = [DocHeader new];
[header setClassName: [class name]];
[pageWeaver weaveHeader: header];
[pageWeaver weaveClassNamed: [class name]
superclassName: [[class superclass] name]];
for (SCKIvar *ivar in [class ivars])
{
DocIVar *docIVar = [DocIVar new];
[docIVar parseProgramComponent: ivar];
[pageWeaver weaveIVar: docIVar];
}
for (SCKProperty *property in [class properties])
{
DocProperty *docProperty = [DocProperty new];
[docProperty parseProgramComponent: property];
[pageWeaver weaveProperty: docProperty];
}
for (SCKMethod *method in [class methods])
{
DocMethod *docMethod = [DocMethod new];
[docMethod parseProgramComponent: method];
[pageWeaver weaveMethod: docMethod];
}
for (SCKCategory *category in [class categories])
{
[pageWeaver weaveCategoryNamed: [category name]
className: [class name] isInformalProtocol: YES];
// TODO: Enable once supported by SCK
/*for (SCKProperty *property in [category properties])
{
DocProperty *docProperty = [DocProperty new];
[docProperty parseProgramComponent: property];
[pageWeaver weaveProperty: docProperty];
}
for (SCKMethod *method in [category methods])
{
DocMethod *docMethod = [DocMethod new];
[docMethod parseProgramComponent: method];
[pageWeaver weaveMethod: docMethod];
}*/
}
}
}
- (void) parseProtocols
{
DocHeader *header = nil;
for (SCKProtocol *protocol in [[sourceCollection protocols] objectEnumerator])
{
[pageWeaver weaveHeader: [DocHeader new]];
[pageWeaver weaveProtocolNamed: [protocol name]];
for (SCKMethod *method in [protocol requiredMethods])
{
DocMethod *docMethod = [DocMethod new];
[docMethod parseProgramComponent: method];
[pageWeaver weaveMethod: docMethod];
}
for (SCKMethod *method in [protocol optionalMethods])
{
DocMethod *docMethod = [DocMethod new];
[docMethod parseProgramComponent: method];
[pageWeaver weaveMethod: docMethod];
}
// TODO: Add support for -requiredProperties and -optionalProperties once supported by SCK
}
}
- (void) parseMacros
{
for (SCKMacro *macro in [[sourceFile macros] objectEnumerator])
{
DocMacro *docMacro = [DocMacro new];
[docMacro parseProgramComponent: macro];
[pageWeaver weaveMacro: docMacro];
}
}
- (void) parseEnumerations
{
for (SCKEnumeration *enumeration in [sourceFile enumerations])
{
DocConstant *docEnumeration = [DocConstant new];
[docEnumeration parseProgramComponent: enumeration];
[pageWeaver weaveConstant: docEnumeration];
}
for (SCKEnumerationValue *enumValue in [[sourceFile enumerationValues] objectEnumerator])
{
DocConstant *docEnumValue = [DocConstant new];
[docEnumValue parseProgramComponent: enumValue];
[pageWeaver weaveConstant: docEnumValue];
}
}
- (void) parseFunctions
{
/* Static Functions */
for (SCKFunction *function in [sourceFile functions])
{
DocFunction *docFunction = [DocFunction new];
[docFunction parseProgramComponent: function];
[pageWeaver weaveFunction: docFunction];
}
/* Global Functions */
for (SCKFunction *function in [[sourceCollection functions] objectEnumerator])
{
DocFunction *docFunction = [DocFunction new];
[docFunction parseProgramComponent: function];
[pageWeaver weaveFunction: docFunction];
}
}
- (void) parseVariables
{
/* Global Variables */
for (SCKGlobal *global in [[sourceCollection globals] objectEnumerator])
{
DocVariable *docGlobal = [DocVariable new];
[docGlobal parseProgramComponent: global];
[pageWeaver weaveOtherDataType: docGlobal];
}
// TODO: Parse static variables once supported by SCK
}
- (id <DocWeaving>)weaver
{
return pageWeaver;
}
- (void)setWeaver: (id <DocWeaving>)aDocWeaver
{
pageWeaver = aDocWeaver;
}
@end