<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 2, 2010, at 12:19 AM, Pierre Habouzit wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Fri, Oct 01, 2010 at 02:14:09PM -0700, jahanian wrote:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">On Oct 1, 2010, at 1:42 PM, Pierre Habouzit wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">While I'm at it, the objc rewriter tries hard to rewrite typeof() for a<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">reason that eludes me.  Given that typeof() is often used inside macros,<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">and that rewriting inside macros may not work (that I can understand<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">;p), this is really painful.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">We needed to support rewriting of __typeof because of our requirements.<br></blockquote><blockquote type="cite">There is a test case under Rewrite/rewrite-typeof.mm which specifically<br></blockquote><blockquote type="cite">tests this.<br></blockquote><br>To be frank it still doesn't explain why you need it at all, but fine :)</div></blockquote></div><div><blockquote type="cite"><div><br><blockquote type="cite">This is one other reason to have a separate rewriter  without baggage<br></blockquote><blockquote type="cite">associated with our specific needs.<br></blockquote><br>Well, I've made the work of taking the block rewriting code from<br>RewriteObjC.cpp, it's huge, and I'm uncomfortable duplicating that<br>amount of code.<br><br>So what is the best approach, is it writing a new RewriteBlocks class<br></div></blockquote><div><br></div>You want a rewriter which rewrites a c program containing blocks into</div><div>a c program with all the block code synthesized into their underlying c</div><div>implementation.  This can be accomplished by declaring a new </div><div>RewriteBlock class  derived from <span class="Apple-style-span" style="color: rgb(85, 129, 134); font-family: Menlo; font-size: 11px; ">ASTConsumer. Pretty much follow how </span></div><div><font class="Apple-style-span" color="#558186" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px;"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">RewriteObjC object is constructed (and where) by setting</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">breakpoint in <span class="Apple-style-span" style="color: rgb(0, 0, 0); ">RewriteObjC::</span><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">RewriteObjC and see how rewriter gets</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">called by setting breakpoint at clang::ParseAST. </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">Then it is matter of lots of stripping off all the ObjC</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">rewriter stuff in code you bring from ObjC rewriter and</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">getting rid off all the c++-ness of block rewriting.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">Rewriting of blocks is very substantive and what ObjC </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">rewriter does involves code which interacts with NeXt''s </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">block runtime. But you can rewrite a block which does</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">^{ printf("Hello");}();</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">pretty quickly.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">- Fariborz</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><br></span></div></span></font><blockquote type="cite"><div>that RewriteObjC would inherit from (but it's a very huge work) or<br>simply make RewriteObjC have a "bool RewriteBlocksOnly" setting that is<br>selected whether it's called from -rewrite-objc or -rewrite-blocks on<br>the command line, and that would affect how code is generated ?<br><br>I'd rather go for the latter that is simpler, as mostly for now, it will<br>just disable the typeof rewriting, simplify the preamble (the objc stuff<br>isn't required), and keep my previous patch so that the generated code<br>still works when compiled with a c++ compiler.<br><br>Would that be acceptable ?<br>-- <br>·O·  Pierre Habouzit<br>··O                                                <a href="mailto:madcoder@debian.org">madcoder@debian.org</a><br>OOO                                                <a href="http://www.madism.org">http://www.madism.org</a><br></div></blockquote></div><br></body></html>