objp_base.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /**
  3. * ObjectivePParserBase contains all instance variables and settings for the parser
  4. * separated from the main file for easier navigation.
  5. */
  6. class ObjectivePParserBase {
  7. // Frameworks to parse (loaded from frameworks.xml)
  8. var $frameworks = array();
  9. var $maximum_method_length = 111; // WE GET THIS ERROR: NSDelegatesAll.pas(6109,296) Error: Identifier not found "NSDelegateController_NSLayoutManagerDelegate_layoutManager_shouldUseTemporaryAttributes_forDrawingToScreen_atCharacterIndex_effectiveRange"
  10. var $output; // current output file handle
  11. var $root; // root for printing/locating resources
  12. var $out; // directory to print
  13. var $show; // print output to screen instead of file
  14. var $framework; // current framework being parsed
  15. var $current_class; // reference to current class structure being parsed
  16. var $current_header; // reference to current header structure being parsed
  17. var $method_count; // count of all methods parsed
  18. var $class_count; // count of all classes parsed
  19. var $warning_count; // count of parser warnings
  20. var $parser_skipping; // the parser is skipping lines in the current file
  21. var $inside_macro_block; // the parser is inside a macro block, no nesting!
  22. var $instance_var_scope; // current scope of the instance variable parser
  23. var $dump = array(); // Convert Pascal classes
  24. var $delegate_methods = array(); // Delegate methods and types from GEN_BRIDGE_METADATA XML data
  25. var $delegate_method_names = array(); // Delegate method name array
  26. var $type_encodings = array(); // Master listing of type encodings for each method in the frameworks
  27. var $docset; // Current parsed docset for the framework (-all only)
  28. // Comments Builder
  29. var $comment_eol;
  30. var $comment_terminated;
  31. var $comment_fragment;
  32. var $comment_fragment_previous;
  33. var $comment_fragment_open;
  34. var $comment_previous;
  35. var $comment_block_open;
  36. var $comment_block_closed;
  37. var $comment_header;
  38. // Macros Builder
  39. var $macro_block = "";
  40. var $in_macro_block = false;
  41. /**
  42. * PARSER OPTIONS
  43. */
  44. var $objc_id = "id"; // Default type for generic objects
  45. var $sel_string = "SEL"; // The selector string type which registers selectors internally
  46. var $protocol_suffix = "Protocol"; // All protocols append this suffix
  47. var $pointer_type_suffx = "Ref"; // NS*** pointers in parameter lists are suffixed with this
  48. var $class_pointer_suffix = "Pointer"; // Pointers to NS*** classes are suffxed with this
  49. var $register_selectors = true; // Register selectors automatically inside the wrappers
  50. var $show_added_messages = false; // show messages when methods are added to a class
  51. var $show_class_hierarchy = false;
  52. var $objects_are_wrappers = false; // Treat all objects (id) like wrappers. i.e aObject.Handle;
  53. var $replace_hinted_params = false; // replace comment hints with hinted type - (void * /* CMProfileRef */)colorSyncProfile;
  54. var $record_keyword = "record"; // The keyword used for printing records
  55. var $bitpacked_record_keyword = "bitpacked record"; // The keyword used for printing bitpacked records
  56. var $string_macro = "NSString";
  57. var $category_suffix = "Category"; // To prevent naming conlicts all objccategories are suffixed with this work
  58. var $parse_comments = false; // Comments are parsed and inserted by context
  59. var $merge_headers = false; // Headers are printed by merging difference instead of overwritting
  60. var $comment_break = "\n"; // This text will be inserted before each comment to break lines
  61. var $comment_padding_left = " "; // Padding applied to the left side of all comments
  62. var $comment_padding_right = " "; // Padding applied to the right side of all comments
  63. var $varargs_param_name = "firstKey"; // The name of the first parameter for methods using varargs
  64. var $parse_docsets = false; // Parses docsets for symbol documentation
  65. // array of all known framework classes (both regular and anonymous)
  66. var $cocoa_classes = array("Protocol");
  67. // array of all anonymous external classes. This list will include
  68. // classes that are first defined anonymously and then normally
  69. var $anon_cocoa_classes = array();
  70. // array of all defined external classes. This list will only
  71. // include classes that are completely defined
  72. var $defined_cocoa_classes = array();
  73. // array of function pointer types that are declared without an indirection
  74. // (e.g. NSUncaughtExceptionHandler in NSException.h) -> do not add Ptr
  75. // suffix when deriving the pointer type
  76. var $implicit_function_pointer_types = array();
  77. // array of opaque struct pointer types
  78. var $opaque_structs = array();
  79. // array of all known framework categories
  80. var $cocoa_categories = array();
  81. // Pascal keywords to protect
  82. var $reserved_keywords = array( "const", "object", "string", "array", "var", "set", "interface", "unit", "begin", "end",
  83. "type", "raise", "property", "to", "for", "with", "function", "procedure", "result",
  84. "pointer", "create", "new", "dispose", "label", "packed", "record", "class", "implementation",
  85. );
  86. // FPC methods that can't be overloaded
  87. var $reserved_methods = array("");
  88. // Types which can not be altered by reserved keywords
  89. var $reserved_types = array("Pointer");
  90. // Objective-c types to convert
  91. var $replace_types = array("BOOL"=>"Boolean", "long"=>"clong", "int"=>"cint",
  92. "unsigned long"=>"culong", "unsigned short"=>"cushort", "void *"=>"Pointer", "unsigned int"=>"cuint",
  93. "Class"=>"Pobjc_class", "uint"=>"cuint",
  94. "uint8_t"=>"cuint8", "signed int"=>"cint", "const char"=>"char", "const void *"=>"Pointer",
  95. "const uint8_t"=>"cuint8", "unsigned"=>"cuint", "int32_t"=>"cint32", "float"=>"single",
  96. "unsigned long long"=>"culonglong", "int64_t"=>"cint64", "uint32_t"=>"cuint32", "uint16_t"=>"cuint16",
  97. "unsigned char"=>"char", "short"=>"cshort", "double"=>"double", "long long"=>"clonglong",
  98. "uintptr_t"=>"culong","intptr_t"=>"clong",
  99. "signed char"=>"char", "uint64_t"=>"cuint64",
  100. // work-arounds - the type replacement needs regex to handle with spaces I guess
  101. "void*"=>"Pointer",
  102. // macros
  103. "IBAction"=>"void", "IBOutlet"=>"",
  104. // special pointers
  105. "const id *"=>"NSObjectArrayOfObjectsPtr", "Protocol *"=>"objc_protocol", "NSObject *"=>"NSObject",
  106. "const char *"=>"PChar", "const void *"=>"Pointer", "unsigned char *"=>"PByte", "char *"=>"PChar",
  107. "unsigned *"=>"pcuint", "unichar *"=>"PChar", "const unichar *"=>"PChar",
  108. );
  109. // These "types" are hints to the Objective-C garbage collector
  110. var $garbage_collector_hints = array("__strong", "__weak", "volatile", "___strong", "___weak");
  111. // These identifiers are used with remote messaging
  112. var $remote_messaging_modifiers = array("oneway", "in", "out", "inout", "bycopy", "byref");
  113. var $null_macros = array("IBOutlet", "IBAction");
  114. // External NSString macros. Additional values are imported from frameworks.xml
  115. var $external_string_macros = "APPKIT_EXTERN|FOUNDATION_EXPORT|EXTERN|extern";
  116. // Types which have known pointers declared in the headers
  117. var $pointer_types = array( // MacOSAll types
  118. // C/Cocoa types
  119. "void"=>"Pointer","const void"=>"Pointer",
  120. "Boolean"=>"pboolean",
  121. "clong"=>"pclong","cint"=>"pcint",
  122. "culong"=>"pculong","cushort"=>"pcushort","cuint"=>"pcuint",
  123. "cuint8"=>"pbyte","char"=>"PChar",
  124. "clonglong"=>"pclonglong","culonglong"=>"pculonglong",
  125. "cint64"=>"pcint64",
  126. "cuint32"=>"pcuint32","cuint16"=>"pcuint16",
  127. "cshort"=>"pcshort",
  128. "single"=>"psingle", "double"=>"pdouble",
  129. );
  130. // These methods require that the last parameter append a trailing underscore (if $trailing_underscore is on)
  131. // Method format should be Objective-C copied directly from the headers
  132. var $trailing_underscore_methods = array( "- (void)copy:(id)sender;",
  133. "- (void)setNeedsDisplay:(BOOL)flag;",
  134. "- (void*)QTMovie;","- (QTMovie *)QTMovie;",
  135. "- (BOOL)load:(NSError **)error;",
  136. );
  137. var $trailing_underscore = true;
  138. // Types to ignore
  139. var $ignore_types = array("CGFloat");
  140. // Comments (or fragments starting with the pattern) to ignore (regex)
  141. var $ignore_comments = array();
  142. // Categories to ignore
  143. // NSURLLoading is deprecated in 10.4 and later, and causes problems
  144. // when parsing the iPhoneOS foundation
  145. var $ignore_categories = array("NSURLLoading");
  146. // Methods to ignore
  147. var $ignore_methods = array();
  148. // methods to rename to particular alternatives
  149. var $replace_instance_methods = array ( "class" => "_class", );
  150. var $replace_class_methods = array ("respondsToSelector" => "classRespondsToSelector",
  151. "isEqual" => "classIsEqual",
  152. "hash" => "classHash",
  153. "superClass" => "classSuperClass",
  154. "class" => "classClass",
  155. "conformsToProtocol" => "classConformsToProtocol",
  156. "classDescription" => "_classDescription", );
  157. // Lines to ignore
  158. var $ignore_lines = array();
  159. // Default protected keywords by class/category
  160. // These may be useful if super classes were not parsed before
  161. var $default_protected = array( "*"=>array("description", "classDescription", "zone"),
  162. // "NSDeprecated"=>array("accessoryView"),
  163. "NSToolbarSupport"=>array("toolbar"),
  164. "DOMNode"=>array("version"),
  165. "WebView"=>array("frame"),
  166. "DOMImplementation"=>array("version"),
  167. "NSTableView"=>array("cell","toolTip","menu"),
  168. "NSMovie"=>array("QTMovie"),
  169. "UIAcceleration"=>array("timestamp","x","y","z"),
  170. );
  171. var $skip_blocks = array( //"^#if __LP64__.*"=>"^#(else|endif)+",
  172. "^#if __BLOCKS__"=>"^#(else|endif)+",
  173. "^#if NS_BLOCKS_AVAILABLE"=>"^#(else|endif)+",
  174. "^#ifndef CGFLOAT_DEFINED"=>"^#(else|endif)+",
  175. );
  176. var $macro_blocks = array( "^#if \(__LP64__\)"=>"\$ifdef cpu64",
  177. "^#if __LP64__.*"=>"\$ifdef cpu64",
  178. "^#if !__LP64__.*"=>"\$ifndef cpu64",
  179. "^#if defined \(__LP64__\)"=>"\$ifdef cpu64",
  180. "^#if ![[:space:]]*\(__LP64__\)"=>"\$ifndef cpu64",
  181. "^#ifdef __BIG_ENDIAN__"=>"\$ifdef fpc_big_endian",
  182. // not really clean (assumes all arm devices are embedded)
  183. "^#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)",
  184. // replacement must be updated once we support AppleTV (presumably defines TARGET_OS_EMBEDDED but not TARGET_OS_IPHONE)
  185. "^#if __LP64__ \|\| (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) \|\| TARGET_OS_WIN32 \|\| NS_BUILD_32_LIKE_64"=>"\$if defined(cpu64) or defined(win32)"
  186. //"^#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_[0-9]+_[0-9]+"=>"*",
  187. );
  188. // These macros are used to suggest which version of a framework the symbol is available in but removed to assist the parser
  189. var $version_macros = array( "[[:space:]]*DEPRECATED_IN_[^(]*_VERSION_[0-9]+_[0-9]+_AND_LATER[[:space:]]*",
  190. "[[:space:]]*AVAILABLE_[^(]*_VERSION_[0-9]+_[0-9]+_AND_LATER_BUT_DEPRECATED_IN_[^(]*_VERSION_[0-9]+_[0-9]+[[:space:]]*",
  191. "[[:space:]]*AVAILABLE_[^(]*_VERSION_[0-9]+_[0-9]+_AND_LATER_BUT_DEPRECATED[[:space:]]*",
  192. "[[:space:]]*AVAILABLE_[^(]*_VERSION_[0-9]+_[0-9]+_AND_LATER[[:space:]]*",
  193. "[[:space:]]*AVAILABLE_[^(]*_VERSION_[0-9]+_[0-9]+[[:space:]]*",
  194. "[[:space:]]*.*_VERSION_MAX_ALLOWED[[:space:]]*",
  195. "[[:space:]]__OSX_AVAILABLE[^(]*\([^;)]+\)[[:space:]]*",
  196. "[[:space:]]*UIKIT_CLASS_AVAILABLE\([^;]*\)[[:space:]]*",
  197. "[[:space:]]*NS_AVAILABLE[^(]*\([^;]*\)[[:space:]]*",
  198. "[[:space:]]*NS_DEPRECATED[^(]*\([^;]*\)[[:space:]]*",
  199. "[[:space:]]WEBKIT_OBJC_METHOD_ANNOTATION\([^;]*\)[[:space:]]*",
  200. );
  201. // Subpats to search for docsets
  202. var $docset_paths = array( "com.apple.adc.documentation.AppleSnowLeopard.CoreReference.docset" => array("/Cocoa/Reference"),
  203. "com.apple.adc.documentation.AppleiOS4_2.iOSLibrary.docset" => array("/UIKit/Reference"),
  204. );
  205. /**
  206. * COMMON REGULAR EXPRESIONS
  207. */
  208. var $pregex_objc_method_params = "!^(-|\+)\s*\(([^)]*)\)\s*(\w+):([^;]*)\s*[^:;]*;!";
  209. var $pregex_objc_method_no_params = "!^(-|\+)\s*\(([^)]*)\)\s*(\w+)\s*[^:;]*;!";
  210. var $pregex_objc_method_partial = "!^(-|\+)\s*\(([^)]*)\)\s*(\w+):([^;]*)!";
  211. var $pregex_objc_method_terminate = "!([^;]*);\s*$!";
  212. var $regex_objc_category = "^@interface ([a-zA-Z]+)[[:space:]]*\(([a-zA-Z]+)\)";
  213. var $regex_objc_class = "^@interface ([a-zA-Z]+)[[:space:]]*:[[:space:]]*([a-zA-Z0-9_]+)[[:space:]]*(<(.*)>)*";
  214. var $regex_objc_class_no_super = "^@interface ([a-zA-Z]+)[[:space:]]*<(.*)>[[:space:]]*";
  215. var $regex_objc_protocol = "^@protocol ([a-zA-Z0-9_]+)";
  216. var $regex_procedure_type = "^[[:space:]]*(void|IBAction)+[[:space:]]*$";
  217. var $regex_scope_compiler_directive = "^\s*@(private|protected|public)(;*)+\s*$";
  218. var $regex_objc_property_attributes = "^@property[[:space:]]*\(([^)]*)\)[[:space:]]*([a-zA-Z_0-9]+)[[:space:]]*(\*)*[[:space:]]*(.*);";
  219. var $regex_objc_property = "^@property[[:space:]]*([a-zA-Z_0-9]+)[[:space:]]*(\*)*[[:space:]]*(.*);";
  220. var $regex_objc_anon_class = "^@class[[:space:]]*(.*);";
  221. // $1 = return type
  222. // $2 = pointer modifiers
  223. // $3 = inline para name if any
  224. // $4 = parameteres
  225. var $pregex_function_pointer = "!^\s*([^*]+)\s*([*]*)\s*\(\s*[*]\s*(\w+)?\s*\)\s*\((.*)\)\s*;\s*$!";
  226. // same as above except no ";" at the end
  227. var $pregex_function_pointer_c_paratype = "!^\s*([^*]+)\s*([*]*)\s*\(\s*[*]\s*(\w+)?\s*\)\s*\((.*)\)\s*$!";
  228. // Obj-C: additional brackets and para name
  229. // $1 = return type
  230. // $2 = pointer modifiers for return type
  231. // $3 = inline type name if any
  232. // $4 = parameters
  233. // $5 = para name
  234. // last "word" is next part of method name before next colon
  235. var $pregex_function_pointer_objc_paratype = "!^\s*\(([^*]+)\s*([*]*)\s*\(\s*[*]\s*(\w+)?\s*\)\s*\((.*)\)\s*\)\s*(\w+)\s*\w+\s*$!";
  236. // the (*) for the function pointer is "optional" in the sense that you can
  237. // also declare a (useless?) function type (i.e., without the pointer) and
  238. // then afterwards declare variables to be pointers to this type
  239. var $pregex_function_pointer_typedef = "!^\s*typedef\s*([^*]+)\s*([*]*)\b\s*(?:\(\s*([*])\s*(\w+)?\s*\)|(\w+))\s*\((.*)\)\s*(\w+)?\s*;\s*$!";
  240. // semi-colon optional because sometimes on next line with availability
  241. // macro
  242. // $1 = return type
  243. // $2 = pointer modifiers for return type
  244. // $3 = function name
  245. // $4 = parameters
  246. var $pregex_external_function_end = "\s+([^*]+)\s*([*]*)\b\s*(\w+)\s*\((.*)\)\s*;?\s*$!";
  247. var $pregex_deprecated_macro = "!DEPRECATED!";
  248. }
  249. ?>