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

Side by Side Diff: runtime/vm/parser.cc

Issue 1278003002: Change heuristic to determine which fields contain modifieable double boxes: do it if field was ini… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: better Created 5 years, 4 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 3954 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 // For instance fields, the expression is parsed when a constructor 3965 // For instance fields, the expression is parsed when a constructor
3966 // is compiled. 3966 // is compiled.
3967 // For static fields with very simple initializer expressions 3967 // For static fields with very simple initializer expressions
3968 // (e.g. a literal number or string), we optimize away the 3968 // (e.g. a literal number or string), we optimize away the
3969 // kImplicitStaticFinalGetter and initialize the field here. 3969 // kImplicitStaticFinalGetter and initialize the field here.
3970 // However, the class finalizer will check the value type for 3970 // However, the class finalizer will check the value type for
3971 // assignability once the declared field type can be resolved. If the 3971 // assignability once the declared field type can be resolved. If the
3972 // value is not assignable (assuming checked mode and disregarding actual 3972 // value is not assignable (assuming checked mode and disregarding actual
3973 // mode), the field value is reset and a kImplicitStaticFinalGetter is 3973 // mode), the field value is reset and a kImplicitStaticFinalGetter is
3974 // created at finalization time. 3974 // created at finalization time.
3975 if (LookaheadToken(1) == Token::kSEMICOLON) { 3975 if ((LookaheadToken(1) == Token::kSEMICOLON) ||
3976 (LookaheadToken(1) == Token::kCOMMA)) {
3976 has_simple_literal = IsSimpleLiteral(*field->type, &init_value); 3977 has_simple_literal = IsSimpleLiteral(*field->type, &init_value);
3977 } 3978 }
3978 SkipExpr(); 3979 SkipExpr();
3979 } else { 3980 } else {
3980 // Static const and static final fields must have an initializer. 3981 // Static const and static final fields must have an initializer.
3981 // Static const fields are implicitly final. 3982 // Static const fields are implicitly final.
3982 if (field->has_static && field->has_final) { 3983 if (field->has_static && field->has_final) {
3983 ReportError(field->name_pos, 3984 ReportError(field->name_pos,
3984 "static %s field '%s' must have an initializer expression", 3985 "static %s field '%s' must have an initializer expression",
3985 field->has_const ? "const" : "final", 3986 field->has_const ? "const" : "final",
(...skipping 15 matching lines...) Expand all
4001 field->field_ = &class_field; 4002 field->field_ = &class_field;
4002 if (field->metadata_pos >= 0) { 4003 if (field->metadata_pos >= 0) {
4003 library_.AddFieldMetadata(class_field, field->metadata_pos); 4004 library_.AddFieldMetadata(class_field, field->metadata_pos);
4004 } 4005 }
4005 4006
4006 // Start tracking types for fields with simple initializers in their 4007 // Start tracking types for fields with simple initializers in their
4007 // definition. This avoids some of the overhead to track this at runtime 4008 // definition. This avoids some of the overhead to track this at runtime
4008 // and rules out many fields from being unnecessary unboxing candidates. 4009 // and rules out many fields from being unnecessary unboxing candidates.
4009 if (!field->has_static && has_initializer && has_simple_literal) { 4010 if (!field->has_static && has_initializer && has_simple_literal) {
4010 class_field.RecordStore(init_value); 4011 class_field.RecordStore(init_value);
4012 if (!init_value.IsNull() && init_value.IsDouble()) {
4013 class_field.set_is_double_initialized(true);
4014 }
4011 } 4015 }
4012 4016
4013 // For static final fields (this includes static const fields), set value to 4017 // For static final fields (this includes static const fields), set value to
4014 // "uninitialized" and create a kImplicitStaticFinalGetter getter method. 4018 // "uninitialized" and create a kImplicitStaticFinalGetter getter method.
4015 if (field->has_static && has_initializer) { 4019 if (field->has_static && has_initializer) {
4016 class_field.set_value(init_value); 4020 class_field.set_value(init_value);
4017 if (!has_simple_literal) { 4021 if (!has_simple_literal) {
4018 String& getter_name = 4022 String& getter_name =
4019 String::Handle(Z, Field::GetterSymbol(*field->name)); 4023 String::Handle(Z, Field::GetterSymbol(*field->name));
4020 getter = Function::New(getter_name, 4024 getter = Function::New(getter_name,
(...skipping 10033 matching lines...) Expand 10 before | Expand all | Expand 10 after
14054 void Parser::SkipQualIdent() { 14058 void Parser::SkipQualIdent() {
14055 ASSERT(IsIdentifier()); 14059 ASSERT(IsIdentifier());
14056 ConsumeToken(); 14060 ConsumeToken();
14057 if (CurrentToken() == Token::kPERIOD) { 14061 if (CurrentToken() == Token::kPERIOD) {
14058 ConsumeToken(); // Consume the kPERIOD token. 14062 ConsumeToken(); // Consume the kPERIOD token.
14059 ExpectIdentifier("identifier expected after '.'"); 14063 ExpectIdentifier("identifier expected after '.'");
14060 } 14064 }
14061 } 14065 }
14062 14066
14063 } // namespace dart 14067 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698