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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
<?php
$version = "FrameworkParser: 1.3. PasCocoa 0.3, Objective-P 0.4";
require("pascocoa_parser.php");
require("objp_parser.php");
/**
* Cocoa framework parser for PasCocoa
*
* @author Ryan Joseph
**/
// These files have duplicates in AppKit and Foundation so we ignore the foundation versions and everything is merged into AppKit
$duplicate_headers = array("foundation/NSAttributedString.inc", "foundation/NSAffineTransform.inc");
// Print only these files
$only_files = null;
$options = array();
function HandleCommandLineOptions ($argv) {
global $options;
global $root_path;
global $ignore_headers;
global $only_files;
// defaults
$options["framework_path"] = "/System/Library/Frameworks";
foreach ($argv as $option) {
$pair = explode("=", $option);
$key = trim($pair[0], "-");
$value = $pair[1];
switch ($key) {
case 'root':
$root_path = trim($value, "\"");
break;
case 'header':
$where = explode("/", trim($value, "\""));
$options[$key]["framework"] = ucfirst($where[0]);
$options[$key]["name"] = $where[1];
break;
case 'framework_path':
$options["framework_path"] = trim($value, "\"");
break;
case 'all':
$options[$key] = true;
break;
case 'objp':
$options[$key] = true;
break;
case 'encodings':
$options[$key] = true;
break;
case 'delegates':
$options[$key] = true;
break;
case 'noprint':
$options[$key] = true;
break;
case 'show':
$options[$key] = true;
break;
case 'reference':
$options[$key] = true;
break;
case 'iphone':
$options[$key] = true;
break;
case 'cocoa':
$options[$key] = true;
break;
case 'webkit':
$options[$key] = true;
break;
case 'ignore':
$ignore_headers = explode(",", trim($value, "\""));
break;
case 'only':
$only_files = explode(",", trim($value, "\""));
break;
case 'frameworks':
$options[$key] = explode(",", trim($value, "\""));
break;
default:
//print("unknown switch $key\n");
break;
}
}
}
// ??? TESTING
$testing = false;
if ($testing) {
$GLOBALS["argv"][] = "-webkit";
$GLOBALS["argv"][] = "-root=/Developer/ObjectivePascal";
$GLOBALS["argv"][] = "-delegates";
//$GLOBALS["argv"][] = "-reference";
//$GLOBALS["argv"][] = "-all";
$GLOBALS["argv"][] = "-noprint";
//$GLOBALS["argv"][] = "-show";
//$GLOBALS["argv"][] = "-only=\"UIWindow.h\"";
//$GLOBALS["argv"][] = "-frameworks=\"appkit,foundation\"";
//$GLOBALS["argv"][] = "-framework_path=\"/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks\"";
//$GLOBALS["argv"][] = "-header=\"uikit/UIView.h\"";
//$GLOBALS["argv"][] = "-framework_path=\"/System/Library/Frameworks\"";
//$GLOBALS["argv"][] = "-header=\"webkit/DOMDocument.h\"";
//$GLOBALS["argv"][] = "-framework_path=\"/System/Library/Frameworks\"";
//$GLOBALS["argv"][] = "-header=\"foundation/NSBundle.h\"";
//$GLOBALS["argv"][] = "-header=\"appkit/NSBundle.h\"";
$GLOBALS["argv"][] = "-ignore=\"NSGeometry.h,NSRange.h\"";
$GLOBALS["argv"][] = "-objp";
// Objective-P
/* Notes for master compile (-all):
• CocoaAll.pas:
Compiling /Developer/ObjectivePascal/CocoaAll.pas
1) NSWorkspace.inc(35,46) Error: Duplicate identifier "NSWorkspaceLaunchAllowingClassicStartup"
2) NSClassDescription.inc(60,55) Error: Duplicate identifier "description"
3) NSScriptObjectSpecifiers.inc(194,44) Error: Duplicate identifier "classDescription"
4) NSScriptSuiteRegistry.inc(75,40) Error: Duplicate identifier "classDescription"
5) NSControl.inc(136,15) Error: Mismatch between number of declared parameters and number of colons in message string.
6) NSWorkspace.inc(135,189) Error: Duplicate identifier "description"
7) NSMenuItemCell.inc(64,9) Error: Duplicate identifier "reserved"
8) NSRuleEditor.inc(127,15) Error: Mismatch between number of declared parameters and number of colons in message string.
9) NSObjCRuntime.inc(79,24) Fatal: Syntax error, "identifier" expected but ":" found
Fatal: Compilation aborted
1) NSWorkspace.h has a duplicate NSWorkspaceLaunchAllowingClassicStartup constant
2) NSObjcRuntime.h contains a bad external function:
function __attribute__(: (format(__NSString__; : 1; : 2))): void NSLog(NSStringRef *format, ...); cdecl; external name '__attribute__';
procedure NSLog(fmt:NSString); cdecl; varargs; external;
3) NSMenuItemCell.h has a duplicate (case sensitive name not allowed in Pascal) field that must be changed by hand.
4) These methods have problems in the params. This is a Objc convention where an absent type is always "id"
- (void)performClick:sender;
- (void)setDelegate:delegate;
NSControl.inc(136,15) Error: Mismatch between number of declared parameters and number of colons in message string.
NSRuleEditor.inc(124,15) Error: Mismatch between number of declared parameters and number of colons in message string.
5) NSInteger types are wrong in NSObjcRuntime (should be long)
NSInteger = clong;
NSUInteger = culong;
NSNotFound = high(NSInteger);
6) Many description and classDescription identifiers are not protected in name space and cause errors
• iPhoneAll.pas
1) UIAccelerometer: FPC bug causes methods with a single character message to fail. Remove the 3 methods affected
UIAccelerometer.inc(67,49) Error: Illegal expression after message directive
2) There's no way to know that UITextInputTraits is actually UITextInputTraitsProtocol due to name changes for Pascal syntax
UITextField.inc(91,32) Error: Identifier not found "UITextInputTraits"
• WebKit.pas
1) Extra duplicate type in DOMObject.inc
DOMObjectInternal = Pointer;
DOMObjectInternal = DOMObjectInternal;
2) DOMDocument has method with reserved keyword name "implementation"
function implementation: DOMImplementation; message 'implementation';
3) DOMEvent has method with reserved keyword name "type"
function type: NSString; message 'type';
* reserved keywords are not protected in method names. This is messing up WebKit parsing badly
- General notes:
1) NSObject.h is parsed for the merged category methods that should be inserted manually into the real root class
2) NSRange.h was ignored because it contains custom code and can be maintained by hand very easily
3) NSGeometry.h was ignored because it contains many parsing errors and custom code, do this by hand for now.
4) All instance variables are placed into "private" for now. There are a very small number of classes that have public ivar's.
*/
//$GLOBALS["argv"][] = "-show";
}
if (count($GLOBALS["argv"]) == 1) {
print("Cocoa Framework Parser ($version) usage:\n");
print("php parser.php [switches]\n\n");
print("switches:\n\n");
print(" -all print all headers (.h) from AppKit/Foundation frameworks\n");
print(" -header=\"foundation/NSObject.h\" prints a single header from system frameworks\n");
print(" -root sets the root path of the pascocoa directory\n");
print(" -framework_path sets the root path of the frameworks directory (defaults to /System/Library/Frameworks)\n");
print(" -show prints output to screen instead of file\n");
print(" -ignore=\"NSObject.h,NSArray.h\" ignores the list of headers during parsing (-all only, no spaces)\n");
print(" -only=\"NSObject.h,NSArray.h\" only prints these files (-all only, no spaces)\n");
print(" -noprint parses but does not print (-all only)\n");
print(" -encodings prints Pascal type encoding glue for GenerateTypeEncodings.p (-all only)\n");
print(" -delegates prints NSDelegateController.inc to foundation (-all only)\n");
print(" -objp prints classes in FPC Objective-P dialect\n");
print(" -iphone one-time parse for iPhone headers\n");
print(" -cocoa one-time parse for Cocoa (AppKit/Foundation) headers\n");
print(" -frameworks=\"appkit,foundation\" list of supported frameworks to parse\n");
print("\n\n");
}
// get the command line options
if (count($GLOBALS["argv"]) > 1) {
HandleCommandLineOptions($GLOBALS["argv"]);
//print_r($options);
}
// Make the output directory
if ($options["out"]) {
@mkdir($root_path, 0777);
@mkdir($root_path."/foundation", 0777);
@mkdir($root_path."/appkit", 0777);
// @mkdir($root_path."/webkit", 0777);
@mkdir($root_path."/uikit", 0777);
// @mkdir($root_path."/reference", 0777);
}
// setup -iphone options
if ($options["iphone"]) {
$options["all"] = true;
$options["objp"] = true;
$options["frameworks"] = array("uikit");
}
// setup -cocoa options
if ($options["cocoa"]) {
$options["all"] = true;
$options["objp"] = true;
$options["frameworks"] = array("appkit","foundation");
$ignore_headers = array("NSGeometry.h","NSRange.h");
}
if ($options["webkit"]) {
$options["all"] = true;
$options["objp"] = true;
$options["frameworks"] = array("webkit");
}
// create the parser instance
if ($options["objp"]) {
$parser = new TObjPParser ($root_path, "", $options["frameworks"], $options["show"]);
} else {
$parser = new TPasCocoaParser ($root_path, "", $options["frameworks"], $options["show"]);
}
// Process single headers
if ($options["header"] && !$options["all"]) {
$path = $options["framework_path"]."/".$options["header"]["framework"].".framework/Headers/".$options["header"]["name"];
print("* Processing $path...\n");
$parser->ProcessFile($path, true);
}
//$parser->PrintIvarSizeComparison("/Users/ryanjoseph/Desktop/objp/IvarSize.p");
//exit;
// Process all headers
if ($options["all"]) {
$parser->ParseCocoaFrameworks($ignore_headers, null);
if (!$options["noprint"]) $parser->PrintAllHeaders("", $duplicate_headers, $only_files, $options["reference"]);
if ($options["delegates"]) $parser->ParseDelegateClasses();
if ($options["encodings"]) $parser->PrintTypeEncodingGlue();
}
?>
|