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

Side by Side Diff: src/scopeinfo.h

Issue 2908009: Create a separate class to encapsulate ScopeInfo serialization.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 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/runtime.cc ('k') | src/scopeinfo.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 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // in debugging-unrelated contexts. 47 // in debugging-unrelated contexts.
48 48
49 // Forward defined as 49 // Forward defined as
50 // template <class Allocator = FreeStoreAllocationPolicy> class ScopeInfo; 50 // template <class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
51 template<class Allocator> 51 template<class Allocator>
52 class ScopeInfo BASE_EMBEDDED { 52 class ScopeInfo BASE_EMBEDDED {
53 public: 53 public:
54 // Create a ScopeInfo instance from a scope. 54 // Create a ScopeInfo instance from a scope.
55 explicit ScopeInfo(Scope* scope); 55 explicit ScopeInfo(Scope* scope);
56 56
57 // Create a ScopeInfo instance from an Object holding the serialized data. 57 // Create a ScopeInfo instance from SerializedScopeInfo.
58 explicit ScopeInfo(Object* data); 58 explicit ScopeInfo(SerializedScopeInfo* data);
59 59
60 // Creates a heap object holding the serialized scope info. 60 // Creates a SerializedScopeInfo holding the serialized scope info.
61 Handle<Object> Serialize(); 61 Handle<SerializedScopeInfo> Serialize();
62
63 static Handle<Object> CreateHeapObject(Scope* scope);
64
65 // Serializes empty scope info.
66 static Object* EmptyHeapObject();
67 62
68 // -------------------------------------------------------------------------- 63 // --------------------------------------------------------------------------
69 // Lookup 64 // Lookup
70 65
71 Handle<String> function_name() const { return function_name_; } 66 Handle<String> function_name() const { return function_name_; }
72 67
73 Handle<String> parameter_name(int i) const { return parameters_[i]; } 68 Handle<String> parameter_name(int i) const { return parameters_[i]; }
74 int number_of_parameters() const { return parameters_.length(); } 69 int number_of_parameters() const { return parameters_.length(); }
75 70
76 Handle<String> stack_slot_name(int i) const { return stack_slots_[i]; } 71 Handle<String> stack_slot_name(int i) const { return stack_slots_[i]; }
77 int number_of_stack_slots() const { return stack_slots_.length(); } 72 int number_of_stack_slots() const { return stack_slots_.length(); }
78 73
79 Handle<String> context_slot_name(int i) const { 74 Handle<String> context_slot_name(int i) const {
80 return context_slots_[i - Context::MIN_CONTEXT_SLOTS]; 75 return context_slots_[i - Context::MIN_CONTEXT_SLOTS];
81 } 76 }
82 int number_of_context_slots() const { 77 int number_of_context_slots() const {
83 int l = context_slots_.length(); 78 int l = context_slots_.length();
84 return l == 0 ? 0 : l + Context::MIN_CONTEXT_SLOTS; 79 return l == 0 ? 0 : l + Context::MIN_CONTEXT_SLOTS;
85 } 80 }
86 81
87 Handle<String> LocalName(int i) const; 82 Handle<String> LocalName(int i) const;
88 int NumberOfLocals() const; 83 int NumberOfLocals() const;
89 84
90 // -------------------------------------------------------------------------- 85 // --------------------------------------------------------------------------
91 // The following functions provide quick access to scope info details
92 // for runtime routines w/o the need to explicitly create a ScopeInfo
93 // object.
94 //
95 // ScopeInfo is the only class which should have to know about the
96 // encoding of it's information in a FixedArray object, which is why these
97 // functions are in this class.
98
99 // Does this scope call eval.
100 static bool CallsEval(Object* data);
101
102 // Return the number of stack slots for code.
103 static int NumberOfStackSlots(Object* data);
104
105 // Return the number of context slots for code.
106 static int NumberOfContextSlots(Object* data);
107
108 // Return if this has context slots besides MIN_CONTEXT_SLOTS;
109 static bool HasHeapAllocatedLocals(Object* data);
110
111 // Lookup support for serialized scope info. Returns the
112 // the stack slot index for a given slot name if the slot is
113 // present; otherwise returns a value < 0. The name must be a symbol
114 // (canonicalized).
115 static int StackSlotIndex(Object* data, String* name);
116
117 // Lookup support for serialized scope info. Returns the
118 // context slot index for a given slot name if the slot is present; otherwise
119 // returns a value < 0. The name must be a symbol (canonicalized).
120 // If the slot is present and mode != NULL, sets *mode to the corresponding
121 // mode for that variable.
122 static int ContextSlotIndex(Object* data, String* name, Variable::Mode* mode);
123
124 // Lookup support for serialized scope info. Returns the
125 // parameter index for a given parameter name if the parameter is present;
126 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
127 static int ParameterIndex(Object* data, String* name);
128
129 // Lookup support for serialized scope info. Returns the
130 // function context slot index if the function name is present (named
131 // function expressions, only), otherwise returns a value < 0. The name
132 // must be a symbol (canonicalized).
133 static int FunctionContextSlotIndex(Object* data, String* name);
134
135 // --------------------------------------------------------------------------
136 // Debugging support 86 // Debugging support
137 87
138 #ifdef DEBUG 88 #ifdef DEBUG
139 void Print(); 89 void Print();
140 #endif 90 #endif
141 91
142 private: 92 private:
143 Handle<String> function_name_; 93 Handle<String> function_name_;
144 bool calls_eval_; 94 bool calls_eval_;
145 List<Handle<String>, Allocator > parameters_; 95 List<Handle<String>, Allocator > parameters_;
146 List<Handle<String>, Allocator > stack_slots_; 96 List<Handle<String>, Allocator > stack_slots_;
147 List<Handle<String>, Allocator > context_slots_; 97 List<Handle<String>, Allocator > context_slots_;
148 List<Variable::Mode, Allocator > context_modes_; 98 List<Variable::Mode, Allocator > context_modes_;
149 }; 99 };
150 100
151 101
102 // This object provides quick access to scope info details for runtime
103 // routines w/o the need to explicitly create a ScopeInfo object.
104 class SerializedScopeInfo : public FixedArray {
105 public :
106
107 static SerializedScopeInfo* cast(Object* object) {
108 ASSERT(object->IsFixedArray());
109 return reinterpret_cast<SerializedScopeInfo*>(object);
110 }
111
112 // Does this scope call eval.
113 bool CallsEval();
114
115 // Return the number of stack slots for code.
116 int NumberOfStackSlots();
117
118 // Return the number of context slots for code.
119 int NumberOfContextSlots();
120
121 // Return if this has context slots besides MIN_CONTEXT_SLOTS;
122 bool HasHeapAllocatedLocals();
123
124 // Lookup support for serialized scope info. Returns the
125 // the stack slot index for a given slot name if the slot is
126 // present; otherwise returns a value < 0. The name must be a symbol
127 // (canonicalized).
128 int StackSlotIndex(String* name);
129
130 // Lookup support for serialized scope info. Returns the
131 // context slot index for a given slot name if the slot is present; otherwise
132 // returns a value < 0. The name must be a symbol (canonicalized).
133 // If the slot is present and mode != NULL, sets *mode to the corresponding
134 // mode for that variable.
135 int ContextSlotIndex(String* name, Variable::Mode* mode);
136
137 // Lookup support for serialized scope info. Returns the
138 // parameter index for a given parameter name if the parameter is present;
139 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
140 int ParameterIndex(String* name);
141
142 // Lookup support for serialized scope info. Returns the
143 // function context slot index if the function name is present (named
144 // function expressions, only), otherwise returns a value < 0. The name
145 // must be a symbol (canonicalized).
146 int FunctionContextSlotIndex(String* name);
147
148 static Handle<SerializedScopeInfo> Create(Scope* scope);
149
150 // Serializes empty scope info.
151 static SerializedScopeInfo* Empty();
152
153 private:
154
155 inline Object** ContextEntriesAddr();
156
157 inline Object** ParameterEntriesAddr();
158
159 inline Object** StackSlotEntriesAddr();
160 };
161
162
152 // Cache for mapping (data, property name) into context slot index. 163 // Cache for mapping (data, property name) into context slot index.
153 // The cache contains both positive and negative results. 164 // The cache contains both positive and negative results.
154 // Slot index equals -1 means the property is absent. 165 // Slot index equals -1 means the property is absent.
155 // Cleared at startup and prior to mark sweep collection. 166 // Cleared at startup and prior to mark sweep collection.
156 class ContextSlotCache { 167 class ContextSlotCache {
157 public: 168 public:
158 // Lookup context slot index for (data, name). 169 // Lookup context slot index for (data, name).
159 // If absent, kNotFound is returned. 170 // If absent, kNotFound is returned.
160 static int Lookup(Object* data, 171 static int Lookup(Object* data,
161 String* name, 172 String* name,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 }; 224 };
214 225
215 static Key keys_[kLength]; 226 static Key keys_[kLength];
216 static uint32_t values_[kLength]; 227 static uint32_t values_[kLength];
217 }; 228 };
218 229
219 230
220 } } // namespace v8::internal 231 } } // namespace v8::internal
221 232
222 #endif // V8_SCOPEINFO_H_ 233 #endif // V8_SCOPEINFO_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698