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 23 matching lines...) Expand all Loading... |
34 #define DUMMY ) // to make indentation work | 34 #define DUMMY ) // to make indentation work |
35 #undef DUMMY | 35 #undef DUMMY |
36 | 36 |
37 // Used in functions where the return type is not ExpressionT. | 37 // Used in functions where the return type is not ExpressionT. |
38 #define CHECK_OK_CUSTOM(x) ok); \ | 38 #define CHECK_OK_CUSTOM(x) ok); \ |
39 if (!*ok) return this->x(); \ | 39 if (!*ok) return this->x(); \ |
40 ((void)0 | 40 ((void)0 |
41 #define DUMMY ) // to make indentation work | 41 #define DUMMY ) // to make indentation work |
42 #undef DUMMY | 42 #undef DUMMY |
43 | 43 |
44 void PreParserTraits::ReportMessageAt(Scanner::Location source_location, | 44 void ParserBaseTraits<PreParser>::ReportMessageAt( |
45 MessageTemplate::Template message, | 45 Scanner::Location source_location, MessageTemplate::Template message, |
46 const char* arg, | 46 const char* arg, ParseErrorType error_type) { |
47 ParseErrorType error_type) { | 47 delegate()->log_->LogMessage(source_location.beg_pos, source_location.end_pos, |
48 pre_parser_->log_->LogMessage(source_location.beg_pos, | 48 message, arg, error_type); |
49 source_location.end_pos, message, arg, | |
50 error_type); | |
51 } | 49 } |
52 | 50 |
53 void PreParserTraits::ReportMessageAt(Scanner::Location source_location, | 51 void ParserBaseTraits<PreParser>::ReportMessageAt( |
54 MessageTemplate::Template message, | 52 Scanner::Location source_location, MessageTemplate::Template message, |
55 const AstRawString* arg, | 53 const AstRawString* arg, ParseErrorType error_type) { |
56 ParseErrorType error_type) { | |
57 UNREACHABLE(); | 54 UNREACHABLE(); |
58 } | 55 } |
59 | 56 |
60 | 57 PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol( |
61 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) const { | 58 Scanner* scanner) const { |
62 switch (scanner->current_token()) { | 59 switch (scanner->current_token()) { |
63 case Token::ENUM: | 60 case Token::ENUM: |
64 return PreParserIdentifier::Enum(); | 61 return PreParserIdentifier::Enum(); |
65 case Token::AWAIT: | 62 case Token::AWAIT: |
66 return PreParserIdentifier::Await(); | 63 return PreParserIdentifier::Await(); |
67 case Token::FUTURE_STRICT_RESERVED_WORD: | 64 case Token::FUTURE_STRICT_RESERVED_WORD: |
68 return PreParserIdentifier::FutureStrictReserved(); | 65 return PreParserIdentifier::FutureStrictReserved(); |
69 case Token::LET: | 66 case Token::LET: |
70 return PreParserIdentifier::Let(); | 67 return PreParserIdentifier::Let(); |
71 case Token::STATIC: | 68 case Token::STATIC: |
(...skipping 10 matching lines...) Expand all Loading... |
82 if (scanner->UnescapedLiteralMatches("undefined", 9)) | 79 if (scanner->UnescapedLiteralMatches("undefined", 9)) |
83 return PreParserIdentifier::Undefined(); | 80 return PreParserIdentifier::Undefined(); |
84 if (scanner->LiteralMatches("prototype", 9)) | 81 if (scanner->LiteralMatches("prototype", 9)) |
85 return PreParserIdentifier::Prototype(); | 82 return PreParserIdentifier::Prototype(); |
86 if (scanner->LiteralMatches("constructor", 11)) | 83 if (scanner->LiteralMatches("constructor", 11)) |
87 return PreParserIdentifier::Constructor(); | 84 return PreParserIdentifier::Constructor(); |
88 return PreParserIdentifier::Default(); | 85 return PreParserIdentifier::Default(); |
89 } | 86 } |
90 } | 87 } |
91 | 88 |
92 | 89 PreParserExpression ParserBaseTraits<PreParser>::ExpressionFromString( |
93 PreParserExpression PreParserTraits::ExpressionFromString( | |
94 int pos, Scanner* scanner, PreParserFactory* factory) const { | 90 int pos, Scanner* scanner, PreParserFactory* factory) const { |
95 if (scanner->UnescapedLiteralMatches("use strict", 10)) { | 91 if (scanner->UnescapedLiteralMatches("use strict", 10)) { |
96 return PreParserExpression::UseStrictStringLiteral(); | 92 return PreParserExpression::UseStrictStringLiteral(); |
97 } | 93 } |
98 return PreParserExpression::StringLiteral(); | 94 return PreParserExpression::StringLiteral(); |
99 } | 95 } |
100 | 96 |
101 | 97 PreParserExpression ParserBaseTraits<PreParser>::ParseV8Intrinsic(bool* ok) { |
102 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 98 return delegate()->ParseV8Intrinsic(ok); |
103 return pre_parser_->ParseV8Intrinsic(ok); | |
104 } | 99 } |
105 | 100 |
106 | 101 PreParserExpression ParserBaseTraits<PreParser>::ParseFunctionLiteral( |
107 PreParserExpression PreParserTraits::ParseFunctionLiteral( | |
108 PreParserIdentifier name, Scanner::Location function_name_location, | 102 PreParserIdentifier name, Scanner::Location function_name_location, |
109 FunctionNameValidity function_name_validity, FunctionKind kind, | 103 FunctionNameValidity function_name_validity, FunctionKind kind, |
110 int function_token_position, FunctionLiteral::FunctionType type, | 104 int function_token_position, FunctionLiteral::FunctionType type, |
111 LanguageMode language_mode, bool* ok) { | 105 LanguageMode language_mode, bool* ok) { |
112 return pre_parser_->ParseFunctionLiteral( | 106 return delegate()->ParseFunctionLiteral( |
113 name, function_name_location, function_name_validity, kind, | 107 name, function_name_location, function_name_validity, kind, |
114 function_token_position, type, language_mode, ok); | 108 function_token_position, type, language_mode, ok); |
115 } | 109 } |
116 | 110 |
117 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 111 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
118 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 112 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
119 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, | 113 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, |
120 int* use_counts) { | 114 int* use_counts) { |
121 parsing_module_ = parsing_module; | 115 parsing_module_ = parsing_module; |
122 log_ = log; | 116 log_ = log; |
(...skipping 24 matching lines...) Expand all Loading... |
147 if (is_strict(scope()->language_mode())) { | 141 if (is_strict(scope()->language_mode())) { |
148 int end_pos = scanner()->location().end_pos; | 142 int end_pos = scanner()->location().end_pos; |
149 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 143 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
150 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); | 144 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); |
151 if (!ok) return kPreParseSuccess; | 145 if (!ok) return kPreParseSuccess; |
152 } | 146 } |
153 } | 147 } |
154 return kPreParseSuccess; | 148 return kPreParseSuccess; |
155 } | 149 } |
156 | 150 |
157 PreParserExpression PreParserTraits::ParseClassLiteral( | 151 PreParserExpression ParserBaseTraits<PreParser>::ParseClassLiteral( |
158 Type::ExpressionClassifier* classifier, PreParserIdentifier name, | 152 Type::ExpressionClassifier* classifier, PreParserIdentifier name, |
159 Scanner::Location class_name_location, bool name_is_strict_reserved, | 153 Scanner::Location class_name_location, bool name_is_strict_reserved, |
160 int pos, bool* ok) { | 154 int pos, bool* ok) { |
161 return pre_parser_->ParseClassLiteral(classifier, name, class_name_location, | 155 return delegate()->ParseClassLiteral(classifier, name, class_name_location, |
162 name_is_strict_reserved, pos, ok); | 156 name_is_strict_reserved, pos, ok); |
163 } | 157 } |
164 | 158 |
165 | 159 |
166 // Preparsing checks a JavaScript program and emits preparse-data that helps | 160 // Preparsing checks a JavaScript program and emits preparse-data that helps |
167 // a later parsing to be faster. | 161 // a later parsing to be faster. |
168 // See preparser-data.h for the data. | 162 // See preparser-data.h for the data. |
169 | 163 |
170 // The PreParser checks that the syntax follows the grammar for JavaScript, | 164 // The PreParser checks that the syntax follows the grammar for JavaScript, |
171 // and collects some information about the program along the way. | 165 // and collects some information about the program along the way. |
172 // The grammar check is only performed in order to understand the program | 166 // The grammar check is only performed in order to understand the program |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 // do '{' StatementList '}' | 1267 // do '{' StatementList '}' |
1274 Expect(Token::DO, CHECK_OK); | 1268 Expect(Token::DO, CHECK_OK); |
1275 Expect(Token::LBRACE, CHECK_OK); | 1269 Expect(Token::LBRACE, CHECK_OK); |
1276 while (peek() != Token::RBRACE) { | 1270 while (peek() != Token::RBRACE) { |
1277 ParseStatementListItem(CHECK_OK); | 1271 ParseStatementListItem(CHECK_OK); |
1278 } | 1272 } |
1279 Expect(Token::RBRACE, CHECK_OK); | 1273 Expect(Token::RBRACE, CHECK_OK); |
1280 return PreParserExpression::Default(); | 1274 return PreParserExpression::Default(); |
1281 } | 1275 } |
1282 | 1276 |
1283 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( | 1277 void ParserBaseTraits<PreParser>::ParseAsyncArrowSingleExpressionBody( |
1284 PreParserStatementList body, bool accept_IN, | 1278 PreParserStatementList body, bool accept_IN, |
1285 Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 1279 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
1286 Scope* scope = pre_parser_->scope(); | 1280 Scope* scope = delegate()->scope(); |
1287 scope->ForceContextAllocation(); | 1281 scope->ForceContextAllocation(); |
1288 | 1282 |
1289 PreParserExpression return_value = pre_parser_->ParseAssignmentExpression( | 1283 PreParserExpression return_value = delegate()->ParseAssignmentExpression( |
1290 accept_IN, classifier, CHECK_OK_CUSTOM(Void)); | 1284 accept_IN, classifier, CHECK_OK_CUSTOM(Void)); |
1291 | 1285 |
1292 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 1286 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
1293 } | 1287 } |
1294 | 1288 |
1295 #undef CHECK_OK | 1289 #undef CHECK_OK |
1296 #undef CHECK_OK_CUSTOM | 1290 #undef CHECK_OK_CUSTOM |
1297 | 1291 |
1298 | 1292 |
1299 } // namespace internal | 1293 } // namespace internal |
1300 } // namespace v8 | 1294 } // namespace v8 |
OLD | NEW |