OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSING_FUNC_NAME_INFERRER_H_ | 5 #ifndef V8_PARSING_FUNC_NAME_INFERRER_H_ |
6 #define V8_PARSING_FUNC_NAME_INFERRER_H_ | 6 #define V8_PARSING_FUNC_NAME_INFERRER_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/zone.h" | 9 #include "src/zone.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 public: | 30 public: |
31 FuncNameInferrer(AstValueFactory* ast_value_factory, Zone* zone); | 31 FuncNameInferrer(AstValueFactory* ast_value_factory, Zone* zone); |
32 | 32 |
33 // Returns whether we have entered name collection state. | 33 // Returns whether we have entered name collection state. |
34 bool IsOpen() const { return !entries_stack_.is_empty(); } | 34 bool IsOpen() const { return !entries_stack_.is_empty(); } |
35 | 35 |
36 // Pushes an enclosing the name of enclosing function onto names stack. | 36 // Pushes an enclosing the name of enclosing function onto names stack. |
37 void PushEnclosingName(const AstRawString* name); | 37 void PushEnclosingName(const AstRawString* name); |
38 | 38 |
39 // Enters name collection state. | 39 // Enters name collection state. |
40 void Enter() { | 40 void Enter() { entries_stack_.Add(names_stack_.length(), zone()); } |
41 entries_stack_.Add(names_stack_.length(), zone()); | |
42 } | |
43 | 41 |
44 // Pushes an encountered name onto names stack when in collection state. | 42 // Pushes an encountered name onto names stack when in collection state. |
45 void PushLiteralName(const AstRawString* name); | 43 void PushLiteralName(const AstRawString* name); |
46 | 44 |
47 void PushVariableName(const AstRawString* name); | 45 void PushVariableName(const AstRawString* name); |
48 | 46 |
49 // Adds a function to infer name for. | 47 // Adds a function to infer name for. |
50 void AddFunction(FunctionLiteral* func_to_infer) { | 48 void AddFunction(FunctionLiteral* func_to_infer) { |
51 if (IsOpen()) { | 49 if (IsOpen()) { |
52 funcs_to_infer_.Add(func_to_infer, zone()); | 50 funcs_to_infer_.Add(func_to_infer, zone()); |
(...skipping 11 matching lines...) Expand all Loading... |
64 DCHECK(IsOpen()); | 62 DCHECK(IsOpen()); |
65 if (!funcs_to_infer_.is_empty()) { | 63 if (!funcs_to_infer_.is_empty()) { |
66 InferFunctionsNames(); | 64 InferFunctionsNames(); |
67 } | 65 } |
68 } | 66 } |
69 | 67 |
70 // Leaves names collection state. | 68 // Leaves names collection state. |
71 void Leave() { | 69 void Leave() { |
72 DCHECK(IsOpen()); | 70 DCHECK(IsOpen()); |
73 names_stack_.Rewind(entries_stack_.RemoveLast()); | 71 names_stack_.Rewind(entries_stack_.RemoveLast()); |
74 if (entries_stack_.is_empty()) | 72 if (entries_stack_.is_empty()) funcs_to_infer_.Clear(); |
75 funcs_to_infer_.Clear(); | |
76 } | 73 } |
77 | 74 |
78 private: | 75 private: |
79 enum NameType { | 76 enum NameType { kEnclosingConstructorName, kLiteralName, kVariableName }; |
80 kEnclosingConstructorName, | |
81 kLiteralName, | |
82 kVariableName | |
83 }; | |
84 struct Name { | 77 struct Name { |
85 Name(const AstRawString* name, NameType type) : name(name), type(type) {} | 78 Name(const AstRawString* name, NameType type) : name(name), type(type) {} |
86 const AstRawString* name; | 79 const AstRawString* name; |
87 NameType type; | 80 NameType type; |
88 }; | 81 }; |
89 | 82 |
90 Zone* zone() const { return zone_; } | 83 Zone* zone() const { return zone_; } |
91 | 84 |
92 // Constructs a full name in dotted notation from gathered names. | 85 // Constructs a full name in dotted notation from gathered names. |
93 const AstString* MakeNameFromStack(); | 86 const AstString* MakeNameFromStack(); |
94 | 87 |
95 // A helper function for MakeNameFromStack. | 88 // A helper function for MakeNameFromStack. |
96 const AstString* MakeNameFromStackHelper(int pos, | 89 const AstString* MakeNameFromStackHelper(int pos, const AstString* prev); |
97 const AstString* prev); | |
98 | 90 |
99 // Performs name inferring for added functions. | 91 // Performs name inferring for added functions. |
100 void InferFunctionsNames(); | 92 void InferFunctionsNames(); |
101 | 93 |
102 AstValueFactory* ast_value_factory_; | 94 AstValueFactory* ast_value_factory_; |
103 ZoneList<int> entries_stack_; | 95 ZoneList<int> entries_stack_; |
104 ZoneList<Name> names_stack_; | 96 ZoneList<Name> names_stack_; |
105 ZoneList<FunctionLiteral*> funcs_to_infer_; | 97 ZoneList<FunctionLiteral*> funcs_to_infer_; |
106 Zone* zone_; | 98 Zone* zone_; |
107 | 99 |
108 DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer); | 100 DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer); |
109 }; | 101 }; |
110 | 102 |
111 | 103 |
112 } // namespace internal | 104 } // namespace internal |
113 } // namespace v8 | 105 } // namespace v8 |
114 | 106 |
115 #endif // V8_PARSING_FUNC_NAME_INFERRER_H_ | 107 #endif // V8_PARSING_FUNC_NAME_INFERRER_H_ |
OLD | NEW |