OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 #include "src/parsing/func-name-inferrer.h" | 5 #include "src/parsing/func-name-inferrer.h" |
6 | 6 |
7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
8 #include "src/ast/ast-value-factory.h" | 8 #include "src/ast/ast-value-factory.h" |
9 #include "src/list-inl.h" | 9 #include "src/list-inl.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 FuncNameInferrer::FuncNameInferrer(AstValueFactory* ast_value_factory, | 14 FuncNameInferrer::FuncNameInferrer(AstValueFactory* ast_value_factory, |
15 Zone* zone) | 15 Zone* zone) |
16 : ast_value_factory_(ast_value_factory), | 16 : ast_value_factory_(ast_value_factory), |
17 entries_stack_(10, zone), | 17 entries_stack_(10, zone), |
18 names_stack_(5, zone), | 18 names_stack_(5, zone), |
19 funcs_to_infer_(4, zone), | 19 funcs_to_infer_(4, zone), |
20 zone_(zone) { | 20 zone_(zone) { |
21 } | 21 } |
22 | 22 |
23 | |
Dan Ehrenberg
2016/08/12 21:29:58
Nit: Revert irrelevant whitespace change.
| |
24 void FuncNameInferrer::PushEnclosingName(const AstRawString* name) { | 23 void FuncNameInferrer::PushEnclosingName(const AstRawString* name) { |
25 // Enclosing name is a name of a constructor function. To check | 24 // Enclosing name is a name of a constructor function. To check |
26 // that it is really a constructor, we check that it is not empty | 25 // that it is really a constructor, we check that it is not empty |
27 // and starts with a capital letter. | 26 // and starts with a capital letter. |
28 if (!name->IsEmpty() && unibrow::Uppercase::Is(name->FirstCharacter())) { | 27 if (!name->IsEmpty() && unibrow::Uppercase::Is(name->FirstCharacter())) { |
29 names_stack_.Add(Name(name, kEnclosingConstructorName), zone()); | 28 names_stack_.Add(Name(name, kEnclosingConstructorName), zone()); |
30 } | 29 } |
31 } | 30 } |
32 | 31 |
33 | 32 |
34 void FuncNameInferrer::PushLiteralName(const AstRawString* name) { | 33 void FuncNameInferrer::PushLiteralName(const AstRawString* name) { |
35 if (IsOpen() && name != ast_value_factory_->prototype_string()) { | 34 if (IsOpen() && name != ast_value_factory_->prototype_string()) { |
36 names_stack_.Add(Name(name, kLiteralName), zone()); | 35 names_stack_.Add(Name(name, kLiteralName), zone()); |
37 } | 36 } |
38 } | 37 } |
39 | 38 |
40 | 39 |
41 void FuncNameInferrer::PushVariableName(const AstRawString* name) { | 40 void FuncNameInferrer::PushVariableName(const AstRawString* name) { |
42 if (IsOpen() && name != ast_value_factory_->dot_result_string()) { | 41 if (IsOpen() && name != ast_value_factory_->dot_result_string()) { |
43 names_stack_.Add(Name(name, kVariableName), zone()); | 42 names_stack_.Add(Name(name, kVariableName), zone()); |
44 } | 43 } |
45 } | 44 } |
46 | 45 |
46 void FuncNameInferrer::RemoveAsyncKeywordAtIndex(int index) { | |
47 DCHECK(index >= 0); | |
48 DCHECK(index < names_stack_.length()); | |
49 DCHECK(names_stack_.at(index).name->IsOneByteEqualTo("async")); | |
50 names_stack_.Remove(index); | |
51 } | |
47 | 52 |
48 const AstString* FuncNameInferrer::MakeNameFromStack() { | 53 const AstString* FuncNameInferrer::MakeNameFromStack() { |
49 return MakeNameFromStackHelper(0, ast_value_factory_->empty_string()); | 54 return MakeNameFromStackHelper(0, ast_value_factory_->empty_string()); |
50 } | 55 } |
51 | 56 |
52 const AstString* FuncNameInferrer::MakeNameFromStackHelper( | 57 const AstString* FuncNameInferrer::MakeNameFromStackHelper( |
53 int pos, const AstString* prev) { | 58 int pos, const AstString* prev) { |
54 if (pos >= names_stack_.length()) return prev; | 59 if (pos >= names_stack_.length()) return prev; |
55 if (pos < names_stack_.length() - 1 && | 60 if (pos < names_stack_.length() - 1 && |
56 names_stack_.at(pos).type == kVariableName && | 61 names_stack_.at(pos).type == kVariableName && |
(...skipping 19 matching lines...) Expand all Loading... | |
76 const AstString* func_name = MakeNameFromStack(); | 81 const AstString* func_name = MakeNameFromStack(); |
77 for (int i = 0; i < funcs_to_infer_.length(); ++i) { | 82 for (int i = 0; i < funcs_to_infer_.length(); ++i) { |
78 funcs_to_infer_[i]->set_raw_inferred_name(func_name); | 83 funcs_to_infer_[i]->set_raw_inferred_name(func_name); |
79 } | 84 } |
80 funcs_to_infer_.Rewind(0); | 85 funcs_to_infer_.Rewind(0); |
81 } | 86 } |
82 | 87 |
83 | 88 |
84 } // namespace internal | 89 } // namespace internal |
85 } // namespace v8 | 90 } // namespace v8 |
OLD | NEW |