How do I output Clang's source code transition of Blocks?

For example, the Block Implementation Specification says

^ { printf(“hello world\n”); }

is translated to

struct __block_literal_1 {
void *isa;
int flags;
int reserved;
void (*invoke)(struct __block_literal_1 *);
struct __block_descriptor_1 *descriptor;
void __block_invoke_1(struct __block_literal_1 *_block) {
printf(“hello world\n”);
static struct __block_descriptor_1 {
unsigned long int reserved;
unsigned long int Block_size;
} __block_descriptor_1 = { 0, sizeof(struct __block_literal_1), __block_invoke_1 };

struct __block_literal_1 _block_literal = {
(1<<29), ,

Thanks for any help.
Richard Catlin

Clang does not actually perform a source translation for block literals. Instead, it generates code similar to what would have been generated had the user written the equivalent code.

There are many reasons why actually implementing this feature via source code translation would be difficult, but probably the most compelling is performance: there is really no reason for the compiler to go through all the work of parsing new source code when it already knows that it represents a block.

What do you actually need this for?

Hi Richard,

You can find the closest thing to that, clang's source-level blocks translator, in RewriteObjC.cpp.

As Jordan points out, the main compilation path in clang doesn't use source-level translation.

The aforementioned rewrite facility was developed in order to target Objective-C code to MSVC back before clang itself was viable on Windows.