Skip to content

Commit 54031f1

Browse files
authored
Merge pull request #4609 from DougGregor/scope-map
Introduce a new data structure to explicitly model scopes in the AST
2 parents a262532 + f47fc34 commit 54031f1

File tree

15 files changed

+3000
-2
lines changed

15 files changed

+3000
-2
lines changed

include/swift/AST/ASTScope.h

Lines changed: 576 additions & 0 deletions
Large diffs are not rendered by default.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ ERROR(error_immediate_mode_primary_file,none,
9191
"immediate mode is incompatible with -primary-file", ())
9292
ERROR(error_missing_frontend_action,none,
9393
"no frontend action was selected", ())
94+
ERROR(error_invalid_source_location_str,none,
95+
"invalid source location string '%0'", (StringRef))
96+
ERROR(error_no_source_location_scope_map,none,
97+
"-dump-scope-maps argument must be 'expanded' or a list of source locations",
98+
())
9499

95100
ERROR(error_mode_cannot_emit_dependencies,none,
96101
"this mode does not support emitting dependency files", ())

include/swift/AST/Module.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace clang {
4444
namespace swift {
4545
enum class ArtificialMainKind : uint8_t;
4646
class ASTContext;
47+
class ASTScope;
4748
class ASTWalker;
4849
class BraceStmt;
4950
class Decl;
@@ -818,6 +819,9 @@ class SourceFile final : public FileUnit {
818819
/// source file.
819820
llvm::SetVector<NormalProtocolConformance *> UsedConformances;
820821

822+
/// The scope map that describes this source file.
823+
ASTScope *Scope = nullptr;
824+
821825
friend ASTContext;
822826
friend Impl;
823827

@@ -968,6 +972,9 @@ class SourceFile final : public FileUnit {
968972
/// Otherwise, return an empty string.
969973
StringRef getFilename() const;
970974

975+
/// Retrieve the scope that describes this source file.
976+
ASTScope &getScope();
977+
971978
void dump() const;
972979
void dump(raw_ostream &os) const;
973980

include/swift/Frontend/FrontendOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class FrontendOptions {
142142
DumpAST, ///< Parse, type-check, and dump AST
143143
PrintAST, ///< Parse, type-check, and pretty-print AST
144144

145+
/// Parse and dump scope map.
146+
DumpScopeMaps,
147+
145148
/// Parse, type-check, and dump type refinement context hierarchy
146149
DumpTypeRefinementContexts,
147150

@@ -251,6 +254,10 @@ class FrontendOptions {
251254
/// Indicates a debug crash mode for the frontend.
252255
DebugCrashMode CrashMode = DebugCrashMode::None;
253256

257+
/// Line and column for each of the locations to be probed by
258+
/// -dump-scope-maps.
259+
SmallVector<std::pair<unsigned, unsigned>, 2> DumpScopeMapLocations;
260+
254261
/// Indicates whether the RequestedAction has output.
255262
bool actionHasOutput() const;
256263

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ def dump_parse : Flag<["-"], "dump-parse">,
423423
def dump_ast : Flag<["-"], "dump-ast">,
424424
HelpText<"Parse and type-check input file(s) and dump AST(s)">, ModeOpt,
425425
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
426+
def dump_scope_maps : Separate<["-"], "dump-scope-maps">,
427+
HelpText<"Parse and type-check input file(s) and dump the scope map(s)">,
428+
MetaVarName<"<expanded-or-list-of-line:column>">,
429+
ModeOpt,
430+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
426431
def dump_type_refinement_contexts :
427432
Flag<["-"], "dump-type-refinement-contexts">,
428433
HelpText<"Type-check input file(s) and dump type refinement contexts(s)">,

0 commit comments

Comments
 (0)