CFHipsterRef Low-Level Programming on iOS & Mac OS X

Translation Units

The first step to working with source code is to load it into memory. Clang operates on translation units, which are the ultimate form of C or Objective-C source code, after all of the #include, #import, and any other preprocessor directives have been evaluated.

A translation unit is created by passing a path to the source code file, and any command-line compilation arguments:

CXIndex idx = clang_createIndex(0, 0);
const char *filename = "path/to/Source.m";
int argc;
const char *argv[];

CXTranslationUnit tu = clang_parseTranslationUnit(idx, filename, 0, argv, argc, 0, CXTranslationUnit_None);
{ ... }
clang_disposeTranslationUnit(tu);
clang_disposeIndex(idx);