Hi,<br><br>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.<br><br>I also would like to check on some issues:<br>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.<br>
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.<br>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.<br>
<br>Code:<br>In the class declaration I add Stmt *Clone(ASTContext &C) const;<br><br>For the implementation:<br><br>Stmt *BinaryOperator::Clone(ASTContext &C) const {<br> SourceLocation cpLoc;<br> Expr* lhs =dyn_cast<Expr>(SubExprs[LHS]->Clone(C));<br>
Expr* rhs =dyn_cast<Expr>(SubExprs[RHS]->Clone(C));<br> BinaryOperator *cp= new (C) BinaryOperator(lhs, rhs , Opc, getType(), cpLoc);<br> return cp;<br>}<br><br>Stmt *ArraySubscriptExpr::Clone(ASTContext &C) const {<br>
SourceLocation cpLoc; <br> Expr* lhs =dyn_cast<Expr>(SubExprs[LHS]->Clone(C));<br> Expr* rhs =dyn_cast<Expr>(SubExprs[RHS]->Clone(C));<br> ArraySubscriptExpr *cp= new (C) ArraySubscriptExpr(lhs,rhs, getType(), cpLoc);<br>
return cp;<br>}<br><br>Stmt *ImplicitCastExpr::Clone(ASTContext &C) const {<br>
SourceLocation cpLoc; <br>
ImplicitCastExpr *cp= new (C) ImplicitCastExpr(getType(), dyn_cast<Expr>(getSubExpr()->Clone(C)), isLvalueCast());<br>
return cp;<br>
}<br>
<br>
<br>P.S: I have read the llvm developer policy.<br>
<br>Thanks,<br>Moataz <br>