[PATCH] D47632: [ASTImporter] Refactor Decl creation

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 1 06:27:09 PDT 2018


martong created this revision.
martong added reviewers: a.sidorin, balazske, xazax.hun, r.stahl.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

Generalize the creation of Decl nodes during Import.  With this patch we do the
same things after and before a new AST node is created (::Create) The import
logic should be really simple, we create the node, then we mark that as
imported, then we recursively import the parts for that node and then set them
on that node.  However, the AST is actually a graph, so we have to handle
circles.  If we mark something as imported (`MapImported()`) then we return with
the corresponding `To` decl whenever we want to import that node again, this way
circles are handled.  In order to make this algorithm work we must ensure
things, which are handled in the generic CreateDecl<> template:

- There are no `Import()` calls in between any node creation (::Create)

and the `MapImported()` call.

- Before actually creating an AST node (::Create), we must check if

the Node had been imported already, if yes then return with that one.
One very important case for this is connected to templates: we may
start an import both from the templated decl of a template and from
the template itself.

Now, the virtual `Imported` function is called in `ASTImporter::Impor(Decl *)`,
but only once, when the `Decl` is imported.  One point of this refactor is to
separate responsibilities. The original `Imported()` had 3 responsibilities:

- notify subclasses when an import happened
- register the decl into `ImportedDecls`
- initialise the Decl (set attributes, etc)

Now all of these are in separate functions:

- `Imported`
- `MapImported`
- `InitializeImportedDecl`

I tried to check all the clients, I executed tests for `ExternalASTMerger.cpp`
and some unittests for lldb.


Repository:
  rC Clang

https://reviews.llvm.org/D47632

Files:
  include/clang/AST/ASTImporter.h
  include/clang/AST/DeclBase.h
  lib/AST/ASTImporter.cpp
  lib/AST/ExternalASTMerger.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47632.149453.patch
Type: text/x-patch
Size: 69675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180601/20371291/attachment-0001.bin>


More information about the cfe-commits mailing list