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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 924943010: Minor changes in analyzer to make it easier to extend (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/pubspec.yaml » ('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) 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:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 8291 matching lines...) Expand 10 before | Expand all | Expand 10 after
8302 * cycle. 8302 * cycle.
8303 * 8303 *
8304 * @throws AnalysisException if any of the type hierarchies could not be resol ved 8304 * @throws AnalysisException if any of the type hierarchies could not be resol ved
8305 */ 8305 */
8306 void _buildTypeHierarchies() { 8306 void _buildTypeHierarchies() {
8307 PerformanceTag prevTag = 8307 PerformanceTag prevTag =
8308 PerformanceStatistics.resolve.makeCurrent(); 8308 PerformanceStatistics.resolve.makeCurrent();
8309 try { 8309 try {
8310 for (Library library in _librariesInCycles) { 8310 for (Library library in _librariesInCycles) {
8311 for (Source source in library.compilationUnitSources) { 8311 for (Source source in library.compilationUnitSources) {
8312 TypeResolverVisitor visitor = 8312 var typeResolverVisitorFactory =
Brian Wilkerson 2015/02/20 21:39:07 We provide type annotations everywhere, so please
Siggi Cherem (dart-lang) 2015/02/20 22:12:59 Done.
8313 new TypeResolverVisitor.con1(library, source, _typeProvider); 8313 analysisContext.typeResolverVisitorFactory;
8314 TypeResolverVisitor visitor = (typeResolverVisitorFactory == null)
8315 ? new TypeResolverVisitor.con1(library, source, _typeProvider)
8316 : typeResolverVisitorFactory(library, source, _typeProvider);
8314 library.getAST(source).accept(visitor); 8317 library.getAST(source).accept(visitor);
8315 } 8318 }
8316 } 8319 }
8317 } finally { 8320 } finally {
8318 prevTag.makeCurrent(); 8321 prevTag.makeCurrent();
8319 } 8322 }
8320 } 8323 }
8321 8324
8322 /** 8325 /**
8323 * Compute a dependency map of libraries reachable from the given library. A d ependency map is a 8326 * Compute a dependency map of libraries reachable from the given library. A d ependency map is a
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
8585 * the library cannot be analyzed 8588 * the library cannot be analyzed
8586 */ 8589 */
8587 void _resolveReferencesAndTypesInLibrary(Library library) { 8590 void _resolveReferencesAndTypesInLibrary(Library library) {
8588 PerformanceTag prevTag = 8591 PerformanceTag prevTag =
8589 PerformanceStatistics.resolve.makeCurrent(); 8592 PerformanceStatistics.resolve.makeCurrent();
8590 try { 8593 try {
8591 for (Source source in library.compilationUnitSources) { 8594 for (Source source in library.compilationUnitSources) {
8592 CompilationUnit ast = library.getAST(source); 8595 CompilationUnit ast = library.getAST(source);
8593 ast.accept( 8596 ast.accept(
8594 new VariableResolverVisitor.con1(library, source, _typeProvider)); 8597 new VariableResolverVisitor.con1(library, source, _typeProvider));
8595 ResolverVisitor visitor = 8598 var visitorFactory = analysisContext.resolverVisitorFactory;
8596 new ResolverVisitor.con1(library, source, _typeProvider); 8599 ResolverVisitor visitor = visitorFactory != null
8600 ? visitorFactory(library, source, _typeProvider)
8601 : new ResolverVisitor.con1(library, source, _typeProvider);
8597 ast.accept(visitor); 8602 ast.accept(visitor);
8598 } 8603 }
8599 } finally { 8604 } finally {
8600 prevTag.makeCurrent(); 8605 prevTag.makeCurrent();
8601 } 8606 }
8602 } 8607 }
8603 8608
8604 /** 8609 /**
8605 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 8610 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
8606 * given library, or `null` if the URI is not valid. 8611 * given library, or `null` if the URI is not valid.
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
10365 const ResolverErrorCode(String name, String message, [String correction]) 10370 const ResolverErrorCode(String name, String message, [String correction])
10366 : super(name, message, correction); 10371 : super(name, message, correction);
10367 10372
10368 @override 10373 @override
10369 ErrorSeverity get errorSeverity => type.severity; 10374 ErrorSeverity get errorSeverity => type.severity;
10370 10375
10371 @override 10376 @override
10372 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; 10377 ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
10373 } 10378 }
10374 10379
10380 typedef ResolverVisitor ResolverVisitorFactory(
10381 Library library, Source source, TypeProvider typeProvider);
10382
10383 typedef TypeResolverVisitor TypeResolverVisitorFactory(
10384 Library library, Source source, TypeProvider typeProvider);
10385
10375 /** 10386 /**
10376 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single 10387 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single
10377 * compilation unit. 10388 * compilation unit.
10378 */ 10389 */
10379 class ResolverVisitor extends ScopedVisitor { 10390 class ResolverVisitor extends ScopedVisitor {
10380 /** 10391 /**
10381 * The manager for the inheritance mappings. 10392 * The manager for the inheritance mappings.
10382 */ 10393 */
10383 InheritanceManager _inheritanceManager; 10394 InheritanceManager _inheritanceManager;
10384 10395
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
10443 bool resolveOnlyCommentInFunctionBody = false; 10454 bool resolveOnlyCommentInFunctionBody = false;
10444 10455
10445 /** 10456 /**
10446 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10457 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10447 * 10458 *
10448 * @param library the library containing the compilation unit being resolved 10459 * @param library the library containing the compilation unit being resolved
10449 * @param source the source representing the compilation unit being visited 10460 * @param source the source representing the compilation unit being visited
10450 * @param typeProvider the object used to access the types from the core libra ry 10461 * @param typeProvider the object used to access the types from the core libra ry
10451 */ 10462 */
10452 ResolverVisitor.con1(Library library, Source source, 10463 ResolverVisitor.con1(Library library, Source source,
10453 TypeProvider typeProvider) 10464 TypeProvider typeProvider,
10465 {StaticTypeAnalyzer typeAnalyzer, typeAnalyzerFactory})
Brian Wilkerson 2015/02/20 21:39:07 ... and annotate all parameters.
Siggi Cherem (dart-lang) 2015/02/20 22:12:59 Done.
10454 : super.con1(library, source, typeProvider) { 10466 : super.con1(library, source, typeProvider) {
10455 this._inheritanceManager = library.inheritanceManager; 10467 this._inheritanceManager = library.inheritanceManager;
10456 this._elementResolver = new ElementResolver(this); 10468 this._elementResolver = new ElementResolver(this);
10457 this._typeAnalyzer = new StaticTypeAnalyzer(this); 10469 this._typeAnalyzer = typeAnalyzer != null
10470 ? typeAnalyzer
10471 : (typeAnalyzerFactory != null
10472 ? typeAnalyzerFactory(this)
10473 : new StaticTypeAnalyzer(this));
10458 } 10474 }
10459 10475
10476
10460 /** 10477 /**
10461 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10478 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10462 * 10479 *
10463 * @param definingLibrary the element for the library containing the compilati on unit being 10480 * @param definingLibrary the element for the library containing the compilati on unit being
10464 * visited 10481 * visited
10465 * @param source the source representing the compilation unit being visited 10482 * @param source the source representing the compilation unit being visited
10466 * @param typeProvider the object used to access the types from the core libra ry 10483 * @param typeProvider the object used to access the types from the core libra ry
10467 * @param errorListener the error listener that will be informed of any errors that are found 10484 * @param errorListener the error listener that will be informed of any errors that are found
10468 * during resolution 10485 * during resolution
10469 */ 10486 */
(...skipping 3481 matching lines...) Expand 10 before | Expand all | Expand 10 after
13951 } 13968 }
13952 SimpleIdentifier stackTrace = node.stackTraceParameter; 13969 SimpleIdentifier stackTrace = node.stackTraceParameter;
13953 if (stackTrace != null) { 13970 if (stackTrace != null) {
13954 _recordType(stackTrace, typeProvider.stackTraceType); 13971 _recordType(stackTrace, typeProvider.stackTraceType);
13955 } 13972 }
13956 return null; 13973 return null;
13957 } 13974 }
13958 13975
13959 @override 13976 @override
13960 Object visitClassDeclaration(ClassDeclaration node) { 13977 Object visitClassDeclaration(ClassDeclaration node) {
13978 _hasReferenceToSuper = false;
13979 super.visitClassDeclaration(node);
13980 ClassElement classElement = _getClassElement(node.name);
13981 if (classElement != null) {
13982 classElement.hasReferenceToSuper = _hasReferenceToSuper;
13983 }
13984 }
13985
13986 @override
13987 void visitClassDeclarationInScope(ClassDeclaration node) {
13988 super.visitClassDeclarationInScope(node);
13961 ExtendsClause extendsClause = node.extendsClause; 13989 ExtendsClause extendsClause = node.extendsClause;
13962 WithClause withClause = node.withClause; 13990 WithClause withClause = node.withClause;
13963 ImplementsClause implementsClause = node.implementsClause; 13991 ImplementsClause implementsClause = node.implementsClause;
13964 _hasReferenceToSuper = false;
13965 super.visitClassDeclaration(node);
13966 ClassElementImpl classElement = _getClassElement(node.name); 13992 ClassElementImpl classElement = _getClassElement(node.name);
13967 InterfaceType superclassType = null; 13993 InterfaceType superclassType = null;
13968 if (extendsClause != null) { 13994 if (extendsClause != null) {
13969 ErrorCode errorCode = (withClause == null ? 13995 ErrorCode errorCode = (withClause == null ?
13970 CompileTimeErrorCode.EXTENDS_NON_CLASS : 13996 CompileTimeErrorCode.EXTENDS_NON_CLASS :
13971 CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS); 13997 CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS);
13972 superclassType = _resolveType( 13998 superclassType = _resolveType(
13973 extendsClause.superclass, 13999 extendsClause.superclass,
13974 errorCode, 14000 errorCode,
13975 CompileTimeErrorCode.EXTENDS_ENUM, 14001 CompileTimeErrorCode.EXTENDS_ENUM,
13976 errorCode); 14002 errorCode);
13977 if (!identical(superclassType, typeProvider.objectType)) { 14003 if (!identical(superclassType, typeProvider.objectType)) {
13978 classElement.validMixin = false; 14004 classElement.validMixin = false;
13979 } 14005 }
13980 } 14006 }
13981 if (classElement != null) { 14007 if (classElement != null) {
13982 if (superclassType == null) { 14008 if (superclassType == null) {
13983 InterfaceType objectType = typeProvider.objectType; 14009 InterfaceType objectType = typeProvider.objectType;
13984 if (!identical(classElement.type, objectType)) { 14010 if (!identical(classElement.type, objectType)) {
13985 superclassType = objectType; 14011 superclassType = objectType;
13986 } 14012 }
13987 } 14013 }
13988 classElement.supertype = superclassType; 14014 classElement.supertype = superclassType;
13989 classElement.hasReferenceToSuper = _hasReferenceToSuper;
13990 } 14015 }
13991 _resolve(classElement, withClause, implementsClause); 14016 _resolve(classElement, withClause, implementsClause);
13992 return null; 14017 return null;
13993 } 14018 }
13994 14019
13995 @override 14020 @override
13996 void visitClassMembersInScope(ClassDeclaration node) { 14021 void visitClassMembersInScope(ClassDeclaration node) {
13997 // 14022 //
13998 // Process field declarations before constructors and methods so that the 14023 // Process field declarations before constructors and methods so that the
13999 // types of field formal parameters can be correctly resolved. 14024 // types of field formal parameters can be correctly resolved.
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after
15693 * library. 15718 * library.
15694 */ 15719 */
15695 final HashSet<String> members = new HashSet<String>(); 15720 final HashSet<String> members = new HashSet<String>();
15696 15721
15697 /** 15722 /**
15698 * Names of resolved or unresolved class members that are read in the 15723 * Names of resolved or unresolved class members that are read in the
15699 * library. 15724 * library.
15700 */ 15725 */
15701 final HashSet<String> readMembers = new HashSet<String>(); 15726 final HashSet<String> readMembers = new HashSet<String>();
15702 } 15727 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698