[cfe-dev] Adding support for Cloning in the AST

moataz ragab mtzrgb at gmail.com
Sat May 16 12:48:28 PDT 2009


Hi Sebastian,

Thanks.

Attached 3 files: the patch "clone.diff". should be applied on the clang
directory.
                         RewriteLoopUnroll.cpp you have to put it in the
clang-cc directory.
                         test2.c: simple testcase for a forloop with array
access in the body.


you can invoke the loopunroller using:

 ../../../../Debug/bin/clang-cc -loop-unroll tests/test2.c

Currently it crashes because ImplicitCastExpr object doesn't get cloned. The
Stmt base class gets called instead of ImplicitCastExpr

Best regards,
Moataz

On Sat, May 16, 2009 at 8:48 PM, Sebastian Redl <
sebastian.redl at getdesigned.at> wrote:

> moataz ragab wrote:
> > Hi,
> >
> > I am implementing the clone method and would like to contribute the
> > implementation. Since this my first contribution, I would check if
> > anybody have technical issues to highlight.
> Be careful. Everyone who's working on template instantiation could be
> implementing these as they go along. I'm about to commit cloners for
> various literals (FloatingLiteral, CharacterLiteral, StringLiteral,
> CXXBooleanLiteralExpr, CXXNullPtrExpr, GNUNullExpr, PredefinedExpr).
> >
> > I also would like to check on some issues:
> > 1.  I started out by making it virtual and provided default impl. in
> > the base classes that just print the object class name. This is to
> > allow me to test my clone methods before implementing it in all the
> > AST classes. but finally it should be pure virtual.
> Yes, it should.
> > 2.  Should the clone return base class pointers or derived class
> > pointers? For example currently, there is clone method implemented for
> > literals in Expr.cpp. and it returns a pointer to the specifc literal
> > type.
> Always return the type you're cloning. Covariance is a wonderful thing.
> > 3. I have implemented the clone method for different Stmts and Exprs
> > and it seems working fine with exception of ImplicitCastExpr. Whenever
> > I call clone on objects of these class I get the base class (Stmt)
> > clone method invoked. I would appericiate if you could advise on this.
> >
> > Stmt *ImplicitCastExpr::Clone(ASTContext &C) const {
> >   SourceLocation cpLoc;
> >   ImplicitCastExpr *cp= new (C) ImplicitCastExpr(getType(),
> > dyn_cast<Expr>(getSubExpr()->Clone(C)), isLvalueCast());
> >   return cp;
> > }
> I see nothing wrong with this. Perhaps if you sent a patch and an
> example where we can try it out?
>
> One comment: in the code above, you know that the result of
> getSubExpr()->Clone() has to be an Expr. Use cast<> instead of
> dyn_cast<> there.
>
> Sebastian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090516/b4ea1e2c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clone.diff
Type: text/x-patch
Size: 10895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090516/b4ea1e2c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RewriteLoopUnroll.cpp
Type: text/x-c++src
Size: 9189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090516/b4ea1e2c/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.c
Type: text/x-csrc
Size: 82 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090516/b4ea1e2c/attachment.c>


More information about the cfe-dev mailing list