summaryrefslogtreecommitdiff
path: root/packages/cocoaint/utils/parser.php
blob: a9c7ae1be629a151c2cd45580a3dc04b53174e97 (plain)
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
<?php

$version = "2.1.2";

require("source/pascocoa_parser.php");
require("source/objp_parser.php");

/**
 * Cocoa framework parser for Objective-Pascal
 * 
 * @author Ryan Joseph
 * @author Jonas Maebe
 **/

// 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");
$duplicate_headers = array();

// 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];
				$options["all"] = false;	// headers override -all
				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 'noprint':
				$options[$key] = true;
				break;
				
			case 'comments':
				$options[$key] = true;
				break;
				
			case 'merge':
				$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) {
	print("=== WARNING: TESTING MODE ENABLED - COMMAND LINE IS OVERRIDDEN! ===\n");
	//$GLOBALS["argv"][] = "-webkit";
	$GLOBALS["argv"][] = "-root=/Developer/ObjectivePascal/dev";
	//$GLOBALS["argv"][] = "-delegates";
	$GLOBALS["argv"][] = "-objp";
	$GLOBALS["argv"][] = "-comments";
	//$GLOBALS["argv"][] = "-reference";
	$GLOBALS["argv"][] = "-all";
	//$GLOBALS["argv"][] = "-noprint";
	//$GLOBALS["argv"][] = "-show";
	//$GLOBALS["argv"][] = "-only=\"UIWindow.h\"";
	$GLOBALS["argv"][] = "-frameworks=\"^foundation,quartzcore,appkit\"";

	//$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/NSObjcRuntime.h\"";
	//$GLOBALS["argv"][] = "-header=\"foundation/NSMapTable.h\"";
	$GLOBALS["argv"][] = "-header=\"appkit/NSApplication.h\"";
	//$GLOBALS["argv"][] = "-header=\"quartzcore/CALayer.h\""; //CAMediaTimingFunction

	//$GLOBALS["argv"][] = "-show";
}

if (count($GLOBALS["argv"]) == 1) {
	print("Cocoa Framework Parser ($version) usage:\n");
	print("php parser.php [options]\n\n");
	print("Options:\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 (if specified) or direct path.\n");
	print("  -root          	Sets the root path of the output 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 (mutually exclusive to -noprint).\n");
	print("  -comments     		Parses comments.\n");
	print("  -merge     		Headers are merged by difference (using diff/patch) instead of overwritten.\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 print 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("  -objp     			Prints classes in FPC Objective Pascal dialect (obsolete).\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("foundation","quartzcore","uikit");
}

// setup -cocoa options
if ($options["cocoa"]) {
	$options["all"] = true;
	$options["objp"] = true;
	$options["frameworks"] = array("appkit","foundation","quartzcore");
	$ignore_headers = array();
}

if ($options["webkit"]) {
	$options["all"] = true;
	$options["objp"] = true;
	$options["frameworks"] = array("foundation","webkit");
}

// create the parser instance
$parser = new TObjPParser ($root_path, "", $options["frameworks"],  $options["framework_path"], $options["show"]);

// Set additional options
$parser->parse_comments = $options["comments"];
$parser->merge_headers = $options["merge"];

// 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, !$options["noprint"]);
}

//$parser->PrintIvarSizeComparison("/Users/ryanjoseph/Desktop/objp/IvarSize.p");
//exit;

// Process all headers
if ($options["all"]) {
	$parser->ParseAllFrameworks($ignore_headers, null);
	if (!$options["noprint"]) $parser->PrintAllHeaders("", $duplicate_headers, $only_files, $options["reference"]);
	if ($options["delegates"]) $parser->ParseDelegateClasses();
	if ($options["encodings"]) $parser->PrintTypeEncodingGlue();
}

?>