| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 Scope(Scope* outer_scope, Type type); | 98 Scope(Scope* outer_scope, Type type); |
| 99 | 99 |
| 100 virtual ~Scope() { } | 100 virtual ~Scope() { } |
| 101 | 101 |
| 102 // Compute top scope and allocate variables. For lazy compilation the top | 102 // Compute top scope and allocate variables. For lazy compilation the top |
| 103 // scope only contains the single lazily compiled function, so this | 103 // scope only contains the single lazily compiled function, so this |
| 104 // doesn't re-allocate variables repeatedly. | 104 // doesn't re-allocate variables repeatedly. |
| 105 static bool Analyze(CompilationInfo* info); | 105 static bool Analyze(CompilationInfo* info); |
| 106 | 106 |
| 107 // The scope name is only used for printing/debugging. | 107 // The scope name is only used for printing/debugging. |
| 108 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } | 108 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } |
| 109 | 109 |
| 110 virtual void Initialize(bool inside_with); | 110 virtual void Initialize(bool inside_with); |
| 111 | 111 |
| 112 // Called just before leaving a scope. | 112 // Called just before leaving a scope. |
| 113 virtual void Leave() { | 113 virtual void Leave() { |
| 114 // No cleanup or fixup necessary. | 114 // No cleanup or fixup necessary. |
| 115 } | 115 } |
| 116 | 116 |
| 117 // --------------------------------------------------------------------------- | 117 // --------------------------------------------------------------------------- |
| 118 // Declarations | 118 // Declarations |
| (...skipping 30 matching lines...) Expand all Loading... |
| 149 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with); | 149 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with); |
| 150 | 150 |
| 151 // Remove a unresolved variable. During parsing, an unresolved variable | 151 // Remove a unresolved variable. During parsing, an unresolved variable |
| 152 // may have been added optimistically, but then only the variable name | 152 // may have been added optimistically, but then only the variable name |
| 153 // was used (typically for labels). If the variable was not declared, the | 153 // was used (typically for labels). If the variable was not declared, the |
| 154 // addition introduced a new unresolved variable which may end up being | 154 // addition introduced a new unresolved variable which may end up being |
| 155 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 155 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| 156 // such a variable again if it was added; otherwise this is a no-op. | 156 // such a variable again if it was added; otherwise this is a no-op. |
| 157 void RemoveUnresolved(VariableProxy* var); | 157 void RemoveUnresolved(VariableProxy* var); |
| 158 | 158 |
| 159 // Creates a new temporary variable in this scope and binds a proxy to it. | 159 // Creates a new temporary variable in this scope. The name is only used |
| 160 // The name is only used for printing and cannot be used to find the variable. | 160 // for printing and cannot be used to find the variable. In particular, |
| 161 // In particular, the only way to get hold of the temporary is by keeping the | 161 // the only way to get hold of the temporary is by keeping the Variable* |
| 162 // VariableProxy* around. | 162 // around. |
| 163 virtual VariableProxy* NewTemporary(Handle<String> name); | 163 virtual Variable* NewTemporary(Handle<String> name); |
| 164 | 164 |
| 165 // Adds the specific declaration node to the list of declarations in | 165 // Adds the specific declaration node to the list of declarations in |
| 166 // this scope. The declarations are processed as part of entering | 166 // this scope. The declarations are processed as part of entering |
| 167 // the scope; see codegen.cc:ProcessDeclarations. | 167 // the scope; see codegen.cc:ProcessDeclarations. |
| 168 void AddDeclaration(Declaration* declaration); | 168 void AddDeclaration(Declaration* declaration); |
| 169 | 169 |
| 170 // --------------------------------------------------------------------------- | 170 // --------------------------------------------------------------------------- |
| 171 // Illegal redeclaration support. | 171 // Illegal redeclaration support. |
| 172 | 172 |
| 173 // Set an expression node that will be executed when the scope is | 173 // Set an expression node that will be executed when the scope is |
| 174 // entered. We only keep track of one illegal redeclaration node per | 174 // entered. We only keep track of one illegal redeclaration node per |
| 175 // scope - the first one - so if you try to set it multiple times | 175 // scope - the first one - so if you try to set it multiple times |
| 176 // the additional requests will be silently ignored. | 176 // the additional requests will be silently ignored. |
| 177 void SetIllegalRedeclaration(Expression* expression); | 177 void SetIllegalRedeclaration(Expression* expression); |
| 178 | 178 |
| 179 // Visit the illegal redeclaration expression. Do not call if the | 179 // Visit the illegal redeclaration expression. Do not call if the |
| 180 // scope doesn't have an illegal redeclaration node. | 180 // scope doesn't have an illegal redeclaration node. |
| 181 void VisitIllegalRedeclaration(AstVisitor* visitor); | 181 void VisitIllegalRedeclaration(AstVisitor* visitor); |
| 182 | 182 |
| 183 // Check if the scope has (at least) one illegal redeclaration. | 183 // Check if the scope has (at least) one illegal redeclaration. |
| 184 bool HasIllegalRedeclaration() const { return illegal_redecl_ != NULL; } | 184 bool HasIllegalRedeclaration() const { return illegal_redecl_ != NULL; } |
| 185 | 185 |
| 186 | 186 |
| 187 // --------------------------------------------------------------------------- | 187 // --------------------------------------------------------------------------- |
| 188 // Scope-specific info. | 188 // Scope-specific info. |
| 189 | 189 |
| 190 // Inform the scope that the corresponding code contains a with statement. | 190 // Inform the scope that the corresponding code contains a with statement. |
| 191 void RecordWithStatement() { scope_contains_with_ = true; } | 191 void RecordWithStatement() { scope_contains_with_ = true; } |
| 192 | 192 |
| 193 // Inform the scope that the corresponding code contains an eval call. | 193 // Inform the scope that the corresponding code contains an eval call. |
| 194 void RecordEvalCall() { scope_calls_eval_ = true; } | 194 void RecordEvalCall() { scope_calls_eval_ = true; } |
| 195 | 195 |
| 196 | 196 |
| 197 // --------------------------------------------------------------------------- | 197 // --------------------------------------------------------------------------- |
| 198 // Predicates. | 198 // Predicates. |
| 199 | 199 |
| 200 // Specific scope types. | 200 // Specific scope types. |
| 201 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } | 201 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } |
| 202 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } | 202 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } |
| 203 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } | 203 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } |
| 204 | 204 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 } | 416 } |
| 417 ASSERT(inside_with_level_ <= nesting_level_); | 417 ASSERT(inside_with_level_ <= nesting_level_); |
| 418 } | 418 } |
| 419 | 419 |
| 420 virtual Variable* Lookup(Handle<String> name) { return NULL; } | 420 virtual Variable* Lookup(Handle<String> name) { return NULL; } |
| 421 | 421 |
| 422 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { | 422 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { |
| 423 return NULL; | 423 return NULL; |
| 424 } | 424 } |
| 425 | 425 |
| 426 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } | 426 virtual Variable* NewTemporary(Handle<String> name) { return NULL; } |
| 427 | 427 |
| 428 virtual bool HasTrivialOuterContext() const { | 428 virtual bool HasTrivialOuterContext() const { |
| 429 return (nesting_level_ == 0 || inside_with_level_ <= 0); | 429 return (nesting_level_ == 0 || inside_with_level_ <= 0); |
| 430 } | 430 } |
| 431 | 431 |
| 432 private: | 432 private: |
| 433 static const int kNotInsideWith = -1; | 433 static const int kNotInsideWith = -1; |
| 434 // Number of surrounding scopes of the current scope. | 434 // Number of surrounding scopes of the current scope. |
| 435 int nesting_level_; | 435 int nesting_level_; |
| 436 // Nesting level of outermost scope that is contained in a with statement, | 436 // Nesting level of outermost scope that is contained in a with statement, |
| 437 // or kNotInsideWith if there are no with's around the current scope. | 437 // or kNotInsideWith if there are no with's around the current scope. |
| 438 int inside_with_level_; | 438 int inside_with_level_; |
| 439 }; | 439 }; |
| 440 | 440 |
| 441 | 441 |
| 442 } } // namespace v8::internal | 442 } } // namespace v8::internal |
| 443 | 443 |
| 444 #endif // V8_SCOPES_H_ | 444 #endif // V8_SCOPES_H_ |
| OLD | NEW |