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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 #define CHECK_OK_VALUE(x) ok); \ | 32 #define CHECK_OK_VALUE(x) ok); \ |
33 if (!*ok) return x; \ | 33 if (!*ok) return x; \ |
34 ((void)0 | 34 ((void)0 |
35 #define DUMMY ) // to make indentation work | 35 #define DUMMY ) // to make indentation work |
36 #undef DUMMY | 36 #undef DUMMY |
37 | 37 |
38 #define CHECK_OK CHECK_OK_VALUE(Statement::Default()) | 38 #define CHECK_OK CHECK_OK_VALUE(Statement::Default()) |
39 #define CHECK_OK_VOID CHECK_OK_VALUE(this->Void()) | 39 #define CHECK_OK_VOID CHECK_OK_VALUE(this->Void()) |
40 | 40 |
41 namespace { | 41 PreParserIdentifier PreParser::GetSymbol() const { |
42 | 42 switch (scanner()->current_token()) { |
43 PreParserIdentifier GetSymbolHelper(Scanner* scanner) { | |
44 switch (scanner->current_token()) { | |
45 case Token::ENUM: | 43 case Token::ENUM: |
46 return PreParserIdentifier::Enum(); | 44 return PreParserIdentifier::Enum(); |
47 case Token::AWAIT: | 45 case Token::AWAIT: |
48 return PreParserIdentifier::Await(); | 46 return PreParserIdentifier::Await(); |
49 case Token::FUTURE_STRICT_RESERVED_WORD: | 47 case Token::FUTURE_STRICT_RESERVED_WORD: |
50 return PreParserIdentifier::FutureStrictReserved(); | 48 return PreParserIdentifier::FutureStrictReserved(); |
51 case Token::LET: | 49 case Token::LET: |
52 return PreParserIdentifier::Let(); | 50 return PreParserIdentifier::Let(); |
53 case Token::STATIC: | 51 case Token::STATIC: |
54 return PreParserIdentifier::Static(); | 52 return PreParserIdentifier::Static(); |
55 case Token::YIELD: | 53 case Token::YIELD: |
56 return PreParserIdentifier::Yield(); | 54 return PreParserIdentifier::Yield(); |
57 case Token::ASYNC: | 55 case Token::ASYNC: |
58 return PreParserIdentifier::Async(); | 56 return PreParserIdentifier::Async(); |
59 default: | 57 default: |
60 if (scanner->UnescapedLiteralMatches("eval", 4)) | 58 if (scanner()->UnescapedLiteralMatches("eval", 4)) |
61 return PreParserIdentifier::Eval(); | 59 return PreParserIdentifier::Eval(); |
62 if (scanner->UnescapedLiteralMatches("arguments", 9)) | 60 if (scanner()->UnescapedLiteralMatches("arguments", 9)) |
63 return PreParserIdentifier::Arguments(); | 61 return PreParserIdentifier::Arguments(); |
64 if (scanner->UnescapedLiteralMatches("undefined", 9)) | 62 if (scanner()->UnescapedLiteralMatches("undefined", 9)) |
65 return PreParserIdentifier::Undefined(); | 63 return PreParserIdentifier::Undefined(); |
66 if (scanner->LiteralMatches("prototype", 9)) | 64 if (scanner()->LiteralMatches("prototype", 9)) |
67 return PreParserIdentifier::Prototype(); | 65 return PreParserIdentifier::Prototype(); |
68 if (scanner->LiteralMatches("constructor", 11)) | 66 if (scanner()->LiteralMatches("constructor", 11)) |
69 return PreParserIdentifier::Constructor(); | 67 return PreParserIdentifier::Constructor(); |
70 return PreParserIdentifier::Default(); | 68 return PreParserIdentifier::Default(); |
71 } | 69 } |
72 } | 70 } |
73 | 71 |
74 } // unnamed namespace | |
75 | |
76 PreParserIdentifier PreParser::GetSymbol() const { | |
77 PreParserIdentifier symbol = GetSymbolHelper(scanner()); | |
78 if (track_unresolved_variables_) { | |
79 const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory()); | |
80 DCHECK_NOT_NULL(result); | |
81 symbol.string_ = result; | |
82 } | |
83 return symbol; | |
84 } | |
85 | |
86 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 72 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, | 73 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
88 ParserRecorder* log, bool is_inner_function, bool may_abort, | 74 bool parsing_module, ParserRecorder* log, bool may_abort, int* use_counts) { |
89 int* use_counts) { | |
90 parsing_module_ = parsing_module; | 75 parsing_module_ = parsing_module; |
91 log_ = log; | 76 log_ = log; |
92 use_counts_ = use_counts; | 77 use_counts_ = use_counts; |
93 DCHECK(!track_unresolved_variables_); | 78 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
94 track_unresolved_variables_ = is_inner_function; | |
95 | |
96 // The caller passes the function_scope which is not yet inserted into the | |
97 // scope_state_. All scopes above the function_scope are ignored by the | |
98 // PreParser. | |
99 DCHECK_NULL(scope_state_); | 79 DCHECK_NULL(scope_state_); |
| 80 DeclarationScope* top_scope = NewScriptScope(); |
| 81 FunctionState top_state(&function_state_, &scope_state_, top_scope, |
| 82 kNormalFunction); |
| 83 scope()->SetLanguageMode(language_mode); |
| 84 DeclarationScope* function_scope = NewFunctionScope(kind); |
| 85 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); |
100 FunctionState function_state(&function_state_, &scope_state_, function_scope, | 86 FunctionState function_state(&function_state_, &scope_state_, function_scope, |
101 kind); | 87 kind); |
102 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 88 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
103 bool ok = true; | 89 bool ok = true; |
104 int start_position = peek_position(); | 90 int start_position = peek_position(); |
105 LazyParsingResult result = ParseLazyFunctionLiteralBody(may_abort, &ok); | 91 LazyParsingResult result = ParseLazyFunctionLiteralBody(may_abort, &ok); |
106 use_counts_ = nullptr; | 92 use_counts_ = nullptr; |
107 track_unresolved_variables_ = false; | |
108 if (result == kLazyParsingAborted) { | 93 if (result == kLazyParsingAborted) { |
109 return kPreParseAbort; | 94 return kPreParseAbort; |
110 } else if (stack_overflow()) { | 95 } else if (stack_overflow()) { |
111 return kPreParseStackOverflow; | 96 return kPreParseStackOverflow; |
112 } else if (!ok) { | 97 } else if (!ok) { |
113 ReportUnexpectedToken(scanner()->current_token()); | 98 ReportUnexpectedToken(scanner()->current_token()); |
114 } else { | 99 } else { |
115 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 100 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
116 if (is_strict(scope()->language_mode())) { | 101 if (is_strict(scope()->language_mode())) { |
117 int end_pos = scanner()->location().end_pos; | 102 int end_pos = scanner()->location().end_pos; |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 bool accept_IN, int pos, | 533 bool accept_IN, int pos, |
549 bool* ok) { | 534 bool* ok) { |
550 scope()->ForceContextAllocation(); | 535 scope()->ForceContextAllocation(); |
551 | 536 |
552 PreParserExpression return_value = | 537 PreParserExpression return_value = |
553 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); | 538 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); |
554 | 539 |
555 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 540 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
556 } | 541 } |
557 | 542 |
558 PreParserExpression PreParser::ExpressionFromIdentifier( | |
559 PreParserIdentifier name, int start_position, int end_position, | |
560 InferName infer) { | |
561 if (track_unresolved_variables_) { | |
562 AstNodeFactory factory(ast_value_factory()); | |
563 // Setting the Zone is necessary because zone_ might be the temp Zone, and | |
564 // AstValueFactory doesn't know about it. | |
565 factory.set_zone(zone()); | |
566 DCHECK_NOT_NULL(name.string_); | |
567 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, | |
568 NORMAL_VARIABLE); | |
569 } | |
570 return PreParserExpression::FromIdentifier(name); | |
571 } | |
572 | |
573 #undef CHECK_OK | 543 #undef CHECK_OK |
574 #undef CHECK_OK_CUSTOM | 544 #undef CHECK_OK_CUSTOM |
575 | 545 |
576 | 546 |
577 } // namespace internal | 547 } // namespace internal |
578 } // namespace v8 | 548 } // namespace v8 |
OLD | NEW |