| 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 'dart:uri'; | 7 import 'dart:uri'; |
| 8 | 8 |
| 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. | 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. |
| 10 import '../../compiler.dart' as api_e; | 10 import '../../compiler.dart' as api_e; |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 533 |
| 534 void setPartOf(PartOf tag, DiagnosticListener listener) { | 534 void setPartOf(PartOf tag, DiagnosticListener listener) { |
| 535 LibraryElement library = enclosingElement; | 535 LibraryElement library = enclosingElement; |
| 536 if (library.entryCompilationUnit == this) { | 536 if (library.entryCompilationUnit == this) { |
| 537 listener.reportMessage( | 537 listener.reportMessage( |
| 538 listener.spanFromNode(tag), | 538 listener.spanFromNode(tag), |
| 539 MessageKind.ILLEGAL_DIRECTIVE.error(), | 539 MessageKind.ILLEGAL_DIRECTIVE.error(), |
| 540 api_e.Diagnostic.WARNING); | 540 api_e.Diagnostic.WARNING); |
| 541 return; | 541 return; |
| 542 } | 542 } |
| 543 if (!localMembers.isEmpty()) { | 543 if (!localMembers.isEmpty) { |
| 544 listener.reportMessage( | 544 listener.reportMessage( |
| 545 listener.spanFromNode(tag), | 545 listener.spanFromNode(tag), |
| 546 MessageKind.BEFORE_TOP_LEVEL.error(), | 546 MessageKind.BEFORE_TOP_LEVEL.error(), |
| 547 api_e.Diagnostic.ERROR); | 547 api_e.Diagnostic.ERROR); |
| 548 return; | 548 return; |
| 549 } | 549 } |
| 550 if (partTag != null) { | 550 if (partTag != null) { |
| 551 listener.reportMessage( | 551 listener.reportMessage( |
| 552 listener.spanFromNode(tag), | 552 listener.spanFromNode(tag), |
| 553 MessageKind.DUPLICATED_PART_OF.error(), | 553 MessageKind.DUPLICATED_PART_OF.error(), |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 VariableListElement variables, | 834 VariableListElement variables, |
| 835 ElementKind kind, | 835 ElementKind kind, |
| 836 this.cachedNode) | 836 this.cachedNode) |
| 837 : this.variables = variables, | 837 : this.variables = variables, |
| 838 super(name, kind, variables.enclosingElement); | 838 super(name, kind, variables.enclosingElement); |
| 839 | 839 |
| 840 Node parseNode(DiagnosticListener listener) { | 840 Node parseNode(DiagnosticListener listener) { |
| 841 if (cachedNode != null) return cachedNode; | 841 if (cachedNode != null) return cachedNode; |
| 842 VariableDefinitions definitions = variables.parseNode(listener); | 842 VariableDefinitions definitions = variables.parseNode(listener); |
| 843 for (Link<Node> link = definitions.definitions.nodes; | 843 for (Link<Node> link = definitions.definitions.nodes; |
| 844 !link.isEmpty(); link = link.tail) { | 844 !link.isEmpty; link = link.tail) { |
| 845 Expression initializedIdentifier = link.head; | 845 Expression initializedIdentifier = link.head; |
| 846 Identifier identifier = initializedIdentifier.asIdentifier(); | 846 Identifier identifier = initializedIdentifier.asIdentifier(); |
| 847 if (identifier == null) { | 847 if (identifier == null) { |
| 848 identifier = initializedIdentifier.asSendSet().selector.asIdentifier(); | 848 identifier = initializedIdentifier.asSendSet().selector.asIdentifier(); |
| 849 } | 849 } |
| 850 if (identical(name, identifier.source)) { | 850 if (identical(name, identifier.source)) { |
| 851 cachedNode = initializedIdentifier; | 851 cachedNode = initializedIdentifier; |
| 852 return cachedNode; | 852 return cachedNode; |
| 853 } | 853 } |
| 854 } | 854 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 | 918 |
| 919 DartType computeType(Compiler compiler) { | 919 DartType computeType(Compiler compiler) { |
| 920 if (type != null) return type; | 920 if (type != null) return type; |
| 921 compiler.withCurrentElement(this, () { | 921 compiler.withCurrentElement(this, () { |
| 922 VariableDefinitions node = parseNode(compiler); | 922 VariableDefinitions node = parseNode(compiler); |
| 923 if (node.type != null) { | 923 if (node.type != null) { |
| 924 type = compiler.resolveTypeAnnotation(this, node.type); | 924 type = compiler.resolveTypeAnnotation(this, node.type); |
| 925 } else { | 925 } else { |
| 926 // Is node.definitions exactly one FunctionExpression? | 926 // Is node.definitions exactly one FunctionExpression? |
| 927 Link<Node> link = node.definitions.nodes; | 927 Link<Node> link = node.definitions.nodes; |
| 928 if (!link.isEmpty() && | 928 if (!link.isEmpty && |
| 929 link.head.asFunctionExpression() != null && | 929 link.head.asFunctionExpression() != null && |
| 930 link.tail.isEmpty()) { | 930 link.tail.isEmpty) { |
| 931 FunctionExpression functionExpression = link.head; | 931 FunctionExpression functionExpression = link.head; |
| 932 // We found exactly one FunctionExpression | 932 // We found exactly one FunctionExpression |
| 933 functionSignature = | 933 functionSignature = |
| 934 compiler.resolveFunctionExpression(this, functionExpression); | 934 compiler.resolveFunctionExpression(this, functionExpression); |
| 935 type = compiler.computeFunctionType(compiler.functionClass, | 935 type = compiler.computeFunctionType(compiler.functionClass, |
| 936 functionSignature); | 936 functionSignature); |
| 937 } else { | 937 } else { |
| 938 type = compiler.types.dynamicType; | 938 type = compiler.types.dynamicType; |
| 939 } | 939 } |
| 940 } | 940 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 | 1024 |
| 1025 FunctionSignature(this.requiredParameters, | 1025 FunctionSignature(this.requiredParameters, |
| 1026 this.optionalParameters, | 1026 this.optionalParameters, |
| 1027 this.requiredParameterCount, | 1027 this.requiredParameterCount, |
| 1028 this.optionalParameterCount, | 1028 this.optionalParameterCount, |
| 1029 this.optionalParametersAreNamed, | 1029 this.optionalParametersAreNamed, |
| 1030 this.returnType); | 1030 this.returnType); |
| 1031 | 1031 |
| 1032 void forEachRequiredParameter(void function(Element parameter)) { | 1032 void forEachRequiredParameter(void function(Element parameter)) { |
| 1033 for (Link<Element> link = requiredParameters; | 1033 for (Link<Element> link = requiredParameters; |
| 1034 !link.isEmpty(); | 1034 !link.isEmpty; |
| 1035 link = link.tail) { | 1035 link = link.tail) { |
| 1036 function(link.head); | 1036 function(link.head); |
| 1037 } | 1037 } |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 void forEachOptionalParameter(void function(Element parameter)) { | 1040 void forEachOptionalParameter(void function(Element parameter)) { |
| 1041 for (Link<Element> link = optionalParameters; | 1041 for (Link<Element> link = optionalParameters; |
| 1042 !link.isEmpty(); | 1042 !link.isEmpty; |
| 1043 link = link.tail) { | 1043 link = link.tail) { |
| 1044 function(link.head); | 1044 function(link.head); |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 List<Element> get orderedOptionalParameters { | 1048 List<Element> get orderedOptionalParameters { |
| 1049 if (_orderedOptionalParameters != null) return _orderedOptionalParameters; | 1049 if (_orderedOptionalParameters != null) return _orderedOptionalParameters; |
| 1050 List<Element> list = new List<Element>.from(optionalParameters); | 1050 List<Element> list = new List<Element>.from(optionalParameters); |
| 1051 if (optionalParametersAreNamed) { | 1051 if (optionalParametersAreNamed) { |
| 1052 list.sort((Element a, Element b) { | 1052 list.sort((Element a, Element b) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 * Creates the type variables, their type and corresponding element, for the | 1263 * Creates the type variables, their type and corresponding element, for the |
| 1264 * type variables declared in [parameter] on [element]. The bounds of the type | 1264 * type variables declared in [parameter] on [element]. The bounds of the type |
| 1265 * variables are not set until [element] has been resolved. | 1265 * variables are not set until [element] has been resolved. |
| 1266 */ | 1266 */ |
| 1267 static Link<DartType> createTypeVariables(TypeDeclarationElement element, | 1267 static Link<DartType> createTypeVariables(TypeDeclarationElement element, |
| 1268 NodeList parameters) { | 1268 NodeList parameters) { |
| 1269 if (parameters == null) return const Link<DartType>(); | 1269 if (parameters == null) return const Link<DartType>(); |
| 1270 | 1270 |
| 1271 // Create types and elements for type variable. | 1271 // Create types and elements for type variable. |
| 1272 var arguments = new LinkBuilder<DartType>(); | 1272 var arguments = new LinkBuilder<DartType>(); |
| 1273 for (Link link = parameters.nodes; !link.isEmpty(); link = link.tail) { | 1273 for (Link link = parameters.nodes; !link.isEmpty; link = link.tail) { |
| 1274 TypeVariable node = link.head; | 1274 TypeVariable node = link.head; |
| 1275 SourceString variableName = node.name.source; | 1275 SourceString variableName = node.name.source; |
| 1276 TypeVariableElement variableElement = | 1276 TypeVariableElement variableElement = |
| 1277 new TypeVariableElement(variableName, element, node); | 1277 new TypeVariableElement(variableName, element, node); |
| 1278 TypeVariableType variableType = new TypeVariableType(variableElement); | 1278 TypeVariableType variableType = new TypeVariableType(variableElement); |
| 1279 variableElement.type = variableType; | 1279 variableElement.type = variableType; |
| 1280 arguments.addLast(variableType); | 1280 arguments.addLast(variableType); |
| 1281 } | 1281 } |
| 1282 return arguments.toLink(); | 1282 return arguments.toLink(); |
| 1283 } | 1283 } |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 | 1935 |
| 1936 MetadataAnnotation ensureResolved(Compiler compiler) { | 1936 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 1937 if (resolutionState == STATE_NOT_STARTED) { | 1937 if (resolutionState == STATE_NOT_STARTED) { |
| 1938 compiler.resolver.resolveMetadataAnnotation(this); | 1938 compiler.resolver.resolveMetadataAnnotation(this); |
| 1939 } | 1939 } |
| 1940 return this; | 1940 return this; |
| 1941 } | 1941 } |
| 1942 | 1942 |
| 1943 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1943 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 1944 } | 1944 } |
| OLD | NEW |