| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 public: | 88 public: |
| 89 // --------------------------------------------------------------------------- | 89 // --------------------------------------------------------------------------- |
| 90 // Construction | 90 // Construction |
| 91 | 91 |
| 92 enum Type { | 92 enum Type { |
| 93 EVAL_SCOPE, // the top-level scope for an 'eval' source | 93 EVAL_SCOPE, // the top-level scope for an 'eval' source |
| 94 FUNCTION_SCOPE, // the top-level scope for a function | 94 FUNCTION_SCOPE, // the top-level scope for a function |
| 95 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval | 95 GLOBAL_SCOPE // the top-level scope for a program or a top-level eval |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 enum LocalType { | |
| 99 PARAMETER, | |
| 100 VAR_OR_CONST | |
| 101 }; | |
| 102 | |
| 103 Scope(Scope* outer_scope, Type type); | 98 Scope(Scope* outer_scope, Type type); |
| 104 | 99 |
| 105 virtual ~Scope() { } | 100 virtual ~Scope() { } |
| 106 | 101 |
| 107 // Compute top scope and allocate variables. For lazy compilation the top | 102 // Compute top scope and allocate variables. For lazy compilation the top |
| 108 // scope only contains the single lazily compiled function, so this | 103 // scope only contains the single lazily compiled function, so this |
| 109 // doesn't re-allocate variables repeatedly. | 104 // doesn't re-allocate variables repeatedly. |
| 110 static bool Analyze(CompilationInfo* info); | 105 static bool Analyze(CompilationInfo* info); |
| 111 | 106 |
| 112 static Scope* DeserializeScopeChain(CompilationInfo* info, | 107 static Scope* DeserializeScopeChain(CompilationInfo* info, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 130 | 125 |
| 131 // Lookup a variable in this scope or outer scopes. | 126 // Lookup a variable in this scope or outer scopes. |
| 132 // Returns the variable or NULL if not found. | 127 // Returns the variable or NULL if not found. |
| 133 virtual Variable* Lookup(Handle<String> name); | 128 virtual Variable* Lookup(Handle<String> name); |
| 134 | 129 |
| 135 // Declare the function variable for a function literal. This variable | 130 // Declare the function variable for a function literal. This variable |
| 136 // is in an intermediate scope between this function scope and the the | 131 // is in an intermediate scope between this function scope and the the |
| 137 // outer scope. Only possible for function scopes; at most one variable. | 132 // outer scope. Only possible for function scopes; at most one variable. |
| 138 Variable* DeclareFunctionVar(Handle<String> name); | 133 Variable* DeclareFunctionVar(Handle<String> name); |
| 139 | 134 |
| 135 // Declare a parameter in this scope. When there are duplicated |
| 136 // parameters the rightmost one 'wins'. However, the implementation |
| 137 // expects all parameters to be declared and from left to right. |
| 138 void DeclareParameter(Handle<String> name); |
| 139 |
| 140 // Declare a local variable in this scope. If the variable has been | 140 // Declare a local variable in this scope. If the variable has been |
| 141 // declared before, the previously declared variable is returned. | 141 // declared before, the previously declared variable is returned. |
| 142 virtual Variable* DeclareLocal(Handle<String> name, | 142 Variable* DeclareLocal(Handle<String> name, Variable::Mode mode); |
| 143 Variable::Mode mode, | |
| 144 LocalType type); | |
| 145 | 143 |
| 146 // Declare an implicit global variable in this scope which must be a | 144 // Declare an implicit global variable in this scope which must be a |
| 147 // global scope. The variable was introduced (possibly from an inner | 145 // global scope. The variable was introduced (possibly from an inner |
| 148 // scope) by a reference to an unresolved variable with no intervening | 146 // scope) by a reference to an unresolved variable with no intervening |
| 149 // with statements or eval calls. | 147 // with statements or eval calls. |
| 150 Variable* DeclareGlobal(Handle<String> name); | 148 Variable* DeclareGlobal(Handle<String> name); |
| 151 | 149 |
| 152 // Add a parameter to the parameter list. The parameter must have been | |
| 153 // declared via Declare. The same parameter may occur more than once in | |
| 154 // the parameter list; they must be added in source order, from left to | |
| 155 // right. | |
| 156 void AddParameter(Variable* var); | |
| 157 | |
| 158 // Create a new unresolved variable. | 150 // Create a new unresolved variable. |
| 159 virtual VariableProxy* NewUnresolved(Handle<String> name, | 151 virtual VariableProxy* NewUnresolved(Handle<String> name, |
| 160 bool inside_with, | 152 bool inside_with, |
| 161 int position = RelocInfo::kNoPosition); | 153 int position = RelocInfo::kNoPosition); |
| 162 | 154 |
| 163 // Remove a unresolved variable. During parsing, an unresolved variable | 155 // Remove a unresolved variable. During parsing, an unresolved variable |
| 164 // may have been added optimistically, but then only the variable name | 156 // may have been added optimistically, but then only the variable name |
| 165 // was used (typically for labels). If the variable was not declared, the | 157 // was used (typically for labels). If the variable was not declared, the |
| 166 // addition introduced a new unresolved variable which may end up being | 158 // addition introduced a new unresolved variable which may end up being |
| 167 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 159 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 int nesting_level_; | 490 int nesting_level_; |
| 499 // Nesting level of outermost scope that is contained in a with statement, | 491 // Nesting level of outermost scope that is contained in a with statement, |
| 500 // or kNotInsideWith if there are no with's around the current scope. | 492 // or kNotInsideWith if there are no with's around the current scope. |
| 501 int inside_with_level_; | 493 int inside_with_level_; |
| 502 }; | 494 }; |
| 503 | 495 |
| 504 | 496 |
| 505 } } // namespace v8::internal | 497 } } // namespace v8::internal |
| 506 | 498 |
| 507 #endif // V8_SCOPES_H_ | 499 #endif // V8_SCOPES_H_ |
| OLD | NEW |