[cfe-dev] implementing clone for ASTNodes

Aleksei Sidorin via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 18 09:32:03 PST 2017


CC'ing cfe-dev again.

There should be no infinite loops in ASTImporter as they are broken by 
GetAlreadyImportedOrNull() method.
It is also interesting for me what will be the difference between 
clone() methods and methods of ASTImporter. Do you have any example?


18.01.2017 20:24, Gaetano Checinski пишет:
> The ASTImporter creates a lookup table ( DenseMap<Decl*,Decl*> 
> importedDecls), to keep track of the imported Decls and not to end up 
> in a infinite loop.
> This is why my proposed signature for the clone contains not only an 
> ASTContext to clone into but also a `DenseMap<Decl*, Decl*>& 
> ImportedDeclsCache` to keep track of those already imported Decls.
>
>
> 2017-01-18 17:16 GMT+00:00 Aleksei Sidorin <a.sidorin at samsung.com 
> <mailto:a.sidorin at samsung.com>>:
>
>     Hello Gaetano,
>
>     ASTImporter not just "imports" AST nodes. It also searches if they
>     already exist in the destination AST. It is required to get a
>     consistent AST.
>
>     I was thinking about "clone" approach some time ago, but the
>     question how to handle complex dependencies is still open here.
>
>
>
>     18.01.2017 19:55, Gaetano Checinski via cfe-dev пишет:
>>     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>
>>
>>
>>     _______________________________________________
>>     cfe-dev mailing list
>>     cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>     http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>     <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>
>     -- 
>     Best regards,
>     Aleksei Sidorin,
>     SRR, Samsung Electronics
>
-- 
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170118/1e7e4a4f/attachment.html>


More information about the cfe-dev mailing list