OLD | NEW |
1 // Copyright 2006-2008 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 15 matching lines...) Expand all Loading... |
27 | 27 |
28 #ifndef V8_SCOPES_H_ | 28 #ifndef V8_SCOPES_H_ |
29 #define V8_SCOPES_H_ | 29 #define V8_SCOPES_H_ |
30 | 30 |
31 #include "ast.h" | 31 #include "ast.h" |
32 #include "hashmap.h" | 32 #include "hashmap.h" |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
| 37 class CompilationInfo; |
| 38 |
| 39 |
37 // A hash map to support fast variable declaration and lookup. | 40 // A hash map to support fast variable declaration and lookup. |
38 class VariableMap: public HashMap { | 41 class VariableMap: public HashMap { |
39 public: | 42 public: |
40 VariableMap(); | 43 VariableMap(); |
41 | 44 |
42 // Dummy constructor. This constructor doesn't set up the map | 45 // Dummy constructor. This constructor doesn't set up the map |
43 // properly so don't use it unless you have a good reason. | 46 // properly so don't use it unless you have a good reason. |
44 explicit VariableMap(bool gotta_love_static_overloading); | 47 explicit VariableMap(bool gotta_love_static_overloading); |
45 | 48 |
46 virtual ~VariableMap(); | 49 virtual ~VariableMap(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 enum Type { | 92 enum Type { |
90 EVAL_SCOPE, // the top-level scope for an 'eval' source | 93 EVAL_SCOPE, // the top-level scope for an 'eval' source |
91 FUNCTION_SCOPE, // the top-level scope for a function | 94 FUNCTION_SCOPE, // the top-level scope for a function |
92 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 |
93 }; | 96 }; |
94 | 97 |
95 Scope(Scope* outer_scope, Type type); | 98 Scope(Scope* outer_scope, Type type); |
96 | 99 |
97 virtual ~Scope() { } | 100 virtual ~Scope() { } |
98 | 101 |
| 102 // Compute top scope and allocate variables. For lazy compilation the top |
| 103 // scope only contains the single lazily compiled function, so this |
| 104 // doesn't re-allocate variables repeatedly. |
| 105 static bool Analyze(CompilationInfo* info); |
| 106 |
99 // The scope name is only used for printing/debugging. | 107 // The scope name is only used for printing/debugging. |
100 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } | 108 void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; } |
101 | 109 |
102 virtual void Initialize(bool inside_with); | 110 virtual void Initialize(bool inside_with); |
103 | 111 |
104 // Called just before leaving a scope. | 112 // Called just before leaving a scope. |
105 virtual void Leave() { | 113 virtual void Leave() { |
106 // No cleanup or fixup necessary. | 114 // No cleanup or fixup necessary. |
107 } | 115 } |
108 | 116 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 int nesting_level_; | 435 int nesting_level_; |
428 // 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, |
429 // 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. |
430 int inside_with_level_; | 438 int inside_with_level_; |
431 }; | 439 }; |
432 | 440 |
433 | 441 |
434 } } // namespace v8::internal | 442 } } // namespace v8::internal |
435 | 443 |
436 #endif // V8_SCOPES_H_ | 444 #endif // V8_SCOPES_H_ |
OLD | NEW |