| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// ----------------------------------------------------------------------- | 5 /// ----------------------------------------------------------------------- |
| 6 /// ERROR HANDLING | 6 /// ERROR HANDLING |
| 7 /// ----------------------------------------------------------------------- | 7 /// ----------------------------------------------------------------------- |
| 8 /// | 8 /// |
| 9 /// As a rule of thumb, errors that can be detected statically are handled by | 9 /// As a rule of thumb, errors that can be detected statically are handled by |
| 10 /// the frontend, typically by translating the erroneous code into a 'throw' or | 10 /// the frontend, typically by translating the erroneous code into a 'throw' or |
| (...skipping 3698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3709 /// For locals, this is the initial value. | 3709 /// For locals, this is the initial value. |
| 3710 /// For parameters, this is the default value. | 3710 /// For parameters, this is the default value. |
| 3711 /// | 3711 /// |
| 3712 /// Should be null in other cases. | 3712 /// Should be null in other cases. |
| 3713 Expression initializer; // May be null. | 3713 Expression initializer; // May be null. |
| 3714 | 3714 |
| 3715 VariableDeclaration(this.name, | 3715 VariableDeclaration(this.name, |
| 3716 {this.initializer, | 3716 {this.initializer, |
| 3717 this.type: const DynamicType(), | 3717 this.type: const DynamicType(), |
| 3718 bool isFinal: false, | 3718 bool isFinal: false, |
| 3719 bool isConst: false}) { | 3719 bool isConst: false, |
| 3720 bool isFieldFormal: false}) { |
| 3720 assert(type != null); | 3721 assert(type != null); |
| 3721 initializer?.parent = this; | 3722 initializer?.parent = this; |
| 3722 this.isFinal = isFinal; | 3723 this.isFinal = isFinal; |
| 3723 this.isConst = isConst; | 3724 this.isConst = isConst; |
| 3725 this.isFieldFormal = isFieldFormal; |
| 3724 } | 3726 } |
| 3725 | 3727 |
| 3726 /// Creates a synthetic variable with the given expression as initializer. | 3728 /// Creates a synthetic variable with the given expression as initializer. |
| 3727 VariableDeclaration.forValue(this.initializer, | 3729 VariableDeclaration.forValue(this.initializer, |
| 3728 {bool isFinal: true, | 3730 {bool isFinal: true, |
| 3729 bool isConst: false, | 3731 bool isConst: false, |
| 3732 bool isFieldFormal: false, |
| 3730 this.type: const DynamicType()}) { | 3733 this.type: const DynamicType()}) { |
| 3731 assert(type != null); | 3734 assert(type != null); |
| 3732 initializer?.parent = this; | 3735 initializer?.parent = this; |
| 3733 this.isFinal = isFinal; | 3736 this.isFinal = isFinal; |
| 3734 this.isConst = isConst; | 3737 this.isConst = isConst; |
| 3738 this.isFieldFormal = isFieldFormal; |
| 3735 } | 3739 } |
| 3736 | 3740 |
| 3737 static const int FlagFinal = 1 << 0; // Must match serialized bit positions. | 3741 static const int FlagFinal = 1 << 0; // Must match serialized bit positions. |
| 3738 static const int FlagConst = 1 << 1; | 3742 static const int FlagConst = 1 << 1; |
| 3739 static const int FlagInScope = 1 << 2; // Temporary flag used by verifier. | 3743 static const int FlagFieldFormal = 1 << 2; |
| 3744 static const int FlagInScope = 1 << 3; // Temporary flag used by verifier. |
| 3740 | 3745 |
| 3741 bool get isFinal => flags & FlagFinal != 0; | 3746 bool get isFinal => flags & FlagFinal != 0; |
| 3742 bool get isConst => flags & FlagConst != 0; | 3747 bool get isConst => flags & FlagConst != 0; |
| 3743 | 3748 |
| 3749 /// Whether the variable is declared as a field formal parameter of |
| 3750 /// a constructor. |
| 3751 @informative |
| 3752 bool get isFieldFormal => flags & FlagFieldFormal != 0; |
| 3753 |
| 3744 void set isFinal(bool value) { | 3754 void set isFinal(bool value) { |
| 3745 flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); | 3755 flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); |
| 3746 } | 3756 } |
| 3747 | 3757 |
| 3748 void set isConst(bool value) { | 3758 void set isConst(bool value) { |
| 3749 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); | 3759 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); |
| 3750 } | 3760 } |
| 3751 | 3761 |
| 3762 @informative |
| 3763 void set isFieldFormal(bool value) { |
| 3764 flags = value ? (flags | FlagFieldFormal) : (flags & ~FlagFieldFormal); |
| 3765 } |
| 3766 |
| 3752 accept(StatementVisitor v) => v.visitVariableDeclaration(this); | 3767 accept(StatementVisitor v) => v.visitVariableDeclaration(this); |
| 3753 accept1(StatementVisitor1 v, arg) => v.visitVariableDeclaration(this, arg); | 3768 accept1(StatementVisitor1 v, arg) => v.visitVariableDeclaration(this, arg); |
| 3754 | 3769 |
| 3755 visitChildren(Visitor v) { | 3770 visitChildren(Visitor v) { |
| 3756 type?.accept(v); | 3771 type?.accept(v); |
| 3757 initializer?.accept(v); | 3772 initializer?.accept(v); |
| 3758 } | 3773 } |
| 3759 | 3774 |
| 3760 transformChildren(Transformer v) { | 3775 transformChildren(Transformer v) { |
| 3761 type = v.visitDartType(type); | 3776 type = v.visitDartType(type); |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4636 if (typedef_.canonicalName == null) { | 4651 if (typedef_.canonicalName == null) { |
| 4637 throw '$typedef_ has no canonical name'; | 4652 throw '$typedef_ has no canonical name'; |
| 4638 } | 4653 } |
| 4639 return typedef_.canonicalName; | 4654 return typedef_.canonicalName; |
| 4640 } | 4655 } |
| 4641 | 4656 |
| 4642 /// Annotation describing information which is not part of Dart semantics; in | 4657 /// Annotation describing information which is not part of Dart semantics; in |
| 4643 /// other words, if this information (or any information it refers to) changes, | 4658 /// other words, if this information (or any information it refers to) changes, |
| 4644 /// static analysis and runtime behavior of the library are unaffected. | 4659 /// static analysis and runtime behavior of the library are unaffected. |
| 4645 const informative = null; | 4660 const informative = null; |
| OLD | NEW |