Index: src/parsing/func-name-inferrer.h |
diff --git a/src/parsing/func-name-inferrer.h b/src/parsing/func-name-inferrer.h |
index d0e4cad429cdc0d0264162a9b82a5c67fce2f6e2..ba38ffeb241c348ab8e285a842b08e5f12590615 100644 |
--- a/src/parsing/func-name-inferrer.h |
+++ b/src/parsing/func-name-inferrer.h |
@@ -30,17 +30,29 @@ class FuncNameInferrer : public ZoneObject { |
public: |
FuncNameInferrer(AstValueFactory* ast_value_factory, Zone* zone); |
+ // To enter function name inference state, put a FuncNameInferrer::State |
+ // on the stack. |
+ class State { |
+ public: |
+ explicit State(FuncNameInferrer* fni) : fni_(fni) { |
+ if (fni_ != nullptr) fni_->Enter(); |
+ } |
+ ~State() { |
+ if (fni_ != nullptr) fni_->Leave(); |
+ } |
+ |
+ private: |
+ FuncNameInferrer* fni_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(State); |
+ }; |
+ |
// Returns whether we have entered name collection state. |
bool IsOpen() const { return !entries_stack_.is_empty(); } |
// Pushes an enclosing the name of enclosing function onto names stack. |
void PushEnclosingName(const AstRawString* name); |
- // Enters name collection state. |
- void Enter() { |
- entries_stack_.Add(names_stack_.length(), zone()); |
- } |
- |
// Pushes an encountered name onto names stack when in collection state. |
void PushLiteralName(const AstRawString* name); |
@@ -67,14 +79,6 @@ class FuncNameInferrer : public ZoneObject { |
} |
} |
- // Leaves names collection state. |
- void Leave() { |
- DCHECK(IsOpen()); |
- names_stack_.Rewind(entries_stack_.RemoveLast()); |
- if (entries_stack_.is_empty()) |
- funcs_to_infer_.Clear(); |
- } |
- |
private: |
enum NameType { |
kEnclosingConstructorName, |
@@ -87,6 +91,14 @@ class FuncNameInferrer : public ZoneObject { |
NameType type; |
}; |
+ void Enter() { entries_stack_.Add(names_stack_.length(), zone()); } |
+ |
+ void Leave() { |
+ DCHECK(IsOpen()); |
+ names_stack_.Rewind(entries_stack_.RemoveLast()); |
+ if (entries_stack_.is_empty()) funcs_to_infer_.Clear(); |
+ } |
+ |
Zone* zone() const { return zone_; } |
// Constructs a full name in dotted notation from gathered names. |