Skip to content

Commit f47fc34

Browse files
committed
[Scope map] Document the ASTScope class.
1 parent 69adfac commit f47fc34

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

include/swift/AST/ASTScope.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// describes the scopes that exist within a Swift AST.
1515
//
1616
//===----------------------------------------------------------------------===//
17-
#ifndef SWIFT_AST_SCOPE_MAP_H
18-
#define SWIFT_AST_SCOPE_MAP_H
17+
#ifndef SWIFT_AST_AST_SCOPE_H
18+
#define SWIFT_AST_AST_SCOPE_H
1919

2020
#include "swift/AST/ASTNode.h"
2121
#include "swift/Basic/LLVM.h"
@@ -116,6 +116,32 @@ enum class ASTScopeKind : uint8_t {
116116
TopLevelCode,
117117
};
118118

119+
/// Describes a lexical scope within a source file.
120+
///
121+
/// Each \c ASTScope is a node within a tree that describes all of the lexical
122+
/// scopes within a particular source range. The root of this scope tree is
123+
/// always a \c SourceFile node, and the tree covers the entire source file.
124+
/// The children of a particular node are the lexical scopes immediately
125+
/// nested within that node, and have source ranges that are enclosed within
126+
/// the source range of their parent node. At the leaves are lexical scopes
127+
/// that cannot be subdivided further.
128+
///
129+
/// The tree provides source-location-based query operations, allowing one to
130+
/// find the innermost scope that contains a given source location. Navigation
131+
/// to parent nodes from that scope allows one to walk the lexically enclosing
132+
/// scopes outward to the source file. Given a scope, one can also query the
133+
/// associated \c DeclContext for additional contextual information.
134+
///
135+
/// As an implementation detail, the scope tree is lazily constructed as it is
136+
/// queried, and only the relevant subtrees (i.e., trees whose source ranges
137+
/// enclose the queried source location or whose children were explicitly
138+
/// requested by the client) will be constructed. The \c expandAll() operation
139+
/// can be used to fully-expand the tree, constructing all of its nodes, but
140+
/// should only be used for testing or debugging purposes, e.g., via the
141+
/// frontend option
142+
/// \code
143+
/// -dump-scope-maps expanded
144+
/// \endcode
119145
class ASTScope {
120146
/// The kind of scope this represents.
121147
ASTScopeKind kind;
@@ -547,4 +573,4 @@ class ASTScope {
547573

548574
}
549575

550-
#endif // SWIFT_BASIC_SOURCE_RANGE_MAP_H
576+
#endif // SWIFT_AST_AST_SCOPE_H

0 commit comments

Comments
 (0)