Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Unified Diff: src/scopes.h

Issue 8344046: Reapply r9673 "Scope tree serialization and ScopeIterator cleanup." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Skip nested contexts of an internal function. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.h
diff --git a/src/scopes.h b/src/scopes.h
index 72f1e31878efb744ac8d1210f531d1d16b7a0026..58b683b8d3e506f9ac5a54feabefbed35987a212 100644
--- a/src/scopes.h
+++ b/src/scopes.h
@@ -89,16 +89,7 @@ class Scope: public ZoneObject {
// ---------------------------------------------------------------------------
// Construction
- enum Type {
- EVAL_SCOPE, // The top-level scope for an eval source.
- FUNCTION_SCOPE, // The top-level scope for a function.
- GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
- CATCH_SCOPE, // The scope introduced by catch.
- BLOCK_SCOPE, // The scope introduced by a new block.
- WITH_SCOPE // The scope introduced by with.
- };
-
- Scope(Scope* outer_scope, Type type);
+ Scope(Scope* outer_scope, ScopeType type);
// Compute top scope and allocate variables. For lazy compilation the top
// scope only contains the single lazily compiled function, so this
@@ -206,6 +197,37 @@ class Scope: public ZoneObject {
strict_mode_ = FLAG_strict_mode;
}
+ // Position in the source where this scope begins and ends.
+ //
+ // * For the scope of a with statement
+ // with (obj) stmt
+ // start position: start position of first token of 'stmt'
+ // end position: end position of last token of 'stmt'
+ // * For the scope of a block
+ // { stmts }
+ // start position: start position of '{'
+ // end position: end position of '}'
+ // * For the scope of a function literal or decalaration
+ // function fun(a,b) { stmts }
+ // start position: start position of '('
+ // end position: end position of '}'
+ // * For the scope of a catch block
+ // try { stms } catch(e) { stmts }
+ // start position: start position of '('
+ // end position: end position of ')'
+ // * For the scope of a for-statement
+ // for (let x ...) stmt
+ // start position: start position of '('
+ // end position: end position of last token of 'stmt'
+ int start_position() const { return start_position_; }
+ void set_start_position(int statement_pos) {
+ start_position_ = statement_pos;
+ }
+ int end_position() const { return end_position_; }
+ void set_end_position(int statement_pos) {
+ end_position_ = statement_pos;
+ }
+
// ---------------------------------------------------------------------------
// Predicates.
@@ -244,6 +266,9 @@ class Scope: public ZoneObject {
// ---------------------------------------------------------------------------
// Accessors.
+ // The type of this scope.
+ ScopeType type() const { return type_; }
+
// The variable corresponding the 'this' value.
Variable* receiver() { return receiver_; }
@@ -270,6 +295,8 @@ class Scope: public ZoneObject {
// Declarations list.
ZoneList<Declaration*>* declarations() { return &decls_; }
+ // Inner scope list.
+ ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; }
// ---------------------------------------------------------------------------
// Variable allocation.
@@ -313,6 +340,13 @@ class Scope: public ZoneObject {
Handle<SerializedScopeInfo> GetSerializedScopeInfo();
+ // Get the chain of nested scopes within this scope for the source statement
+ // position. The scopes will be added to the list from the outermost scope to
+ // the innermost scope. Only nested block, catch or with scopes are tracked
+ // and will be returned, but no inner function scopes.
+ void GetNestedScopeChain(List<Handle<SerializedScopeInfo> >* chain,
+ int statement_position);
+
// ---------------------------------------------------------------------------
// Strict mode support.
bool IsDeclared(Handle<String> name) {
@@ -336,7 +370,7 @@ class Scope: public ZoneObject {
protected:
friend class ParserFactory;
- explicit Scope(Type type);
+ explicit Scope(ScopeType type);
Isolate* const isolate_;
@@ -345,7 +379,7 @@ class Scope: public ZoneObject {
ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes
// The scope type.
- Type type_;
+ ScopeType type_;
// Debugging support.
Handle<String> scope_name_;
@@ -387,6 +421,9 @@ class Scope: public ZoneObject {
bool scope_calls_eval_;
// This scope is a strict mode scope.
bool strict_mode_;
+ // Source positions.
+ int start_position_;
+ int end_position_;
// Computed via PropagateScopeInfo.
bool outer_scope_calls_non_strict_eval_;
@@ -489,7 +526,9 @@ class Scope: public ZoneObject {
private:
// Construct a scope based on the scope info.
- Scope(Scope* inner_scope, Type type, Handle<SerializedScopeInfo> scope_info);
+ Scope(Scope* inner_scope,
+ ScopeType type,
+ Handle<SerializedScopeInfo> scope_info);
// Construct a catch scope with a binding for the name.
Scope(Scope* inner_scope, Handle<String> catch_variable_name);
@@ -501,7 +540,7 @@ class Scope: public ZoneObject {
}
}
- void SetDefaults(Type type,
+ void SetDefaults(ScopeType type,
Scope* outer_scope,
Handle<SerializedScopeInfo> scope_info);
};
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698