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

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

Issue 1217373005: Generic method support in element model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
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:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'constant.dart'; 10 import 'constant.dart';
(...skipping 2654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2665 } 2665 }
2666 _currentHolder.addParameter(parameter); 2666 _currentHolder.addParameter(parameter);
2667 parameterName.staticElement = parameter; 2667 parameterName.staticElement = parameter;
2668 } 2668 }
2669 // 2669 //
2670 // The children of this parameter include any parameters defined on the type 2670 // The children of this parameter include any parameters defined on the type
2671 // of this parameter. 2671 // of this parameter.
2672 // 2672 //
2673 ElementHolder holder = new ElementHolder(); 2673 ElementHolder holder = new ElementHolder();
2674 _visitChildren(holder, node); 2674 _visitChildren(holder, node);
2675 (node.element as ParameterElementImpl).parameters = holder.parameters; 2675 ParameterElementImpl element = node.element;
2676 element.parameters = holder.parameters;
2677 element.typeParameters = holder.typeParameters;
2676 holder.validate(); 2678 holder.validate();
2677 return null; 2679 return null;
2678 } 2680 }
2679 2681
2680 @override 2682 @override
2681 Object visitFunctionDeclaration(FunctionDeclaration node) { 2683 Object visitFunctionDeclaration(FunctionDeclaration node) {
2682 FunctionExpression expression = node.functionExpression; 2684 FunctionExpression expression = node.functionExpression;
2683 if (expression != null) { 2685 if (expression != null) {
2684 ElementHolder holder = new ElementHolder(); 2686 ElementHolder holder = new ElementHolder();
2685 bool wasInFunction = _inFunction; 2687 bool wasInFunction = _inFunction;
2686 _inFunction = true; 2688 _inFunction = true;
2687 try { 2689 try {
2688 _visitChildren(holder, node); 2690 _visitChildren(holder, node);
2689 } finally { 2691 } finally {
2690 _inFunction = wasInFunction; 2692 _inFunction = wasInFunction;
2691 } 2693 }
2692 FunctionBody body = expression.body; 2694 FunctionBody body = expression.body;
2693 sc.Token property = node.propertyKeyword; 2695 sc.Token property = node.propertyKeyword;
2694 if (property == null || _inFunction) { 2696 if (property == null || _inFunction) {
2695 SimpleIdentifier functionName = node.name; 2697 SimpleIdentifier functionName = node.name;
2696 FunctionElementImpl element = 2698 FunctionElementImpl element =
2697 new FunctionElementImpl.forNode(functionName); 2699 new FunctionElementImpl.forNode(functionName);
2698 if (node.externalKeyword != null) { 2700 if (node.externalKeyword != null) {
2699 element.external = true; 2701 element.external = true;
2700 } 2702 }
2701 element.functions = holder.functions; 2703 element.functions = holder.functions;
2702 element.labels = holder.labels; 2704 element.labels = holder.labels;
2703 element.localVariables = holder.localVariables; 2705 element.localVariables = holder.localVariables;
2704 element.parameters = holder.parameters; 2706 element.parameters = holder.parameters;
2707 element.typeParameters = holder.typeParameters;
2705 if (body.isAsynchronous) { 2708 if (body.isAsynchronous) {
2706 element.asynchronous = true; 2709 element.asynchronous = true;
2707 } 2710 }
2708 if (body.isGenerator) { 2711 if (body.isGenerator) {
2709 element.generator = true; 2712 element.generator = true;
2710 } 2713 }
2711 if (_inFunction) { 2714 if (_inFunction) {
2712 Block enclosingBlock = node.getAncestor((node) => node is Block); 2715 Block enclosingBlock = node.getAncestor((node) => node is Block);
2713 if (enclosingBlock != null) { 2716 if (enclosingBlock != null) {
2714 int functionEnd = node.offset + node.length; 2717 int functionEnd = node.offset + node.length;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 } finally { 2805 } finally {
2803 _inFunction = wasInFunction; 2806 _inFunction = wasInFunction;
2804 } 2807 }
2805 FunctionBody body = node.body; 2808 FunctionBody body = node.body;
2806 FunctionElementImpl element = 2809 FunctionElementImpl element =
2807 new FunctionElementImpl.forOffset(node.beginToken.offset); 2810 new FunctionElementImpl.forOffset(node.beginToken.offset);
2808 element.functions = holder.functions; 2811 element.functions = holder.functions;
2809 element.labels = holder.labels; 2812 element.labels = holder.labels;
2810 element.localVariables = holder.localVariables; 2813 element.localVariables = holder.localVariables;
2811 element.parameters = holder.parameters; 2814 element.parameters = holder.parameters;
2815 element.typeParameters = holder.typeParameters;
2812 if (body.isAsynchronous) { 2816 if (body.isAsynchronous) {
2813 element.asynchronous = true; 2817 element.asynchronous = true;
2814 } 2818 }
2815 if (body.isGenerator) { 2819 if (body.isGenerator) {
2816 element.generator = true; 2820 element.generator = true;
2817 } 2821 }
2818 if (_inFunction) { 2822 if (_inFunction) {
2819 Block enclosingBlock = node.getAncestor((node) => node is Block); 2823 Block enclosingBlock = node.getAncestor((node) => node is Block);
2820 if (enclosingBlock != null) { 2824 if (enclosingBlock != null) {
2821 int functionEnd = node.offset + node.length; 2825 int functionEnd = node.offset + node.length;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2864 _setParameterVisibleRange(node, parameter); 2868 _setParameterVisibleRange(node, parameter);
2865 _currentHolder.addParameter(parameter); 2869 _currentHolder.addParameter(parameter);
2866 parameterName.staticElement = parameter; 2870 parameterName.staticElement = parameter;
2867 } 2871 }
2868 // 2872 //
2869 // The children of this parameter include any parameters defined on the type 2873 // The children of this parameter include any parameters defined on the type
2870 //of this parameter. 2874 //of this parameter.
2871 // 2875 //
2872 ElementHolder holder = new ElementHolder(); 2876 ElementHolder holder = new ElementHolder();
2873 _visitChildren(holder, node); 2877 _visitChildren(holder, node);
2874 (node.element as ParameterElementImpl).parameters = holder.parameters; 2878 ParameterElementImpl element = node.element;
2879 element.parameters = holder.parameters;
2880 element.typeParameters = holder.typeParameters;
2875 holder.validate(); 2881 holder.validate();
2876 return null; 2882 return null;
2877 } 2883 }
2878 2884
2879 @override 2885 @override
2880 Object visitLabeledStatement(LabeledStatement node) { 2886 Object visitLabeledStatement(LabeledStatement node) {
2881 bool onSwitchStatement = node.statement is SwitchStatement; 2887 bool onSwitchStatement = node.statement is SwitchStatement;
2882 for (Label label in node.labels) { 2888 for (Label label in node.labels) {
2883 SimpleIdentifier labelName = label.label; 2889 SimpleIdentifier labelName = label.label;
2884 LabelElementImpl element = 2890 LabelElementImpl element =
(...skipping 29 matching lines...) Expand all
2914 new MethodElementImpl(nameOfMethod, methodName.offset); 2920 new MethodElementImpl(nameOfMethod, methodName.offset);
2915 element.abstract = node.isAbstract; 2921 element.abstract = node.isAbstract;
2916 if (node.externalKeyword != null) { 2922 if (node.externalKeyword != null) {
2917 element.external = true; 2923 element.external = true;
2918 } 2924 }
2919 element.functions = holder.functions; 2925 element.functions = holder.functions;
2920 element.labels = holder.labels; 2926 element.labels = holder.labels;
2921 element.localVariables = holder.localVariables; 2927 element.localVariables = holder.localVariables;
2922 element.parameters = holder.parameters; 2928 element.parameters = holder.parameters;
2923 element.static = isStatic; 2929 element.static = isStatic;
2930 element.typeParameters = holder.typeParameters;
2924 if (body.isAsynchronous) { 2931 if (body.isAsynchronous) {
2925 element.asynchronous = true; 2932 element.asynchronous = true;
2926 } 2933 }
2927 if (body.isGenerator) { 2934 if (body.isGenerator) {
2928 element.generator = true; 2935 element.generator = true;
2929 } 2936 }
2930 _currentHolder.addMethod(element); 2937 _currentHolder.addMethod(element);
2931 methodName.staticElement = element; 2938 methodName.staticElement = element;
2932 } else { 2939 } else {
2933 SimpleIdentifier propertyNameNode = node.name; 2940 SimpleIdentifier propertyNameNode = node.name;
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
4288 4295
4289 /** 4296 /**
4290 * Return `true` if the given [node] exits. 4297 * Return `true` if the given [node] exits.
4291 */ 4298 */
4292 static bool exits(AstNode node) { 4299 static bool exits(AstNode node) {
4293 return new ExitDetector()._nodeExits(node); 4300 return new ExitDetector()._nodeExits(node);
4294 } 4301 }
4295 } 4302 }
4296 4303
4297 /** 4304 /**
4298 * Instances of the class `FunctionScope` implement the scope defined by a funct ion. 4305 * The scope defined by a function.
4299 */ 4306 */
4300 class FunctionScope extends EnclosedScope { 4307 class FunctionScope extends EnclosedScope {
4308 /**
4309 * The element representing the function that defines this scope.
4310 */
4301 final ExecutableElement _functionElement; 4311 final ExecutableElement _functionElement;
4302 4312
4313 /**
4314 * A flag indicating whether the parameters have already been defined, used to
4315 * prevent the parameters from being defined multiple times.
4316 */
4303 bool _parametersDefined = false; 4317 bool _parametersDefined = false;
4304 4318
4305 /** 4319 /**
4306 * Initialize a newly created scope enclosed within another scope. 4320 * Initialize a newly created scope enclosed within the [enclosingScope] that
4307 * 4321 * represents the given [_functionElement].
4308 * @param enclosingScope the scope in which this scope is lexically enclosed
4309 * @param functionElement the element representing the type represented by thi s scope
4310 */ 4322 */
4311 FunctionScope(Scope enclosingScope, this._functionElement) 4323 FunctionScope(Scope enclosingScope, this._functionElement)
4312 : super(new EnclosedScope(enclosingScope)) { 4324 : super(new EnclosedScope(new EnclosedScope(enclosingScope))) {
4313 if (_functionElement == null) { 4325 if (_functionElement == null) {
4314 throw new IllegalArgumentException("function element cannot be null"); 4326 throw new IllegalArgumentException("function element cannot be null");
4315 } 4327 }
4328 _defineTypeParameters();
4316 } 4329 }
4317 4330
4318 /** 4331 /**
4319 * Define the parameters for the given function in the scope that encloses thi s function. 4332 * Define the parameters for the given function in the scope that encloses
4333 * this function.
4320 */ 4334 */
4321 void defineParameters() { 4335 void defineParameters() {
4322 if (_parametersDefined) { 4336 if (_parametersDefined) {
4323 return; 4337 return;
4324 } 4338 }
4325 _parametersDefined = true; 4339 _parametersDefined = true;
4326 Scope parameterScope = enclosingScope; 4340 Scope parameterScope = enclosingScope;
4327 for (ParameterElement parameter in _functionElement.parameters) { 4341 for (ParameterElement parameter in _functionElement.parameters) {
4328 if (!parameter.isInitializingFormal) { 4342 if (!parameter.isInitializingFormal) {
4329 parameterScope.define(parameter); 4343 parameterScope.define(parameter);
4330 } 4344 }
4331 } 4345 }
4332 } 4346 }
4347
4348 /**
4349 * Define the type parameters for the function.
4350 */
4351 void _defineTypeParameters() {
4352 Scope typeParameterScope = enclosingScope.enclosingScope;
4353 for (TypeParameterElement typeParameter
4354 in _functionElement.typeParameters) {
4355 typeParameterScope.define(typeParameter);
4356 }
4357 }
4333 } 4358 }
4334 4359
4335 /** 4360 /**
4336 * Instances of the class `FunctionTypeScope` implement the scope defined by a f unction type 4361 * The scope defined by a function type alias.
4337 * alias.
4338 */ 4362 */
4339 class FunctionTypeScope extends EnclosedScope { 4363 class FunctionTypeScope extends EnclosedScope {
4340 final FunctionTypeAliasElement _typeElement; 4364 final FunctionTypeAliasElement _typeElement;
4341 4365
4342 bool _parametersDefined = false; 4366 bool _parametersDefined = false;
4343 4367
4344 /** 4368 /**
4345 * Initialize a newly created scope enclosed within another scope. 4369 * Initialize a newly created scope enclosed within the [enclosingScope] that
4346 * 4370 * represents the given [_typeElement].
4347 * @param enclosingScope the scope in which this scope is lexically enclosed
4348 * @param typeElement the element representing the type alias represented by t his scope
4349 */ 4371 */
4350 FunctionTypeScope(Scope enclosingScope, this._typeElement) 4372 FunctionTypeScope(Scope enclosingScope, this._typeElement)
4351 : super(new EnclosedScope(enclosingScope)) { 4373 : super(new EnclosedScope(enclosingScope)) {
4352 _defineTypeParameters(); 4374 _defineTypeParameters();
4353 } 4375 }
4354 4376
4355 /** 4377 /**
4356 * Define the parameters for the function type alias. 4378 * Define the parameters for the function type alias.
4357 *
4358 * @param typeElement the element representing the type represented by this sc ope
4359 */ 4379 */
4360 void defineParameters() { 4380 void defineParameters() {
4361 if (_parametersDefined) { 4381 if (_parametersDefined) {
4362 return; 4382 return;
4363 } 4383 }
4364 _parametersDefined = true; 4384 _parametersDefined = true;
4365 for (ParameterElement parameter in _typeElement.parameters) { 4385 for (ParameterElement parameter in _typeElement.parameters) {
4366 define(parameter); 4386 define(parameter);
4367 } 4387 }
4368 } 4388 }
4369 4389
4370 /** 4390 /**
4371 * Define the type parameters for the function type alias. 4391 * Define the type parameters for the function type alias.
4372 *
4373 * @param typeElement the element representing the type represented by this sc ope
4374 */ 4392 */
4375 void _defineTypeParameters() { 4393 void _defineTypeParameters() {
4376 Scope typeParameterScope = enclosingScope; 4394 Scope typeParameterScope = enclosingScope;
4377 for (TypeParameterElement typeParameter in _typeElement.typeParameters) { 4395 for (TypeParameterElement typeParameter in _typeElement.typeParameters) {
4378 typeParameterScope.define(typeParameter); 4396 typeParameterScope.define(typeParameter);
4379 } 4397 }
4380 } 4398 }
4381 } 4399 }
4382 4400
4383 /** 4401 /**
(...skipping 7689 matching lines...) Expand 10 before | Expand all | Expand 10 after
12073 try { 12091 try {
12074 nameScope = new FunctionTypeScope(nameScope, node.element); 12092 nameScope = new FunctionTypeScope(nameScope, node.element);
12075 super.visitFunctionTypeAlias(node); 12093 super.visitFunctionTypeAlias(node);
12076 } finally { 12094 } finally {
12077 nameScope = outerScope; 12095 nameScope = outerScope;
12078 } 12096 }
12079 return null; 12097 return null;
12080 } 12098 }
12081 12099
12082 @override 12100 @override
12101 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
12102 Scope outerScope = nameScope;
12103 try {
12104 ParameterElement parameterElement = node.element;
12105 if (parameterElement == null) {
12106 AnalysisEngine.instance.logger.logInformation(
12107 "Missing element for function typed formal parameter ${node.identifi er.name} in ${definingLibrary.source.fullName}",
12108 new CaughtException(new AnalysisException(), null));
12109 } else {
12110 nameScope = new EnclosedScope(nameScope);
12111 for (TypeParameterElement typeParameter
12112 in parameterElement.typeParameters) {
12113 nameScope.define(typeParameter);
12114 }
12115 }
12116 super.visitFunctionTypedFormalParameter(node);
12117 } finally {
12118 nameScope = outerScope;
12119 }
12120 return null;
12121 }
12122
12123 @override
12083 Object visitIfStatement(IfStatement node) { 12124 Object visitIfStatement(IfStatement node) {
12084 safelyVisit(node.condition); 12125 safelyVisit(node.condition);
12085 visitStatementInScope(node.thenStatement); 12126 visitStatementInScope(node.thenStatement);
12086 visitStatementInScope(node.elseStatement); 12127 visitStatementInScope(node.elseStatement);
12087 return null; 12128 return null;
12088 } 12129 }
12089 12130
12090 @override 12131 @override
12091 Object visitLabeledStatement(LabeledStatement node) { 12132 Object visitLabeledStatement(LabeledStatement node) {
12092 LabelScope outerScope = _addScopesFor(node.labels, node.unlabeled); 12133 LabelScope outerScope = _addScopesFor(node.labels, node.unlabeled);
(...skipping 3053 matching lines...) Expand 10 before | Expand all | Expand 10 after
15146 nonFields.add(node); 15187 nonFields.add(node);
15147 return null; 15188 return null;
15148 } 15189 }
15149 15190
15150 @override 15191 @override
15151 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15192 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15152 15193
15153 @override 15194 @override
15154 Object visitWithClause(WithClause node) => null; 15195 Object visitWithClause(WithClause node) => null;
15155 } 15196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698