5 #include "src/parsing/func-name-inferrer.h" 7 #include "src/ast/ast-value-factory.h" 8 #include "src/ast/ast.h" 9 #include "src/objects-inl.h" 14 FuncNameInferrer::FuncNameInferrer(AstValueFactory* ast_value_factory)
15 : ast_value_factory_(ast_value_factory) {}
17 void FuncNameInferrer::PushEnclosingName(
const AstRawString* name) {
21 if (!name->IsEmpty() && unibrow::Uppercase::Is(name->FirstCharacter())) {
22 names_stack_.push_back(Name(name, kEnclosingConstructorName));
27 void FuncNameInferrer::PushLiteralName(
const AstRawString* name) {
28 if (IsOpen() && name != ast_value_factory_->prototype_string()) {
29 names_stack_.push_back(Name(name, kLiteralName));
34 void FuncNameInferrer::PushVariableName(
const AstRawString* name) {
35 if (IsOpen() && name != ast_value_factory_->dot_result_string()) {
36 names_stack_.push_back(Name(name, kVariableName));
40 void FuncNameInferrer::RemoveAsyncKeywordFromEnd() {
42 CHECK_GT(names_stack_.size(), 0);
43 CHECK(names_stack_.back().name()->IsOneByteEqualTo(
"async"));
44 names_stack_.pop_back();
48 const AstConsString* FuncNameInferrer::MakeNameFromStack() {
49 if (names_stack_.size() == 0) {
50 return ast_value_factory_->empty_cons_string();
52 AstConsString* result = ast_value_factory_->NewConsString();
53 auto it = names_stack_.begin();
54 while (it != names_stack_.end()) {
58 if (it != names_stack_.end() && current->type() == kVariableName &&
59 it->type() == kVariableName) {
63 Zone* zone = ast_value_factory_->zone();
64 if (!result->IsEmpty()) {
65 result->AddString(zone, ast_value_factory_->dot_string());
67 result->AddString(zone, current->name());
72 void FuncNameInferrer::InferFunctionsNames() {
73 const AstConsString* func_name = MakeNameFromStack();
74 for (FunctionLiteral* func : funcs_to_infer_) {
75 func->set_raw_inferred_name(func_name);
77 funcs_to_infer_.resize(0);