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

Side by Side Diff: src/ast/ast.cc

Issue 2302643002: Split the AST representation of class properties from object properties (Closed)
Patch Set: rebase 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/ast/ast.h ('k') | src/ast/ast-expression-rewriter.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/ast/ast.h" 5 #include "src/ast/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 8
9 #include "src/ast/compile-time-value.h" 9 #include "src/ast/compile-time-value.h"
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return scope()->language_mode(); 316 return scope()->language_mode();
317 } 317 }
318 318
319 319
320 bool FunctionLiteral::NeedsHomeObject(Expression* expr) { 320 bool FunctionLiteral::NeedsHomeObject(Expression* expr) {
321 if (expr == nullptr || !expr->IsFunctionLiteral()) return false; 321 if (expr == nullptr || !expr->IsFunctionLiteral()) return false;
322 DCHECK_NOT_NULL(expr->AsFunctionLiteral()->scope()); 322 DCHECK_NOT_NULL(expr->AsFunctionLiteral()->scope());
323 return expr->AsFunctionLiteral()->scope()->NeedsHomeObject(); 323 return expr->AsFunctionLiteral()->scope()->NeedsHomeObject();
324 } 324 }
325 325
326
327 ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value, 326 ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value,
328 Kind kind, bool is_static, 327 Kind kind, bool is_computed_name)
329 bool is_computed_name) 328 : LiteralProperty(key, value, is_computed_name),
330 : key_(key),
331 value_(value),
332 kind_(kind), 329 kind_(kind),
333 emit_store_(true), 330 emit_store_(true) {}
334 is_static_(is_static),
335 is_computed_name_(is_computed_name) {}
336
337 331
338 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, 332 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory,
339 Expression* key, Expression* value, 333 Expression* key, Expression* value,
340 bool is_static,
341 bool is_computed_name) 334 bool is_computed_name)
342 : key_(key), 335 : LiteralProperty(key, value, is_computed_name), emit_store_(true) {
343 value_(value),
344 emit_store_(true),
345 is_static_(is_static),
346 is_computed_name_(is_computed_name) {
347 if (!is_computed_name && 336 if (!is_computed_name &&
348 key->AsLiteral()->raw_value()->EqualsString( 337 key->AsLiteral()->raw_value()->EqualsString(
349 ast_value_factory->proto_string())) { 338 ast_value_factory->proto_string())) {
350 kind_ = PROTOTYPE; 339 kind_ = PROTOTYPE;
351 } else if (value_->AsMaterializedLiteral() != NULL) { 340 } else if (value_->AsMaterializedLiteral() != NULL) {
352 kind_ = MATERIALIZED_LITERAL; 341 kind_ = MATERIALIZED_LITERAL;
353 } else if (value_->IsLiteral()) { 342 } else if (value_->IsLiteral()) {
354 kind_ = CONSTANT; 343 kind_ = CONSTANT;
355 } else { 344 } else {
356 kind_ = COMPUTED; 345 kind_ = COMPUTED;
357 } 346 }
358 } 347 }
359 348
360 bool ObjectLiteralProperty::NeedsSetFunctionName() const { 349 bool LiteralProperty::NeedsSetFunctionName() const {
361 return is_computed_name_ && 350 return is_computed_name_ &&
362 (value_->IsAnonymousFunctionDefinition() || 351 (value_->IsAnonymousFunctionDefinition() ||
363 (value_->IsFunctionLiteral() && 352 (value_->IsFunctionLiteral() &&
364 IsConciseMethod(value_->AsFunctionLiteral()->kind()))); 353 IsConciseMethod(value_->AsFunctionLiteral()->kind())));
365 } 354 }
366 355
356 ClassLiteralProperty::ClassLiteralProperty(Expression* key, Expression* value,
357 Kind kind, bool is_static,
358 bool is_computed_name)
359 : LiteralProperty(key, value, is_computed_name),
360 kind_(kind),
361 is_static_(is_static) {}
362
367 void ClassLiteral::AssignFeedbackVectorSlots(Isolate* isolate, 363 void ClassLiteral::AssignFeedbackVectorSlots(Isolate* isolate,
368 FeedbackVectorSpec* spec, 364 FeedbackVectorSpec* spec,
369 FeedbackVectorSlotCache* cache) { 365 FeedbackVectorSlotCache* cache) {
370 // This logic that computes the number of slots needed for vector store 366 // This logic that computes the number of slots needed for vector store
371 // ICs must mirror FullCodeGenerator::VisitClassLiteral. 367 // ICs must mirror FullCodeGenerator::VisitClassLiteral.
372 prototype_slot_ = spec->AddLoadICSlot(); 368 prototype_slot_ = spec->AddLoadICSlot();
373 if (NeedsProxySlot()) { 369 if (NeedsProxySlot()) {
374 proxy_slot_ = spec->AddStoreICSlot(); 370 proxy_slot_ = spec->AddStoreICSlot();
375 } 371 }
376 372
377 for (int i = 0; i < properties()->length(); i++) { 373 for (int i = 0; i < properties()->length(); i++) {
378 ObjectLiteral::Property* property = properties()->at(i); 374 ClassLiteral::Property* property = properties()->at(i);
379 Expression* value = property->value(); 375 Expression* value = property->value();
380 if (FunctionLiteral::NeedsHomeObject(value)) { 376 if (FunctionLiteral::NeedsHomeObject(value)) {
381 property->SetSlot(spec->AddStoreICSlot()); 377 property->SetSlot(spec->AddStoreICSlot());
382 } 378 }
383 } 379 }
384 } 380 }
385 381
386 382 bool ObjectLiteral::Property::IsCompileTimeValue() const {
387 bool ObjectLiteral::Property::IsCompileTimeValue() {
388 return kind_ == CONSTANT || 383 return kind_ == CONSTANT ||
389 (kind_ == MATERIALIZED_LITERAL && 384 (kind_ == MATERIALIZED_LITERAL &&
390 CompileTimeValue::IsCompileTimeValue(value_)); 385 CompileTimeValue::IsCompileTimeValue(value_));
391 } 386 }
392 387
393 388
394 void ObjectLiteral::Property::set_emit_store(bool emit_store) { 389 void ObjectLiteral::Property::set_emit_store(bool emit_store) {
395 emit_store_ = emit_store; 390 emit_store_ = emit_store;
396 } 391 }
397 392
398 393 bool ObjectLiteral::Property::emit_store() const { return emit_store_; }
399 bool ObjectLiteral::Property::emit_store() {
400 return emit_store_;
401 }
402
403 394
404 void ObjectLiteral::AssignFeedbackVectorSlots(Isolate* isolate, 395 void ObjectLiteral::AssignFeedbackVectorSlots(Isolate* isolate,
405 FeedbackVectorSpec* spec, 396 FeedbackVectorSpec* spec,
406 FeedbackVectorSlotCache* cache) { 397 FeedbackVectorSlotCache* cache) {
407 // This logic that computes the number of slots needed for vector store 398 // This logic that computes the number of slots needed for vector store
408 // ics must mirror FullCodeGenerator::VisitObjectLiteral. 399 // ics must mirror FullCodeGenerator::VisitObjectLiteral.
409 int property_index = 0; 400 int property_index = 0;
410 for (; property_index < properties()->length(); property_index++) { 401 for (; property_index < properties()->length(); property_index++) {
411 ObjectLiteral::Property* property = properties()->at(property_index); 402 ObjectLiteral::Property* property = properties()->at(property_index);
412 if (property->is_computed_name()) break; 403 if (property->is_computed_name()) break;
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 // static 959 // static
969 bool Literal::Match(void* literal1, void* literal2) { 960 bool Literal::Match(void* literal1, void* literal2) {
970 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 961 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
971 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 962 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
972 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 963 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
973 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 964 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
974 } 965 }
975 966
976 } // namespace internal 967 } // namespace internal
977 } // namespace v8 968 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/ast.h ('k') | src/ast/ast-expression-rewriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698