Difference between revisions of "ObjCParser"

From Lazarus wiki
Jump to navigationJump to search
(New page: ObjCparser is the tool that helps to convert obj-c header to FPC headers as described at PasCocoa Currently ObjCParser supports Objective-C 1.0 language specification. (Objective-C 2....)
 
m
Line 10: Line 10:
 
-all  (any file named *.h is considered a header file and being parsed);
 
-all  (any file named *.h is considered a header file and being parsed);
 
-ini  (setting file)
 
-ini  (setting file)
-uini (setting file to write to updated files. Type definition information [TypeDefs]  
+
-uini (setting file to write to updated files. Type definition information [TypeDefs] is written  to the specified file  )
  is written  to the specified file  )
 
 
-noout (.inc files are not generated, though config file (is still written, if specified)
 
-noout (.inc files are not generated, though config file (is still written, if specified)
  
*** Configuration File Sections ***
+
=== Configuration File Sections ===
  
 
Configuration file uses simple .INI file format, so it can be easily edited by any editor available.
 
Configuration file uses simple .INI file format, so it can be easily edited by any editor available.
  
** Common flags ***
+
== Common flags ==
  
 
Following parsing settings are defined at [Common] section
 
Following parsing settings are defined at [Common] section
Line 33: Line 32:
 
   (like: CoreFoundation/SomeFile.h,  CoreFoundation/SomeFile2.h)
 
   (like: CoreFoundation/SomeFile.h,  CoreFoundation/SomeFile2.h)
  
** Type replacement **
+
== Type replacement ==
  
 
[TypeReplace]
 
[TypeReplace]
Line 51: Line 50:
 
function SomeClass.doSomethingWithNumber(num: PLongword): LongWord;
 
function SomeClass.doSomethingWithNumber(num: PLongword): LongWord;
  
** Type name definition **
+
== Type name definition ==
  
 
[TypeDefs]
 
[TypeDefs]
Line 64: Line 63:
 
this information is critical to select proper objc_msgSend function (implementation section). objcclass types are also replaced with 'objc.id' type to avoid type naming conflicts between pascal and objc class names.
 
this information is critical to select proper objc_msgSend function (implementation section). objcclass types are also replaced with 'objc.id' type to avoid type naming conflicts between pascal and objc class names.
  
** Token Replacament **
+
== Token Replacament ==
  
 
Token replacement (currently REMOVE ONLY) should be used to get rid of C pre-compiler defined values.   
 
Token replacement (currently REMOVE ONLY) should be used to get rid of C pre-compiler defined values.   

Revision as of 12:29, 29 April 2008

ObjCparser is the tool that helps to convert obj-c header to FPC headers as described at PasCocoa Currently ObjCParser supports Objective-C 1.0 language specification. (Objective-C 2.0 properties are not yet supported).

ObjCParser is available at PasCocoa/Parser folder

Command line usage is the following: objcparser [switches] [headername.h]

Supported switches: -all (any file named *.h is considered a header file and being parsed); -ini (setting file) -uini (setting file to write to updated files. Type definition information [TypeDefs] is written to the specified file ) -noout (.inc files are not generated, though config file (is still written, if specified)

Configuration File Sections

Configuration file uses simple .INI file format, so it can be easily edited by any editor available.

Common flags

Following parsing settings are defined at [Common] section

mainunit=mainunitname

 defines the main unit specifier to be added to the generated pascal files
 {$mainunit maununitname}

ignoreinclude

  specifies, what file #include or #import must be ignored, otherwise
  file would be also {$include}-d .
  full file name must be specified, or if file name ends with back slash
  (CoreFoundation/), all files that belongs to the path would also be ignored
  (like: CoreFoundation/SomeFile.h,  CoreFoundation/SomeFile2.h)

Type replacement

[TypeReplace] Replaces type name (at method params, results, and type structures) with specified type name. type replacement can also be specified for type references, for this case type name must end with '*' (asterix)

for example [TypeReplace] NSUInteger = Longword; NSUInteger* = LongWord;

so the following code would be generated objc: -(NSUInteger) doSomethingWithNumber: (NSUInteger *) num

pascal: function SomeClass.doSomethingWithNumber(num: PLongword): LongWord;

Type name definition

[TypeDefs] Specifies the type name usage.

There're 4 types available: int (any type that can be casted to 4-byte integer) float (float point value: single or double) struct (any type or structure that cannot be cased to 4 byte integer or larger than 4 bytes) objcclass (objective-c class)

this information is critical to select proper objc_msgSend function (implementation section). objcclass types are also replaced with 'objc.id' type to avoid type naming conflicts between pascal and objc class names.

Token Replacament

Token replacement (currently REMOVE ONLY) should be used to get rid of C pre-compiler defined values. [TokenReplace] AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER=""

AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER token is usually met by method, function or type declaration. It should be removed, or file is cannot be parsed correctly. Remember double quotes "" (empty string) must be specified, or parser ignores TokenReplacement