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 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 element.modifiers.isFactory()) { | 843 element.modifiers.isFactory()) { |
844 constructors[element.name] = element; | 844 constructors[element.name] = element; |
845 } else if (element.kind == ElementKind.GETTER | 845 } else if (element.kind == ElementKind.GETTER |
846 || element.kind == ElementKind.SETTER) { | 846 || element.kind == ElementKind.SETTER) { |
847 addGetterOrSetter(element, localMembers[element.name], listener); | 847 addGetterOrSetter(element, localMembers[element.name], listener); |
848 } else { | 848 } else { |
849 localMembers[element.name] = element; | 849 localMembers[element.name] = element; |
850 } | 850 } |
851 } | 851 } |
852 | 852 |
853 /** | |
854 * Called to ensure that type parameters and the type of this class have been | |
855 * created. The bounds of the type variables are not set here but instead | |
856 * during resolution of the class. This split is needed to create the type | |
857 * of the class before it has been resolved, which in turns enables the | |
858 * resolution to handle cyclic dependencies as for instance imposed by default | |
859 * classes. | |
860 */ | |
861 void ensureParametersAndType(Compiler compiler) { | |
862 if (type === null) { | |
floitsch
2012/07/26 11:14:40
no need to === anymore. == is enough.
| |
863 ClassNode node = parseNode(compiler); | |
864 Link<Node> parameters = | |
865 node.typeParameters !== null ? node.typeParameters.nodes | |
866 : const EmptyLink<TypeVariable>(); | |
867 // Create types and elements for type variable. | |
868 var arguments = new LinkBuilder<Type>(); | |
869 for (Link<Node> link = parameters; !link.isEmpty(); link = link.tail) { | |
870 TypeVariable typeNode = link.head; | |
871 SourceString variableName = typeNode.name.source; | |
872 TypeVariableType variableType = new TypeVariableType(variableName); | |
873 arguments.addLast(variableType); | |
874 TypeVariableElement variableElement = | |
875 new TypeVariableElement(variableName, this, node, | |
876 variableType); | |
877 variableType.element = variableElement; | |
878 typeParameters[variableName] = variableElement; | |
879 } | |
880 type = new InterfaceType(this, arguments.toLink()); | |
881 } | |
882 } | |
883 | |
853 Type computeType(compiler) { | 884 Type computeType(compiler) { |
854 if (type === null) { | 885 ensureParametersAndType(compiler); |
855 type = new InterfaceType(this); | |
856 } | |
857 return type; | 886 return type; |
858 } | 887 } |
859 | 888 |
860 ClassElement ensureResolved(Compiler compiler) { | 889 ClassElement ensureResolved(Compiler compiler) { |
861 compiler.resolveClass(this); | 890 compiler.resolveClass(this); |
862 return this; | 891 return this; |
863 } | 892 } |
864 | 893 |
865 Element lookupTypeParameter(SourceString parameterName) { | 894 Element lookupTypeParameter(SourceString parameterName) { |
866 Element result = typeParameters[parameterName]; | 895 Element result = typeParameters[parameterName]; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 final Node node; | 1212 final Node node; |
1184 Type bound; | 1213 Type bound; |
1185 Type type; | 1214 Type type; |
1186 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1215 TypeVariableElement(name, Element enclosing, this.node, this.type, |
1187 [this.bound]) | 1216 [this.bound]) |
1188 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1217 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
1189 Type computeType(compiler) => type; | 1218 Type computeType(compiler) => type; |
1190 Node parseNode(compiler) => node; | 1219 Node parseNode(compiler) => node; |
1191 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1220 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
1192 } | 1221 } |
OLD | NEW |