-
Notifications
You must be signed in to change notification settings - Fork 2
/
DocCDataType.m
193 lines (151 loc) · 4.44 KB
/
DocCDataType.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
/*
Copyright (C) 2010 Quentin Mathe
Author: Quentin Mathe <[email protected]>
Date: November 2010
License: Modified BSD (see COPYING)
*/
#import <objc/runtime.h>
#import "DocCDataType.h"
#import "DocDescriptionParser.h"
#import "DocIndex.h"
#import "DocHTMLElement.h"
#import "DocParameter.h"
@implementation DocCDataType
@synthesize type;
- (BOOL) isConstant
{
return ([type hasPrefix: @"enum"] || [type hasPrefix: @"union"]
|| [type hasPrefix: @"const"] || [type hasSuffix: @"const"]);
}
- (void) turnIntoDocConstantIfNeeded
{
if ([self isConstant])
{
object_setClass(self, [DocConstant class]);
}
}
- (void) parser: (GSDocParser *)parser
startElement: (NSString *)elementName
withAttributes: (NSDictionary *)attributeDict
{
if ([elementName isEqualToString: [self GSDocElementName]]) /* Opening tag */
{
BEGINLOG();
[self setType: [attributeDict objectForKey: @"type"]];
[self setName: [attributeDict objectForKey: @"name"]];
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
- (void) parser: (GSDocParser *)parser
endElement: (NSString *)elementName
withContent: (NSString *)trimmed
{
if ([elementName isEqualToString: @"desc"])
{
[self appendToRawDescription: trimmed];
CONTENTLOG();
}
else if ([elementName isEqualToString: [self GSDocElementName]]) /* Closing tag */
{
DocDescriptionParser* descParser = [DocDescriptionParser new];
[descParser parse: [self rawDescription]];
//NSLog(@"C Data Type raw description <%@>", [self rawDescription]);
[self addInformationFrom: descParser];
/* Switch the class to get the right -weaveSelector */
[self turnIntoDocConstantIfNeeded];
[(id)[parser weaver] performSelector: [self weaveSelector] withObject: self];
ENDLOG2(name, [self task]);
}
}
#pragma clang diagnostic pop
- (NSString *) GSDocElementName
{
return @"type";
}
- (SEL) weaveSelector
{
return @selector(weaveOtherDataType:);
}
- (NSString *) formattedType
{
return [self type];
// TODO: Fix or remove... This code wrongly truncates the types.
// TODO: Insert links in the returned type
DocParameter *formatter = [DocParameter parameterWithName: nil type: [self type]];
NSString *formattedType = @"";
if ([formatter typePrefix] != nil)
{
formattedType = [formattedType stringByAppendingString: [formatter typePrefix]];
}
if ([formatter typeSuffix] != nil)
{
if ([formattedType length] != 0)
{
formattedType = [formattedType stringByAppendingFormat: @"%@ %@", @"", [formatter typeSuffix]];
}
else
{
formattedType = [formattedType stringByAppendingString: [formatter typeSuffix]];
}
}
return formattedType;
}
- (DocHTMLElement *) HTMLRepresentation
{
// TODO: Use more correct span class names
H hType = [SPAN class: @"returnType" with: [SPAN class: @"type" with: [self formattedType]]];
H hSymbolName = [SPAN class: @"selector" with: @" " and: [self name]];
H hDesc = [DIV class: @"methodDescription" with: [self HTMLDescriptionWithDocIndex: [DocIndex currentIndex]]];
H hDataType = [DIV class: @"method" with: [DL class: @"collapsable" with: [DT with: hType and: hSymbolName]
and: [DD with: hDesc]]];
return hDataType;
}
@end
@implementation DocVariable
- (NSString *) GSDocElementName
{
return @"variable";
}
- (SEL) weaveSelector
{
return @selector(weaveConstant:);
}
- (void)parseProgramComponent: (SCKGlobal *)aVariable
{
/*
[self setName: [aVariable name]];
[self setType: [aVariable typeEncoding]];
[self appendToRawDescription: [[aVariable documentation] string]];
DocDescriptionParser *descriptionParser = [DocDescriptionParser new];
[descriptionParser parse: [self rawDescription]];
[self addInformationFrom: descriptionParser];*/
}
@end
@implementation DocConstant
- (NSString *) GSDocElementName
{
return @"constant";
}
- (SEL) weaveSelector
{
return @selector(weaveConstant:);
}
- (void)parseProgramComponent: (id)aConstant
{
[self setName: [aConstant name]];
// FIXME: Needs fixing SCK to parse documentation.
// Just check the value now in order to prevent throwing an exception.
if (nil != [[aConstant documentation] string])
{
[self appendToRawDescription: [[aConstant documentation] string]];
}
else
{
[self appendToRawDescription: @""];
}
DocDescriptionParser *descriptionParser = [DocDescriptionParser new];
[descriptionParser parse: [self rawDescription]];
[self addInformationFrom: descriptionParser];
}
@end