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

Side by Side Diff: src/preparser.cc

Issue 1100713002: Factor formal argument parsing into ParserBase (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Avoid DuplicateFinder creation in the full parser 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') | src/scopes.h » ('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 // FormalParameterList :: 929 FormalParameterErrorLocations error_locs;
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();
943 930
944 bool is_rest = false; 931 bool is_rest = false;
945 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || 932 Expect(Token::LPAREN, CHECK_OK);
946 (peek() == Token::RPAREN && 933 int start_position = scanner()->location().beg_pos;
947 arity_restriction != FunctionLiteral::SETTER_ARITY); 934 function_scope->set_start_position(start_position);
948 while (!done) { 935 int num_parameters;
949 bool is_strict_reserved = false; 936 {
950 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); 937 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
951 if (is_rest) { 938 num_parameters = ParseFormalParameterList(&duplicate_finder, &error_locs,
952 Consume(Token::ELLIPSIS); 939 &is_rest, CHECK_OK);
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 } 940 }
984 Expect(Token::RPAREN, CHECK_OK); 941 Expect(Token::RPAREN, CHECK_OK);
942 int formals_end_position = scanner()->location().end_pos;
943
944 CheckArityRestrictions(num_parameters, arity_restriction, start_position,
945 formals_end_position, CHECK_OK);
985 946
986 // See Parser::ParseFunctionLiteral for more information about lazy parsing 947 // See Parser::ParseFunctionLiteral for more information about lazy parsing
987 // and lazy compilation. 948 // and lazy compilation.
988 bool is_lazily_parsed = 949 bool is_lazily_parsed =
989 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); 950 (outer_is_script_scope && allow_lazy() && !parenthesized_function_);
990 parenthesized_function_ = false; 951 parenthesized_function_ = false;
991 952
992 Expect(Token::LBRACE, CHECK_OK); 953 Expect(Token::LBRACE, CHECK_OK);
993 if (is_lazily_parsed) { 954 if (is_lazily_parsed) {
994 ParseLazyFunctionLiteralBody(CHECK_OK); 955 ParseLazyFunctionLiteralBody(CHECK_OK);
995 } else { 956 } else {
996 ParseStatementList(Token::RBRACE, CHECK_OK); 957 ParseStatementList(Token::RBRACE, CHECK_OK);
997 } 958 }
998 Expect(Token::RBRACE, CHECK_OK); 959 Expect(Token::RBRACE, CHECK_OK);
999 960
1000 // Validate name and parameter names. We can do this only after parsing the 961 // Validate name and parameter names. We can do this only after parsing the
1001 // function, since the function can declare itself strict. 962 // function, since the function can declare itself strict.
1002 CheckFunctionName(language_mode(), kind, function_name, 963 CheckFunctionName(language_mode(), kind, function_name,
1003 name_is_strict_reserved, function_name_location, CHECK_OK); 964 name_is_strict_reserved, function_name_location, CHECK_OK);
1004 const bool use_strict_params = is_rest || IsConciseMethod(kind); 965 const bool use_strict_params = is_rest || IsConciseMethod(kind);
1005 CheckFunctionParameterNames(language_mode(), use_strict_params, eval_args_loc, 966 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs,
1006 undefined_loc, dupe_loc, reserved_loc, CHECK_OK); 967 CHECK_OK);
1007 968
1008 if (is_strict(language_mode())) { 969 if (is_strict(language_mode())) {
1009 int end_position = scanner()->location().end_pos; 970 int end_position = scanner()->location().end_pos;
1010 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 971 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
1011 } 972 }
1012 973
1013 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 974 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
1014 if (!function_state.super_call_location().IsValid()) { 975 if (!function_state.super_call_location().IsValid()) {
1015 ReportMessageAt(function_name_location, "strong_super_call_missing", 976 ReportMessageAt(function_name_location, "strong_super_call_missing",
1016 kReferenceError); 977 kReferenceError);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 1067
1107 DCHECK(!spread_pos.IsValid()); 1068 DCHECK(!spread_pos.IsValid());
1108 1069
1109 return Expression::Default(); 1070 return Expression::Default();
1110 } 1071 }
1111 1072
1112 #undef CHECK_OK 1073 #undef CHECK_OK
1113 1074
1114 1075
1115 } } // v8::internal 1076 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698