<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hello Gaetano,<br>
      <br>
      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.<br>
      <br>
      I was thinking about "clone" approach some time ago, but the
      question how to handle complex dependencies is still open here.<br>
      <br>
      <br>
      <br>
      18.01.2017 19:55, Gaetano Checinski via cfe-dev пишет:<br>
    </div>
    <blockquote
cite="mid:CAN0NuG7ey+xL18d7seEaU853=Yz3Cr_yxd-FPm5sLq6Tww31kA@mail.gmail.com"
      type="cite">
      <div dir="ltr">I was wondering if anybody spend some efforts in
        implementing a clone Method for all ASTNodes?
        <div><br>
        </div>
        <div>It seems to me, that the current approach implemented in
          the ASTImporter is error-prone and hard to maintain.</div>
        <div><br>
        </div>
        <div>Currently it looks to me that Decls / Stmt's are being
          probed for their type and then downcasted, eg.:<br>
          <br>
        </div>
        <blockquote style="margin:0 0 0 40px;border:none;padding:0px">
          <div><font face="monospace, monospace">/* ASTNodeImporter::VisitExplicitCastExpr
              */</font></div>
          <div><font face="monospace, monospace">/* ASTImporter.cpp:6060
              */</font></div>
          <div><font face="monospace, monospace">switch
              (E->getStmtClass()) {</font></div>
          <div><font face="monospace, monospace">  case
              Stmt::CStyleCastExprClass: {</font></div>
          <div><font face="monospace, monospace">     CStyleCastExpr
              *CCE = cast<CStyleCastExpr>(E);</font></div>
          <div><font face="monospace, monospace">     return
              CStyleCastExpr::Create(Importer.getToContext(), T,</font></div>
          <div><font face="monospace, monospace">       
              E->getValueKind(), E->getCastKind(),</font></div>
          <div><font face="monospace, monospace">        SubExpr,
              &BasePath, TInfo,</font></div>
          <div><font face="monospace, monospace">       
              Importer.Import(CCE->getLParenLoc()),</font></div>
          <div><font face="monospace, monospace">       
              Importer.Import(CCE->getRParenLoc()));</font></div>
          <div><font face="monospace, monospace">}</font></div>
          <div><font face="monospace, monospace">/* more cases*/</font></div>
        </blockquote>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>As the AST contains circular references and many nodes
          require an ASTContext</div>
        <div>for construction, i'm wondering how feasible it would be to
          implement the following interface for each Decl?</div>
        <div><br>
        </div>
        <blockquote style="margin:0 0 0 40px;border:none;padding:0px">
          <div><font face="monospace, monospace"> virtual Decl* clone(</font></div>
          <div><font face="monospace, monospace">   ASTContext*
              newContext, </font></div>
          <div><font face="monospace, monospace">   DenseMap<Decl*,
              Decl*> ImportedDeclsCache = {}</font></div>
          <div><font face="monospace, monospace"> );</font></div>
        </blockquote>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
          <br>
          <br>
          <div class="mt-signature"><a moz-do-not-send="true"
href="https://mailtrack.io/trace/link/b910ce4d02f08facbacacd7152c370d845d81397?url=https%3A%2F%2Fmailtrack.io%2F&signature=e6da9dfa433d9e41"
              class="gmail-mt-signature-logo"
              style="text-decoration:none"><img moz-do-not-send="true"
src="https://s3-eu-west-1.amazonaws.com/mailtrack-crx/icon-signature.png"
                height="14" width="16"> </a><font
              class="mt-signature-text" color="#999999">Sent with <a
                moz-do-not-send="true"
href="https://mailtrack.io/install?source=signature&lang=en&referral=gaetano.checinski@gmail.com&idSignature=22"
                class="mt-install">Mailtrack</a></font></div>
        </div>
        <img moz-do-not-send="true" class="mailtrack-img"
src="https://mailtrack.io/trace/mail/60b1fad8a10e8e81bb7515ece8f346d88128107a.png?u=931501"
          height="0" width="0"></div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
    </blockquote>
    <br>
    <p><br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics
</pre>
  </body>
</html>