mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-17 03:39:28 +02:00
* version 2.13 of the parser, by Ryan Joseph: mainly restructuring and
cleanup git-svn-id: trunk@16666 -
This commit is contained in:
parent
15e1abddf7
commit
482a244f30
5
.gitattributes
vendored
5
.gitattributes
vendored
@ -1578,8 +1578,9 @@ packages/cocoaint/utils/make-ios-headers.sh svneol=native#text/plain
|
||||
packages/cocoaint/utils/parser.php svneol=native#text/plain
|
||||
packages/cocoaint/utils/patches/cocoa-coredata-webkit.patch svneol=native#text/plain
|
||||
packages/cocoaint/utils/patches/uikit.patch svneol=native#text/plain
|
||||
packages/cocoaint/utils/source/objp_parser.php svneol=native#text/plain
|
||||
packages/cocoaint/utils/source/pascocoa_parser.php svneol=native#text/plain
|
||||
packages/cocoaint/utils/source/objp.php svneol=native#text/plain
|
||||
packages/cocoaint/utils/source/objp_base.php svneol=native#text/plain
|
||||
packages/cocoaint/utils/source/utilities.php svneol=native#text/plain
|
||||
packages/cocoaint/utils/uikit-skel/src/InlineFunctions.inc svneol=native#text/plain
|
||||
packages/cocoaint/utils/uikit-skel/src/UndefinedTypes.inc svneol=native#text/plain
|
||||
packages/cocoaint/utils/uikit-skel/src/foundation/Foundation.inc svneol=native#text/plain
|
||||
|
@ -6,9 +6,9 @@ set -e
|
||||
# convert basic cocoa headers
|
||||
php parser.php -cocoa -root=`pwd`/cocoa-skel/src
|
||||
# convert webkit headers
|
||||
php parser.php -objp -all -frameworks=foundation,webkit -root=`pwd`/cocoa-skel/src
|
||||
php parser.php -all -frameworks=foundation,webkit -root=`pwd`/cocoa-skel/src
|
||||
# convert coredata headers
|
||||
php parser.php -objp -all -frameworks=foundation,coredata -root=`pwd`/cocoa-skel/src
|
||||
php parser.php -all -frameworks=foundation,coredata -root=`pwd`/cocoa-skel/src
|
||||
# correct some translations the automatic translation cannot handle
|
||||
patch -p0 < patches/cocoa-coredata-webkit.patch
|
||||
# empty two headers that exist both in foundation and in appkit, and that
|
||||
|
@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
$version = "2.1.2";
|
||||
$version = "2.1.3";
|
||||
|
||||
require("source/pascocoa_parser.php");
|
||||
require("source/objp_parser.php");
|
||||
require("source/objp.php");
|
||||
|
||||
/**
|
||||
* Cocoa framework parser for Objective-Pascal
|
||||
@ -27,7 +26,7 @@ function HandleCommandLineOptions ($argv) {
|
||||
global $ignore_headers;
|
||||
global $only_files;
|
||||
|
||||
// defaults
|
||||
// Define defaults
|
||||
$options["framework_path"] = "/System/Library/Frameworks";
|
||||
|
||||
foreach ($argv as $option) {
|
||||
@ -56,10 +55,6 @@ function HandleCommandLineOptions ($argv) {
|
||||
$options[$key] = true;
|
||||
break;
|
||||
|
||||
case 'objp':
|
||||
$options[$key] = true;
|
||||
break;
|
||||
|
||||
case 'encodings':
|
||||
$options[$key] = true;
|
||||
break;
|
||||
@ -95,6 +90,10 @@ function HandleCommandLineOptions ($argv) {
|
||||
case 'webkit':
|
||||
$options[$key] = true;
|
||||
break;
|
||||
|
||||
case 'sdk':
|
||||
$options[$key] = trim($value, "\"");
|
||||
break;
|
||||
|
||||
case 'ignore':
|
||||
$ignore_headers = explode(",", trim($value, "\""));
|
||||
@ -115,38 +114,7 @@ function HandleCommandLineOptions ($argv) {
|
||||
}
|
||||
}
|
||||
|
||||
// ??? 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";
|
||||
}
|
||||
|
||||
// Print the script usage if the command line is empty
|
||||
if (count($GLOBALS["argv"]) == 1) {
|
||||
print("Cocoa Framework Parser ($version) usage:\n");
|
||||
print("php parser.php [options]\n\n");
|
||||
@ -160,9 +128,8 @@ if (count($GLOBALS["argv"]) == 1) {
|
||||
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(" -noprint Parses but does not print.\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");
|
||||
@ -180,36 +147,38 @@ 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");
|
||||
|
||||
if (!$options["sdk"]) $options["sdk"] = "4.2";
|
||||
|
||||
//$options["framework_path"] = "/Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS$sdk_version.sdk/System/Library/Frameworks";
|
||||
$options["framework_path"] = "/Developer/Platforms/iPhoneSimulator.Platform/Developer/SDKs/iPhoneSimulator".$options["sdk"].".sdk/System/Library/Frameworks";
|
||||
|
||||
$options["frameworks"] = array("foundation","quartzcore","opengles","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"]);
|
||||
$parser = new ObjectivePParser($root_path, "", $options["frameworks"], $options["framework_path"], $options["show"]);
|
||||
|
||||
// Set additional options
|
||||
// ??? These should be accessors
|
||||
$parser->parse_comments = $options["comments"];
|
||||
$parser->merge_headers = $options["merge"];
|
||||
|
||||
@ -220,15 +189,10 @@ if ($options["header"] && !$options["all"]) {
|
||||
$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();
|
||||
}
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
277
packages/cocoaint/utils/source/objp_base.php
Normal file
277
packages/cocoaint/utils/source/objp_base.php
Normal file
@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ObjectivePParserBase contains all instance variables and settings for the parser
|
||||
* separated from the main file for easier navigation.
|
||||
*/
|
||||
|
||||
class ObjectivePParserBase {
|
||||
|
||||
// Frameworks to parse (loaded from frameworks.xml)
|
||||
var $frameworks = array();
|
||||
|
||||
var $maximum_method_length = 111; // WE GET THIS ERROR: NSDelegatesAll.pas(6109,296) Error: Identifier not found "NSDelegateController_NSLayoutManagerDelegate_layoutManager_shouldUseTemporaryAttributes_forDrawingToScreen_atCharacterIndex_effectiveRange"
|
||||
|
||||
var $output; // current output file handle
|
||||
var $root; // root for printing/locating resources
|
||||
var $out; // directory to print
|
||||
var $show; // print output to screen instead of file
|
||||
var $framework; // current framework being parsed
|
||||
var $current_class; // reference to current class structure being parsed
|
||||
var $current_header; // reference to current header structure being parsed
|
||||
var $method_count; // count of all methods parsed
|
||||
var $class_count; // count of all classes parsed
|
||||
var $warning_count; // count of parser warnings
|
||||
var $parser_skipping; // the parser is skipping lines in the current file
|
||||
var $inside_macro_block; // the parser is inside a macro block, no nesting!
|
||||
var $instance_var_scope; // current scope of the instance variable parser
|
||||
var $dump = array(); // Convert Pascal classes
|
||||
var $delegate_methods = array(); // Delegate methods and types from GEN_BRIDGE_METADATA XML data
|
||||
var $delegate_method_names = array(); // Delegate method name array
|
||||
var $type_encodings = array(); // Master listing of type encodings for each method in the frameworks
|
||||
|
||||
// Comments Builder
|
||||
var $comment_eol;
|
||||
var $comment_terminated;
|
||||
var $comment_fragment;
|
||||
var $comment_fragment_previous;
|
||||
var $comment_fragment_open;
|
||||
var $comment_previous;
|
||||
var $comment_block_open;
|
||||
var $comment_block_closed;
|
||||
var $comment_header;
|
||||
|
||||
// Macros Builder
|
||||
var $macro_block = "";
|
||||
var $in_macro_block = false;
|
||||
|
||||
/**
|
||||
* PARSER OPTIONS
|
||||
*/
|
||||
var $objc_id = "id"; // Default type for generic objects
|
||||
var $sel_string = "SEL"; // The selector string type which registers selectors internally
|
||||
var $protocol_suffix = "Protocol"; // All protocols append this suffix
|
||||
var $pointer_type_suffx = "Ref"; // NS*** pointers in parameter lists are suffixed with this
|
||||
var $class_pointer_suffix = "Pointer"; // Pointers to NS*** classes are suffxed with this
|
||||
var $register_selectors = true; // Register selectors automatically inside the wrappers
|
||||
var $show_added_messages = false; // show messages when methods are added to a class
|
||||
var $show_class_hierarchy = false;
|
||||
var $objects_are_wrappers = false; // Treat all objects (id) like wrappers. i.e aObject.Handle;
|
||||
var $replace_hinted_params = false; // replace comment hints with hinted type - (void * /* CMProfileRef */)colorSyncProfile;
|
||||
var $record_keyword = "record"; // The keyword used for printing records
|
||||
var $bitpacked_record_keyword = "bitpacked record"; // The keyword used for printing bitpacked records
|
||||
var $string_macro = "NSString";
|
||||
var $category_suffix = "Category"; // To prevent naming conlicts all objccategories are suffixed with this work
|
||||
var $parse_comments = false; // Comments are parsed and inserted by context
|
||||
var $merge_headers = false; // Headers are printed by merging difference instead of overwritting
|
||||
var $comment_break = "\n"; // This text will be inserted before each comment to break lines
|
||||
var $comment_padding_left = " "; // Padding applied to the left side of all comments
|
||||
var $comment_padding_right = " "; // Padding applied to the right side of all comments
|
||||
var $varargs_param_name = "firstKey"; // The name of the first parameter for methods using varargs
|
||||
|
||||
// array of all known framework classes (both regular and anonymous)
|
||||
var $cocoa_classes = array("Protocol");
|
||||
|
||||
// array of all anonymous external classes. This list will include
|
||||
// classes that are first defined anonymously and then normally
|
||||
var $anon_cocoa_classes = array();
|
||||
|
||||
// array of all defined external classes. This list will only
|
||||
// include classes that are completely defined
|
||||
var $defined_cocoa_classes = array();
|
||||
|
||||
// array of function pointer types that are declared without an indirection
|
||||
// (e.g. NSUncaughtExceptionHandler in NSException.h) -> do not add Ptr
|
||||
// suffix when deriving the pointer type
|
||||
var $implicit_function_pointer_types = array();
|
||||
|
||||
// array of opaque struct pointer types
|
||||
var $opaque_structs = array();
|
||||
|
||||
// array of all known framework categories
|
||||
var $cocoa_categories = array();
|
||||
|
||||
// Pascal keywords to protect
|
||||
var $reserved_keywords = array( "const", "object", "string", "array", "var", "set", "interface", "unit", "begin", "end",
|
||||
"type", "raise", "property", "to", "for", "with", "function", "procedure", "result",
|
||||
"pointer", "create", "new", "dispose", "label", "packed", "record", "class", "implementation",
|
||||
);
|
||||
|
||||
|
||||
// FPC methods that can't be overloaded
|
||||
var $reserved_methods = array("");
|
||||
|
||||
// Types which can not be altered by reserved keywords
|
||||
var $reserved_types = array("Pointer");
|
||||
|
||||
// Objective-c types to convert
|
||||
var $replace_types = array("BOOL"=>"Boolean", "long"=>"clong", "int"=>"cint",
|
||||
"unsigned long"=>"culong", "unsigned short"=>"cushort", "void *"=>"Pointer", "unsigned int"=>"cuint",
|
||||
"Class"=>"Pobjc_class", "uint"=>"cuint",
|
||||
"uint8_t"=>"cuint8", "signed int"=>"cint", "const char"=>"char", "const void *"=>"Pointer",
|
||||
"const uint8_t"=>"cuint8", "unsigned"=>"cuint", "int32_t"=>"cint32", "float"=>"single",
|
||||
"unsigned long long"=>"culonglong", "int64_t"=>"cint64", "uint32_t"=>"cuint32", "uint16_t"=>"cuint16",
|
||||
"unsigned char"=>"char", "short"=>"cshort", "double"=>"double", "long long"=>"clonglong",
|
||||
"uintptr_t"=>"culong","intptr_t"=>"clong",
|
||||
"signed char"=>"char", "uint64_t"=>"cuint64",
|
||||
|
||||
// work-arounds - the type replacement needs regex to handle with spaces I guess
|
||||
"void*"=>"Pointer",
|
||||
|
||||
// macros
|
||||
"IBAction"=>"void", "IBOutlet"=>"",
|
||||
|
||||
// special pointers
|
||||
"const id *"=>"NSObjectArrayOfObjectsPtr", "Protocol *"=>"objc_protocol", "NSObject *"=>"NSObject",
|
||||
"const char *"=>"PChar", "const void *"=>"Pointer", "unsigned char *"=>"PByte", "char *"=>"PChar",
|
||||
"unsigned *"=>"pcuint", "unichar *"=>"PChar", "const unichar *"=>"PChar",
|
||||
);
|
||||
|
||||
// These "types" are hints to the Objective-C garbage collector
|
||||
var $garbage_collector_hints = array("__strong", "__weak", "volatile", "___strong", "___weak");
|
||||
|
||||
// These identifiers are used with remote messaging
|
||||
var $remote_messaging_modifiers = array("oneway", "in", "out", "inout", "bycopy", "byref");
|
||||
|
||||
var $null_macros = array("IBOutlet", "IBAction");
|
||||
|
||||
// External NSString macros. Additional values are imported from frameworks.xml
|
||||
var $external_string_macros = "APPKIT_EXTERN|FOUNDATION_EXPORT|EXTERN|extern";
|
||||
|
||||
// Types which have known pointers declared in the headers
|
||||
var $pointer_types = array( // MacOSAll types
|
||||
// C/Cocoa types
|
||||
"void"=>"Pointer","const void"=>"Pointer",
|
||||
"Boolean"=>"pboolean",
|
||||
"clong"=>"pclong","cint"=>"pcint",
|
||||
"culong"=>"pculong","cushort"=>"pcushort","cuint"=>"pcuint",
|
||||
"cuint8"=>"pbyte","char"=>"PChar",
|
||||
"clonglong"=>"pclonglong","culonglong"=>"pculonglong",
|
||||
"cint64"=>"pcint64",
|
||||
"cuint32"=>"pcuint32","cuint16"=>"pcuint16",
|
||||
"cshort"=>"pcshort",
|
||||
|
||||
"single"=>"psingle", "double"=>"pdouble",
|
||||
);
|
||||
|
||||
// These methods require that the last parameter append a trailing underscore (if $trailing_underscore is on)
|
||||
// Method format should be Objective-C copied directly from the headers
|
||||
var $trailing_underscore_methods = array( "- (void)copy:(id)sender;",
|
||||
"- (void)setNeedsDisplay:(BOOL)flag;",
|
||||
"- (void*)QTMovie;","- (QTMovie *)QTMovie;",
|
||||
"- (BOOL)load:(NSError **)error;",
|
||||
);
|
||||
var $trailing_underscore = true;
|
||||
|
||||
// Types to ignore
|
||||
var $ignore_types = array("CGFloat");
|
||||
|
||||
// Comments (or fragments starting with the pattern) to ignore (regex)
|
||||
var $ignore_comments = array();
|
||||
|
||||
// Categories to ignore
|
||||
// NSURLLoading is deprecated in 10.4 and later, and causes problems
|
||||
// when parsing the iPhoneOS foundation
|
||||
var $ignore_categories = array("NSURLLoading");
|
||||
|
||||
// Methods to ignore
|
||||
var $ignore_methods = array( "observationInfo",
|
||||
);
|
||||
|
||||
// Lines to ignore
|
||||
var $ignore_lines = array();
|
||||
|
||||
// Default protected keywords by class/category
|
||||
// These may be useful if super classes were not parsed before
|
||||
var $default_protected = array( "*"=>array("description", "classDescription", "zone"),
|
||||
// "NSDeprecated"=>array("accessoryView"),
|
||||
"NSToolbarSupport"=>array("toolbar"),
|
||||
"DOMNode"=>array("version"),
|
||||
"WebView"=>array("frame"),
|
||||
"DOMImplementation"=>array("version"),
|
||||
"NSTableView"=>array("cell","toolTip","menu"),
|
||||
"NSMovie"=>array("QTMovie"),
|
||||
"UIAcceleration"=>array("timestamp","x","y","z"),
|
||||
);
|
||||
|
||||
var $skip_blocks = array( //"^#if __LP64__.*"=>"^#(else|endif)+",
|
||||
"^#if __BLOCKS__"=>"^#(else|endif)+",
|
||||
"^#if NS_BLOCKS_AVAILABLE"=>"^#(else|endif)+",
|
||||
"^#ifndef CGFLOAT_DEFINED"=>"^#(else|endif)+",
|
||||
);
|
||||
|
||||
var $macro_blocks = array( "^#if \(__LP64__\)"=>"\$ifdef cpu64",
|
||||
"^#if __LP64__.*"=>"\$ifdef cpu64",
|
||||
"^#if !__LP64__.*"=>"\$ifndef cpu64",
|
||||
"^#if defined \(__LP64__\)"=>"\$ifdef cpu64",
|
||||
"^#if ![[:space:]]*\(__LP64__\)"=>"\$ifndef cpu64",
|
||||
"^#ifdef __BIG_ENDIAN__"=>"\$ifdef fpc_big_endian",
|
||||
// not really clean (assumes all arm devices are embedded)
|
||||
"^#if __LP64__ \|\| TARGET_OS_EMBEDDED \|\| TARGET_OS_IPHONE \|\| TARGET_OS_WIN32 \|\| NS_BUILD_32_LIKE_64"=>"\$if defined(cpu64) or defined(cpuarm) or defined(win32)",
|
||||
// replacement must be updated once we support AppleTV (presumably defines TARGET_OS_EMBEDDED but not TARGET_OS_IPHONE)
|
||||
"^#if __LP64__ \|\| (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) \|\| TARGET_OS_WIN32 \|\| NS_BUILD_32_LIKE_64"=>"\$if defined(cpu64) or defined(win32)"
|
||||
//"^#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_[0-9]+_[0-9]+"=>"*",
|
||||
);
|
||||
|
||||
// These macros are used to suggest which version of a framework the symbol is available in but removed to assist the parser
|
||||
var $version_macros = array( "[[:space:]]*DEPRECATED_IN_.*_VERSION_[0-9]+_[0-9]+_AND_LATER[[:space:]]*",
|
||||
"[[:space:]]*AVAILABLE_.*_VERSION_[0-9]+_[0-9]+_AND_LATER_BUT_DEPRECATED_IN_.*_VERSION_[0-9]+_[0-9]+[[:space:]]*",
|
||||
"[[:space:]]*AVAILABLE_.*_VERSION_[0-9]+_[0-9]+_AND_LATER[[:space:]]*",
|
||||
"[[:space:]]*AVAILABLE_.*_VERSION_[0-9]+_[0-9]+[[:space:]]*",
|
||||
"[[:space:]]*.*_VERSION_MAX_ALLOWED[[:space:]]*",
|
||||
"[[:space:]]__OSX_AVAILABLE.*\([^)]+\)",
|
||||
"[[:space:]]*UIKIT_CLASS_AVAILABLE\(.*\)[[:space:]]*",
|
||||
"[[:space:]]*__OSX_AVAILABLE_STARTING\(.*\)[[:space:]]*",
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* COMMON REGULAR EXPRESIONS
|
||||
*/
|
||||
var $regex_objc_method_params = "^(-|\+)[[:space:]]*\(([^)]*)\)[[:space:]]*([a-zA-Z0-9]+):(.*);";
|
||||
var $regex_objc_method_no_params = "^(-|\+)[[:space:]]*\(([^)]*)\)[[:space:]]*([a-zA-Z0-9]+);";
|
||||
var $regex_objc_method_partial = "^(-|\+)[[:space:]]*\(([^)]*)\)[[:space:]]*([a-zA-Z0-9]+):(.*)";
|
||||
var $regex_objc_method_terminate = "(.*);[[:space:]]*$";
|
||||
var $regex_objc_category = "^@interface ([a-zA-Z]+)[[:space:]]*\(([a-zA-Z]+)\)";
|
||||
var $regex_objc_class = "^@interface ([a-zA-Z]+)[[:space:]]*:[[:space:]]*([a-zA-Z]+)[[:space:]]*(<(.*)>)*";
|
||||
var $regex_objc_class_no_super = "^@interface ([a-zA-Z]+)[[:space:]]*<(.*)>[[:space:]]*";
|
||||
var $regex_objc_protocol = "^@protocol ([a-zA-Z]+)";
|
||||
var $regex_procedure_type = "^[[:space:]]*(void|IBAction)+[[:space:]]*$";
|
||||
var $regex_scope_compiler_directive = "^\s*@(private|protected|public)(;*)+\s*$";
|
||||
var $regex_objc_property_attributes = "^@property[[:space:]]*\(([^)]*)\)[[:space:]]*([a-zA-Z_0-9]+)[[:space:]]*(\*)*[[:space:]]*(.*);";
|
||||
var $regex_objc_property = "^@property[[:space:]]*([a-zA-Z_0-9]+)[[:space:]]*(\*)*[[:space:]]*(.*);";
|
||||
var $regex_objc_anon_class = "^@class[[:space:]]*(.*);";
|
||||
|
||||
// $1 = return type
|
||||
// $2 = pointer modifiers
|
||||
// $3 = inline para name if any
|
||||
// $4 = parameteres
|
||||
var $pregex_function_pointer = "!^\s*([^*]+)\s*([*]*)\s*\(\s*[*]\s*(\w+)?\s*\)\s*\((.*)\)\s*;\s*$!";
|
||||
// same as above except no ";" at the end
|
||||
var $pregex_function_pointer_c_paratype = "!^\s*([^*]+)\s*([*]*)\s*\(\s*[*]\s*(\w+)?\s*\)\s*\((.*)\)\s*$!";
|
||||
// Obj-C: additional brackets and para name
|
||||
// $1 = return type
|
||||
// $2 = pointer modifiers for return type
|
||||
// $3 = inline type name if any
|
||||
// $4 = parameters
|
||||
// $5 = para name
|
||||
// last "word" is next part of method name before next colon
|
||||
var $pregex_function_pointer_objc_paratype = "!^\s*\(([^*]+)\s*([*]*)\s*\(\s*[*]\s*(\w+)?\s*\)\s*\((.*)\)\s*\)\s*(\w+)\s*\w+\s*$!";
|
||||
// the (*) for the function pointer is "optional" in the sense that you can
|
||||
// also declare a (useless?) function type (i.e., without the pointer) and
|
||||
// then afterwards declare variables to be pointers to this type
|
||||
var $pregex_function_pointer_typedef = "!^\s*typedef\s*([^*]+)\s*([*]*)\b\s*(?:\(\s*([*])\s*(\w+)?\s*\)|(\w+))\s*\((.*)\)\s*(\w+)?\s*;\s*$!";
|
||||
|
||||
// semi-colon optional because sometimes on next line with availability
|
||||
// macro
|
||||
// $1 = return type
|
||||
// $2 = pointer modifiers for return type
|
||||
// $3 = function name
|
||||
// $4 = parameters
|
||||
var $pregex_external_function_end = "\s+([^*]+)\s*([*]*)\b\s*(\w+)\s*\((.*)\)\s*;?\s*$!";
|
||||
|
||||
var $pregex_deprecated_macro = "!DEPRECATED!";
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,500 +0,0 @@
|
||||
<?php
|
||||
|
||||
class TObjPParser extends TPasCocoaParser {
|
||||
|
||||
var $trailing_underscore = true;
|
||||
|
||||
// ignore these classes when testing for ivar size
|
||||
var $ignore_class_ivar_comparison = array( "NSNibOutletConnector", "NSNibConnector", "NSNibControlConnector", "NSPredicateEditorRowTemplate", "NSSegmentedCell",
|
||||
"NSSimpleHorizontalTypesetter", "NSInvocation", "NSPointerFunctions", "NSConstantString");
|
||||
|
||||
// These methods require that the last parameter append a trailing underscore (if $trailing_underscore is on)
|
||||
var $trailing_underscore_methods = array("- (void)copy:(id)sender;", "- (void)setNeedsDisplay:(BOOL)flag;","- (void*)QTMovie;","- (QTMovie *)QTMovie;","- (BOOL)load:(NSError **)error;");
|
||||
|
||||
var $ignore_methods = array("observationInfo");
|
||||
|
||||
// Converts an Objective-c method name to Pascal
|
||||
function ConvertObjcMethodName ($method) {
|
||||
$params = explode(":", $method);
|
||||
$name = "";
|
||||
$count = 0;
|
||||
|
||||
if (count($params) > 1) {
|
||||
foreach ($params as $value) {
|
||||
if (eregi("([a-zA-Z0-9]+)$", $value, $captures)) $name .= $captures[1]."_";
|
||||
}
|
||||
} else {
|
||||
if (eregi("([a-zA-Z0-9]+)(;)*$", $params[0], $captures)) $name .= $captures[1]."_";
|
||||
}
|
||||
|
||||
// clean it up
|
||||
if ($this->trailing_underscore) {
|
||||
if (!in_array($method, $this->trailing_underscore_methods)) $name = trim($name, "_");
|
||||
}
|
||||
|
||||
$name = $this->ReplaceObjcType($name);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
// Converts an Objective-C method to Pascal format
|
||||
function ConvertObjcMethodToPascal ($class, $source, $parts, $protected_keywords, $has_params, $deprecatedmods) {
|
||||
|
||||
//print("$source\n");
|
||||
//print_r($parts);
|
||||
|
||||
// replace "hinted" params comment with hinted type
|
||||
if ($this->replace_hinted_params) {
|
||||
|
||||
// param string
|
||||
if (eregi("(/\*[[:space:]]*(.*)[[:space:]]*\*/)", $parts[4], $captures)) {
|
||||
// ??? change the parameter to the hinted type
|
||||
//$parts[4] = eregi_replace("(/\*.*\*/)", $captures[2], $parts[4]);
|
||||
//$parts[4] = trim($parts[4], " ");
|
||||
}
|
||||
|
||||
// return type
|
||||
if (eregi("(/\*[[:space:]]*(.*)[[:space:]]*\*/)", $parts[2], $captures)) $parts[2] = $this->ReplaceRemoteMessagingModifiers($captures[2], $null);
|
||||
|
||||
//print_r($parts);
|
||||
|
||||
} else { // remove comments from params and return type
|
||||
$parts[4] = eregi_replace("(/\*.*\*/)", "", $parts[4]);
|
||||
$parts[4] = trim($parts[4]);
|
||||
|
||||
$parts[2] = eregi_replace("(/\*.*\*/)", "", $parts[2]);
|
||||
$parts[2] = $this->ReplaceRemoteMessagingModifiers($parts[2], $null);
|
||||
}
|
||||
|
||||
$return_type_clean = $parts[2];
|
||||
$return_type_pointers = preg_replace("![^*]+!e", "", $return_type_clean);
|
||||
$return_type_clean = trim($return_type_clean,"* ");
|
||||
|
||||
// perform preformatting before attempting to protect keywords
|
||||
$parts[2] = $this->FormatObjcType($parts[2], $modifiers);
|
||||
$parts[4] = $this->FormatObjcParams($parts[4], $variable_arguments);
|
||||
//print($parts[4]."\n");
|
||||
|
||||
if ($has_params) {
|
||||
$name = $this->ConvertObjcMethodName($source);
|
||||
|
||||
// merge default protected keywords for the class/category
|
||||
if ($this->default_protected["*"]) $protected_keywords = array_merge($this->default_protected["*"], $protected_keywords);
|
||||
if ($this->default_protected[$class]) $protected_keywords = array_merge($this->default_protected[$class], $protected_keywords);
|
||||
|
||||
|
||||
$param_array = $this->ConvertObjcParamsToPascal($parts[4], $protected_keywords);
|
||||
$params = "(".$param_array["string"].")";
|
||||
$params_with_modifiers = "(".$param_array["string_with_modifiers"].")";
|
||||
|
||||
} else {
|
||||
$params = "";
|
||||
$params_with_modifiers = "";
|
||||
// no parameters -> definitely no underscore normally, but there are some
|
||||
// conflicts...
|
||||
$name = $parts[3];
|
||||
// clean it up
|
||||
if ($this->trailing_underscore) {
|
||||
if (in_array($source, $this->trailing_underscore_methods)) $name = $name . "_";
|
||||
}
|
||||
$param_array = null;
|
||||
$variable_arguments = false;
|
||||
}
|
||||
|
||||
// protect method name from keywords
|
||||
if ($this->IsKeywordReserved($name)) $name .= "_";
|
||||
|
||||
// replace objc type
|
||||
$return_type = $this->ConvertReturnType($return_type_clean,$return_type_pointers);
|
||||
|
||||
$virtual = "";
|
||||
$class_prefix = "";
|
||||
|
||||
// determine the type based on return value
|
||||
if (ereg($this->regex_procedure_type, $return_type_clean.$return_type_pointers)) {
|
||||
$kind = "procedure";
|
||||
} else {
|
||||
$kind = "function";
|
||||
}
|
||||
|
||||
// determine if this is a class method
|
||||
if ($parts[1] == "+") {
|
||||
$class_prefix = "class ";
|
||||
|
||||
// These methods probably return the an allocated instance of the class, a typical convenience method.
|
||||
// ??? Ack! $class may be the category or protocol name
|
||||
//if ($return_type == $this->objc_id) $return_type = $class;
|
||||
}
|
||||
|
||||
// Replace SEL with the string equivalent
|
||||
if ($this->register_selectors) {
|
||||
$params_with_modifiers = str_replace_word("SEL", $this->sel_string, $params_with_modifiers);
|
||||
}
|
||||
|
||||
// make method templates
|
||||
if ($kind != "function") {
|
||||
if ($variable_arguments) $modifier .= " varargs;";
|
||||
|
||||
$method = "$class_prefix$kind $name$params_with_modifiers;$modifier$virtual";
|
||||
$method_template = "[KIND] [PREFIX]$name"."[PARAMS];$modifier";
|
||||
} else {
|
||||
if ($variable_arguments) $return_type = "$return_type; varargs";
|
||||
|
||||
$method = $class_prefix."function $name$params_with_modifiers: $return_type;$modifier$virtual";
|
||||
$method_template = "[KIND] [PREFIX]$name"."[PARAMS]: [RETURN];$modifier";
|
||||
}
|
||||
|
||||
$method_template_procedure = "procedure [PREFIX]$name"."[PARAMS];$modifier";
|
||||
$method_template_function = "function [PREFIX]$name"."[PARAMS]: [RETURN];$modifier";
|
||||
|
||||
// build structure
|
||||
$struct["def"] = $method;
|
||||
$struct["template"] = $method_template;
|
||||
$struct["template_function"] = $method_template_function;
|
||||
$struct["template_procedure"] = $method_template_procedure;
|
||||
$struct["objc_method"] = $this->CopyObjcMethodName($source);
|
||||
$struct["class_prefix"] = $class_prefix;
|
||||
if ($deprecatedmods != "") $struct["deprecated"] = $deprecatedmods.";";
|
||||
//$struct["def_objc"] = eregi("(.*);", $source, $captures[1]);
|
||||
if ($return_type == "void") $return_type = "";
|
||||
$struct["return"] = $return_type;
|
||||
|
||||
if (in_array($return_type, $this->cocoa_classes)) $struct["returns_wrapper"] = true;
|
||||
$struct["param_string_clean"] = trim($params, "()");
|
||||
$struct["param_string_clean_with_modifiers"] = trim($params_with_modifiers, "()");
|
||||
$struct["param_string"] = $params;
|
||||
$struct["param_string_with_modifiers"] = $params_with_modifiers;
|
||||
$struct["param_array"] = $param_array["pairs"];
|
||||
$struct["param_list"] = $param_array["list"];
|
||||
$struct["class"] = $class;
|
||||
$struct["name"] = $name;
|
||||
$struct["kind"] = $kind;
|
||||
|
||||
if ($struct["param_array"] != null) $struct["has_params"] = true;
|
||||
|
||||
// FPC bug work around
|
||||
if (strlen($name) > $this->maximum_method_length) {
|
||||
$struct["can_override"] = false;
|
||||
print(" # WARNING: method $name can't override because the name is too long\n");
|
||||
$this->warning_count ++;
|
||||
}
|
||||
|
||||
return $struct;
|
||||
}
|
||||
|
||||
function InsertPatches ($header) {
|
||||
$path = "$this->root/patches/".$header["name_clean"].".patch";
|
||||
if ($handle = @fopen($path, "r")) {
|
||||
$text = ReadTextFile($path);
|
||||
$this->PrintOutput(0, $text);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
function HeaderContainsPatch ($header) {
|
||||
if ($handle = @fopen("$this->root/patches/".$header["name_clean"].".patch", "r")) {
|
||||
fclose($handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function PrintGlobalClassInfo($all_classes, $defined_classes, $anon_classes) {
|
||||
// add all classes as anonymous external classes to a separate unit.
|
||||
// They will be overridden by the actual definitions in the translated
|
||||
// headers part of the main unit, but this way they can appear as record
|
||||
// field types and as callback parameters
|
||||
|
||||
// open the output file if we not printing to terminal
|
||||
if (!$this->show) {
|
||||
$this->output = fopen("$this->root$this->out/AnonClassDefinitions".ucfirst($this->framework).".pas", "w+");
|
||||
}
|
||||
|
||||
$this->PrintOutput(0, "{ Parsed from ".ucfirst($this->framework)." }");
|
||||
|
||||
$date = @date("D M j G:i:s T Y");
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
// allows parameter names conflicting with field names
|
||||
$this->PrintOutput(0, "{\$mode delphi}");
|
||||
$this->PrintOutput(0, "{\$modeswitch objectivec1}");
|
||||
// enables "external" after the semi-colon
|
||||
$this->PrintOutput(0, "{\$modeswitch cvar}");
|
||||
$this->PrintOutput(0, "");
|
||||
|
||||
$this->PrintOutPut(0,"unit AnonClassDefinitions".ucfirst($this->framework).";");
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "interface");
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "type");
|
||||
|
||||
foreach ($all_classes as $class)
|
||||
$this->PrintOutput(1, $class." = objcclass; external;");
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "implementation");
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "end.");
|
||||
|
||||
|
||||
// Now all anonymous external classes that have no real definition to an
|
||||
// include file that is added to the main unit. This way it is possible
|
||||
// to declare variables of these types in user programs without having to
|
||||
// include the unit above will all anonymous classes (should not be used)
|
||||
|
||||
// open the output file if we not printing to terminal
|
||||
if (!$this->show) {
|
||||
$this->output = fopen("$this->root$this->out/$this->framework/AnonIncludeClassDefinitions".ucfirst($this->framework).".inc", "w+");
|
||||
}
|
||||
|
||||
$this->PrintOutput(0, "{ Parsed from ".ucfirst($this->framework)." }");
|
||||
|
||||
$date = @date("D M j G:i:s T Y");
|
||||
|
||||
|
||||
// add all classes as anonymous external classes. They will be overridden
|
||||
// by the actual definitions in the translated headers, but this way they
|
||||
// can appear as record field types and as callback parameters
|
||||
$first = true;
|
||||
foreach ($anon_classes as $class) {
|
||||
if (!in_array($class,$defined_classes)) {
|
||||
if ($first) {
|
||||
$this->PrintOutput(0, "type");
|
||||
$first = false;
|
||||
}
|
||||
$this->PrintOutput(1, $class." = objcclass; external;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Prints all classes from the header in Objective-P FPC format
|
||||
function PrintHeader ($header) {
|
||||
global $version;
|
||||
//print_r($header);
|
||||
//print_r($this->dump["categories"]);
|
||||
|
||||
// open the output file if we not printing to terminal
|
||||
if (!$this->show) {
|
||||
if ($this->merge_headers) {
|
||||
$this->output = fopen($header["path_merge"], "w+");
|
||||
} else {
|
||||
$this->output = fopen($header["path"], "w+");
|
||||
}
|
||||
}
|
||||
|
||||
$this->PrintOutput(0, "{ Parsed from ".ucfirst($header["framework"]).".framework ".$header["name"]." }");
|
||||
|
||||
$date = @date("D M j G:i:s T Y");
|
||||
$this->PrintOutput(0, "{ Version: $version - $date }");
|
||||
$this->PrintOutput(0, "");
|
||||
|
||||
$macro = strtoupper(substr($header["name"], 0, (strripos($header["name"], "."))));
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef TYPES}");
|
||||
$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_T}");
|
||||
$this->PrintOutput(0, "{\$define $macro"."_PAS_T}");
|
||||
$this->PrintTypes($header, false);
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef RECORDS}");
|
||||
$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_R}");
|
||||
$this->PrintOutput(0, "{\$define $macro"."_PAS_R}");
|
||||
|
||||
// Records from types
|
||||
$this->PrintRecords($header);
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef FUNCTIONS}");
|
||||
$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_F}");
|
||||
$this->PrintOutput(0, "{\$define $macro"."_PAS_F}");
|
||||
$this->PrintFunctions($header);
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef EXTERNAL_SYMBOLS}");
|
||||
$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_S}");
|
||||
$this->PrintOutput(0, "{\$define $macro"."_PAS_S}");
|
||||
$this->PrintExternalSymbols($header);
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
|
||||
// insert user patches
|
||||
if ($this->HeaderContainsPatch($header)) {
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef USER_PATCHES}");
|
||||
//$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_PATCH}");
|
||||
//$this->PrintOutput(0, "{\$define $macro"."_PAS_PATCH}");
|
||||
$this->InsertPatches($header);
|
||||
$this->PrintOutput(0, "");
|
||||
//$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
}
|
||||
|
||||
if (($header["classes"]) || ($header["protocols"])) {
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef FORWARD}");
|
||||
|
||||
if ($header["protocols"]) {
|
||||
foreach ($header["protocols"] as $protocol) $this->PrintOutput(1, $protocol["name"]."$this->protocol_suffix = objcprotocol;");
|
||||
}
|
||||
|
||||
if ($header["classes"]) {
|
||||
foreach ($header["classes"] as $class) {
|
||||
if ($class["name"]) {
|
||||
$this->PrintOutput(1, $class["name"]." = objcclass;");
|
||||
$this->PrintOutput(1, $class["name"].$this->class_pointer_suffix." = ^".$class["name"].";");
|
||||
// for consistency also offer Ptr-name variant
|
||||
$this->PrintOutput(1, $class["name"]."Ptr = ".$class["name"].$this->class_pointer_suffix.";");
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
}
|
||||
|
||||
if ($header["classes"]) {
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$ifdef CLASSES}");
|
||||
$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_C}");
|
||||
$this->PrintOutput(0, "{\$define $macro"."_PAS_C}");
|
||||
|
||||
foreach ($header["classes"] as $class) {
|
||||
if ($class["name"]) $this->PrintClass($class);
|
||||
}
|
||||
|
||||
if (count($header["categories"]) > 0) {
|
||||
foreach ($header["categories"] as $category) {
|
||||
$this->PrintCategory($class, $category);
|
||||
}
|
||||
}
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
}
|
||||
|
||||
|
||||
if ($header["protocols"]) {
|
||||
$this->PrintOutput(0, "{\$ifdef PROTOCOLS}");
|
||||
$this->PrintOutput(0, "{\$ifndef $macro"."_PAS_P}");
|
||||
$this->PrintOutput(0, "{\$define $macro"."_PAS_P}");
|
||||
|
||||
|
||||
foreach ($header["protocols"] as $protocol) {
|
||||
$this->PrintOutput(1, "");
|
||||
$this->PrintOutput(0, "{ ".$protocol["name"]." Protocol }");
|
||||
if ($protocol["comment"]) $this->PrintOutput(0, $protocol["comment"]);
|
||||
$this->PrintOutput(1, $protocol["name"]."$this->protocol_suffix = objcprotocol");
|
||||
|
||||
// print methods
|
||||
if ($protocol["methods"]) {
|
||||
foreach ($protocol["methods"] as $name => $method) {
|
||||
if ($method["comment"]) $this->PrintOutput(2, $method["comment"]);
|
||||
$this->PrintOutput(2, $method["def"]." message '".$method["objc_method"]."';".$method["deprecated"]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->PrintOutput(1, "end; external name '".$protocol["name"]."';");
|
||||
}
|
||||
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
$this->PrintOutput(0, "{\$endif}");
|
||||
}
|
||||
}
|
||||
|
||||
function PrintCategory ($class, $category) {
|
||||
|
||||
// declare real category if external
|
||||
if ($category["external"]) {
|
||||
$new_name = " name '".$category["external_name"]."'";
|
||||
}
|
||||
|
||||
$category_name = $category["name"].$this->category_suffix;
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{ $category_name }");
|
||||
if ($category["comment"]) $this->PrintOutput(0, $category["comment"]);
|
||||
|
||||
// print super class or protocol which the class conforms to
|
||||
$this->PrintOutput(1, "$category_name = objccategory(".$category["super"].")");
|
||||
|
||||
// print methods
|
||||
if ($category["methods"]) {
|
||||
foreach ($category["methods"] as $method) {
|
||||
if ($method["comment"]) $this->PrintOutput(2, $method["comment"]);
|
||||
$this->PrintOutput(2, $method["def"]." message '".$method["objc_method"]."';".$method["deprecated"]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->PrintOutput(1, "end; external$new_name;");
|
||||
}
|
||||
|
||||
function PrintClass ($class) {
|
||||
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(0, "{ ".$class["name"]." }");
|
||||
|
||||
if ($class["comment"]) $this->PrintOutput(0, $class["comment"]);
|
||||
//print_r($class["methods"]);
|
||||
|
||||
|
||||
// print super class or protocol which the class conforms to
|
||||
if ($class["adopts"]) {
|
||||
$this->PrintOutput(1, $class["name"]." = objcclass(".$class["super"].", ".$class["adopts"].")");
|
||||
} elseif ($class["super"]) {
|
||||
$this->PrintOutput(1, $class["name"]." = objcclass(".$class["super"].")");
|
||||
}
|
||||
|
||||
// print instance variables
|
||||
if ($class["ivars"]) {
|
||||
$this->PrintOutput(1, "private");
|
||||
foreach ($class["ivars"] as $ivar) {
|
||||
$this->PrintOutput(2, $ivar);
|
||||
}
|
||||
}
|
||||
|
||||
// print alloc method for the class
|
||||
$this->PrintOutput(2, "");
|
||||
$this->PrintOutput(1, "public");
|
||||
$this->PrintOutput(2, "class function alloc: ".$class["name"]."; message 'alloc';");
|
||||
|
||||
// print class-level methods
|
||||
if ($class["methods"]) {
|
||||
$this->PrintOutput(0, "");
|
||||
foreach ($class["methods"] as $method) {
|
||||
if ($method["comment"]) $this->PrintOutput(2, $method["comment"]);
|
||||
$this->PrintOutput(2, $method["def"]." message '".$method["objc_method"]."';".$method["deprecated"]);
|
||||
}
|
||||
}
|
||||
|
||||
// print adopted protocol methods
|
||||
if (count($class["protocols"]) > 0) {
|
||||
$this->PrintOutput(0, "");
|
||||
$this->PrintOutput(2, "{ Adopted Protocols }");
|
||||
//print_r($this->dump["protocols"]);
|
||||
|
||||
foreach ($class["protocols"] as $name) {
|
||||
if ($this->dump["protocols"][$name]) {
|
||||
foreach ($this->dump["protocols"][$name] as $method) {
|
||||
if (!$this->ClassContainsMethod($class, $method)) $this->PrintOutput(2, $method["def"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->PrintOutput(1, "end; external;");
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
60
packages/cocoaint/utils/source/utilities.php
Normal file
60
packages/cocoaint/utils/source/utilities.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
function str_replace_word ($needle, $replacement, $haystack) {
|
||||
$pattern = "/\b$needle\b/";
|
||||
$haystack = preg_replace($pattern, $replacement, $haystack);
|
||||
return $haystack;
|
||||
}
|
||||
|
||||
function istr_replace_word ($needle, $replacement, $haystack) {
|
||||
$pattern = "/\b$needle\b/i";
|
||||
$haystack = preg_replace($pattern, $replacement, $haystack);
|
||||
return $haystack;
|
||||
}
|
||||
|
||||
function strtolowerref(&$str) {
|
||||
$str = strtolower($str);
|
||||
}
|
||||
|
||||
// converts "STR_XX_YY_ZZ" to "Str Xx Yy Zz"
|
||||
function DeprecatedMacroToDirective($str) {
|
||||
// AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4 etc
|
||||
if (preg_match("!DEPRECATED_(IN_.*VERSION_.*)_AND_LATER!", $str, $matches)) {
|
||||
$str = strtolower($matches[1]);
|
||||
// cleanup
|
||||
$str = preg_replace("!in_mac_os_x_version_!", "in Mac OS X ", $str);
|
||||
$str = preg_replace("!([0-9])_([0-9])!e", '\1.\2', $str);
|
||||
return " deprecated '" . $str . " and later'";
|
||||
// NS_DEPRECATED(__MAC_10_1,__MAC_10_6,__IPHONE_NA,__IPHONE_NA),
|
||||
// __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_6,__IPHONE_NA,__IPHONE_NA,
|
||||
// NS_DEPRECATED_IPHONE(__IPHONE_2_0,__IPHONE_2_0),
|
||||
// NS_DEPRECATED_MAC(__MAC_10_1, __MAC_10_5)
|
||||
} elseif (preg_match("!DEPRECATED(_IPHONE|_MAC)?\(([^)]+)\)!", $str, $matches)) {
|
||||
$str = strtolower($matches[2]);
|
||||
$versions = preg_replace("!__MAC_!e", "Mac OS X ", $str);
|
||||
$versions = preg_replace("!__IPHONE_!e", "iOS ", $versions);
|
||||
$versions = preg_replace("!([0-9])_([0-9])!e", '\1.\2', $versions);
|
||||
$deprecatedversions = explode(",", $matches[2]);
|
||||
$result = "";
|
||||
if ($matches[1] == "") {
|
||||
$macindex = 2;
|
||||
$iphoneindex = 4;
|
||||
} elseif ($matches[1] == "_IPHONE") {
|
||||
$macindex = -1;
|
||||
$iphoneindex = 2;
|
||||
} else {
|
||||
$macindex = 2;
|
||||
$iphoneindex = -1;
|
||||
}
|
||||
if (($macindex != -1) && !preg_match("!Mac OS X( Version)? NA|MAC_NA!", $deprecatedversions[$macindex])) {
|
||||
$result = "in " . $deprecatedversions[$macindex] . " and later";
|
||||
}
|
||||
if (($iphoneindex != -1) && !preg_match("!iOS( Version)? NA|IPHONE_NA!", $deprecatedversions[$iphoneindex])) {
|
||||
if ($result != "") $result .= ", ";
|
||||
$result .= "in " . $deprecatedversions[$iphoneindex] . " and later";
|
||||
}
|
||||
return " deprecated '" . $result . "'";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user