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

Side by Side Diff: pkg/compiler/lib/src/resolution/signatures.dart

Issue 2710973002: Revert "Add support for the new function-type syntax." (Closed)
Patch Set: Created 3 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
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 dart2js.resolution.signatures; 5 library dart2js.resolution.signatures;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart'; 8 import '../common/resolution.dart';
9 import '../elements/resolution_types.dart'; 9 import '../elements/resolution_types.dart';
10 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_CONST); 86 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_CONST);
87 } 87 }
88 if (node.modifiers.isStatic) { 88 if (node.modifiers.isStatic) {
89 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_STATIC); 89 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_STATIC);
90 } 90 }
91 91
92 if (currentDefinitions != null) { 92 if (currentDefinitions != null) {
93 reporter.internalError(node, 'function type parameters not supported'); 93 reporter.internalError(node, 'function type parameters not supported');
94 } 94 }
95 currentDefinitions = node; 95 currentDefinitions = node;
96 FormalElementX element = definition == null 96 FormalElementX element = definition.accept(this);
97 ? createUnnamedParameter() // This happens in function types.
98 : definition.accept(this);
99 if (currentDefinitions.metadata != null) { 97 if (currentDefinitions.metadata != null) {
100 element.metadataInternal = 98 element.metadataInternal =
101 resolution.resolver.resolveMetadata(element, node); 99 resolution.resolver.resolveMetadata(element, node);
102 } 100 }
103 currentDefinitions = null; 101 currentDefinitions = null;
104 return element; 102 return element;
105 } 103 }
106 104
107 void validateName(Identifier node) { 105 void validateName(Identifier node) {
108 if (isOptionalParameter && 106 if (isOptionalParameter &&
109 optionalParametersAreNamed && 107 optionalParametersAreNamed &&
110 Name.isPrivateName(node.source)) { 108 Name.isPrivateName(node.source)) {
111 reporter.reportErrorMessage(node, MessageKind.PRIVATE_NAMED_PARAMETER); 109 reporter.reportErrorMessage(node, MessageKind.PRIVATE_NAMED_PARAMETER);
112 } 110 }
113 } 111 }
114 112
115 void computeParameterType(FormalElementX element, 113 void computeParameterType(FormalElementX element,
116 [VariableElement fieldElement]) { 114 [VariableElement fieldElement]) {
117 // Function-type as in `foo(int bar(String x))` 115 void computeFunctionType(FunctionExpression functionExpression) {
118 void computeInlineFunctionType(FunctionExpression functionExpression) {
119 FunctionSignature functionSignature = SignatureResolver.analyze( 116 FunctionSignature functionSignature = SignatureResolver.analyze(
120 resolution, 117 resolution,
121 scope, 118 scope,
122 functionExpression.typeVariables, 119 functionExpression.typeVariables,
123 functionExpression.parameters, 120 functionExpression.parameters,
124 functionExpression.returnType, 121 functionExpression.returnType,
125 element, 122 element,
126 registry, 123 registry,
127 defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT); 124 defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT);
128 element.functionSignature = functionSignature; 125 element.functionSignature = functionSignature;
129 } 126 }
130 127
131 if (currentDefinitions.type != null) { 128 if (currentDefinitions.type != null) {
132 element.typeCache = resolveTypeAnnotation(currentDefinitions.type); 129 element.typeCache = resolveTypeAnnotation(currentDefinitions.type);
133 } else { 130 } else {
134 // Is node.definitions exactly one FunctionExpression? 131 // Is node.definitions exactly one FunctionExpression?
135 Link<Node> link = currentDefinitions.definitions.nodes; 132 Link<Node> link = currentDefinitions.definitions.nodes;
136 assert(invariant(currentDefinitions, !link.isEmpty)); 133 assert(invariant(currentDefinitions, !link.isEmpty));
137 assert(invariant(currentDefinitions, link.tail.isEmpty)); 134 assert(invariant(currentDefinitions, link.tail.isEmpty));
138 if (link.head.asFunctionExpression() != null) { 135 if (link.head.asFunctionExpression() != null) {
139 // Inline function typed parameter, like `void m(int f(String s))`. 136 // Inline function typed parameter, like `void m(int f(String s))`.
140 computeInlineFunctionType(link.head); 137 computeFunctionType(link.head);
141 } else if (link.head.asSend() != null && 138 } else if (link.head.asSend() != null &&
142 link.head.asSend().selector.asFunctionExpression() != null) { 139 link.head.asSend().selector.asFunctionExpression() != null) {
143 // Inline function typed initializing formal or 140 // Inline function typed initializing formal or
144 // parameter with default value, like `C(int this.f(String s))` or 141 // parameter with default value, like `C(int this.f(String s))` or
145 // `void m([int f(String s) = null])`. 142 // `void m([int f(String s) = null])`.
146 computeInlineFunctionType( 143 computeFunctionType(link.head.asSend().selector.asFunctionExpression());
147 link.head.asSend().selector.asFunctionExpression());
148 } else { 144 } else {
149 assert(invariant(currentDefinitions, 145 assert(invariant(currentDefinitions,
150 link.head.asIdentifier() != null || link.head.asSend() != null)); 146 link.head.asIdentifier() != null || link.head.asSend() != null));
151 if (fieldElement != null) { 147 if (fieldElement != null) {
152 element.typeCache = fieldElement.computeType(resolution); 148 element.typeCache = fieldElement.computeType(resolution);
153 } else { 149 } else {
154 element.typeCache = const ResolutionDynamicType(); 150 element.typeCache = const ResolutionDynamicType();
155 } 151 }
156 } 152 }
157 } 153 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 enclosingElement, currentDefinitions, name, initializer, 190 enclosingElement, currentDefinitions, name, initializer,
195 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed); 191 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed);
196 } else { 192 } else {
197 parameter = new FormalElementX( 193 parameter = new FormalElementX(
198 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name); 194 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name);
199 } 195 }
200 computeParameterType(parameter); 196 computeParameterType(parameter);
201 return parameter; 197 return parameter;
202 } 198 }
203 199
204 FormalElementX createUnnamedParameter() {
205 FormalElementX parameter;
206 assert(!createRealParameters);
207 parameter = new FormalElementX.unnamed(
208 ElementKind.PARAMETER, enclosingElement, currentDefinitions);
209 computeParameterType(parameter);
210 return parameter;
211 }
212
213 InitializingFormalElementX createFieldParameter( 200 InitializingFormalElementX createFieldParameter(
214 Send node, Expression initializer) { 201 Send node, Expression initializer) {
215 InitializingFormalElementX element; 202 InitializingFormalElementX element;
216 Identifier receiver = node.receiver.asIdentifier(); 203 Identifier receiver = node.receiver.asIdentifier();
217 if (receiver == null || !receiver.isThis()) { 204 if (receiver == null || !receiver.isThis()) {
218 reporter.reportErrorMessage(node, MessageKind.INVALID_PARAMETER); 205 reporter.reportErrorMessage(node, MessageKind.INVALID_PARAMETER);
219 return new ErroneousInitializingFormalElementX( 206 return new ErroneousInitializingFormalElementX(
220 getParameterName(node), enclosingElement); 207 getParameterName(node), enclosingElement);
221 } else { 208 } else {
222 if (!enclosingElement.isGenerativeConstructor) { 209 if (!enclosingElement.isGenerativeConstructor) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 for (FormalElement parameter in parameters) { 419 for (FormalElement parameter in parameters) {
433 parameterTypes.addLast(parameter.type); 420 parameterTypes.addLast(parameter.type);
434 } 421 }
435 List<ResolutionDartType> optionalParameterTypes = 422 List<ResolutionDartType> optionalParameterTypes =
436 const <ResolutionDartType>[]; 423 const <ResolutionDartType>[];
437 List<String> namedParameters = const <String>[]; 424 List<String> namedParameters = const <String>[];
438 List<ResolutionDartType> namedParameterTypes = const <ResolutionDartType>[]; 425 List<ResolutionDartType> namedParameterTypes = const <ResolutionDartType>[];
439 List<Element> orderedOptionalParameters = 426 List<Element> orderedOptionalParameters =
440 visitor.optionalParameters.toList(); 427 visitor.optionalParameters.toList();
441 if (visitor.optionalParametersAreNamed) { 428 if (visitor.optionalParametersAreNamed) {
442 // TODO(karlklose); replace when [visitor.optionalParameters] is a [List]. 429 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List].
443 orderedOptionalParameters.sort((Element a, Element b) { 430 orderedOptionalParameters.sort((Element a, Element b) {
444 return a.name.compareTo(b.name); 431 return a.name.compareTo(b.name);
445 }); 432 });
446 LinkBuilder<String> namedParametersBuilder = new LinkBuilder<String>(); 433 LinkBuilder<String> namedParametersBuilder = new LinkBuilder<String>();
447 LinkBuilder<ResolutionDartType> namedParameterTypesBuilder = 434 LinkBuilder<ResolutionDartType> namedParameterTypesBuilder =
448 new LinkBuilder<ResolutionDartType>(); 435 new LinkBuilder<ResolutionDartType>();
449 for (FormalElement parameter in orderedOptionalParameters) { 436 for (FormalElement parameter in orderedOptionalParameters) {
450 namedParametersBuilder.addLast(parameter.name); 437 namedParametersBuilder.addLast(parameter.name);
451 namedParameterTypesBuilder.addLast(parameter.type); 438 namedParameterTypesBuilder.addLast(parameter.type);
452 } 439 }
453 namedParameters = namedParametersBuilder.toLink().toList(growable: false); 440 namedParameters = namedParametersBuilder.toLink().toList(growable: false);
454 namedParameterTypes = 441 namedParameterTypes =
455 namedParameterTypesBuilder.toLink().toList(growable: false); 442 namedParameterTypesBuilder.toLink().toList(growable: false);
456 } else { 443 } else {
457 // TODO(karlklose); replace when [visitor.optionalParameters] is a [List]. 444 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List].
458 LinkBuilder<ResolutionDartType> optionalParameterTypesBuilder = 445 LinkBuilder<ResolutionDartType> optionalParameterTypesBuilder =
459 new LinkBuilder<ResolutionDartType>(); 446 new LinkBuilder<ResolutionDartType>();
460 for (FormalElement parameter in visitor.optionalParameters) { 447 for (FormalElement parameter in visitor.optionalParameters) {
461 optionalParameterTypesBuilder.addLast(parameter.type); 448 optionalParameterTypesBuilder.addLast(parameter.type);
462 } 449 }
463 optionalParameterTypes = 450 optionalParameterTypes =
464 optionalParameterTypesBuilder.toLink().toList(growable: false); 451 optionalParameterTypesBuilder.toLink().toList(growable: false);
465 } 452 }
466 ResolutionFunctionType type = new ResolutionFunctionType( 453 ResolutionFunctionType type = new ResolutionFunctionType(
467 element.declaration, 454 element.declaration,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 /// variables of the function signature itself when its signature is analyzed. 490 /// variables of the function signature itself when its signature is analyzed.
504 class FunctionSignatureBuildingScope extends TypeVariablesScope { 491 class FunctionSignatureBuildingScope extends TypeVariablesScope {
505 @override 492 @override
506 final List<ResolutionDartType> typeVariables; 493 final List<ResolutionDartType> typeVariables;
507 494
508 FunctionSignatureBuildingScope(Scope parent, this.typeVariables) 495 FunctionSignatureBuildingScope(Scope parent, this.typeVariables)
509 : super(parent); 496 : super(parent);
510 497
511 String toString() => 'FunctionSignatureBuildingScope($typeVariables)'; 498 String toString() => 'FunctionSignatureBuildingScope($typeVariables)';
512 } 499 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/resolution_common.dart ('k') | pkg/compiler/lib/src/resolution/type_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698