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. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
| 30 #include "scopes.h" |
| 31 |
| 32 #include "bootstrapper.h" |
| 33 #include "compiler.h" |
30 #include "prettyprinter.h" | 34 #include "prettyprinter.h" |
31 #include "scopeinfo.h" | 35 #include "scopeinfo.h" |
32 #include "scopes.h" | |
33 | 36 |
34 namespace v8 { | 37 namespace v8 { |
35 namespace internal { | 38 namespace internal { |
36 | 39 |
37 // ---------------------------------------------------------------------------- | 40 // ---------------------------------------------------------------------------- |
38 // A Zone allocator for use with LocalsMap. | 41 // A Zone allocator for use with LocalsMap. |
39 | 42 |
40 class ZoneAllocator: public Allocator { | 43 class ZoneAllocator: public Allocator { |
41 public: | 44 public: |
42 /* nothing to do */ | 45 /* nothing to do */ |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 num_stack_slots_(0), | 164 num_stack_slots_(0), |
162 num_heap_slots_(0) { | 165 num_heap_slots_(0) { |
163 // At some point we might want to provide outer scopes to | 166 // At some point we might want to provide outer scopes to |
164 // eval scopes (by walking the stack and reading the scope info). | 167 // eval scopes (by walking the stack and reading the scope info). |
165 // In that case, the ASSERT below needs to be adjusted. | 168 // In that case, the ASSERT below needs to be adjusted. |
166 ASSERT((type == GLOBAL_SCOPE || type == EVAL_SCOPE) == (outer_scope == NULL)); | 169 ASSERT((type == GLOBAL_SCOPE || type == EVAL_SCOPE) == (outer_scope == NULL)); |
167 ASSERT(!HasIllegalRedeclaration()); | 170 ASSERT(!HasIllegalRedeclaration()); |
168 } | 171 } |
169 | 172 |
170 | 173 |
| 174 bool Scope::Analyze(CompilationInfo* info) { |
| 175 ASSERT(info->function() != NULL); |
| 176 Scope* top = info->function()->scope(); |
| 177 while (top->outer_scope() != NULL) top = top->outer_scope(); |
| 178 top->AllocateVariables(info->calling_context()); |
| 179 |
| 180 #ifdef DEBUG |
| 181 if (Bootstrapper::IsActive() |
| 182 ? FLAG_print_builtin_scopes |
| 183 : FLAG_print_scopes) { |
| 184 info->function()->scope()->Print(); |
| 185 } |
| 186 #endif |
| 187 |
| 188 info->SetScope(info->function()->scope()); |
| 189 return true; // Can not fail. |
| 190 } |
| 191 |
| 192 |
171 void Scope::Initialize(bool inside_with) { | 193 void Scope::Initialize(bool inside_with) { |
172 // Add this scope as a new inner scope of the outer scope. | 194 // Add this scope as a new inner scope of the outer scope. |
173 if (outer_scope_ != NULL) { | 195 if (outer_scope_ != NULL) { |
174 outer_scope_->inner_scopes_.Add(this); | 196 outer_scope_->inner_scopes_.Add(this); |
175 scope_inside_with_ = outer_scope_->scope_inside_with_ || inside_with; | 197 scope_inside_with_ = outer_scope_->scope_inside_with_ || inside_with; |
176 } else { | 198 } else { |
177 scope_inside_with_ = inside_with; | 199 scope_inside_with_ = inside_with; |
178 } | 200 } |
179 | 201 |
180 // Declare convenience variables. | 202 // Declare convenience variables. |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 973 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
952 !must_have_local_context) { | 974 !must_have_local_context) { |
953 num_heap_slots_ = 0; | 975 num_heap_slots_ = 0; |
954 } | 976 } |
955 | 977 |
956 // Allocation done. | 978 // Allocation done. |
957 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 979 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
958 } | 980 } |
959 | 981 |
960 } } // namespace v8::internal | 982 } } // namespace v8::internal |
OLD | NEW |