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 PreParserIdentifier PreParser::GetSymbol() const { | 41 namespace { |
42 switch (scanner()->current_token()) { | 42 |
| 43 PreParserIdentifier GetSymbolHelper(Scanner* scanner) { |
| 44 switch (scanner->current_token()) { |
43 case Token::ENUM: | 45 case Token::ENUM: |
44 return PreParserIdentifier::Enum(); | 46 return PreParserIdentifier::Enum(); |
45 case Token::AWAIT: | 47 case Token::AWAIT: |
46 return PreParserIdentifier::Await(); | 48 return PreParserIdentifier::Await(); |
47 case Token::FUTURE_STRICT_RESERVED_WORD: | 49 case Token::FUTURE_STRICT_RESERVED_WORD: |
48 return PreParserIdentifier::FutureStrictReserved(); | 50 return PreParserIdentifier::FutureStrictReserved(); |
49 case Token::LET: | 51 case Token::LET: |
50 return PreParserIdentifier::Let(); | 52 return PreParserIdentifier::Let(); |
51 case Token::STATIC: | 53 case Token::STATIC: |
52 return PreParserIdentifier::Static(); | 54 return PreParserIdentifier::Static(); |
53 case Token::YIELD: | 55 case Token::YIELD: |
54 return PreParserIdentifier::Yield(); | 56 return PreParserIdentifier::Yield(); |
55 case Token::ASYNC: | 57 case Token::ASYNC: |
56 return PreParserIdentifier::Async(); | 58 return PreParserIdentifier::Async(); |
57 default: | 59 default: |
58 if (scanner()->UnescapedLiteralMatches("eval", 4)) | 60 if (scanner->UnescapedLiteralMatches("eval", 4)) |
59 return PreParserIdentifier::Eval(); | 61 return PreParserIdentifier::Eval(); |
60 if (scanner()->UnescapedLiteralMatches("arguments", 9)) | 62 if (scanner->UnescapedLiteralMatches("arguments", 9)) |
61 return PreParserIdentifier::Arguments(); | 63 return PreParserIdentifier::Arguments(); |
62 if (scanner()->UnescapedLiteralMatches("undefined", 9)) | 64 if (scanner->UnescapedLiteralMatches("undefined", 9)) |
63 return PreParserIdentifier::Undefined(); | 65 return PreParserIdentifier::Undefined(); |
64 if (scanner()->LiteralMatches("prototype", 9)) | 66 if (scanner->LiteralMatches("prototype", 9)) |
65 return PreParserIdentifier::Prototype(); | 67 return PreParserIdentifier::Prototype(); |
66 if (scanner()->LiteralMatches("constructor", 11)) | 68 if (scanner->LiteralMatches("constructor", 11)) |
67 return PreParserIdentifier::Constructor(); | 69 return PreParserIdentifier::Constructor(); |
68 return PreParserIdentifier::Default(); | 70 return PreParserIdentifier::Default(); |
69 } | 71 } |
70 } | 72 } |
71 | 73 |
| 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 |
72 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 86 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
73 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, |
74 bool parsing_module, ParserRecorder* log, bool may_abort, int* use_counts) { | 88 ParserRecorder* log, bool is_inner_function, bool may_abort, |
| 89 int* use_counts) { |
75 parsing_module_ = parsing_module; | 90 parsing_module_ = parsing_module; |
76 log_ = log; | 91 log_ = log; |
77 use_counts_ = use_counts; | 92 use_counts_ = use_counts; |
78 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 93 DCHECK(!track_unresolved_variables_); |
| 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. |
79 DCHECK_NULL(scope_state_); | 99 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(); | |
86 FunctionState function_state(&function_state_, &scope_state_, function_scope, | 100 FunctionState function_state(&function_state_, &scope_state_, function_scope, |
87 kind); | 101 kind); |
88 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 102 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
89 bool ok = true; | 103 bool ok = true; |
90 int start_position = peek_position(); | 104 int start_position = peek_position(); |
91 LazyParsingResult result = ParseLazyFunctionLiteralBody(may_abort, &ok); | 105 LazyParsingResult result = ParseLazyFunctionLiteralBody(may_abort, &ok); |
92 use_counts_ = nullptr; | 106 use_counts_ = nullptr; |
| 107 track_unresolved_variables_ = false; |
93 if (result == kLazyParsingAborted) { | 108 if (result == kLazyParsingAborted) { |
94 return kPreParseAbort; | 109 return kPreParseAbort; |
95 } else if (stack_overflow()) { | 110 } else if (stack_overflow()) { |
96 return kPreParseStackOverflow; | 111 return kPreParseStackOverflow; |
97 } else if (!ok) { | 112 } else if (!ok) { |
98 ReportUnexpectedToken(scanner()->current_token()); | 113 ReportUnexpectedToken(scanner()->current_token()); |
99 } else { | 114 } else { |
100 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 115 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
101 if (is_strict(scope()->language_mode())) { | 116 if (is_strict(scope()->language_mode())) { |
102 int end_pos = scanner()->location().end_pos; | 117 int end_pos = scanner()->location().end_pos; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 bool accept_IN, int pos, | 348 bool accept_IN, int pos, |
334 bool* ok) { | 349 bool* ok) { |
335 scope()->ForceContextAllocation(); | 350 scope()->ForceContextAllocation(); |
336 | 351 |
337 PreParserExpression return_value = | 352 PreParserExpression return_value = |
338 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); | 353 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); |
339 | 354 |
340 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 355 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
341 } | 356 } |
342 | 357 |
| 358 PreParserExpression PreParser::ExpressionFromIdentifier( |
| 359 PreParserIdentifier name, int start_position, int end_position, |
| 360 InferName infer) { |
| 361 if (track_unresolved_variables_) { |
| 362 AstNodeFactory factory(ast_value_factory()); |
| 363 // Setting the Zone is necessary because zone_ might be the temp Zone, and |
| 364 // AstValueFactory doesn't know about it. |
| 365 factory.set_zone(zone()); |
| 366 DCHECK_NOT_NULL(name.string_); |
| 367 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, |
| 368 NORMAL_VARIABLE); |
| 369 } |
| 370 return PreParserExpression::FromIdentifier(name); |
| 371 } |
| 372 |
343 #undef CHECK_OK | 373 #undef CHECK_OK |
344 #undef CHECK_OK_CUSTOM | 374 #undef CHECK_OK_CUSTOM |
345 | 375 |
346 | 376 |
347 } // namespace internal | 377 } // namespace internal |
348 } // namespace v8 | 378 } // namespace v8 |
OLD | NEW |