| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 19 matching lines...) Expand all Loading... |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 | 31 |
| 32 #include "scopeinfo.h" | 32 #include "scopeinfo.h" |
| 33 #include "scopes.h" | 33 #include "scopes.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 | 38 |
| 39 static int CompareLocal(Variable* const* v, Variable* const* w) { | 39 static int CompareLocal(Variable* const* v, Variable* const* w) { |
| 40 Slot* s = (*v)->slot(); | 40 Slot* s = (*v)->AsSlot(); |
| 41 Slot* t = (*w)->slot(); | 41 Slot* t = (*w)->AsSlot(); |
| 42 // We may have rewritten parameters (that are in the arguments object) | 42 // We may have rewritten parameters (that are in the arguments object) |
| 43 // and which may have a NULL slot... - find a better solution... | 43 // and which may have a NULL slot... - find a better solution... |
| 44 int x = (s != NULL ? s->index() : 0); | 44 int x = (s != NULL ? s->index() : 0); |
| 45 int y = (t != NULL ? t->index() : 0); | 45 int y = (t != NULL ? t->index() : 0); |
| 46 // Consider sorting them according to type as well? | 46 // Consider sorting them according to type as well? |
| 47 return x - y; | 47 return x - y; |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 template<class Allocator> | 51 template<class Allocator> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 76 // ScopeInfo list. | 76 // ScopeInfo list. |
| 77 List<Variable*, Allocator> locals(32); // 32 is a wild guess | 77 List<Variable*, Allocator> locals(32); // 32 is a wild guess |
| 78 ASSERT(locals.is_empty()); | 78 ASSERT(locals.is_empty()); |
| 79 scope->CollectUsedVariables(&locals); | 79 scope->CollectUsedVariables(&locals); |
| 80 locals.Sort(&CompareLocal); | 80 locals.Sort(&CompareLocal); |
| 81 | 81 |
| 82 List<Variable*, Allocator> heap_locals(locals.length()); | 82 List<Variable*, Allocator> heap_locals(locals.length()); |
| 83 for (int i = 0; i < locals.length(); i++) { | 83 for (int i = 0; i < locals.length(); i++) { |
| 84 Variable* var = locals[i]; | 84 Variable* var = locals[i]; |
| 85 if (var->is_used()) { | 85 if (var->is_used()) { |
| 86 Slot* slot = var->slot(); | 86 Slot* slot = var->AsSlot(); |
| 87 if (slot != NULL) { | 87 if (slot != NULL) { |
| 88 switch (slot->type()) { | 88 switch (slot->type()) { |
| 89 case Slot::PARAMETER: | 89 case Slot::PARAMETER: |
| 90 // explicitly added to parameters_ above - ignore | 90 // explicitly added to parameters_ above - ignore |
| 91 break; | 91 break; |
| 92 | 92 |
| 93 case Slot::LOCAL: | 93 case Slot::LOCAL: |
| 94 ASSERT(stack_slots_.length() == slot->index()); | 94 ASSERT(stack_slots_.length() == slot->index()); |
| 95 stack_slots_.Add(var->name()); | 95 stack_slots_.Add(var->name()); |
| 96 break; | 96 break; |
| 97 | 97 |
| 98 case Slot::CONTEXT: | 98 case Slot::CONTEXT: |
| 99 heap_locals.Add(var); | 99 heap_locals.Add(var); |
| 100 break; | 100 break; |
| 101 | 101 |
| 102 case Slot::LOOKUP: | 102 case Slot::LOOKUP: |
| 103 // This is currently not used. | 103 // This is currently not used. |
| 104 UNREACHABLE(); | 104 UNREACHABLE(); |
| 105 break; | 105 break; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Add heap locals. | 111 // Add heap locals. |
| 112 if (scope->num_heap_slots() > 0) { | 112 if (scope->num_heap_slots() > 0) { |
| 113 // Add user-defined slots. | 113 // Add user-defined slots. |
| 114 for (int i = 0; i < heap_locals.length(); i++) { | 114 for (int i = 0; i < heap_locals.length(); i++) { |
| 115 ASSERT(heap_locals[i]->slot()->index() - Context::MIN_CONTEXT_SLOTS == | 115 ASSERT(heap_locals[i]->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == |
| 116 context_slots_.length()); | 116 context_slots_.length()); |
| 117 ASSERT(heap_locals[i]->slot()->index() - Context::MIN_CONTEXT_SLOTS == | 117 ASSERT(heap_locals[i]->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == |
| 118 context_modes_.length()); | 118 context_modes_.length()); |
| 119 context_slots_.Add(heap_locals[i]->name()); | 119 context_slots_.Add(heap_locals[i]->name()); |
| 120 context_modes_.Add(heap_locals[i]->mode()); | 120 context_modes_.Add(heap_locals[i]->mode()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } else { | 123 } else { |
| 124 ASSERT(heap_locals.length() == 0); | 124 ASSERT(heap_locals.length() == 0); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Add the function context slot, if present. | 127 // Add the function context slot, if present. |
| 128 // For now, this must happen at the very end because of the | 128 // For now, this must happen at the very end because of the |
| 129 // ordering of the scope info slots and the respective slot indices. | 129 // ordering of the scope info slots and the respective slot indices. |
| 130 if (scope->is_function_scope()) { | 130 if (scope->is_function_scope()) { |
| 131 Variable* var = scope->function(); | 131 Variable* var = scope->function(); |
| 132 if (var != NULL && | 132 if (var != NULL && |
| 133 var->is_used() && | 133 var->is_used() && |
| 134 var->slot()->type() == Slot::CONTEXT) { | 134 var->AsSlot()->type() == Slot::CONTEXT) { |
| 135 function_name_ = var->name(); | 135 function_name_ = var->name(); |
| 136 // Note that we must not find the function name in the context slot | 136 // Note that we must not find the function name in the context slot |
| 137 // list - instead it must be handled separately in the | 137 // list - instead it must be handled separately in the |
| 138 // Contexts::Lookup() function. Thus record an empty symbol here so we | 138 // Contexts::Lookup() function. Thus record an empty symbol here so we |
| 139 // get the correct number of context slots. | 139 // get the correct number of context slots. |
| 140 ASSERT(var->slot()->index() - Context::MIN_CONTEXT_SLOTS == | 140 ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == |
| 141 context_slots_.length()); | 141 context_slots_.length()); |
| 142 ASSERT(var->slot()->index() - Context::MIN_CONTEXT_SLOTS == | 142 ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == |
| 143 context_modes_.length()); | 143 context_modes_.length()); |
| 144 context_slots_.Add(Factory::empty_symbol()); | 144 context_slots_.Add(Factory::empty_symbol()); |
| 145 context_modes_.Add(Variable::INTERNAL); | 145 context_modes_.Add(Variable::INTERNAL); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 // Encoding format in a FixedArray object: | 151 // Encoding format in a FixedArray object: |
| 152 // | 152 // |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 } | 628 } |
| 629 #endif // DEBUG | 629 #endif // DEBUG |
| 630 | 630 |
| 631 | 631 |
| 632 // Make sure the classes get instantiated by the template system. | 632 // Make sure the classes get instantiated by the template system. |
| 633 template class ScopeInfo<FreeStoreAllocationPolicy>; | 633 template class ScopeInfo<FreeStoreAllocationPolicy>; |
| 634 template class ScopeInfo<PreallocatedStorage>; | 634 template class ScopeInfo<PreallocatedStorage>; |
| 635 template class ScopeInfo<ZoneListAllocationPolicy>; | 635 template class ScopeInfo<ZoneListAllocationPolicy>; |
| 636 | 636 |
| 637 } } // namespace v8::internal | 637 } } // namespace v8::internal |
| OLD | NEW |