Commit Graph

224 Commits

Author SHA1 Message Date
Doug Gregor
768f06826b [Scope maps] Reimplement continuation scopes with a more principled approach.
Record the active continuation scope for each scope. When we expand a
child node that introduces name that would be visible in a
continuation, we "steal" the continuation from the parent, so the
child takes over the responsibility of handling the continuation.

A continuation is initially introduced by expanding a brace statement,
where the continuation is itself. The eliminates a DRY violation
between the initial expansion of BraceStmts and
enumerateContinuationScopes() that's been nagging at me.

At present, this should be NFC, but it should make modeling top-level
code more reasonable.
2016-09-09 17:08:42 -07:00
Doug Gregor
2ad6629b49 [Scope map] Temporarily remove the caching of source ranges.
Source range caching needs to account for the fact that the 'end'
location of various scope nodes needs to track the end of the source
file, which can grow when we're working with the REPL. Until we have
that notion, don't cache.
2016-09-09 17:08:41 -07:00
Doug Gregor
abf9bfe9d5 [Scope map] Provide scopes for the generic parameters of protocols and extensions. 2016-09-07 16:44:36 -07:00
Doug Gregor
ead78e046f [Scope map] Explicitly model the scope of a function body.
For methods/initializers/deinitializers, modeling the scope of a
function body allows us to correctly introduce instance member lookup
relative to 'self'. Do so so that we can resolve unqualified name
lookup within methods based on the implicit 'self'.
2016-09-06 22:58:18 -07:00
Doug Gregor
311fc55bdb [Scope map] Query the declarations introduced by a given AST scope.
Introduce an operation that produces the set of local declarations
that are newly introduced by a given AST scope. This is a building
block of unqualified name lookup, which walks upward in the tree
(e.g., from children to parents) looking for declarations that have
been made visible at each step.
2016-09-06 09:05:10 -07:00
Doug Gregor
f47fc34a98 [Scope map] Document the ASTScope class. 2016-09-02 17:13:05 -07:00
Doug Gregor
c612f4feda [Scope map] Add support for querying the immediate and nearest enclosing DeclContexts of a scope. 2016-09-02 17:13:05 -07:00
Doug Gregor
8e39f3e0cd [Scope map] Model the scopes of default arguments. 2016-09-02 17:13:05 -07:00
Doug Gregor
ed173d2fbc [Scope map] Explicitly model pattern bindings and their initializers.
Consistently model all pattern bindings in the scope map, as well as
having specific nodes for their initializers. This provides us with
more consistency (the declarations are represented) as well as giving
us a scope we can use to extract the DeclContext for a non-local
initializer.
2016-09-02 17:13:05 -07:00
Doug Gregor
84b043365c [Scope map] Add a scope node for top-level code declarations. 2016-09-02 17:13:05 -07:00
Doug Gregor
35888ee0c2 [Scope map] Always introduce a node for AbstractFunctionDecls.
Part of making the scope map subsume the DeclContext change, so we can
identify the nearest enclosing DeclContext.
2016-09-02 17:13:05 -07:00
Doug Gregor
65c1bd2112 [Scope map] Cache the source range for a scope node, once computed.
Source ranges are non-trivial to compute, small to store, and used often. Cache 'em.
2016-09-02 17:13:05 -07:00
Doug Gregor
412d1d5e1e [Scope map] Introduce an operation to find the innermost scope based on a given source location.
Given a source location, we can find the innermost enclosing scope
that describes that source location. Introduce this operation into the
scope map, then add a testing mode where we probe the scope map at
specifi locations to see what we find. Test for:

1) Finding the right innermost enclosing scope, and
2) That we're only expanding the part of the scope map that is needed
to identify that scope.
2016-09-02 17:13:05 -07:00
Doug Gregor
4d9a92d898 Split guard statement into three non-overlapping children:
* A child to evaluate the conditions, which covers expressions in the conditions
  * A child for the 'else' body, which does not have access to the names in the conditions
  * A child for the continuation, which re-introduces the names in the conditions for the rest of the body

Now we can assert that the only out-of-order case is for accessors.
2016-09-02 17:13:05 -07:00
Doug Gregor
9a21677663 Add support for closures 2016-09-02 17:13:05 -07:00
Doug Gregor
9ea2fab6b9 Add support for getters/setters. 2016-09-02 17:13:05 -07:00
Doug Gregor
d1ce3b82ef Add support for the C-style 'for' statement. 2016-09-02 17:13:05 -07:00
Doug Gregor
b3855c9057 Add switch/case support 2016-09-02 17:13:05 -07:00
Doug Gregor
1e52d53ae2 Add support for do-catch 2016-09-02 17:13:05 -07:00
Doug Gregor
8c31960900 Add support for for-each statements 2016-09-02 17:13:05 -07:00
Doug Gregor
ebad77e1af Add support for repeat-while. 2016-09-02 17:13:05 -07:00
Doug Gregor
c775d94478 [Scope map] Add support for conditional statements. 2016-09-02 17:13:05 -07:00
Doug Gregor
b6a93246ac [Scope map] Use continuations for local declarations that introduce scopes. 2016-09-02 17:13:05 -07:00
Doug Gregor
4e214687ca [WIP Name binding] Introduce a basic 'scope map' to model scopes in the AST.
The scope map models all of the name lookup scopes within a source
file. It can be queried by source location to find the innermost scope
that contains that source location. Then, one can follow the parent
pointers in the scope to enumerate the enclosing scopes.

The scope map itself is lazily constructed, only creating scope map
nodes when required implicitly (e.g, when searching for a particular
innermost scope) or forced for debugging purposes.

using a lazily-constructed tree that can be searched by source
location. A search within a particular source location will
2016-09-02 17:13:05 -07:00