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

Side by Side Diff: src/full-codegen.h

Issue 7618007: Simplify handling of exits from with and catch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 virtual bool IsContinueTarget(Statement* target) { return false; } 140 virtual bool IsContinueTarget(Statement* target) { return false; }
141 virtual bool IsBreakTarget(Statement* target) { return false; } 141 virtual bool IsBreakTarget(Statement* target) { return false; }
142 142
143 // Generate code to leave the nested statement. This includes 143 // Generate code to leave the nested statement. This includes
144 // cleaning up any stack elements in use and restoring the 144 // cleaning up any stack elements in use and restoring the
145 // stack to the expectations of the surrounding statements. 145 // stack to the expectations of the surrounding statements.
146 // Takes a number of stack elements currently on top of the 146 // Takes a number of stack elements currently on top of the
147 // nested statement's stack, and returns a number of stack 147 // nested statement's stack, and returns a number of stack
148 // elements left on top of the surrounding statement's stack. 148 // elements left on top of the surrounding statement's stack.
149 // The generated code must preserve the result register (which 149 // The generated code must preserve the result register (which
150 // contains the value in case of a return). 150 // contains the value in case of a return).
Vyacheslav Egorov (Chromium) 2011/08/11 11:21:55 Comment is out of date. Please update.
Kevin Millikin (Chromium) 2011/08/11 15:22:20 Done.
151 virtual int Exit(int stack_depth) { 151 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
152 // Default implementation for the case where there is 152 // Default implementation for the case where there is
153 // nothing to clean up. 153 // nothing to clean up.
154 return stack_depth; 154 return previous_;
155 } 155 }
156 NestedStatement* outer() { return previous_; }
157 156
158 protected: 157 protected:
159 MacroAssembler* masm() { return codegen_->masm(); } 158 MacroAssembler* masm() { return codegen_->masm(); }
160 159
161 private:
162 FullCodeGenerator* codegen_; 160 FullCodeGenerator* codegen_;
163 NestedStatement* previous_; 161 NestedStatement* previous_;
164 DISALLOW_COPY_AND_ASSIGN(NestedStatement); 162 DISALLOW_COPY_AND_ASSIGN(NestedStatement);
165 }; 163 };
166 164
167 class Breakable : public NestedStatement { 165 class Breakable : public NestedStatement {
168 public: 166 public:
169 Breakable(FullCodeGenerator* codegen, 167 Breakable(FullCodeGenerator* codegen,
170 BreakableStatement* break_target) 168 BreakableStatement* break_target)
171 : NestedStatement(codegen), 169 : NestedStatement(codegen),
(...skipping 28 matching lines...) Expand all
200 }; 198 };
201 199
202 // The environment inside the try block of a try/catch statement. 200 // The environment inside the try block of a try/catch statement.
203 class TryCatch : public NestedStatement { 201 class TryCatch : public NestedStatement {
204 public: 202 public:
205 explicit TryCatch(FullCodeGenerator* codegen, Label* catch_entry) 203 explicit TryCatch(FullCodeGenerator* codegen, Label* catch_entry)
206 : NestedStatement(codegen), catch_entry_(catch_entry) { } 204 : NestedStatement(codegen), catch_entry_(catch_entry) { }
207 virtual ~TryCatch() {} 205 virtual ~TryCatch() {}
208 virtual TryCatch* AsTryCatch() { return this; } 206 virtual TryCatch* AsTryCatch() { return this; }
209 Label* catch_entry() { return catch_entry_; } 207 Label* catch_entry() { return catch_entry_; }
210 virtual int Exit(int stack_depth); 208 virtual NestedStatement* Exit(int* stack_depth, int* context_length);
211 private: 209 private:
212 Label* catch_entry_; 210 Label* catch_entry_;
213 DISALLOW_COPY_AND_ASSIGN(TryCatch); 211 DISALLOW_COPY_AND_ASSIGN(TryCatch);
214 }; 212 };
215 213
216 // The environment inside the try block of a try/finally statement. 214 // The environment inside the try block of a try/finally statement.
217 class TryFinally : public NestedStatement { 215 class TryFinally : public NestedStatement {
218 public: 216 public:
219 explicit TryFinally(FullCodeGenerator* codegen, Label* finally_entry) 217 explicit TryFinally(FullCodeGenerator* codegen, Label* finally_entry)
220 : NestedStatement(codegen), finally_entry_(finally_entry) { } 218 : NestedStatement(codegen), finally_entry_(finally_entry) { }
221 virtual ~TryFinally() {} 219 virtual ~TryFinally() {}
222 virtual TryFinally* AsTryFinally() { return this; } 220 virtual TryFinally* AsTryFinally() { return this; }
223 Label* finally_entry() { return finally_entry_; } 221 Label* finally_entry() { return finally_entry_; }
224 virtual int Exit(int stack_depth); 222 virtual NestedStatement* Exit(int* stack_depth, int* context_length);
225 private: 223 private:
226 Label* finally_entry_; 224 Label* finally_entry_;
227 DISALLOW_COPY_AND_ASSIGN(TryFinally); 225 DISALLOW_COPY_AND_ASSIGN(TryFinally);
228 }; 226 };
229 227
230 // A FinallyEnvironment represents being inside a finally block. 228 // A FinallyEnvironment represents being inside a finally block.
231 // Abnormal termination of the finally block needs to clean up 229 // Abnormal termination of the finally block needs to clean up
232 // the block's parameters from the stack. 230 // the block's parameters from the stack.
233 class Finally : public NestedStatement { 231 class Finally : public NestedStatement {
234 public: 232 public:
235 explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { } 233 explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
236 virtual ~Finally() {} 234 virtual ~Finally() {}
237 virtual Finally* AsFinally() { return this; } 235 virtual Finally* AsFinally() { return this; }
238 virtual int Exit(int stack_depth) { 236 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
239 return stack_depth + kFinallyStackElementCount; 237 *stack_depth += kFinallyStackElementCount;
238 return previous_;
240 } 239 }
241 private: 240 private:
242 // Number of extra stack slots occupied during a finally block. 241 // Number of extra stack slots occupied during a finally block.
243 static const int kFinallyStackElementCount = 2; 242 static const int kFinallyStackElementCount = 2;
244 DISALLOW_COPY_AND_ASSIGN(Finally); 243 DISALLOW_COPY_AND_ASSIGN(Finally);
245 }; 244 };
246 245
247 // A ForInEnvironment represents being inside a for-in loop. 246 // A ForInEnvironment represents being inside a for-in loop.
248 // Abnormal termination of the for-in block needs to clean up 247 // Abnormal termination of the for-in block needs to clean up
249 // the block's temporary storage from the stack. 248 // the block's temporary storage from the stack.
250 class ForIn : public Iteration { 249 class ForIn : public Iteration {
251 public: 250 public:
252 ForIn(FullCodeGenerator* codegen, 251 ForIn(FullCodeGenerator* codegen,
253 ForInStatement* statement) 252 ForInStatement* statement)
254 : Iteration(codegen, statement) { } 253 : Iteration(codegen, statement) { }
255 virtual ~ForIn() {} 254 virtual ~ForIn() {}
256 virtual ForIn* AsForIn() { return this; } 255 virtual ForIn* AsForIn() { return this; }
257 virtual int Exit(int stack_depth) { 256 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
258 return stack_depth + kForInStackElementCount; 257 *stack_depth += kForInStackElementCount;
258 return previous_;
259 } 259 }
260 private: 260 private:
261 static const int kForInStackElementCount = 5; 261 static const int kForInStackElementCount = 5;
262 DISALLOW_COPY_AND_ASSIGN(ForIn); 262 DISALLOW_COPY_AND_ASSIGN(ForIn);
263 }; 263 };
264 264
265
266 // A WithOrCatch represents being inside the body of a with or catch
267 // statement. Exiting the body needs to remove a link from the context
268 // chain.
269 class WithOrCatch : public NestedStatement {
270 public:
271 explicit WithOrCatch(FullCodeGenerator* codegen)
272 : NestedStatement(codegen) {
273 }
274 virtual ~WithOrCatch() {}
275
276 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
277 ++(*context_length);
278 return previous_;
279 }
280 };
281
265 // The forward bailout stack keeps track of the expressions that can 282 // The forward bailout stack keeps track of the expressions that can
266 // bail out to just before the control flow is split in a child 283 // bail out to just before the control flow is split in a child
267 // node. The stack elements are linked together through the parent 284 // node. The stack elements are linked together through the parent
268 // link when visiting expressions in test contexts after requesting 285 // link when visiting expressions in test contexts after requesting
269 // bailout in child forwarding. 286 // bailout in child forwarding.
270 class ForwardBailoutStack BASE_EMBEDDED { 287 class ForwardBailoutStack BASE_EMBEDDED {
271 public: 288 public:
272 ForwardBailoutStack(Expression* expr, ForwardBailoutStack* parent) 289 ForwardBailoutStack(Expression* expr, ForwardBailoutStack* parent)
273 : expr_(expr), parent_(parent) { } 290 : expr_(expr), parent_(parent) { }
274 291
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 821
805 friend class NestedStatement; 822 friend class NestedStatement;
806 823
807 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); 824 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator);
808 }; 825 };
809 826
810 827
811 } } // namespace v8::internal 828 } } // namespace v8::internal
812 829
813 #endif // V8_FULL_CODEGEN_H_ 830 #endif // V8_FULL_CODEGEN_H_
OLDNEW
« no previous file with comments | « src/frames-inl.h ('k') | src/full-codegen.cc » ('j') | src/full-codegen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698