[cfe-dev] -rewrite-objc, C and blocks
Pierre Habouzit
madcoder at madism.org
Fri Oct 1 10:56:18 PDT 2010
Also, is obj-c++ defining __cplusplus ? if yes, then my proposal works
with obj-c++ just fine
On Fri, Oct 01, 2010 at 07:54:57PM +0200, Pierre Habouzit wrote:
> Well, there used to be a -rewrite-blocks and there is a commmit that
> says that it's superseeded by -rewrite-objc.
>
> Plus what my patch does is that if it's a c++ compiler that is used,
> then the c++ code is used, else it tries to be c-compatible.
>
> So would a pure C-to-C blocks rewriter (reintroducing -rewrite-blocks)
> be accepted ? I'd like to avoid maintaining a custom patch forever :)
>
> On Fri, Oct 01, 2010 at 09:00:57AM -0700, jahanian wrote:
> > Concept is right. However, rewriter project was done for a specific purpose and generates c++ code
> > as the input might be objective-c++. It is best for you to use the rewrite-obj model and have you own
> > -rewrite-block which generates c code.
> >
> > - Fariborz
> >
> > On Oct 1, 2010, at 3:16 AM, Pierre Habouzit wrote:
> >
> > > I intended to use clang -rewrite-objc to be able to compile code using
> > > blocks on targets unsupported by clang. I'm totally uninterested in the
> > > ObjC rewriting, only the blocks one.
> > >
> > > Sadly, this rewriting module rewrites to C++ even when the source code
> > > in question is just plain old C.
> > >
> > > I'm under the impression, that when the source code is C, only the fact
> > > that clang is generating structs with constructors and RAII use of the
> > > defined blocks. For example:
> > >
> > > struct __main_block_impl_0 {
> > > struct __block_impl impl;
> > > struct __main_block_desc_0* Desc;
> > > int a;
> > > __main_block_impl_0(void *fp, struct __main_block_desc_0 *desc, int _a, int flags=0) : a(_a) {
> > > impl.isa = &_NSConcreteStackBlock;
> > > impl.Flags = flags;
> > > impl.FuncPtr = fp;
> > > Desc = desc;
> > > }
> > > };
> > >
> > > [...]
> > >
> > > int main(void) {
> > > int a = 1;
> > > struct __Block_byref_c_0 c = {(void*)0,(struct __Block_byref_c_0 *)&c, 0, sizeof(struct __Block_byref_c_0), 1};
> > >
> > > int (*f)(int) = (int (*)(int))&__main_block_impl_0((void *)__main_block_func_0, &__main_block_desc_0_DATA, a);
> > > [...]
> > > }
> > >
> > > I'm under the impression that the following "rewrite" would be correct:
> > >
> > > struct __main_block_impl_0 {
> > > struct __block_impl impl;
> > > struct __main_block_desc_0* Desc;
> > > int a;
> > > #ifdef __cplusplus
> > > __main_block_impl_0(void *fp, struct __main_block_desc_0 *desc, int _a, int flags=0) : a(_a) {
> > > impl.isa = &_NSConcreteStackBlock;
> > > impl.Flags = flags;
> > > impl.FuncPtr = fp;
> > > Desc = desc;
> > > }
> > > #endif
> > > };
> > > #ifndef __cplusplus
> > > #define __main_block_impl_0(fp, desc, _a, flags) \
> > > ((struct __main_block_impl_0){ \
> > > .impl = { \
> > > .isa = &_NSConcreteStackBlock, \
> > > .Flags = flags, \
> > > .FuncPtr = fp, \
> > > }, \
> > > .Desc = desc, \
> > > .a = (_a), \
> > > })
> > > #endif
> > >
> > > [...]
> > >
> > > int main(void) {
> > > int a = 1;
> > > struct __Block_byref_c_0 c = {(void*)0,(struct __Block_byref_c_0 *)&c, 0, sizeof(struct __Block_byref_c_0), 1};
> > >
> > > int (*f)(int) = (int (*)(int))&__main_block_impl_0((void *)__main_block_func_0, &__main_block_desc_0_DATA, a);
> > > [...]
> > > }
> > >
> > >
> > > Am I correct, or am I missing something obvious ?
> > >
> > >
> > > --
> > > ·O· Pierre Habouzit
> > > ··O madcoder at debian.org
> > > OOO http://www.madism.org
> > > _______________________________________________
> > > cfe-dev mailing list
> > > cfe-dev at cs.uiuc.edu
> > > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >
>
> --
> ·O· Pierre Habouzit
> ··O madcoder at debian.org
> OOO http://www.madism.org
--
·O· Pierre Habouzit
··O madcoder at debian.org
OOO http://www.madism.org
More information about the cfe-dev
mailing list