Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'java_core.dart'; | 10 import 'java_core.dart'; |
| (...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1914 */ | 1914 */ |
| 1915 class UnusedLocalVariableVerifier extends RecursiveElementVisitor { | 1915 class UnusedLocalVariableVerifier extends RecursiveElementVisitor { |
| 1916 /** | 1916 /** |
| 1917 * The error reporter by which errors will be reported. | 1917 * The error reporter by which errors will be reported. |
| 1918 */ | 1918 */ |
| 1919 final ErrorReporter _errorReporter; | 1919 final ErrorReporter _errorReporter; |
| 1920 | 1920 |
| 1921 /** | 1921 /** |
| 1922 * Create a new instance of the [UnusedLocalVariableVerifier]. | 1922 * Create a new instance of the [UnusedLocalVariableVerifier]. |
| 1923 */ | 1923 */ |
| 1924 UnusedLocalVariableVerifier(this._errorReporter); | 1924 UnusedLocalVariableVerifier(this._errorReporter); |
|
Brian Wilkerson
2014/11/10 23:34:47
If the class is checking more than local variables
scheglov
2014/11/11 02:57:06
Done.
| |
| 1925 | 1925 |
| 1926 @override | 1926 @override |
| 1927 visitClassElement(ClassElement element) { | |
| 1928 if (element is ClassElementImpl && !element.isUsed) { | |
| 1929 _errorReporter.reportErrorForElement( | |
| 1930 HintCode.UNUSED_ELEMENT, | |
| 1931 element, | |
| 1932 [element.kind.displayName, element.displayName]); | |
| 1933 } | |
| 1934 element.visitChildren(this); | |
| 1935 } | |
| 1936 | |
| 1937 @override | |
| 1927 visitLocalVariableElement(LocalVariableElement element) { | 1938 visitLocalVariableElement(LocalVariableElement element) { |
| 1928 if (element is LocalVariableElementImpl && !element.isUsed) { | 1939 if (element is LocalVariableElementImpl && !element.isUsed) { |
| 1929 _errorReporter.reportErrorForElement( | 1940 _errorReporter.reportErrorForElement( |
| 1930 HintCode.UNUSED_LOCAL_VARIABLE, | 1941 HintCode.UNUSED_LOCAL_VARIABLE, |
| 1931 element, | 1942 element, |
| 1932 [element.displayName]); | 1943 [element.displayName]); |
| 1933 } | 1944 } |
| 1934 } | 1945 } |
| 1935 } | 1946 } |
| 1936 | 1947 |
| (...skipping 10537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12474 */ | 12485 */ |
| 12475 final TypeProvider typeProvider; | 12486 final TypeProvider typeProvider; |
| 12476 | 12487 |
| 12477 /** | 12488 /** |
| 12478 * The scope used to resolve labels for `break` and `continue` statements, or | 12489 * The scope used to resolve labels for `break` and `continue` statements, or |
| 12479 * `null` if no labels have been defined in the current context. | 12490 * `null` if no labels have been defined in the current context. |
| 12480 */ | 12491 */ |
| 12481 LabelScope _labelScope; | 12492 LabelScope _labelScope; |
| 12482 | 12493 |
| 12483 /** | 12494 /** |
| 12495 * The class containing the AST nodes being visited, | |
| 12496 * or `null` if we are not in the scope of a class. | |
| 12497 */ | |
| 12498 ClassElement _enclosingClass; | |
| 12499 | |
| 12500 /** | |
| 12484 * Initialize a newly created visitor to resolve the nodes in a compilation un it. | 12501 * Initialize a newly created visitor to resolve the nodes in a compilation un it. |
| 12485 * | 12502 * |
| 12486 * @param library the library containing the compilation unit being resolved | 12503 * @param library the library containing the compilation unit being resolved |
| 12487 * @param source the source representing the compilation unit being visited | 12504 * @param source the source representing the compilation unit being visited |
| 12488 * @param typeProvider the object used to access the types from the core libra ry | 12505 * @param typeProvider the object used to access the types from the core libra ry |
| 12489 */ | 12506 */ |
| 12490 ScopedVisitor.con1(Library library, this.source, this.typeProvider) { | 12507 ScopedVisitor.con1(Library library, this.source, this.typeProvider) { |
| 12491 this._definingLibrary = library.libraryElement; | 12508 this._definingLibrary = library.libraryElement; |
| 12492 LibraryScope libraryScope = library.libraryScope; | 12509 LibraryScope libraryScope = library.libraryScope; |
| 12493 this._errorListener = libraryScope.errorListener; | 12510 this._errorListener = libraryScope.errorListener; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12609 Object visitClassDeclaration(ClassDeclaration node) { | 12626 Object visitClassDeclaration(ClassDeclaration node) { |
| 12610 ClassElement classElement = node.element; | 12627 ClassElement classElement = node.element; |
| 12611 Scope outerScope = _nameScope; | 12628 Scope outerScope = _nameScope; |
| 12612 try { | 12629 try { |
| 12613 if (classElement == null) { | 12630 if (classElement == null) { |
| 12614 AnalysisEngine.instance.logger.logInformation( | 12631 AnalysisEngine.instance.logger.logInformation( |
| 12615 "Missing element for class declaration ${node.name.name} in ${defini ngLibrary.source.fullName}", | 12632 "Missing element for class declaration ${node.name.name} in ${defini ngLibrary.source.fullName}", |
| 12616 new CaughtException(new AnalysisException(), null)); | 12633 new CaughtException(new AnalysisException(), null)); |
| 12617 super.visitClassDeclaration(node); | 12634 super.visitClassDeclaration(node); |
| 12618 } else { | 12635 } else { |
| 12619 _nameScope = new TypeParameterScope(_nameScope, classElement); | 12636 ClassElement outerClass = _enclosingClass; |
| 12620 visitClassDeclarationInScope(node); | 12637 try { |
| 12621 _nameScope = new ClassScope(_nameScope, classElement); | 12638 _enclosingClass = node.element; |
| 12622 visitClassMembersInScope(node); | 12639 _nameScope = new TypeParameterScope(_nameScope, classElement); |
| 12640 visitClassDeclarationInScope(node); | |
| 12641 _nameScope = new ClassScope(_nameScope, classElement); | |
| 12642 visitClassMembersInScope(node); | |
| 12643 } finally { | |
| 12644 _enclosingClass = outerClass; | |
| 12645 } | |
| 12623 } | 12646 } |
| 12624 } finally { | 12647 } finally { |
| 12625 _nameScope = outerScope; | 12648 _nameScope = outerScope; |
| 12626 } | 12649 } |
| 12627 return null; | 12650 return null; |
| 12628 } | 12651 } |
| 12629 | 12652 |
| 12630 @override | 12653 @override |
| 12631 Object visitClassTypeAlias(ClassTypeAlias node) { | 12654 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 12632 Scope outerScope = _nameScope; | 12655 Scope outerScope = _nameScope; |
| (...skipping 2450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15083 types.add(type); | 15106 types.add(type); |
| 15084 } | 15107 } |
| 15085 } | 15108 } |
| 15086 return types; | 15109 return types; |
| 15087 } | 15110 } |
| 15088 | 15111 |
| 15089 void _setElement(Identifier typeName, Element element) { | 15112 void _setElement(Identifier typeName, Element element) { |
| 15090 if (element != null) { | 15113 if (element != null) { |
| 15091 if (typeName is SimpleIdentifier) { | 15114 if (typeName is SimpleIdentifier) { |
| 15092 typeName.staticElement = element; | 15115 typeName.staticElement = element; |
| 15116 _markTypeNameElementUsed(typeName, element); | |
| 15093 } else if (typeName is PrefixedIdentifier) { | 15117 } else if (typeName is PrefixedIdentifier) { |
| 15094 PrefixedIdentifier identifier = typeName; | 15118 PrefixedIdentifier identifier = typeName; |
| 15095 identifier.identifier.staticElement = element; | 15119 identifier.identifier.staticElement = element; |
| 15096 SimpleIdentifier prefix = identifier.prefix; | 15120 SimpleIdentifier prefix = identifier.prefix; |
| 15097 Element prefixElement = nameScope.lookup(prefix, definingLibrary); | 15121 Element prefixElement = nameScope.lookup(prefix, definingLibrary); |
| 15098 if (prefixElement != null) { | 15122 if (prefixElement != null) { |
| 15099 prefix.staticElement = prefixElement; | 15123 prefix.staticElement = prefixElement; |
| 15100 } | 15124 } |
| 15101 } | 15125 } |
| 15102 } | 15126 } |
| 15103 } | 15127 } |
| 15104 | 15128 |
| 15105 /** | 15129 /** |
| 15130 * Marks [element] as used in its defining library. | |
| 15131 */ | |
| 15132 void _markTypeNameElementUsed(Identifier typeName, Element element) { | |
| 15133 if (identical(element, _enclosingClass)) { | |
| 15134 return; | |
| 15135 } | |
| 15136 // ignore places where the element is not actually used | |
| 15137 if (typeName.parent is TypeName) { | |
| 15138 AstNode parent2 = typeName.parent.parent; | |
| 15139 if (parent2 is IsExpression) { | |
| 15140 return; | |
| 15141 } | |
| 15142 if (parent2 is VariableDeclarationList) { | |
| 15143 return; | |
| 15144 } | |
| 15145 } | |
| 15146 // check if the element is a local top-level element | |
| 15147 if (element is ElementImpl && | |
| 15148 element.enclosingElement is CompilationUnitElement && | |
| 15149 identical(element.library, definingLibrary)) { | |
| 15150 element.markUsed(); | |
| 15151 } | |
| 15152 } | |
| 15153 | |
| 15154 /** | |
| 15106 * Given a parameter element, create a function type based on the given return type and parameter | 15155 * Given a parameter element, create a function type based on the given return type and parameter |
| 15107 * list and associate the created type with the element. | 15156 * list and associate the created type with the element. |
| 15108 * | 15157 * |
| 15109 * @param element the parameter element whose type is to be set | 15158 * @param element the parameter element whose type is to be set |
| 15110 * @param returnType the (possibly `null`) return type of the function | 15159 * @param returnType the (possibly `null`) return type of the function |
| 15111 * @param parameterList the list of parameters to the function | 15160 * @param parameterList the list of parameters to the function |
| 15112 */ | 15161 */ |
| 15113 void _setFunctionTypedParameterType(ParameterElementImpl element, TypeName ret urnType, FormalParameterList parameterList) { | 15162 void _setFunctionTypedParameterType(ParameterElementImpl element, TypeName ret urnType, FormalParameterList parameterList) { |
| 15114 List<ParameterElement> parameters = _getElements(parameterList); | 15163 List<ParameterElement> parameters = _getElements(parameterList); |
| 15115 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl .forNode(null); | 15164 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl .forNode(null); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15527 /** | 15576 /** |
| 15528 * Return the tag that has the given identifier, or {@code null} if there is n o such tag (the | 15577 * Return the tag that has the given identifier, or {@code null} if there is n o such tag (the |
| 15529 * identifier is not defined). | 15578 * identifier is not defined). |
| 15530 * | 15579 * |
| 15531 * @return the tag that has the given identifier | 15580 * @return the tag that has the given identifier |
| 15532 */ | 15581 */ |
| 15533 String getTagWithId(String identifier) { | 15582 String getTagWithId(String identifier) { |
| 15534 return idToTagMap[identifier]; | 15583 return idToTagMap[identifier]; |
| 15535 } | 15584 } |
| 15536 } | 15585 } |
| OLD | NEW |