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

Side by Side Diff: lib/compiler/implementation/elements/elements.dart

Issue 10392024: Add a "Label" Node around an Identifier that is being used as a label. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressede review comments. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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 // We store the original label here so it can be returned by [parseNode].
989 final Label label;
989 final String labelName; 990 final String labelName;
990 final TargetElement target; 991 final TargetElement target;
991 bool isBreakTarget = false; 992 bool isBreakTarget = false;
992 bool isContinueTarget = false; 993 bool isContinueTarget = false;
993 LabelElement(Identifier label, this.labelName, this.target, 994 LabelElement(Label label, this.labelName, this.target,
994 Element enclosingElement) 995 Element enclosingElement)
995 : this.label = label, 996 : this.label = label,
996 super(label.source, ElementKind.LABEL, enclosingElement); 997 super(label.identifier.source, ElementKind.LABEL, enclosingElement);
997 998
998 void setBreakTarget() { 999 void setBreakTarget() {
999 isBreakTarget = true; 1000 isBreakTarget = true;
1000 target.isBreakTarget = true; 1001 target.isBreakTarget = true;
1001 } 1002 }
1002 void setContinueTarget() { 1003 void setContinueTarget() {
1003 isContinueTarget = true; 1004 isContinueTarget = true;
1004 target.isContinueTarget = true; 1005 target.isContinueTarget = true;
1005 } 1006 }
1006 1007
1007 bool get isTarget() => isBreakTarget || isContinueTarget; 1008 bool get isTarget() => isBreakTarget || isContinueTarget;
1008 Node parseNode(DiagnosticListener l) => label; 1009 Node parseNode(DiagnosticListener l) => label;
1009 1010
1010 Token position() => label.token; 1011 Token position() => label.getBeginToken();
1011 String toString() => "${labelName}:"; 1012 String toString() => "${labelName}:";
1012 } 1013 }
1013 1014
1014 // Represents a reference to a statement, either a label or the 1015 // Represents a reference to a statement or switch-case, either by label or the
1015 // default target of a break or continue. 1016 // default target of a break or continue.
1016 class TargetElement extends Element { 1017 class TargetElement extends Element {
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 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698