Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/parsing/preparser.cc

Issue 2267663002: [parser] Apply an adaptation of the CRTP (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-2263973003-add-const
Patch Set: Rebase w.r.t. PS#2 of 2263973003 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/parsing/parser-base.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 11 matching lines...) Expand all
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
93 PreParserExpression PreParserTraits::ExpressionFromString( 90 PreParserExpression ParserBaseTraits<PreParser>::ExpressionFromString(
94 int pos, Scanner* scanner, PreParserFactory* factory) const { 91 int pos, Scanner* scanner, PreParserFactory* factory) const {
95 if (scanner->UnescapedLiteralMatches("use strict", 10)) { 92 if (scanner->UnescapedLiteralMatches("use strict", 10)) {
96 return PreParserExpression::UseStrictStringLiteral(); 93 return PreParserExpression::UseStrictStringLiteral();
97 } 94 }
98 return PreParserExpression::StringLiteral(); 95 return PreParserExpression::StringLiteral();
99 } 96 }
100 97
101 98
102 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { 99 PreParserExpression ParserBaseTraits<PreParser>::ParseV8Intrinsic(bool* ok) {
103 return pre_parser_->ParseV8Intrinsic(ok); 100 return delegate()->ParseV8Intrinsic(ok);
104 } 101 }
105 102
106 103
107 PreParserExpression PreParserTraits::ParseFunctionLiteral( 104 PreParserExpression ParserBaseTraits<PreParser>::ParseFunctionLiteral(
108 PreParserIdentifier name, Scanner::Location function_name_location, 105 PreParserIdentifier name, Scanner::Location function_name_location,
109 FunctionNameValidity function_name_validity, FunctionKind kind, 106 FunctionNameValidity function_name_validity, FunctionKind kind,
110 int function_token_position, FunctionLiteral::FunctionType type, 107 int function_token_position, FunctionLiteral::FunctionType type,
111 LanguageMode language_mode, bool* ok) { 108 LanguageMode language_mode, bool* ok) {
112 return pre_parser_->ParseFunctionLiteral( 109 return delegate()->ParseFunctionLiteral(
113 name, function_name_location, function_name_validity, kind, 110 name, function_name_location, function_name_validity, kind,
114 function_token_position, type, language_mode, ok); 111 function_token_position, type, language_mode, ok);
115 } 112 }
116 113
117 PreParser::PreParseResult PreParser::PreParseLazyFunction( 114 PreParser::PreParseResult PreParser::PreParseLazyFunction(
118 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, 115 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
119 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, 116 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark,
120 int* use_counts) { 117 int* use_counts) {
121 parsing_module_ = parsing_module; 118 parsing_module_ = parsing_module;
122 log_ = log; 119 log_ = log;
(...skipping 24 matching lines...) Expand all
147 if (is_strict(scope()->language_mode())) { 144 if (is_strict(scope()->language_mode())) {
148 int end_pos = scanner()->location().end_pos; 145 int end_pos = scanner()->location().end_pos;
149 CheckStrictOctalLiteral(start_position, end_pos, &ok); 146 CheckStrictOctalLiteral(start_position, end_pos, &ok);
150 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); 147 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos);
151 if (!ok) return kPreParseSuccess; 148 if (!ok) return kPreParseSuccess;
152 } 149 }
153 } 150 }
154 return kPreParseSuccess; 151 return kPreParseSuccess;
155 } 152 }
156 153
157 PreParserExpression PreParserTraits::ParseClassLiteral( 154 PreParserExpression ParserBaseTraits<PreParser>::ParseClassLiteral(
158 Type::ExpressionClassifier* classifier, PreParserIdentifier name, 155 Type::ExpressionClassifier* classifier, PreParserIdentifier name,
159 Scanner::Location class_name_location, bool name_is_strict_reserved, 156 Scanner::Location class_name_location, bool name_is_strict_reserved,
160 int pos, bool* ok) { 157 int pos, bool* ok) {
161 return pre_parser_->ParseClassLiteral(classifier, name, class_name_location, 158 return delegate()->ParseClassLiteral(classifier, name, class_name_location,
162 name_is_strict_reserved, pos, ok); 159 name_is_strict_reserved, pos, ok);
163 } 160 }
164 161
165 162
166 // Preparsing checks a JavaScript program and emits preparse-data that helps 163 // Preparsing checks a JavaScript program and emits preparse-data that helps
167 // a later parsing to be faster. 164 // a later parsing to be faster.
168 // See preparser-data.h for the data. 165 // See preparser-data.h for the data.
169 166
170 // The PreParser checks that the syntax follows the grammar for JavaScript, 167 // The PreParser checks that the syntax follows the grammar for JavaScript,
171 // and collects some information about the program along the way. 168 // and collects some information about the program along the way.
172 // The grammar check is only performed in order to understand the program 169 // The grammar check is only performed in order to understand the program
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 // do '{' StatementList '}' 1282 // do '{' StatementList '}'
1286 Expect(Token::DO, CHECK_OK); 1283 Expect(Token::DO, CHECK_OK);
1287 Expect(Token::LBRACE, CHECK_OK); 1284 Expect(Token::LBRACE, CHECK_OK);
1288 while (peek() != Token::RBRACE) { 1285 while (peek() != Token::RBRACE) {
1289 ParseStatementListItem(CHECK_OK); 1286 ParseStatementListItem(CHECK_OK);
1290 } 1287 }
1291 Expect(Token::RBRACE, CHECK_OK); 1288 Expect(Token::RBRACE, CHECK_OK);
1292 return PreParserExpression::Default(); 1289 return PreParserExpression::Default();
1293 } 1290 }
1294 1291
1295 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( 1292 void ParserBaseTraits<PreParser>::ParseAsyncArrowSingleExpressionBody(
1296 PreParserStatementList body, bool accept_IN, 1293 PreParserStatementList body, bool accept_IN,
1297 Type::ExpressionClassifier* classifier, int pos, bool* ok) { 1294 Type::ExpressionClassifier* classifier, int pos, bool* ok) {
1298 Scope* scope = pre_parser_->scope(); 1295 Scope* scope = delegate()->scope();
1299 scope->ForceContextAllocation(); 1296 scope->ForceContextAllocation();
1300 1297
1301 PreParserExpression return_value = pre_parser_->ParseAssignmentExpression( 1298 PreParserExpression return_value = delegate()->ParseAssignmentExpression(
1302 accept_IN, classifier, CHECK_OK_CUSTOM(Void)); 1299 accept_IN, classifier, CHECK_OK_CUSTOM(Void));
1303 1300
1304 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); 1301 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
1305 } 1302 }
1306 1303
1307 #undef CHECK_OK 1304 #undef CHECK_OK
1308 #undef CHECK_OK_CUSTOM 1305 #undef CHECK_OK_CUSTOM
1309 1306
1310 1307
1311 } // namespace internal 1308 } // namespace internal
1312 } // namespace v8 1309 } // namespace v8
OLDNEW
« src/parsing/parser-base.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698