| OLD | NEW |
| 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 2547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2558 Function& getter = Function::Handle(); | 2558 Function& getter = Function::Handle(); |
| 2559 Function& setter = Function::Handle(); | 2559 Function& setter = Function::Handle(); |
| 2560 Field& class_field = Field::Handle(); | 2560 Field& class_field = Field::Handle(); |
| 2561 Instance& init_value = Instance::Handle(); | 2561 Instance& init_value = Instance::Handle(); |
| 2562 while (true) { | 2562 while (true) { |
| 2563 bool has_initializer = CurrentToken() == Token::kASSIGN; | 2563 bool has_initializer = CurrentToken() == Token::kASSIGN; |
| 2564 bool has_simple_literal = false; | 2564 bool has_simple_literal = false; |
| 2565 if (has_initializer) { | 2565 if (has_initializer) { |
| 2566 ConsumeToken(); | 2566 ConsumeToken(); |
| 2567 init_value = Object::sentinel(); | 2567 init_value = Object::sentinel(); |
| 2568 // For static final fields, the initialization expression | 2568 // For static const fields, the initialization expression |
| 2569 // will be parsed through the kConstImplicitGetter method | 2569 // will be parsed through the kConstImplicitGetter method |
| 2570 // invocation/compilation. | 2570 // invocation/compilation. |
| 2571 // For instance fields, the expression is parsed when a constructor | 2571 // For instance fields, the expression is parsed when a constructor |
| 2572 // is compiled. | 2572 // is compiled. |
| 2573 // For static fields with very simple initializer expressions | 2573 // For static fields with very simple initializer expressions |
| 2574 // (e.g. a literal number or string) we optimize away the | 2574 // (e.g. a literal number or string) we optimize away the |
| 2575 // kConstImplicitGetter and initialize the field here. | 2575 // kConstImplicitGetter and initialize the field here. |
| 2576 | 2576 |
| 2577 if (field->has_static && (field->has_final || field->has_const) && | 2577 if (field->has_static && (field->has_final || field->has_const) && |
| 2578 (LookaheadToken(1) == Token::kSEMICOLON)) { | 2578 (LookaheadToken(1) == Token::kSEMICOLON)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2595 class_field = Field::New(*field->name, | 2595 class_field = Field::New(*field->name, |
| 2596 field->has_static, | 2596 field->has_static, |
| 2597 field->has_final, | 2597 field->has_final, |
| 2598 field->has_const || field->has_final, | 2598 field->has_const || field->has_final, |
| 2599 current_class(), | 2599 current_class(), |
| 2600 field->name_pos); | 2600 field->name_pos); |
| 2601 class_field.set_type(*field->type); | 2601 class_field.set_type(*field->type); |
| 2602 class_field.set_has_initializer(has_initializer); | 2602 class_field.set_has_initializer(has_initializer); |
| 2603 members->AddField(class_field); | 2603 members->AddField(class_field); |
| 2604 | 2604 |
| 2605 // For static final fields, set value to "uninitialized" and | 2605 // For static const fields, set value to "uninitialized" and |
| 2606 // create a kConstImplicitGetter getter method. | 2606 // create a kConstImplicitGetter getter method. |
| 2607 if (field->has_static && has_initializer) { | 2607 if (field->has_static && has_initializer) { |
| 2608 class_field.set_value(init_value); | 2608 class_field.set_value(init_value); |
| 2609 if (!has_simple_literal) { | 2609 if (!has_simple_literal) { |
| 2610 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 2610 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); |
| 2611 getter = Function::New(getter_name, | 2611 getter = Function::New(getter_name, |
| 2612 RawFunction::kConstImplicitGetter, | 2612 RawFunction::kConstImplicitGetter, |
| 2613 field->has_static, | 2613 field->has_static, |
| 2614 field->has_final, | 2614 field->has_final, |
| 2615 /* is_abstract = */ false, | 2615 /* is_abstract = */ false, |
| (...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3626 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 3626 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 3627 ErrorMsg(name_pos, "getter for '%s' is already defined", | 3627 ErrorMsg(name_pos, "getter for '%s' is already defined", |
| 3628 var_name.ToCString()); | 3628 var_name.ToCString()); |
| 3629 } | 3629 } |
| 3630 accessor_name = Field::SetterName(var_name); | 3630 accessor_name = Field::SetterName(var_name); |
| 3631 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 3631 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 3632 ErrorMsg(name_pos, "setter for '%s' is already defined", | 3632 ErrorMsg(name_pos, "setter for '%s' is already defined", |
| 3633 var_name.ToCString()); | 3633 var_name.ToCString()); |
| 3634 } | 3634 } |
| 3635 | 3635 |
| 3636 field = Field::New( | 3636 // TODO(hausner): const and final are equivalent at the moment. |
| 3637 var_name, is_static, is_final, is_const, current_class(), name_pos); | 3637 field = Field::New(var_name, |
| 3638 is_static, |
| 3639 is_final || is_const, // Const fields are also final. |
| 3640 is_const || is_final, |
| 3641 current_class(), |
| 3642 name_pos); |
| 3638 field.set_type(type); | 3643 field.set_type(type); |
| 3639 field.set_value(Instance::Handle(Instance::null())); | 3644 field.set_value(Instance::Handle(Instance::null())); |
| 3640 top_level->fields.Add(field); | 3645 top_level->fields.Add(field); |
| 3641 library_.AddObject(field, var_name); | 3646 library_.AddObject(field, var_name); |
| 3642 if (CurrentToken() == Token::kASSIGN) { | 3647 if (CurrentToken() == Token::kASSIGN) { |
| 3643 ConsumeToken(); | 3648 ConsumeToken(); |
| 3644 Instance& field_value = Instance::Handle(Object::sentinel()); | 3649 Instance& field_value = Instance::Handle(Object::sentinel()); |
| 3645 bool has_simple_literal = false; | 3650 bool has_simple_literal = false; |
| 3646 if ((is_final || is_const) && (LookaheadToken(1) == Token::kSEMICOLON)) { | 3651 if ((is_final || is_const) && (LookaheadToken(1) == Token::kSEMICOLON)) { |
| 3647 has_simple_literal = IsSimpleLiteral(type, &field_value); | 3652 has_simple_literal = IsSimpleLiteral(type, &field_value); |
| (...skipping 5587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9235 void Parser::SkipQualIdent() { | 9240 void Parser::SkipQualIdent() { |
| 9236 ASSERT(IsIdentifier()); | 9241 ASSERT(IsIdentifier()); |
| 9237 ConsumeToken(); | 9242 ConsumeToken(); |
| 9238 if (CurrentToken() == Token::kPERIOD) { | 9243 if (CurrentToken() == Token::kPERIOD) { |
| 9239 ConsumeToken(); // Consume the kPERIOD token. | 9244 ConsumeToken(); // Consume the kPERIOD token. |
| 9240 ExpectIdentifier("identifier expected after '.'"); | 9245 ExpectIdentifier("identifier expected after '.'"); |
| 9241 } | 9246 } |
| 9242 } | 9247 } |
| 9243 | 9248 |
| 9244 } // namespace dart | 9249 } // namespace dart |
| OLD | NEW |