iPhone headers translator
Pascal iPhone header translator
Anton e-mail: ast DOT a_s AT mail DOT ru
Because no one can redistribute Pascal units for iOS SDK we need a tool that can produce such units from official C headers. Of course everyone can take original headers and manually translate them but it is not the simplest work. Indeed this process can be (at least partially) automated. I'd like to present iPhone headers translator that is written in FPC.
There are several files zip available fro download page:
- parser.pas - main program;
- htranslator.pas - contains main class that perform translation (indeed it only manage this process);
- hscanner.pas - contains "c-header scanner" class;
- hparser.pas - contains common c-header parser, that translates c declarations (without helper functions with implementations (bodies));
- bparser.pas - extends header parser to handle functions with bodies too;
- ocparser.pas - extends parser to handle objective-c declarations;
- decltypes.pas - contains class to manage translated types;
- declids.pas (since 20120410) - contains class to manage globally declared symbols (constants, variables and functions).
Features (main goals of project)
- do not require any additional (input) files, only iPhone SDK C-headers;
- produced Pascal units must not need any manual fixes to be compiled;
- translate also implementations of helper functions
- Initial version from 2012-03-19: can translate UIKit and related frameworks.
- Translation process was tested for the following SDKs:
- iPhoneSimulator 3.0, 3.2, 4.0, 4.1, 4.2, 4.3, 5.0;
- iPhoneOS 5.0.
- Compilation of produced units was tested only for iPhoneSimulator 5.0.
- Test project can be found on download page (ipt.zip contains Lazarus project, notes about its compilation can be found in next section).
- ip_pars20120410: can translate almost all frameworks from SDK 5.0.
- Some frameworks (applicationservices, coreservices, accelerate, carbon) for now are translated to empty units because translation of "nested frameworks" is not implemented yet. Parsing process was tested for iPhoneSimulator 5.0 and iPhoneOS 5.0, compilation was tested only for simulator.
How to parse
To build parser "fpc parser" is enough. Of course you need to install iPhone SDK. Cause I have only simulator, I will use its SDK. Typically it is installed to /Developer/Platforms/iPhoneSimulator/Developer/SDKs/iPhoneSimulator5.0.sdk (for 5.0 version). The path to SDK will be used as a parameter of parser. Indeed, it's time to start it. Parser contains a little help, so it can be used (--help or without parameters).
- one of parameter must be sdk="path_to_sdk" (mandatory);
- there can be parameter dest="output_path" (to place Pascal units, if not specified "src" is used);
- all other parameters are regarded as names of frameworks to parse.
$ ./parser sdk=/Developer/Platforms/iPhoneSimulator/Developer/SDKs/iPhoneSimulator5.0.sdk UIKit
will translate UIKit and all dependant frameworks (cfnetwork, corefoundation, coregraphics, coreimage, corevideo, foundation, opengles, security). I've tested it for SDKs 3.0, 3.2, 4.0, 4.1, 4.2, 4.3, 5.0. Although now it works good there are some "todo's" and unimplemented parts.
ip_pars20120410.zip contains two scripts that can be used to start translation process:
- start_ios.sh for iPhoneOS 5.0 SDK;
- start_sim.sh for iPhoneSimulator 5.0 SDK.
- Before starting these scripts you will need execute chmod +x for them.
- These scripts cannot be used for SDKs of different versions because trying to parse missing framework leads to fatal error.
My test program is also attached (ipt.zip contains Lazarus project). Project output directory must be changed. In order to run it in Simulator I have created empty XCode project "iphone_test" and run it. After that I've closed XCode and run only simulator - it has contained my new program "iphone_test". After that I've simply replaced binary /Users/macuser/Library/Application Support/iPhone Simulator/5.0/Applications/C93F7A57-E612-4A40-B155-DB106CA860D6/iphone_test.app/iphone_test