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

Side by Side Diff: src/scopes.h

Issue 422923004: Track usage of "this" and "arguments" in Scope (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 // --------------------------------------------------------------------------- 205 // ---------------------------------------------------------------------------
206 // Scope-specific info. 206 // Scope-specific info.
207 207
208 // Inform the scope that the corresponding code contains a with statement. 208 // Inform the scope that the corresponding code contains a with statement.
209 void RecordWithStatement() { scope_contains_with_ = true; } 209 void RecordWithStatement() { scope_contains_with_ = true; }
210 210
211 // Inform the scope that the corresponding code contains an eval call. 211 // Inform the scope that the corresponding code contains an eval call.
212 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; } 212 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; }
213 213
214 // Inform the scope that the corresponding code uses "this".
215 void RecordThisUsage() { scope_uses_this_ = true; }
216
217 // Inform the scope that the corresponding code uses "arguments".
218 void RecordArgumentsUsage() { scope_uses_arguments_ = true; }
219
214 // Set the strict mode flag (unless disabled by a global flag). 220 // Set the strict mode flag (unless disabled by a global flag).
215 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } 221 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; }
216 222
217 // Set the ASM module flag. 223 // Set the ASM module flag.
218 void SetAsmModule() { asm_module_ = true; } 224 void SetAsmModule() { asm_module_ = true; }
219 225
220 // Position in the source where this scope begins and ends. 226 // Position in the source where this scope begins and ends.
221 // 227 //
222 // * For the scope of a with statement 228 // * For the scope of a with statement
223 // with (obj) stmt 229 // with (obj) stmt
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 261 }
256 bool has_forced_context_allocation() const { 262 bool has_forced_context_allocation() const {
257 return force_context_allocation_; 263 return force_context_allocation_;
258 } 264 }
259 265
260 // --------------------------------------------------------------------------- 266 // ---------------------------------------------------------------------------
261 // Predicates. 267 // Predicates.
262 268
263 // Specific scope types. 269 // Specific scope types.
264 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } 270 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; }
265 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; } 271 bool is_function_scope() const {
272 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE;
273 }
266 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } 274 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; }
267 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; } 275 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; }
268 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } 276 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; }
269 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } 277 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; }
270 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } 278 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; }
279 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; }
271 bool is_declaration_scope() const { 280 bool is_declaration_scope() const {
272 return is_eval_scope() || is_function_scope() || 281 return is_eval_scope() || is_function_scope() ||
273 is_module_scope() || is_global_scope(); 282 is_module_scope() || is_global_scope();
274 } 283 }
275 bool is_strict_eval_scope() const { 284 bool is_strict_eval_scope() const {
276 return is_eval_scope() && strict_mode_ == STRICT; 285 return is_eval_scope() && strict_mode_ == STRICT;
277 } 286 }
278 287
279 // Information about which scopes calls eval. 288 // Information about which scopes calls eval.
280 bool calls_eval() const { return scope_calls_eval_; } 289 bool calls_eval() const { return scope_calls_eval_; }
281 bool calls_sloppy_eval() { 290 bool calls_sloppy_eval() {
282 return scope_calls_eval_ && strict_mode_ == SLOPPY; 291 return scope_calls_eval_ && strict_mode_ == SLOPPY;
283 } 292 }
284 bool outer_scope_calls_sloppy_eval() const { 293 bool outer_scope_calls_sloppy_eval() const {
285 return outer_scope_calls_sloppy_eval_; 294 return outer_scope_calls_sloppy_eval_;
286 } 295 }
287 bool asm_module() const { return asm_module_; } 296 bool asm_module() const { return asm_module_; }
288 bool asm_function() const { return asm_function_; } 297 bool asm_function() const { return asm_function_; }
289 298
290 // Is this scope inside a with statement. 299 // Is this scope inside a with statement.
291 bool inside_with() const { return scope_inside_with_; } 300 bool inside_with() const { return scope_inside_with_; }
292 // Does this scope contain a with statement. 301 // Does this scope contain a with statement.
293 bool contains_with() const { return scope_contains_with_; } 302 bool contains_with() const { return scope_contains_with_; }
294 303
304 // Does this scope access "this".
305 bool uses_this() const { return scope_uses_this_; }
306 // Does any inner scope access "this".
307 bool inner_uses_this() const { return inner_scope_uses_this_; }
308 // Does this scope access "arguments".
309 bool uses_arguments() const { return scope_uses_arguments_; }
310 // Does any inner scope access "arguments".
311 bool inner_uses_arguments() const { return inner_scope_uses_arguments_; }
312
295 // --------------------------------------------------------------------------- 313 // ---------------------------------------------------------------------------
296 // Accessors. 314 // Accessors.
297 315
298 // The type of this scope. 316 // The type of this scope.
299 ScopeType scope_type() const { return scope_type_; } 317 ScopeType scope_type() const { return scope_type_; }
300 318
301 // The language mode of this scope. 319 // The language mode of this scope.
302 StrictMode strict_mode() const { return strict_mode_; } 320 StrictMode strict_mode() const { return strict_mode_; }
303 321
304 // The variable corresponding the 'this' value. 322 // The variable corresponding the 'this' value.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 479
462 // Scope-specific information computed during parsing. 480 // Scope-specific information computed during parsing.
463 // 481 //
464 // This scope is inside a 'with' of some outer scope. 482 // This scope is inside a 'with' of some outer scope.
465 bool scope_inside_with_; 483 bool scope_inside_with_;
466 // This scope contains a 'with' statement. 484 // This scope contains a 'with' statement.
467 bool scope_contains_with_; 485 bool scope_contains_with_;
468 // This scope or a nested catch scope or with scope contain an 'eval' call. At 486 // This scope or a nested catch scope or with scope contain an 'eval' call. At
469 // the 'eval' call site this scope is the declaration scope. 487 // the 'eval' call site this scope is the declaration scope.
470 bool scope_calls_eval_; 488 bool scope_calls_eval_;
489 // This scope uses "this".
490 bool scope_uses_this_;
491 // This scope uses "arguments".
492 bool scope_uses_arguments_;
471 // This scope contains an "use asm" annotation. 493 // This scope contains an "use asm" annotation.
472 bool asm_module_; 494 bool asm_module_;
473 // This scope's outer context is an asm module. 495 // This scope's outer context is an asm module.
474 bool asm_function_; 496 bool asm_function_;
475 // The strict mode of this scope. 497 // The strict mode of this scope.
476 StrictMode strict_mode_; 498 StrictMode strict_mode_;
477 // Source positions. 499 // Source positions.
478 int start_position_; 500 int start_position_;
479 int end_position_; 501 int end_position_;
480 502
481 // Computed via PropagateScopeInfo. 503 // Computed via PropagateScopeInfo.
482 bool outer_scope_calls_sloppy_eval_; 504 bool outer_scope_calls_sloppy_eval_;
483 bool inner_scope_calls_eval_; 505 bool inner_scope_calls_eval_;
506 bool inner_scope_uses_this_;
507 bool inner_scope_uses_arguments_;
484 bool force_eager_compilation_; 508 bool force_eager_compilation_;
485 bool force_context_allocation_; 509 bool force_context_allocation_;
486 510
487 // True if it doesn't need scope resolution (e.g., if the scope was 511 // True if it doesn't need scope resolution (e.g., if the scope was
488 // constructed based on a serialized scope info or a catch context). 512 // constructed based on a serialized scope info or a catch context).
489 bool already_resolved_; 513 bool already_resolved_;
490 514
491 // Computed as variables are declared. 515 // Computed as variables are declared.
492 int num_var_or_const_; 516 int num_var_or_const_;
493 517
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 Scope* outer_scope, 644 Scope* outer_scope,
621 Handle<ScopeInfo> scope_info); 645 Handle<ScopeInfo> scope_info);
622 646
623 AstValueFactory* ast_value_factory_; 647 AstValueFactory* ast_value_factory_;
624 Zone* zone_; 648 Zone* zone_;
625 }; 649 };
626 650
627 } } // namespace v8::internal 651 } } // namespace v8::internal
628 652
629 #endif // V8_SCOPES_H_ 653 #endif // V8_SCOPES_H_
OLDNEW
« 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