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 #library('elements'); | 5 #library('elements'); |
| 6 | 6 |
| 7 #import('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
| 8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
| 9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
| 10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 978 | 978 |
| 979 static bool isListSupertype(Element element, Compiler compiler) { | 979 static bool isListSupertype(Element element, Compiler compiler) { |
| 980 LibraryElement coreLibrary = compiler.coreLibrary; | 980 LibraryElement coreLibrary = compiler.coreLibrary; |
| 981 return (element == coreLibrary.find(const SourceString('Collection'))) | 981 return (element == coreLibrary.find(const SourceString('Collection'))) |
| 982 || (element == coreLibrary.find(const SourceString('Iterable'))); | 982 || (element == coreLibrary.find(const SourceString('Iterable'))); |
| 983 } | 983 } |
| 984 } | 984 } |
| 985 | 985 |
| 986 | 986 |
| 987 class LabelElement extends Element { | 987 class LabelElement extends Element { |
| 988 final Identifier label; | 988 final Label label; |
|
ahe
2012/05/10 11:52:30
Could you add a comment explaining why you need th
Lasse Reichstein Nielsen
2012/05/10 12:14:20
Done.
| |
| 989 final String labelName; | 989 final String labelName; |
| 990 final TargetElement target; | 990 final TargetElement target; |
| 991 bool isBreakTarget = false; | 991 bool isBreakTarget = false; |
| 992 bool isContinueTarget = false; | 992 bool isContinueTarget = false; |
| 993 LabelElement(Identifier label, this.labelName, this.target, | 993 LabelElement(Label label, this.labelName, this.target, |
| 994 Element enclosingElement) | 994 Element enclosingElement) |
| 995 : this.label = label, | 995 : this.label = label, |
| 996 super(label.source, ElementKind.LABEL, enclosingElement); | 996 super(label.identifier.source, ElementKind.LABEL, enclosingElement); |
| 997 | 997 |
| 998 void setBreakTarget() { | 998 void setBreakTarget() { |
| 999 isBreakTarget = true; | 999 isBreakTarget = true; |
| 1000 target.isBreakTarget = true; | 1000 target.isBreakTarget = true; |
| 1001 } | 1001 } |
| 1002 void setContinueTarget() { | 1002 void setContinueTarget() { |
| 1003 isContinueTarget = true; | 1003 isContinueTarget = true; |
| 1004 target.isContinueTarget = true; | 1004 target.isContinueTarget = true; |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 bool get isTarget() => isBreakTarget || isContinueTarget; | 1007 bool get isTarget() => isBreakTarget || isContinueTarget; |
| 1008 Node parseNode(DiagnosticListener l) => label; | 1008 Node parseNode(DiagnosticListener l) => label; |
| 1009 | 1009 |
| 1010 Token position() => label.token; | 1010 Token position() => label.getBeginToken(); |
| 1011 String toString() => "${labelName}:"; | 1011 String toString() => "${labelName}:"; |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 // Represents a reference to a statement, either a label or the | 1014 // Represents a reference to a statement, either a label or the |
| 1015 // default target of a break or continue. | 1015 // default target of a break or continue. |
| 1016 class TargetElement extends Element { | 1016 class TargetElement extends Element { |
| 1017 // TODO(lrn): StatementElement is not just referencing statements anymore. | 1017 // TODO(lrn): StatementElement is not just referencing statements anymore. |
| 1018 final Node statement; | 1018 final Node statement; |
| 1019 final int nestingLevel; | 1019 final int nestingLevel; |
| 1020 Link<LabelElement> labels = const EmptyLink<LabelElement>(); | 1020 Link<LabelElement> labels = const EmptyLink<LabelElement>(); |
| 1021 bool isBreakTarget = false; | 1021 bool isBreakTarget = false; |
| 1022 bool isContinueTarget = false; | 1022 bool isContinueTarget = false; |
| 1023 | 1023 |
| 1024 TargetElement(this.statement, this.nestingLevel, Element enclosingElement) | 1024 TargetElement(this.statement, this.nestingLevel, Element enclosingElement) |
| 1025 : super(const SourceString(""), ElementKind.STATEMENT, enclosingElement); | 1025 : super(const SourceString(""), ElementKind.STATEMENT, enclosingElement); |
| 1026 bool get isTarget() => isBreakTarget || isContinueTarget; | 1026 bool get isTarget() => isBreakTarget || isContinueTarget; |
| 1027 | 1027 |
| 1028 LabelElement addLabel(Identifier label, String labelName) { | 1028 LabelElement addLabel(Label label, String labelName) { |
| 1029 LabelElement result = new LabelElement(label, labelName, this, | 1029 LabelElement result = new LabelElement(label, labelName, this, |
| 1030 enclosingElement); | 1030 enclosingElement); |
| 1031 labels = labels.prepend(result); | 1031 labels = labels.prepend(result); |
| 1032 return result; | 1032 return result; |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 Node parseNode(DiagnosticListener l) => statement; | 1035 Node parseNode(DiagnosticListener l) => statement; |
| 1036 | 1036 |
| 1037 bool get isSwitch() => statement is SwitchStatement; | 1037 bool get isSwitch() => statement is SwitchStatement; |
| 1038 | 1038 |
| 1039 Token position() => statement.getBeginToken(); | 1039 Token position() => statement.getBeginToken(); |
| 1040 String toString() => statement.toString(); | 1040 String toString() => statement.toString(); |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 class TypeVariableElement extends Element { | 1043 class TypeVariableElement extends Element { |
| 1044 final Node node; | 1044 final Node node; |
| 1045 Type bound; | 1045 Type bound; |
| 1046 Type type; | 1046 Type type; |
| 1047 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1047 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1048 [this.bound]) | 1048 [this.bound]) |
| 1049 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1049 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1050 Type computeType(compiler) => type; | 1050 Type computeType(compiler) => type; |
| 1051 Node parseNode(compiler) => node; | 1051 Node parseNode(compiler) => node; |
| 1052 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1052 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1053 } | 1053 } |
| OLD | NEW |