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

Side by Side Diff: src/preparser.cc

Issue 190853011: Parser & preparser unification: make the ParseFunctionLiteral APIs the same. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 341
342 342
343 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { 343 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
344 // FunctionDeclaration :: 344 // FunctionDeclaration ::
345 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 345 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
346 // GeneratorDeclaration :: 346 // GeneratorDeclaration ::
347 // 'function' '*' Identifier '(' FormalParameterListopt ')' 347 // 'function' '*' Identifier '(' FormalParameterListopt ')'
348 // '{' FunctionBody '}' 348 // '{' FunctionBody '}'
349 Expect(Token::FUNCTION, CHECK_OK); 349 Expect(Token::FUNCTION, CHECK_OK);
350 350 int pos = position();
351 bool is_generator = allow_generators() && Check(Token::MUL); 351 bool is_generator = allow_generators() && Check(Token::MUL);
352 bool is_strict_reserved = false; 352 bool is_strict_reserved = false;
353 Identifier name = ParseIdentifierOrStrictReservedWord( 353 Identifier name = ParseIdentifierOrStrictReservedWord(
354 &is_strict_reserved, CHECK_OK); 354 &is_strict_reserved, CHECK_OK);
355 ParseFunctionLiteral(name, 355 ParseFunctionLiteral(name,
356 scanner()->location(), 356 scanner()->location(),
357 is_strict_reserved, 357 is_strict_reserved,
358 is_generator, 358 is_generator,
359 pos,
360 FunctionLiteral::DECLARATION,
359 CHECK_OK); 361 CHECK_OK);
360 return Statement::FunctionDeclaration(); 362 return Statement::FunctionDeclaration();
361 } 363 }
362 364
363 365
364 PreParser::Statement PreParser::ParseBlock(bool* ok) { 366 PreParser::Statement PreParser::ParseBlock(bool* ok) {
365 // Block :: 367 // Block ::
366 // '{' Statement* '}' 368 // '{' Statement* '}'
367 369
368 // Note that a Block does not introduce a new execution scope! 370 // Note that a Block does not introduce a new execution scope!
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 // ('[' Expression ']' | '.' Identifier | Arguments)* 1058 // ('[' Expression ']' | '.' Identifier | Arguments)*
1057 1059
1058 // The '[' Expression ']' and '.' Identifier parts are parsed by 1060 // The '[' Expression ']' and '.' Identifier parts are parsed by
1059 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the 1061 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the
1060 // caller. 1062 // caller.
1061 1063
1062 // Parse the initial primary or function expression. 1064 // Parse the initial primary or function expression.
1063 Expression result = Expression::Default(); 1065 Expression result = Expression::Default();
1064 if (peek() == Token::FUNCTION) { 1066 if (peek() == Token::FUNCTION) {
1065 Consume(Token::FUNCTION); 1067 Consume(Token::FUNCTION);
1066 1068 int function_token_position = position();
1067 bool is_generator = allow_generators() && Check(Token::MUL); 1069 bool is_generator = allow_generators() && Check(Token::MUL);
1068 Identifier name = Identifier::Default(); 1070 Identifier name = Identifier::Default();
1069 bool is_strict_reserved_name = false; 1071 bool is_strict_reserved_name = false;
1070 Scanner::Location function_name_location = Scanner::Location::invalid(); 1072 Scanner::Location function_name_location = Scanner::Location::invalid();
1073 FunctionLiteral::FunctionType function_type =
1074 FunctionLiteral::ANONYMOUS_EXPRESSION;
1071 if (peek_any_identifier()) { 1075 if (peek_any_identifier()) {
1072 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1076 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1073 CHECK_OK); 1077 CHECK_OK);
1074 function_name_location = scanner()->location(); 1078 function_name_location = scanner()->location();
1079 function_type = FunctionLiteral::NAMED_EXPRESSION;
1075 } 1080 }
1076 result = ParseFunctionLiteral(name, 1081 result = ParseFunctionLiteral(name,
1077 function_name_location, 1082 function_name_location,
1078 is_strict_reserved_name, 1083 is_strict_reserved_name,
1079 is_generator, 1084 is_generator,
1085 function_token_position,
1086 function_type,
1080 CHECK_OK); 1087 CHECK_OK);
1081 } else { 1088 } else {
1082 result = ParsePrimaryExpression(CHECK_OK); 1089 result = ParsePrimaryExpression(CHECK_OK);
1083 } 1090 }
1084 result = ParseMemberExpressionContinuation(result, CHECK_OK); 1091 result = ParseMemberExpressionContinuation(result, CHECK_OK);
1085 return result; 1092 return result;
1086 } 1093 }
1087 1094
1088 1095
1089 PreParser::Expression PreParser::ParseMemberExpressionContinuation( 1096 PreParser::Expression PreParser::ParseMemberExpressionContinuation(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 return Expression::Default(); 1162 return Expression::Default();
1156 } 1163 }
1157 // Validate the property 1164 // Validate the property
1158 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; 1165 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty;
1159 checker.CheckProperty(next, type, CHECK_OK); 1166 checker.CheckProperty(next, type, CHECK_OK);
1160 PreParserIdentifier name = GetSymbol(scanner()); 1167 PreParserIdentifier name = GetSymbol(scanner());
1161 ParseFunctionLiteral(name, 1168 ParseFunctionLiteral(name,
1162 scanner()->location(), 1169 scanner()->location(),
1163 false, // reserved words are allowed here 1170 false, // reserved words are allowed here
1164 false, // not a generator 1171 false, // not a generator
1172 RelocInfo::kNoPosition,
1173 FunctionLiteral::ANONYMOUS_EXPRESSION,
1165 CHECK_OK); 1174 CHECK_OK);
1166 if (peek() != Token::RBRACE) { 1175 if (peek() != Token::RBRACE) {
1167 Expect(Token::COMMA, CHECK_OK); 1176 Expect(Token::COMMA, CHECK_OK);
1168 } 1177 }
1169 continue; // restart the while 1178 continue; // restart the while
1170 } 1179 }
1171 break; 1180 break;
1172 } 1181 }
1173 case Token::STRING: 1182 case Token::STRING:
1174 Consume(next); 1183 Consume(next);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 } 1234 }
1226 Expect(Token::RPAREN, ok); 1235 Expect(Token::RPAREN, ok);
1227 return argc; 1236 return argc;
1228 } 1237 }
1229 1238
1230 PreParser::Expression PreParser::ParseFunctionLiteral( 1239 PreParser::Expression PreParser::ParseFunctionLiteral(
1231 Identifier function_name, 1240 Identifier function_name,
1232 Scanner::Location function_name_location, 1241 Scanner::Location function_name_location,
1233 bool name_is_strict_reserved, 1242 bool name_is_strict_reserved,
1234 bool is_generator, 1243 bool is_generator,
1244 int function_token_pos,
1245 FunctionLiteral::FunctionType function_type,
1235 bool* ok) { 1246 bool* ok) {
1236 // Function :: 1247 // Function ::
1237 // '(' FormalParameterList? ')' '{' FunctionBody '}' 1248 // '(' FormalParameterList? ')' '{' FunctionBody '}'
1238 1249
1239 // Parse function body. 1250 // Parse function body.
1240 ScopeType outer_scope_type = scope_->type(); 1251 ScopeType outer_scope_type = scope_->type();
1241 bool inside_with = scope_->inside_with(); 1252 bool inside_with = scope_->inside_with();
1242 PreParserScope function_scope(scope_, FUNCTION_SCOPE); 1253 PreParserScope function_scope(scope_, FUNCTION_SCOPE);
1243 FunctionState function_state(&function_state_, &scope_, &function_scope); 1254 FunctionState function_state(&function_state_, &scope_, &function_scope);
1244 function_state.set_is_generator(is_generator); 1255 function_state.set_is_generator(is_generator);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 int identifier_pos = position(); 1388 int identifier_pos = position();
1378 if (scanner()->is_literal_ascii()) { 1389 if (scanner()->is_literal_ascii()) {
1379 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); 1390 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string());
1380 } else { 1391 } else {
1381 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); 1392 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string());
1382 } 1393 }
1383 } 1394 }
1384 1395
1385 1396
1386 } } // v8::internal 1397 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698