Chromium Code Reviews| 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)) { |
| 2579 has_simple_literal = IsSimpleLiteral(*field->type, &init_value); | 2579 has_simple_literal = IsSimpleLiteral(*field->type, &init_value); |
| 2580 } | 2580 } |
| 2581 SkipExpr(); | 2581 SkipExpr(); |
| 2582 } else { | 2582 } else { |
| 2583 if (field->has_const || (field->has_static && field->has_final)) { | 2583 if (field->has_const || (field->has_static && field->has_final)) { |
| 2584 ErrorMsg(field->name_pos, | 2584 ErrorMsg(field->name_pos, |
| 2585 "%s%s field '%s' must have an initializer expression", | 2585 "%s%s field '%s' must have an initializer expression", |
| 2586 field->has_static ? "static " : "", | 2586 field->has_static ? "static " : "", |
| 2587 field->has_const ? "const" : "final", | 2587 field->has_const ? "const" : "final", |
| 2588 field->name->ToCString()); | 2588 field->name->ToCString()); |
| 2589 } | 2589 } |
| 2590 } | 2590 } |
| 2591 | 2591 |
| 2592 // Create the field object. | 2592 // Create the field object. |
| 2593 // TODO(hausner): For now, all static final fields are constant. Remove | 2593 // TODO(hausner): For now, all static const fields are constant. Remove |
|
hausner
2012/08/27 22:12:04
Please revert change in this comment.
Ivan Posva
2012/08/27 23:49:49
Mechanical replacement only works so far. Thanks f
| |
| 2594 // this when lazy init of static variables is implemented. | 2594 // this when lazy init of static variables is implemented. |
| 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 6619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9235 void Parser::SkipQualIdent() { | 9235 void Parser::SkipQualIdent() { |
| 9236 ASSERT(IsIdentifier()); | 9236 ASSERT(IsIdentifier()); |
| 9237 ConsumeToken(); | 9237 ConsumeToken(); |
| 9238 if (CurrentToken() == Token::kPERIOD) { | 9238 if (CurrentToken() == Token::kPERIOD) { |
| 9239 ConsumeToken(); // Consume the kPERIOD token. | 9239 ConsumeToken(); // Consume the kPERIOD token. |
| 9240 ExpectIdentifier("identifier expected after '.'"); | 9240 ExpectIdentifier("identifier expected after '.'"); |
| 9241 } | 9241 } |
| 9242 } | 9242 } |
| 9243 | 9243 |
| 9244 } // namespace dart | 9244 } // namespace dart |
| OLD | NEW |