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

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

Issue 2279773002: [parser] Clean up type definitions (Closed)
Patch Set: 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
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 3847 matching lines...) Expand 10 before | Expand all | Expand 10 after
3858 CHECK_OK_VOID); 3858 CHECK_OK_VOID);
3859 3859
3860 scope_snapshot.Reparent(parameters->scope); 3860 scope_snapshot.Reparent(parameters->scope);
3861 3861
3862 if (parameters->Arity() > Code::kMaxArguments) { 3862 if (parameters->Arity() > Code::kMaxArguments) {
3863 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); 3863 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
3864 *ok = false; 3864 *ok = false;
3865 return; 3865 return;
3866 } 3866 }
3867 3867
3868 Type::ExpressionClassifier classifier(this); 3868 ExpressionClassifier classifier(this);
3869 if (!parameters->is_simple) { 3869 if (!parameters->is_simple) {
3870 classifier.RecordNonSimpleParameter(); 3870 classifier.RecordNonSimpleParameter();
3871 } 3871 }
3872 for (int i = 0; i < parameters->Arity(); ++i) { 3872 for (int i = 0; i < parameters->Arity(); ++i) {
3873 auto parameter = parameters->at(i); 3873 auto parameter = parameters->at(i);
3874 DeclareFormalParameter(parameters->scope, parameter, &classifier); 3874 DeclareFormalParameter(parameters->scope, parameter, &classifier);
3875 if (!duplicate_loc->IsValid()) { 3875 if (!duplicate_loc->IsValid()) {
3876 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3876 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3877 } 3877 }
3878 } 3878 }
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
5252 } else { 5252 } else {
5253 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5253 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5254 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5254 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5255 raw_string->length()); 5255 raw_string->length());
5256 } 5256 }
5257 } 5257 }
5258 5258
5259 return running_hash; 5259 return running_hash;
5260 } 5260 }
5261 5261
5262 5262 ZoneList<Expression*>* Parser::PrepareSpreadArguments(
5263 ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments( 5263 ZoneList<Expression*>* list) {
5264 ZoneList<v8::internal::Expression*>* list) { 5264 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
5265 ZoneList<v8::internal::Expression*>* args =
5266 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5267 if (list->length() == 1) { 5265 if (list->length() == 1) {
5268 // Spread-call with single spread argument produces an InternalArray 5266 // Spread-call with single spread argument produces an InternalArray
5269 // containing the values from the array. 5267 // containing the values from the array.
5270 // 5268 //
5271 // Function is called or constructed with the produced array of arguments 5269 // Function is called or constructed with the produced array of arguments
5272 // 5270 //
5273 // EG: Apply(Func, Spread(spread0)) 5271 // EG: Apply(Func, Spread(spread0))
5274 ZoneList<Expression*>* spread_list = 5272 ZoneList<Expression*>* spread_list =
5275 new (zone()) ZoneList<Expression*>(0, zone()); 5273 new (zone()) ZoneList<Expression*>(0, zone());
5276 spread_list->Add(list->at(0)->AsSpread()->expression(), zone()); 5274 spread_list->Add(list->at(0)->AsSpread()->expression(), zone());
5277 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, 5275 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX,
5278 spread_list, kNoSourcePosition), 5276 spread_list, kNoSourcePosition),
5279 zone()); 5277 zone());
5280 return args; 5278 return args;
5281 } else { 5279 } else {
5282 // Spread-call with multiple arguments produces array literals for each 5280 // Spread-call with multiple arguments produces array literals for each
5283 // sequences of unspread arguments, and converts each spread iterable to 5281 // sequences of unspread arguments, and converts each spread iterable to
5284 // an Internal array. Finally, all of these produced arrays are flattened 5282 // an Internal array. Finally, all of these produced arrays are flattened
5285 // into a single InternalArray, containing the arguments for the call. 5283 // into a single InternalArray, containing the arguments for the call.
5286 // 5284 //
5287 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0), 5285 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0),
5288 // Spread(spread1), [unspread2, unspread3])) 5286 // Spread(spread1), [unspread2, unspread3]))
5289 int i = 0; 5287 int i = 0;
5290 int n = list->length(); 5288 int n = list->length();
5291 while (i < n) { 5289 while (i < n) {
5292 if (!list->at(i)->IsSpread()) { 5290 if (!list->at(i)->IsSpread()) {
5293 ZoneList<v8::internal::Expression*>* unspread = 5291 ZoneList<Expression*>* unspread =
5294 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); 5292 new (zone()) ZoneList<Expression*>(1, zone());
5295 5293
5296 // Push array of unspread parameters 5294 // Push array of unspread parameters
5297 while (i < n && !list->at(i)->IsSpread()) { 5295 while (i < n && !list->at(i)->IsSpread()) {
5298 unspread->Add(list->at(i++), zone()); 5296 unspread->Add(list->at(i++), zone());
5299 } 5297 }
5300 int literal_index = function_state_->NextMaterializedLiteralIndex(); 5298 int literal_index = function_state_->NextMaterializedLiteralIndex();
5301 args->Add(factory()->NewArrayLiteral(unspread, literal_index, 5299 args->Add(factory()->NewArrayLiteral(unspread, literal_index,
5302 kNoSourcePosition), 5300 kNoSourcePosition),
5303 zone()); 5301 zone());
5304 5302
5305 if (i == n) break; 5303 if (i == n) break;
5306 } 5304 }
5307 5305
5308 // Push eagerly spread argument 5306 // Push eagerly spread argument
5309 ZoneList<v8::internal::Expression*>* spread_list = 5307 ZoneList<Expression*>* spread_list =
5310 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); 5308 new (zone()) ZoneList<Expression*>(1, zone());
5311 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); 5309 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone());
5312 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, 5310 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX,
5313 spread_list, kNoSourcePosition), 5311 spread_list, kNoSourcePosition),
5314 zone()); 5312 zone());
5315 } 5313 }
5316 5314
5317 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); 5315 list = new (zone()) ZoneList<Expression*>(1, zone());
5318 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args, 5316 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args,
5319 kNoSourcePosition), 5317 kNoSourcePosition),
5320 zone()); 5318 zone());
5321 return list; 5319 return list;
5322 } 5320 }
5323 UNREACHABLE(); 5321 UNREACHABLE();
5324 } 5322 }
5325 5323
5326
5327 Expression* Parser::SpreadCall(Expression* function, 5324 Expression* Parser::SpreadCall(Expression* function,
5328 ZoneList<v8::internal::Expression*>* args, 5325 ZoneList<Expression*>* args, int pos) {
5329 int pos) {
5330 if (function->IsSuperCallReference()) { 5326 if (function->IsSuperCallReference()) {
5331 // Super calls 5327 // Super calls
5332 // $super_constructor = %_GetSuperConstructor(<this-function>) 5328 // $super_constructor = %_GetSuperConstructor(<this-function>)
5333 // %reflect_construct($super_constructor, args, new.target) 5329 // %reflect_construct($super_constructor, args, new.target)
5334 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); 5330 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone());
5335 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); 5331 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone());
5336 Expression* super_constructor = factory()->NewCallRuntime( 5332 Expression* super_constructor = factory()->NewCallRuntime(
5337 Runtime::kInlineGetSuperConstructor, tmp, pos); 5333 Runtime::kInlineGetSuperConstructor, tmp, pos);
5338 args->InsertAt(0, super_constructor, zone()); 5334 args->InsertAt(0, super_constructor, zone());
5339 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); 5335 args->Add(function->AsSuperCallReference()->new_target_var(), zone());
(...skipping 21 matching lines...) Expand all
5361 } else { 5357 } else {
5362 // Non-method calls 5358 // Non-method calls
5363 args->InsertAt(0, function, zone()); 5359 args->InsertAt(0, function, zone());
5364 args->InsertAt(1, factory()->NewUndefinedLiteral(kNoSourcePosition), 5360 args->InsertAt(1, factory()->NewUndefinedLiteral(kNoSourcePosition),
5365 zone()); 5361 zone());
5366 } 5362 }
5367 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos); 5363 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos);
5368 } 5364 }
5369 } 5365 }
5370 5366
5371
5372 Expression* Parser::SpreadCallNew(Expression* function, 5367 Expression* Parser::SpreadCallNew(Expression* function,
5373 ZoneList<v8::internal::Expression*>* args, 5368 ZoneList<Expression*>* args, int pos) {
5374 int pos) {
5375 args->InsertAt(0, function, zone()); 5369 args->InsertAt(0, function, zone());
5376 5370
5377 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 5371 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
5378 } 5372 }
5379 5373
5380 5374
5381 void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) { 5375 void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) {
5382 v8::Isolate::UseCounterFeature feature; 5376 v8::Isolate::UseCounterFeature feature;
5383 if (is_sloppy(mode)) 5377 if (is_sloppy(mode))
5384 feature = v8::Isolate::kSloppyMode; 5378 feature = v8::Isolate::kSloppyMode;
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
6648 node->Print(Isolate::Current()); 6642 node->Print(Isolate::Current());
6649 } 6643 }
6650 #endif // DEBUG 6644 #endif // DEBUG
6651 6645
6652 #undef CHECK_OK 6646 #undef CHECK_OK
6653 #undef CHECK_OK_VOID 6647 #undef CHECK_OK_VOID
6654 #undef CHECK_FAILED 6648 #undef CHECK_FAILED
6655 6649
6656 } // namespace internal 6650 } // namespace internal
6657 } // namespace v8 6651 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698