[cfe-dev] -rewrite-objc and typeof (Was: -rewrite-objc, C and blocks)

jahanian fjahanian at apple.com
Tue Oct 5 09:45:58 PDT 2010


On Oct 2, 2010, at 12:19 AM, Pierre Habouzit wrote:

> On Fri, Oct 01, 2010 at 02:14:09PM -0700, jahanian wrote:
>> 
>> On Oct 1, 2010, at 1:42 PM, Pierre Habouzit wrote:
>> 
>>> 
>>> While I'm at it, the objc rewriter tries hard to rewrite typeof() for a
>>> reason that eludes me.  Given that typeof() is often used inside macros,
>>> and that rewriting inside macros may not work (that I can understand
>>> ;p), this is really painful.
>> 
>> We needed to support rewriting of __typeof because of our requirements.
>> There is a test case under Rewrite/rewrite-typeof.mm which specifically
>> tests this.
> 
> To be frank it still doesn't explain why you need it at all, but fine :)

> 
>> This is one other reason to have a separate rewriter  without baggage
>> associated with our specific needs.
> 
> Well, I've made the work of taking the block rewriting code from
> RewriteObjC.cpp, it's huge, and I'm uncomfortable duplicating that
> amount of code.
> 
> So what is the best approach, is it writing a new RewriteBlocks class

You want a rewriter which rewrites a c program containing blocks into
a c program with all the block code synthesized into their underlying c
implementation.  This can be accomplished by declaring a new 
RewriteBlock class  derived from ASTConsumer. Pretty much follow how 
RewriteObjC object is constructed (and where) by setting
breakpoint in RewriteObjC::RewriteObjC and see how rewriter gets
called by setting breakpoint at clang::ParseAST. 
Then it is matter of lots of stripping off all the ObjC
rewriter stuff in code you bring from ObjC rewriter and
getting rid off all the c++-ness of block rewriting.
Rewriting of blocks is very substantive and what ObjC 
rewriter does involves code which interacts with NeXt''s 
block runtime. But you can rewrite a block which does
^{ printf("Hello");}();
pretty quickly.

- Fariborz

> that RewriteObjC would inherit from (but it's a very huge work) or
> simply make RewriteObjC have a "bool RewriteBlocksOnly" setting that is
> selected whether it's called from -rewrite-objc or -rewrite-blocks on
> the command line, and that would affect how code is generated ?
> 
> I'd rather go for the latter that is simpler, as mostly for now, it will
> just disable the typeof rewriting, simplify the preamble (the objc stuff
> isn't required), and keep my previous patch so that the generated code
> still works when compiled with a c++ compiler.
> 
> Would that be acceptable ?
> -- 
> ·O·  Pierre Habouzit
> ··O                                                madcoder at debian.org
> OOO                                                http://www.madism.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101005/161b015a/attachment.html>


More information about the cfe-dev mailing list