Skip to content

Commit 5d74978

Browse files
committed
[NFC] Heavily refactor NameBinding
This commit refactors NameBinding.cpp virtually to the point of a rewrite. The goal is to make the import handling code process a struct containing information extracted from an ImportDecl, rather than the ImportDecl itself, so that a future commit can perform the same processing on imports that are not directly represented by an ImportDecl. The result takes more code, but it disentangles a knot of complicated logic into separate threads. One semi-functional change is that validation of scoped imports (i.e. checking that the declaration actually exists) is now deferred until all of the file’s imports have been processed. Once cross-imports are supported, this will be necessary because scoped imports can select declarations from cross-import overlays, and the full set of cross-import overlays can’t be known until all imports have been seen. Some comments refer to things that won’t exist until the next commit, like the visibleModules property. I’ll let you in on a litlte secret: I didn’t really do this all in one go.
1 parent 03832cb commit 5d74978

File tree

2 files changed

+566
-282
lines changed

2 files changed

+566
-282
lines changed

include/swift/AST/Attr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,15 @@ class DeclAttributes {
21032103
return nullptr;
21042104
}
21052105

2106+
/// Retrieve the first attribute with the given kind.
2107+
DeclAttribute *getAttribute(DeclAttrKind DK,
2108+
bool AllowInvalid = false) {
2109+
for (auto Attr : *this)
2110+
if (Attr->getKind() == DK && (Attr->isValid() || AllowInvalid))
2111+
return Attr;
2112+
return nullptr;
2113+
}
2114+
21062115
private:
21072116
/// Predicate used to filter MatchingAttributeRange.
21082117
template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {

0 commit comments

Comments
 (0)