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

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 TypeResolverVisitorFactory typeResolverVisitorFactory =
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 ResolverVisitorFactory visitorFactory =
8596 new ResolverVisitor.con1(library, source, _typeProvider); 8599 analysisContext.resolverVisitorFactory;
8600 ResolverVisitor visitor = visitorFactory != null
8601 ? visitorFactory(library, source, _typeProvider)
8602 : new ResolverVisitor.con1(library, source, _typeProvider);
8597 ast.accept(visitor); 8603 ast.accept(visitor);
8598 } 8604 }
8599 } finally { 8605 } finally {
8600 prevTag.makeCurrent(); 8606 prevTag.makeCurrent();
8601 } 8607 }
8602 } 8608 }
8603 8609
8604 /** 8610 /**
8605 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 8611 * 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. 8612 * 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]) 10371 const ResolverErrorCode(String name, String message, [String correction])
10366 : super(name, message, correction); 10372 : super(name, message, correction);
10367 10373
10368 @override 10374 @override
10369 ErrorSeverity get errorSeverity => type.severity; 10375 ErrorSeverity get errorSeverity => type.severity;
10370 10376
10371 @override 10377 @override
10372 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; 10378 ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
10373 } 10379 }
10374 10380
10381 typedef ResolverVisitor ResolverVisitorFactory(
10382 Library library, Source source, TypeProvider typeProvider);
10383
10384 typedef TypeResolverVisitor TypeResolverVisitorFactory(
10385 Library library, Source source, TypeProvider typeProvider);
10386
10387 typedef StaticTypeAnalyzer StaticTypeAnalyzerFactory(ResolverVisitor visitor);
10388
10375 /** 10389 /**
10376 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single 10390 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single
10377 * compilation unit. 10391 * compilation unit.
10378 */ 10392 */
10379 class ResolverVisitor extends ScopedVisitor { 10393 class ResolverVisitor extends ScopedVisitor {
10380 /** 10394 /**
10381 * The manager for the inheritance mappings. 10395 * The manager for the inheritance mappings.
10382 */ 10396 */
10383 InheritanceManager _inheritanceManager; 10397 InheritanceManager _inheritanceManager;
10384 10398
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
10443 bool resolveOnlyCommentInFunctionBody = false; 10457 bool resolveOnlyCommentInFunctionBody = false;
10444 10458
10445 /** 10459 /**
10446 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10460 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10447 * 10461 *
10448 * @param library the library containing the compilation unit being resolved 10462 * @param library the library containing the compilation unit being resolved
10449 * @param source the source representing the compilation unit being visited 10463 * @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 10464 * @param typeProvider the object used to access the types from the core libra ry
10451 */ 10465 */
10452 ResolverVisitor.con1(Library library, Source source, 10466 ResolverVisitor.con1(Library library, Source source,
10453 TypeProvider typeProvider) 10467 TypeProvider typeProvider, {StaticTypeAnalyzer typeAnalyzer,
10468 StaticTypeAnalyzerFactory typeAnalyzerFactory})
10454 : super.con1(library, source, typeProvider) { 10469 : super.con1(library, source, typeProvider) {
10455 this._inheritanceManager = library.inheritanceManager; 10470 this._inheritanceManager = library.inheritanceManager;
10456 this._elementResolver = new ElementResolver(this); 10471 this._elementResolver = new ElementResolver(this);
10457 this._typeAnalyzer = new StaticTypeAnalyzer(this); 10472 this._typeAnalyzer = typeAnalyzer != null
10473 ? typeAnalyzer
10474 : (typeAnalyzerFactory != null
10475 ? typeAnalyzerFactory(this)
10476 : new StaticTypeAnalyzer(this));
10458 } 10477 }
10459 10478
10479
10460 /** 10480 /**
10461 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10481 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10462 * 10482 *
10463 * @param definingLibrary the element for the library containing the compilati on unit being 10483 * @param definingLibrary the element for the library containing the compilati on unit being
10464 * visited 10484 * visited
10465 * @param source the source representing the compilation unit being visited 10485 * @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 10486 * @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 10487 * @param errorListener the error listener that will be informed of any errors that are found
10468 * during resolution 10488 * during resolution
10469 */ 10489 */
(...skipping 3481 matching lines...) Expand 10 before | Expand all | Expand 10 after
13951 } 13971 }
13952 SimpleIdentifier stackTrace = node.stackTraceParameter; 13972 SimpleIdentifier stackTrace = node.stackTraceParameter;
13953 if (stackTrace != null) { 13973 if (stackTrace != null) {
13954 _recordType(stackTrace, typeProvider.stackTraceType); 13974 _recordType(stackTrace, typeProvider.stackTraceType);
13955 } 13975 }
13956 return null; 13976 return null;
13957 } 13977 }
13958 13978
13959 @override 13979 @override
13960 Object visitClassDeclaration(ClassDeclaration node) { 13980 Object visitClassDeclaration(ClassDeclaration node) {
13981 _hasReferenceToSuper = false;
13982 super.visitClassDeclaration(node);
13983 ClassElementImpl classElement = _getClassElement(node.name);
13984 if (classElement != null) {
13985 classElement.hasReferenceToSuper = _hasReferenceToSuper;
13986 }
13987 }
13988
13989 @override
13990 void visitClassDeclarationInScope(ClassDeclaration node) {
13991 super.visitClassDeclarationInScope(node);
13961 ExtendsClause extendsClause = node.extendsClause; 13992 ExtendsClause extendsClause = node.extendsClause;
13962 WithClause withClause = node.withClause; 13993 WithClause withClause = node.withClause;
13963 ImplementsClause implementsClause = node.implementsClause; 13994 ImplementsClause implementsClause = node.implementsClause;
13964 _hasReferenceToSuper = false;
13965 super.visitClassDeclaration(node);
13966 ClassElementImpl classElement = _getClassElement(node.name); 13995 ClassElementImpl classElement = _getClassElement(node.name);
13967 InterfaceType superclassType = null; 13996 InterfaceType superclassType = null;
13968 if (extendsClause != null) { 13997 if (extendsClause != null) {
13969 ErrorCode errorCode = (withClause == null ? 13998 ErrorCode errorCode = (withClause == null ?
13970 CompileTimeErrorCode.EXTENDS_NON_CLASS : 13999 CompileTimeErrorCode.EXTENDS_NON_CLASS :
13971 CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS); 14000 CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS);
13972 superclassType = _resolveType( 14001 superclassType = _resolveType(
13973 extendsClause.superclass, 14002 extendsClause.superclass,
13974 errorCode, 14003 errorCode,
13975 CompileTimeErrorCode.EXTENDS_ENUM, 14004 CompileTimeErrorCode.EXTENDS_ENUM,
13976 errorCode); 14005 errorCode);
13977 if (!identical(superclassType, typeProvider.objectType)) { 14006 if (!identical(superclassType, typeProvider.objectType)) {
13978 classElement.validMixin = false; 14007 classElement.validMixin = false;
13979 } 14008 }
13980 } 14009 }
13981 if (classElement != null) { 14010 if (classElement != null) {
13982 if (superclassType == null) { 14011 if (superclassType == null) {
13983 InterfaceType objectType = typeProvider.objectType; 14012 InterfaceType objectType = typeProvider.objectType;
13984 if (!identical(classElement.type, objectType)) { 14013 if (!identical(classElement.type, objectType)) {
13985 superclassType = objectType; 14014 superclassType = objectType;
13986 } 14015 }
13987 } 14016 }
13988 classElement.supertype = superclassType; 14017 classElement.supertype = superclassType;
13989 classElement.hasReferenceToSuper = _hasReferenceToSuper;
13990 } 14018 }
13991 _resolve(classElement, withClause, implementsClause); 14019 _resolve(classElement, withClause, implementsClause);
13992 return null; 14020 return null;
13993 } 14021 }
13994 14022
13995 @override 14023 @override
13996 void visitClassMembersInScope(ClassDeclaration node) { 14024 void visitClassMembersInScope(ClassDeclaration node) {
13997 // 14025 //
13998 // Process field declarations before constructors and methods so that the 14026 // Process field declarations before constructors and methods so that the
13999 // types of field formal parameters can be correctly resolved. 14027 // types of field formal parameters can be correctly resolved.
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after
15693 * library. 15721 * library.
15694 */ 15722 */
15695 final HashSet<String> members = new HashSet<String>(); 15723 final HashSet<String> members = new HashSet<String>();
15696 15724
15697 /** 15725 /**
15698 * Names of resolved or unresolved class members that are read in the 15726 * Names of resolved or unresolved class members that are read in the
15699 * library. 15727 * library.
15700 */ 15728 */
15701 final HashSet<String> readMembers = new HashSet<String>(); 15729 final HashSet<String> readMembers = new HashSet<String>();
15702 } 15730 }
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