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

Side by Side Diff: src/preparser.cc

Issue 1094653002: Revert "Factor formal argument parsing into ParserBase" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 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/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | 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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 919 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
920 // Function :: 920 // Function ::
921 // '(' FormalParameterList? ')' '{' FunctionBody '}' 921 // '(' FormalParameterList? ')' '{' FunctionBody '}'
922 922
923 // Parse function body. 923 // Parse function body.
924 bool outer_is_script_scope = scope_->is_script_scope(); 924 bool outer_is_script_scope = scope_->is_script_scope();
925 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); 925 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE);
926 PreParserFactory factory(NULL); 926 PreParserFactory factory(NULL);
927 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 927 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
928 &factory); 928 &factory);
929 FormalParameterErrorLocations error_locs; 929 // FormalParameterList ::
930 // '(' (Identifier)*[','] ')'
931 Expect(Token::LPAREN, CHECK_OK);
932 int start_position = position();
933 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
934 // We don't yet know if the function will be strict, so we cannot yet produce
935 // errors for parameter names or duplicates. However, we remember the
936 // locations of these errors if they occur and produce the errors later.
937 Scanner::Location eval_args_loc = Scanner::Location::invalid();
938 Scanner::Location dupe_loc = Scanner::Location::invalid();
939 Scanner::Location reserved_loc = Scanner::Location::invalid();
940
941 // Similarly for strong mode.
942 Scanner::Location undefined_loc = Scanner::Location::invalid();
930 943
931 bool is_rest = false; 944 bool is_rest = false;
932 Expect(Token::LPAREN, CHECK_OK); 945 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
933 int start_position = scanner()->location().beg_pos; 946 (peek() == Token::RPAREN &&
934 PreParserFormalParameterList params = 947 arity_restriction != FunctionLiteral::SETTER_ARITY);
935 ParseFormalParameterList(&error_locs, &is_rest, CHECK_OK); 948 while (!done) {
949 bool is_strict_reserved = false;
950 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params();
951 if (is_rest) {
952 Consume(Token::ELLIPSIS);
953 }
954
955 Identifier param_name =
956 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
957 if (!eval_args_loc.IsValid() && param_name.IsEvalOrArguments()) {
958 eval_args_loc = scanner()->location();
959 }
960 if (!undefined_loc.IsValid() && param_name.IsUndefined()) {
961 undefined_loc = scanner()->location();
962 }
963 if (!reserved_loc.IsValid() && is_strict_reserved) {
964 reserved_loc = scanner()->location();
965 }
966
967 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1);
968
969 if (!dupe_loc.IsValid() && prev_value != 0) {
970 dupe_loc = scanner()->location();
971 }
972
973 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
974 done = (peek() == Token::RPAREN);
975 if (!done) {
976 if (is_rest) {
977 ReportMessageAt(scanner()->peek_location(), "param_after_rest");
978 *ok = false;
979 return Expression::Default();
980 }
981 Expect(Token::COMMA, CHECK_OK);
982 }
983 }
936 Expect(Token::RPAREN, CHECK_OK); 984 Expect(Token::RPAREN, CHECK_OK);
937 int formals_end_position = scanner()->location().end_pos;
938
939 CheckArityRestrictions(params->length(), arity_restriction, start_position,
940 formals_end_position, ok);
941 if (!*ok) return Expression::Default();
942 985
943 // See Parser::ParseFunctionLiteral for more information about lazy parsing 986 // See Parser::ParseFunctionLiteral for more information about lazy parsing
944 // and lazy compilation. 987 // and lazy compilation.
945 bool is_lazily_parsed = 988 bool is_lazily_parsed =
946 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); 989 (outer_is_script_scope && allow_lazy() && !parenthesized_function_);
947 parenthesized_function_ = false; 990 parenthesized_function_ = false;
948 991
949 Expect(Token::LBRACE, CHECK_OK); 992 Expect(Token::LBRACE, CHECK_OK);
950 if (is_lazily_parsed) { 993 if (is_lazily_parsed) {
951 ParseLazyFunctionLiteralBody(CHECK_OK); 994 ParseLazyFunctionLiteralBody(CHECK_OK);
952 } else { 995 } else {
953 ParseStatementList(Token::RBRACE, CHECK_OK); 996 ParseStatementList(Token::RBRACE, CHECK_OK);
954 } 997 }
955 Expect(Token::RBRACE, CHECK_OK); 998 Expect(Token::RBRACE, CHECK_OK);
956 999
957 // Validate name and parameter names. We can do this only after parsing the 1000 // Validate name and parameter names. We can do this only after parsing the
958 // function, since the function can declare itself strict. 1001 // function, since the function can declare itself strict.
959 CheckFunctionName(language_mode(), kind, function_name, 1002 CheckFunctionName(language_mode(), kind, function_name,
960 name_is_strict_reserved, function_name_location, CHECK_OK); 1003 name_is_strict_reserved, function_name_location, CHECK_OK);
961 const bool use_strict_params = is_rest || IsConciseMethod(kind); 1004 const bool use_strict_params = is_rest || IsConciseMethod(kind);
962 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs, 1005 CheckFunctionParameterNames(language_mode(), use_strict_params, eval_args_loc,
963 CHECK_OK); 1006 undefined_loc, dupe_loc, reserved_loc, CHECK_OK);
964 1007
965 if (is_strict(language_mode())) { 1008 if (is_strict(language_mode())) {
966 int end_position = scanner()->location().end_pos; 1009 int end_position = scanner()->location().end_pos;
967 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 1010 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
968 } 1011 }
969 1012
970 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 1013 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
971 if (!function_state.super_call_location().IsValid()) { 1014 if (!function_state.super_call_location().IsValid()) {
972 ReportMessageAt(function_name_location, "strong_super_call_missing", 1015 ReportMessageAt(function_name_location, "strong_super_call_missing",
973 kReferenceError); 1016 kReferenceError);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1106
1064 DCHECK(!spread_pos.IsValid()); 1107 DCHECK(!spread_pos.IsValid());
1065 1108
1066 return Expression::Default(); 1109 return Expression::Default();
1067 } 1110 }
1068 1111
1069 #undef CHECK_OK 1112 #undef CHECK_OK
1070 1113
1071 1114
1072 } } // v8::internal 1115 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698