Skip to content

Introduce a new data structure to explicitly model scopes in the AST #4609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4e21468
[WIP Name binding] Introduce a basic 'scope map' to model scopes in t…
DougGregor Aug 29, 2016
b6a9324
[Scope map] Use continuations for local declarations that introduce s…
DougGregor Aug 30, 2016
c775d94
[Scope map] Add support for conditional statements.
DougGregor Aug 30, 2016
ebad77e
Add support for repeat-while.
DougGregor Aug 30, 2016
8c31960
Add support for for-each statements
DougGregor Aug 30, 2016
1e52d53
Add support for do-catch
DougGregor Aug 30, 2016
b3855c9
Add switch/case support
DougGregor Aug 31, 2016
d1ce3b8
Add support for the C-style 'for' statement.
DougGregor Aug 31, 2016
9ea2fab
Add support for getters/setters.
DougGregor Aug 31, 2016
9a21677
Add support for closures
DougGregor Sep 1, 2016
d1945e7
[Scope map] Add top-level code declaration support.
DougGregor Sep 1, 2016
4d9a92d
Split guard statement into three non-overlapping children:
DougGregor Sep 1, 2016
b50ba75
Tighten up out-of-order checking, fixing up some issues with computed…
DougGregor Sep 1, 2016
eabf6d0
Check overlap of AST nodes.
DougGregor Sep 1, 2016
412d1d5
[Scope map] Introduce an operation to find the innermost scope based …
DougGregor Sep 1, 2016
65c1bd2
[Scope map] Cache the source range for a scope node, once computed.
DougGregor Sep 1, 2016
35888ee
[Scope map] Always introduce a node for AbstractFunctionDecls.
DougGregor Sep 1, 2016
84b0433
[Scope map] Add a scope node for top-level code declarations.
DougGregor Sep 1, 2016
ed173d2
[Scope map] Explicitly model pattern bindings and their initializers.
DougGregor Sep 2, 2016
8e39f3e
[Scope map] Model the scopes of default arguments.
DougGregor Sep 2, 2016
c612f4f
[Scope map] Add support for querying the immediate and nearest enclos…
DougGregor Sep 2, 2016
69adfac
[Scope map] Deal with some previously-broken ASTs
DougGregor Sep 2, 2016
f47fc34
[Scope map] Document the ASTScope class.
DougGregor Sep 2, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
576 changes: 576 additions & 0 deletions include/swift/AST/ASTScope.h

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ ERROR(error_immediate_mode_primary_file,none,
"immediate mode is incompatible with -primary-file", ())
ERROR(error_missing_frontend_action,none,
"no frontend action was selected", ())
ERROR(error_invalid_source_location_str,none,
"invalid source location string '%0'", (StringRef))
ERROR(error_no_source_location_scope_map,none,
"-dump-scope-maps argument must be 'expanded' or a list of source locations",
())

ERROR(error_mode_cannot_emit_dependencies,none,
"this mode does not support emitting dependency files", ())
Expand Down
7 changes: 7 additions & 0 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace clang {
namespace swift {
enum class ArtificialMainKind : uint8_t;
class ASTContext;
class ASTScope;
class ASTWalker;
class BraceStmt;
class Decl;
Expand Down Expand Up @@ -818,6 +819,9 @@ class SourceFile final : public FileUnit {
/// source file.
llvm::SetVector<NormalProtocolConformance *> UsedConformances;

/// The scope map that describes this source file.
ASTScope *Scope = nullptr;

friend ASTContext;
friend Impl;

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

/// Retrieve the scope that describes this source file.
ASTScope &getScope();

void dump() const;
void dump(raw_ostream &os) const;

Expand Down
7 changes: 7 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class FrontendOptions {
DumpAST, ///< Parse, type-check, and dump AST
PrintAST, ///< Parse, type-check, and pretty-print AST

/// Parse and dump scope map.
DumpScopeMaps,

/// Parse, type-check, and dump type refinement context hierarchy
DumpTypeRefinementContexts,

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

/// Line and column for each of the locations to be probed by
/// -dump-scope-maps.
SmallVector<std::pair<unsigned, unsigned>, 2> DumpScopeMapLocations;

/// Indicates whether the RequestedAction has output.
bool actionHasOutput() const;

Expand Down
5 changes: 5 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ def dump_parse : Flag<["-"], "dump-parse">,
def dump_ast : Flag<["-"], "dump-ast">,
HelpText<"Parse and type-check input file(s) and dump AST(s)">, ModeOpt,
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
def dump_scope_maps : Separate<["-"], "dump-scope-maps">,
HelpText<"Parse and type-check input file(s) and dump the scope map(s)">,
MetaVarName<"<expanded-or-list-of-line:column>">,
ModeOpt,
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
def dump_type_refinement_contexts :
Flag<["-"], "dump-type-refinement-contexts">,
HelpText<"Type-check input file(s) and dump type refinement contexts(s)">,
Expand Down
Loading