iPhone headers translator

From Lazarus wiki
Jump to navigationJump to search

Pascal iPhone header translator

Author

Anton e-mail: ast DOT a_s AT mail DOT ru

Introduction

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.

File structure

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

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).

Parser parameters:

  1. one of parameter must be sdk="path_to_sdk" (mandatory);
  2. there can be parameter dest="output_path" (to place Pascal units, if not specified "src" is used);
  3. all other parameters are regarded as names of frameworks to parse.

Example:

$ ./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. 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

Download

From here: http://sourceforge.net/projects/p-tools/files/iPhone%20headers%20translator/

See Also