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

Side by Side Diff: src/scopeinfo.cc

Issue 7824038: Remove variable rewrites and the unneccesary Slot class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 3 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
OLDNEW
1 // Copyright 2011 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
(...skipping 21 matching lines...) Expand all
32 #include "scopeinfo.h" 32 #include "scopeinfo.h"
33 #include "scopes.h" 33 #include "scopes.h"
34 34
35 #include "allocation-inl.h" 35 #include "allocation-inl.h"
36 36
37 namespace v8 { 37 namespace v8 {
38 namespace internal { 38 namespace internal {
39 39
40 40
41 static int CompareLocal(Variable* const* v, Variable* const* w) { 41 static int CompareLocal(Variable* const* v, Variable* const* w) {
42 Slot* s = (*v)->AsSlot(); 42 int x = (*v)->index();
43 Slot* t = (*w)->AsSlot(); 43 int y = (*w)->index();
44 // We may have rewritten parameters (that are in the arguments object)
45 // and which may have a NULL slot... - find a better solution...
46 int x = (s != NULL ? s->index() : 0);
47 int y = (t != NULL ? t->index() : 0);
48 // Consider sorting them according to type as well? 44 // Consider sorting them according to type as well?
49 return x - y; 45 return x - y;
50 } 46 }
51 47
52 48
53 template<class Allocator> 49 template<class Allocator>
54 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) 50 ScopeInfo<Allocator>::ScopeInfo(Scope* scope)
55 : function_name_(FACTORY->empty_symbol()), 51 : function_name_(FACTORY->empty_symbol()),
56 calls_eval_(scope->calls_eval()), 52 calls_eval_(scope->calls_eval()),
57 is_strict_mode_(scope->is_strict_mode()), 53 is_strict_mode_(scope->is_strict_mode()),
(...skipping 21 matching lines...) Expand all
79 // ScopeInfo list. 75 // ScopeInfo list.
80 List<Variable*, Allocator> locals(32); // 32 is a wild guess 76 List<Variable*, Allocator> locals(32); // 32 is a wild guess
81 ASSERT(locals.is_empty()); 77 ASSERT(locals.is_empty());
82 scope->CollectUsedVariables(&locals); 78 scope->CollectUsedVariables(&locals);
83 locals.Sort(&CompareLocal); 79 locals.Sort(&CompareLocal);
84 80
85 List<Variable*, Allocator> heap_locals(locals.length()); 81 List<Variable*, Allocator> heap_locals(locals.length());
86 for (int i = 0; i < locals.length(); i++) { 82 for (int i = 0; i < locals.length(); i++) {
87 Variable* var = locals[i]; 83 Variable* var = locals[i];
88 if (var->is_used()) { 84 if (var->is_used()) {
89 Slot* slot = var->AsSlot(); 85 switch (var->location()) {
90 if (slot != NULL) { 86 case Variable::UNALLOCATED:
91 switch (slot->type()) { 87 case Variable::PARAMETER:
92 case Slot::PARAMETER: 88 break;
93 // explicitly added to parameters_ above - ignore
94 break;
95 89
96 case Slot::LOCAL: 90 case Variable::LOCAL:
97 ASSERT(stack_slots_.length() == slot->index()); 91 ASSERT(stack_slots_.length() == var->index());
98 stack_slots_.Add(var->name()); 92 stack_slots_.Add(var->name());
99 break; 93 break;
100 94
101 case Slot::CONTEXT: 95 case Variable::CONTEXT:
102 heap_locals.Add(var); 96 heap_locals.Add(var);
103 break; 97 break;
104 98
105 case Slot::LOOKUP: 99 case Variable::LOOKUP:
106 // This is currently not used. 100 // We don't expect lookup variables in the locals list.
107 UNREACHABLE(); 101 UNREACHABLE();
108 break; 102 break;
109 }
110 } 103 }
111 } 104 }
112 } 105 }
113 106
114 // Add heap locals. 107 // Add heap locals.
115 if (scope->num_heap_slots() > 0) { 108 if (scope->num_heap_slots() > 0) {
116 // Add user-defined slots. 109 // Add user-defined slots.
117 for (int i = 0; i < heap_locals.length(); i++) { 110 for (int i = 0; i < heap_locals.length(); i++) {
118 ASSERT(heap_locals[i]->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == 111 ASSERT(heap_locals[i]->index() - Context::MIN_CONTEXT_SLOTS ==
119 context_slots_.length()); 112 context_slots_.length());
120 ASSERT(heap_locals[i]->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == 113 ASSERT(heap_locals[i]->index() - Context::MIN_CONTEXT_SLOTS ==
121 context_modes_.length()); 114 context_modes_.length());
122 context_slots_.Add(heap_locals[i]->name()); 115 context_slots_.Add(heap_locals[i]->name());
123 context_modes_.Add(heap_locals[i]->mode()); 116 context_modes_.Add(heap_locals[i]->mode());
124 } 117 }
125 118
126 } else { 119 } else {
127 ASSERT(heap_locals.length() == 0); 120 ASSERT(heap_locals.length() == 0);
128 } 121 }
129 122
130 // Add the function context slot, if present. 123 // Add the function context slot, if present.
131 // For now, this must happen at the very end because of the 124 // For now, this must happen at the very end because of the
132 // ordering of the scope info slots and the respective slot indices. 125 // ordering of the scope info slots and the respective slot indices.
133 if (scope->is_function_scope()) { 126 if (scope->is_function_scope()) {
134 VariableProxy* proxy = scope->function(); 127 VariableProxy* proxy = scope->function();
135 if (proxy != NULL && 128 if (proxy != NULL &&
136 proxy->var()->is_used() && 129 proxy->var()->is_used() &&
137 proxy->var()->IsContextSlot()) { 130 proxy->var()->IsContextSlot()) {
138 function_name_ = proxy->name(); 131 function_name_ = proxy->name();
139 // Note that we must not find the function name in the context slot 132 // Note that we must not find the function name in the context slot
140 // list - instead it must be handled separately in the 133 // list - instead it must be handled separately in the
141 // Contexts::Lookup() function. Thus record an empty symbol here so we 134 // Contexts::Lookup() function. Thus record an empty symbol here so we
142 // get the correct number of context slots. 135 // get the correct number of context slots.
143 ASSERT(proxy->var()->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == 136 ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS ==
144 context_slots_.length()); 137 context_slots_.length());
145 ASSERT(proxy->var()->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == 138 ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS ==
146 context_modes_.length()); 139 context_modes_.length());
147 context_slots_.Add(FACTORY->empty_symbol()); 140 context_slots_.Add(FACTORY->empty_symbol());
148 context_modes_.Add(Variable::INTERNAL); 141 context_modes_.Add(Variable::INTERNAL);
149 } 142 }
150 } 143 }
151 } 144 }
152 145
153 146
154 // Encoding format in a FixedArray object: 147 // Encoding format in a FixedArray object:
155 // 148 //
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 632 }
640 #endif // DEBUG 633 #endif // DEBUG
641 634
642 635
643 // Make sure the classes get instantiated by the template system. 636 // Make sure the classes get instantiated by the template system.
644 template class ScopeInfo<FreeStoreAllocationPolicy>; 637 template class ScopeInfo<FreeStoreAllocationPolicy>;
645 template class ScopeInfo<PreallocatedStorage>; 638 template class ScopeInfo<PreallocatedStorage>;
646 template class ScopeInfo<ZoneListAllocationPolicy>; 639 template class ScopeInfo<ZoneListAllocationPolicy>;
647 640
648 } } // namespace v8::internal 641 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698