[cfe-dev] implementing clone for ASTNodes

Gaetano Checinski via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 18 08:55:23 PST 2017


I was wondering if anybody spend some efforts in implementing a clone
Method for all ASTNodes?

It seems to me, that the current approach implemented in the ASTImporter is
error-prone and hard to maintain.

Currently it looks to me that Decls / Stmt's are being probed for their
type and then downcasted, eg.:

/* ASTNodeImporter::VisitExplicitCastExpr */
/* ASTImporter.cpp:6060 */
switch (E->getStmtClass()) {
  case Stmt::CStyleCastExprClass: {
     CStyleCastExpr *CCE = cast<CStyleCastExpr>(E);
     return CStyleCastExpr::Create(Importer.getToContext(), T,
        E->getValueKind(), E->getCastKind(),
        SubExpr, &BasePath, TInfo,
        Importer.Import(CCE->getLParenLoc()),
        Importer.Import(CCE->getRParenLoc()));
}
/* more cases*/



As the AST contains circular references and many nodes require an ASTContext
for construction, i'm wondering how feasible it would be to implement the
following interface for each Decl?

 virtual Decl* clone(
   ASTContext* newContext,
   DenseMap<Decl*, Decl*> ImportedDeclsCache = {}
 );








<https://mailtrack.io/trace/link/b910ce4d02f08facbacacd7152c370d845d81397?url=https%3A%2F%2Fmailtrack.io%2F&signature=e6da9dfa433d9e41>Sent
with Mailtrack
<https://mailtrack.io/install?source=signature&lang=en&referral=gaetano.checinski@gmail.com&idSignature=22>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170118/3cb5f2f5/attachment.html>


More information about the cfe-dev mailing list