| 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element get currentElement; | 8 Element get currentElement; |
| 9 Set<Node> get superUses; | 9 Set<Node> get superUses; |
| 10 | 10 |
| (...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1743 return mapping[node] = element; | 1743 return mapping[node] = element; |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 DartType useType(TypeAnnotation annotation, DartType type) { | 1746 DartType useType(TypeAnnotation annotation, DartType type) { |
| 1747 if (type != null) { | 1747 if (type != null) { |
| 1748 mapping.setType(annotation, type); | 1748 mapping.setType(annotation, type); |
| 1749 useElement(annotation, type.element); | 1749 useElement(annotation, type.element); |
| 1750 } | 1750 } |
| 1751 return type; | 1751 return type; |
| 1752 } | 1752 } |
| 1753 |
| 1754 Element defineElement(Node node, Element element, |
| 1755 {bool doAddToScope: true}) { |
| 1756 compiler.ensure(element != null); |
| 1757 mapping[node] = element; |
| 1758 if (doAddToScope) { |
| 1759 Element existing = scope.add(element); |
| 1760 if (existing != element) { |
| 1761 reportDuplicateDefinition(node, element, existing); |
| 1762 } |
| 1763 } |
| 1764 return element; |
| 1765 } |
| 1766 |
| 1767 void reportDuplicateDefinition(/*Node|SourceString*/ name, |
| 1768 Spannable definition, |
| 1769 Spannable existing) { |
| 1770 compiler.reportError( |
| 1771 definition, |
| 1772 MessageKind.DUPLICATE_DEFINITION, {'name': name}); |
| 1773 compiler.reportMessage( |
| 1774 compiler.spanFromSpannable(existing), |
| 1775 MessageKind.EXISTING_DEFINITION.error({'name': name}), |
| 1776 Diagnostic.INFO); |
| 1777 } |
| 1753 } | 1778 } |
| 1754 | 1779 |
| 1755 /** | 1780 /** |
| 1756 * Core implementation of resolution. | 1781 * Core implementation of resolution. |
| 1757 * | 1782 * |
| 1758 * Do not subclass or instantiate this class outside this library | 1783 * Do not subclass or instantiate this class outside this library |
| 1759 * except for testing. | 1784 * except for testing. |
| 1760 */ | 1785 */ |
| 1761 class ResolverVisitor extends MappingVisitor<Element> { | 1786 class ResolverVisitor extends MappingVisitor<Element> { |
| 1762 /** | 1787 /** |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 DartType type = resolveTypeAnnotation(node); | 1960 DartType type = resolveTypeAnnotation(node); |
| 1936 if (type != null) { | 1961 if (type != null) { |
| 1937 if (inCheckContext) { | 1962 if (inCheckContext) { |
| 1938 compiler.enqueuer.resolution.registerIsCheck(type, mapping); | 1963 compiler.enqueuer.resolution.registerIsCheck(type, mapping); |
| 1939 } | 1964 } |
| 1940 return type.element; | 1965 return type.element; |
| 1941 } | 1966 } |
| 1942 return null; | 1967 return null; |
| 1943 } | 1968 } |
| 1944 | 1969 |
| 1945 Element defineElement(Node node, Element element, | |
| 1946 {bool doAddToScope: true}) { | |
| 1947 compiler.ensure(element != null); | |
| 1948 mapping[node] = element; | |
| 1949 if (doAddToScope) { | |
| 1950 Element existing = scope.add(element); | |
| 1951 if (existing != element) { | |
| 1952 compiler.reportError( | |
| 1953 node, MessageKind.DUPLICATE_DEFINITION, {'name': node}); | |
| 1954 compiler.reportMessage( | |
| 1955 compiler.spanFromSpannable(existing), | |
| 1956 MessageKind.EXISTING_DEFINITION.error({'name': node}), | |
| 1957 Diagnostic.INFO); | |
| 1958 } | |
| 1959 } | |
| 1960 return element; | |
| 1961 } | |
| 1962 | |
| 1963 bool isNamedConstructor(Send node) => node.receiver != null; | 1970 bool isNamedConstructor(Send node) => node.receiver != null; |
| 1964 | 1971 |
| 1965 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { | 1972 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { |
| 1966 if (isNamedConstructor(node)) { | 1973 if (isNamedConstructor(node)) { |
| 1967 SourceString constructorName = node.selector.asIdentifier().source; | 1974 SourceString constructorName = node.selector.asIdentifier().source; |
| 1968 return new Selector.callConstructor( | 1975 return new Selector.callConstructor( |
| 1969 constructorName, | 1976 constructorName, |
| 1970 enclosingElement.getLibrary()); | 1977 enclosingElement.getLibrary()); |
| 1971 } else { | 1978 } else { |
| 1972 return new Selector.callDefaultConstructor( | 1979 return new Selector.callDefaultConstructor( |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2330 void resolveArguments(NodeList list) { | 2337 void resolveArguments(NodeList list) { |
| 2331 if (list == null) return; | 2338 if (list == null) return; |
| 2332 Map<SourceString, Node> seenNamedArguments = new Map<SourceString, Node>(); | 2339 Map<SourceString, Node> seenNamedArguments = new Map<SourceString, Node>(); |
| 2333 for (Link<Node> link = list.nodes; !link.isEmpty; link = link.tail) { | 2340 for (Link<Node> link = list.nodes; !link.isEmpty; link = link.tail) { |
| 2334 Expression argument = link.head; | 2341 Expression argument = link.head; |
| 2335 visit(argument); | 2342 visit(argument); |
| 2336 NamedArgument namedArgument = argument.asNamedArgument(); | 2343 NamedArgument namedArgument = argument.asNamedArgument(); |
| 2337 if (namedArgument != null) { | 2344 if (namedArgument != null) { |
| 2338 SourceString source = namedArgument.name.source; | 2345 SourceString source = namedArgument.name.source; |
| 2339 if (seenNamedArguments.containsKey(source)) { | 2346 if (seenNamedArguments.containsKey(source)) { |
| 2340 compiler.reportError( | 2347 reportDuplicateDefinition( |
| 2348 source, |
| 2341 argument, | 2349 argument, |
| 2342 MessageKind.DUPLICATE_DEFINITION, | 2350 seenNamedArguments[source]); |
| 2343 {'name': source}); | |
| 2344 compiler.reportMessage( | |
| 2345 compiler.spanFromSpannable(seenNamedArguments[source]), | |
| 2346 MessageKind.EXISTING_DEFINITION.error({'name': source}), | |
| 2347 Diagnostic.INFO); | |
| 2348 } else { | 2351 } else { |
| 2349 seenNamedArguments[source] = namedArgument; | 2352 seenNamedArguments[source] = namedArgument; |
| 2350 } | 2353 } |
| 2351 } else if (!seenNamedArguments.isEmpty) { | 2354 } else if (!seenNamedArguments.isEmpty) { |
| 2352 error(argument, MessageKind.INVALID_ARGUMENT_AFTER_NAMED); | 2355 error(argument, MessageKind.INVALID_ARGUMENT_AFTER_NAMED); |
| 2353 } | 2356 } |
| 2354 } | 2357 } |
| 2355 } | 2358 } |
| 2356 | 2359 |
| 2357 visitSend(Send node) { | 2360 visitSend(Send node) { |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 TypedefResolverVisitor(Compiler compiler, | 3373 TypedefResolverVisitor(Compiler compiler, |
| 3371 TypedefElement typedefElement, | 3374 TypedefElement typedefElement, |
| 3372 TreeElementMapping mapping) | 3375 TreeElementMapping mapping) |
| 3373 : super(compiler, typedefElement, mapping); | 3376 : super(compiler, typedefElement, mapping); |
| 3374 | 3377 |
| 3375 visitTypedef(Typedef node) { | 3378 visitTypedef(Typedef node) { |
| 3376 TypedefType type = element.computeType(compiler); | 3379 TypedefType type = element.computeType(compiler); |
| 3377 scope = new TypeDeclarationScope(scope, element); | 3380 scope = new TypeDeclarationScope(scope, element); |
| 3378 resolveTypeVariableBounds(node.typeParameters); | 3381 resolveTypeVariableBounds(node.typeParameters); |
| 3379 | 3382 |
| 3380 element.functionSignature = SignatureResolver.analyze( | 3383 FunctionSignature signature = SignatureResolver.analyze( |
| 3381 compiler, node.formals, node.returnType, element, | 3384 compiler, node.formals, node.returnType, element, |
| 3382 defaultValuesAllowed: false); | 3385 defaultValuesAllowed: false); |
| 3386 element.functionSignature = signature; |
| 3383 | 3387 |
| 3384 element.alias = compiler.computeFunctionType( | 3388 scope = new MethodScope(scope, element); |
| 3385 element, element.functionSignature); | 3389 signature.forEachParameter((Element element) { |
| 3390 defineElement(element.parseNode(compiler), element); |
| 3391 }); |
| 3392 |
| 3393 element.alias = compiler.computeFunctionType(element, signature); |
| 3386 | 3394 |
| 3387 void checkCyclicReference() { | 3395 void checkCyclicReference() { |
| 3388 var visitor = new TypedefCyclicVisitor(compiler, element); | 3396 var visitor = new TypedefCyclicVisitor(compiler, element); |
| 3389 type.accept(visitor, null); | 3397 type.accept(visitor, null); |
| 3390 } | 3398 } |
| 3391 compiler.enqueuer.resolution.addPostProcessAction(element, | 3399 compiler.enqueuer.resolution.addPostProcessAction(element, |
| 3392 checkCyclicReference); | 3400 checkCyclicReference); |
| 3393 } | 3401 } |
| 3394 } | 3402 } |
| 3395 | 3403 |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4367 return e; | 4375 return e; |
| 4368 } | 4376 } |
| 4369 | 4377 |
| 4370 /// Assumed to be called by [resolveRedirectingFactory]. | 4378 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4371 Element visitReturn(Return node) { | 4379 Element visitReturn(Return node) { |
| 4372 Node expression = node.expression; | 4380 Node expression = node.expression; |
| 4373 return finishConstructorReference(visit(expression), | 4381 return finishConstructorReference(visit(expression), |
| 4374 expression, expression); | 4382 expression, expression); |
| 4375 } | 4383 } |
| 4376 } | 4384 } |
| OLD | NEW |