Index: src/lithium.h |
=================================================================== |
--- src/lithium.h (revision 6414) |
+++ src/lithium.h (working copy) |
@@ -488,6 +488,71 @@ |
void PrintTo(StringStream* stream); |
+ class ShallowIterator BASE_EMBEDDED { |
+ public: |
+ explicit ShallowIterator(LEnvironment* env) : env_(env), current_(0) { |
+ Advance(); |
+ } |
+ inline bool HasNext() { |
+ return env_ != NULL && current_ < env_->values()->length(); |
+ } |
+ |
+ inline LOperand* Next() { |
+ ASSERT(env_ != NULL); |
Kevin Millikin (Chromium)
2011/01/20 12:20:30
In normal use, should one ever call Next on an env
fschneider
2011/01/20 17:13:08
Done.
|
+ LOperand* elem = HasNext() ? env_->values()->at(current_++) : NULL; |
+ Advance(); |
+ return elem; |
+ } |
+ |
+ private: |
+ inline void Advance() { |
+ while (HasNext() && |
+ (env_->values()->at(current_) == NULL || |
+ env_->values()->at(current_)->IsConstantOperand())) { |
+ current_++; |
+ } |
+ } |
+ |
+ LEnvironment* env_; |
+ int current_; |
+ }; |
+ |
+ // Iterates over the non-null, non-constant operands in this environment. |
+ ShallowIterator shallow_iterator() { return ShallowIterator(this); } |
Kevin Millikin (Chromium)
2011/01/20 12:20:30
This function (and deep_iterator) probably shouldn
fschneider
2011/01/20 17:13:08
Done.
|
+ |
+ class DeepIterator BASE_EMBEDDED { |
+ public: |
+ explicit DeepIterator(LEnvironment* env) |
+ : current_env_(env), current_iterator_(env) { } |
+ |
+ inline bool HasNext() { |
+ if (current_env_ == NULL) return false; |
Kevin Millikin (Chromium)
2011/01/20 12:20:30
I think you can simplify this class's implementati
fschneider
2011/01/20 17:13:08
Done.
|
+ if (current_iterator_.HasNext()) return true; |
+ if (current_env_->outer() == NULL) return false; |
+ Advance(); |
+ return current_iterator_.HasNext(); |
+ } |
+ |
+ inline LOperand* Next() { |
Kevin Millikin (Chromium)
2011/01/20 12:20:30
inline LOperand* Next() {
ASSERT(current_iterato
fschneider
2011/01/20 17:13:08
Done.
|
+ if (current_iterator_.HasNext()) return current_iterator_.Next(); |
+ if (current_env_->outer() == NULL) return NULL; |
+ Advance(); |
+ return current_iterator_.Next(); |
+ } |
+ |
+ private: |
+ inline void Advance() { |
Kevin Millikin (Chromium)
2011/01/20 12:20:30
inline void Advance() {
while (!current_iterator
fschneider
2011/01/20 17:13:08
Done.
|
+ current_iterator_ = LEnvironment::ShallowIterator(current_env_->outer()); |
+ current_env_ = current_env_->outer(); |
+ } |
+ |
+ LEnvironment* current_env_; |
+ ShallowIterator current_iterator_; |
+ }; |
+ |
+ // Iterator for non-null, non-constant operands incl. outer environments. |
+ DeepIterator deep_iterator() { return DeepIterator(this); } |
+ |
private: |
Handle<JSFunction> closure_; |
int arguments_stack_height_; |