Move block rewriting in its own file.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Don't store pointer to temporary objects anymore.

It was a miracle this works on earlier versions of gcc since we kept
pointers to temporary stuff as soon as we assigned a block to a variable.
Instead we now create a variable per block so that we're sure the block
remains valid as long as we don't leave the inner most compound statement.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
fix segfault due to invalid assertion
disable warning when the Block rewriter failed to rewrite ^ to * in macro

Because we rewrite the caret into star manually inside macro we can bypass
this clang limitation.
Fix range of source rewritten.

The rewriter wrongly considered the beginning of the type of the rewritten
variable as the beginning of the declaration of the variable when
rewriting global variables. As a consequence, when rewriting something
like 'static int (^blah)() = ...', the static remained before the output
of the rewriter and thus applied to the implementation structure definition
leading to incorrect C code to be generated.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Fix crash in some cases of rewriting within macros.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
blocks: fix crash when trying to rewrite macro

The rewriter isn't compatible with macros at all, so just avoid to try to
rewrite macros...

+ add some assert() to avoid random crashes in future.
Fix regression of new rewriter that didn't rewrite C++ methods anymore.

This caused regression since the block calls remained function called in
those function with objects that were no function (and thus crashed).

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Resolve typeof() when rewriting the block in order.

This will avoid types of variables to be described as typeof(variable)
in the descriptor of the block that may not see the variable (since that
variable may be local to the function that define the block).

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Introduce -rewrite-blocks

Make it use a subset of the ObjC Rewriter.

For now it basically does two things:
- for one it tries to keep the language the code is written in, whether it
  is C, C++, ObjC or ObjC++, using RAII when the language is C++-based
- it disables typeof and objc rewriting

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
Unused return value for a statement expression is OK

There are too many of them out there (CPU_SET for example), and ignoring
the result of a statement expression is basically the same as ignoring the
return value of a function...

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
Quickly hack a clang #-liner together

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
fix rewriting of function prototype when they take 2 (or more) blocks.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
fix buggy line introduced creating off-by-one in error reporting.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
generates cleaner files by removing the #ifdef __cplusplus

We are able to identify the language of the source we are rewriting, thus
there's not need to insert #ifdefs on the language. This helps keeping the
generated source a bit cleaner.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Fix support for static variadic functions.

Closes: #13446
Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Exclude generated code from lcov coverage.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Fix for clang 3.3

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
Build fixes for clang 3.4

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>