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_scoepe are ignored by the | |
adamk
2016/09/15 18:20:09
Typo: function_scoepe
marja
2016/09/16 08:38:16
Done.
| |
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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 bool accept_IN, int pos, | 548 bool accept_IN, int pos, |
534 bool* ok) { | 549 bool* ok) { |
535 scope()->ForceContextAllocation(); | 550 scope()->ForceContextAllocation(); |
536 | 551 |
537 PreParserExpression return_value = | 552 PreParserExpression return_value = |
538 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); | 553 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); |
539 | 554 |
540 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 555 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
541 } | 556 } |
542 | 557 |
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 factory.set_zone(zone()); | |
adamk
2016/09/15 18:20:08
Why is this necessary? AstNodeFactory's constructo
marja
2016/09/16 08:38:16
Added a comment:
// Setting the Zone is necessary
| |
564 DCHECK_NOT_NULL(name.string_); | |
565 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, | |
566 NORMAL_VARIABLE); | |
567 } | |
568 return PreParserExpression::FromIdentifier(name); | |
569 } | |
570 | |
543 #undef CHECK_OK | 571 #undef CHECK_OK |
544 #undef CHECK_OK_CUSTOM | 572 #undef CHECK_OK_CUSTOM |
545 | 573 |
546 | 574 |
547 } // namespace internal | 575 } // namespace internal |
548 } // namespace v8 | 576 } // namespace v8 |
OLD | NEW |