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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 class AstRawString; | 14 class AstRawString; |
15 class AstString; | 15 class AstString; |
16 class AstValueFactory; | 16 class AstValueFactory; |
17 class FunctionLiteral; | 17 class FunctionLiteral; |
18 | 18 |
19 enum class InferName { Yes, No }; | |
20 | |
19 // FuncNameInferrer is a stateful class that is used to perform name | 21 // FuncNameInferrer is a stateful class that is used to perform name |
20 // inference for anonymous functions during static analysis of source code. | 22 // inference for anonymous functions during static analysis of source code. |
21 // Inference is performed in cases when an anonymous function is assigned | 23 // Inference is performed in cases when an anonymous function is assigned |
22 // to a variable or a property (see test-func-name-inference.cc for examples.) | 24 // to a variable or a property (see test-func-name-inference.cc for examples.) |
23 // | 25 // |
24 // The basic idea is that during parsing of LHSs of certain expressions | 26 // The basic idea is that during parsing of LHSs of certain expressions |
25 // (assignments, declarations, object literals) we collect name strings, | 27 // (assignments, declarations, object literals) we collect name strings, |
26 // and during parsing of the RHS, a function literal can be collected. After | 28 // and during parsing of the RHS, a function literal can be collected. After |
27 // parsing the RHS we can infer a name for function literals that do not have | 29 // parsing the RHS we can infer a name for function literals that do not have |
28 // a name. | 30 // a name. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 funcs_to_infer_.Add(func_to_infer, zone()); | 66 funcs_to_infer_.Add(func_to_infer, zone()); |
65 } | 67 } |
66 } | 68 } |
67 | 69 |
68 void RemoveLastFunction() { | 70 void RemoveLastFunction() { |
69 if (IsOpen() && !funcs_to_infer_.is_empty()) { | 71 if (IsOpen() && !funcs_to_infer_.is_empty()) { |
70 funcs_to_infer_.RemoveLast(); | 72 funcs_to_infer_.RemoveLast(); |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
76 int LastNameIndex() const { return this->names_stack_.length() - 1; } | |
77 | |
78 void RemoveAsyncKeywordAtIndex(int index); | |
Dan Ehrenberg
2016/08/12 21:29:58
Nit: Rather than exposing these two functions, why
caitp
2016/08/12 21:32:45
1. prone to break with future parser changes, and
Dan Ehrenberg
2016/08/12 21:35:28
The logic would be, how many things from the top o
| |
79 | |
74 // Infers a function name and leaves names collection state. | 80 // Infers a function name and leaves names collection state. |
75 void Infer() { | 81 void Infer() { |
76 DCHECK(IsOpen()); | 82 DCHECK(IsOpen()); |
77 if (!funcs_to_infer_.is_empty()) { | 83 if (!funcs_to_infer_.is_empty()) { |
78 InferFunctionsNames(); | 84 InferFunctionsNames(); |
79 } | 85 } |
80 } | 86 } |
81 | 87 |
82 private: | 88 private: |
83 enum NameType { | 89 enum NameType { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 Zone* zone_; | 124 Zone* zone_; |
119 | 125 |
120 DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer); | 126 DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer); |
121 }; | 127 }; |
122 | 128 |
123 | 129 |
124 } // namespace internal | 130 } // namespace internal |
125 } // namespace v8 | 131 } // namespace v8 |
126 | 132 |
127 #endif // V8_PARSING_FUNC_NAME_INFERRER_H_ | 133 #endif // V8_PARSING_FUNC_NAME_INFERRER_H_ |
OLD | NEW |