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

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

Issue 2376293002: [parser] Refactor of ParseFunctionDeclaration (Closed)
Patch Set: The real patch Created 4 years, 2 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
« no previous file with comments | « 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 17 matching lines...) Expand all
28 // CAUTION: This macro appends extra statements after a call, 28 // CAUTION: This macro appends extra statements after a call,
29 // thus it must never be used where only a single statement 29 // thus it must never be used where only a single statement
30 // is correct (e.g. an if statement branch w/o braces)! 30 // is correct (e.g. an if statement branch w/o braces)!
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(Expression::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 namespace {
42 42
43 PreParserIdentifier GetSymbolHelper(Scanner* scanner) { 43 PreParserIdentifier GetSymbolHelper(Scanner* scanner) {
44 switch (scanner->current_token()) { 44 switch (scanner->current_token()) {
45 case Token::ENUM: 45 case Token::ENUM:
46 return PreParserIdentifier::Enum(); 46 return PreParserIdentifier::Enum();
47 case Token::AWAIT: 47 case Token::AWAIT:
48 return PreParserIdentifier::Await(); 48 return PreParserIdentifier::Await();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 // The PreParser checks that the syntax follows the grammar for JavaScript, 129 // The PreParser checks that the syntax follows the grammar for JavaScript,
130 // and collects some information about the program along the way. 130 // and collects some information about the program along the way.
131 // The grammar check is only performed in order to understand the program 131 // The grammar check is only performed in order to understand the program
132 // sufficiently to deduce some information about it, that can be used 132 // sufficiently to deduce some information about it, that can be used
133 // to speed up later parsing. Finding errors is not the goal of pre-parsing, 133 // to speed up later parsing. Finding errors is not the goal of pre-parsing,
134 // rather it is to speed up properly written and correct programs. 134 // rather it is to speed up properly written and correct programs.
135 // That means that contextual checks (like a label being declared where 135 // That means that contextual checks (like a label being declared where
136 // it is used) are generally omitted. 136 // it is used) are generally omitted.
137 137
138 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
139 Consume(Token::FUNCTION);
140 int pos = position();
141 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
142 if (Check(Token::MUL)) {
143 flags |= ParseFunctionFlags::kIsGenerator;
144 if (allow_harmony_restrictive_declarations()) {
145 ReportMessageAt(scanner()->location(),
146 MessageTemplate::kGeneratorInLegacyContext);
147 *ok = false;
148 return Statement::Default();
149 }
150 }
151 // PreParser is not able to parse "export default" yet (since PreParser is
152 // at the moment only used for functions, and it cannot occur
153 // there). TODO(marja): update this when it is.
154 return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
155 }
156
157 // Redefinition of CHECK_OK for parsing expressions.
158 #undef CHECK_OK
159 #define CHECK_OK CHECK_OK_VALUE(Expression::Default())
160
161 PreParser::Expression PreParser::ParseFunctionLiteral( 138 PreParser::Expression PreParser::ParseFunctionLiteral(
162 Identifier function_name, Scanner::Location function_name_location, 139 Identifier function_name, Scanner::Location function_name_location,
163 FunctionNameValidity function_name_validity, FunctionKind kind, 140 FunctionNameValidity function_name_validity, FunctionKind kind,
164 int function_token_pos, FunctionLiteral::FunctionType function_type, 141 int function_token_pos, FunctionLiteral::FunctionType function_type,
165 LanguageMode language_mode, bool* ok) { 142 LanguageMode language_mode, bool* ok) {
166 // Function :: 143 // Function ::
167 // '(' FormalParameterList? ')' '{' FunctionBody '}' 144 // '(' FormalParameterList? ')' '{' FunctionBody '}'
168 145
169 // Parse function body. 146 // Parse function body.
170 PreParserStatementList body; 147 PreParserStatementList body;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 230 }
254 return PreParserExpression::FromIdentifier(name); 231 return PreParserExpression::FromIdentifier(name);
255 } 232 }
256 233
257 #undef CHECK_OK 234 #undef CHECK_OK
258 #undef CHECK_OK_CUSTOM 235 #undef CHECK_OK_CUSTOM
259 236
260 237
261 } // namespace internal 238 } // namespace internal
262 } // namespace v8 239 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698