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

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

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Update status files and update test-generator for checked mode. Created 3 years, 11 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 '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_CONST); 87 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_CONST);
88 } 88 }
89 if (node.modifiers.isStatic) { 89 if (node.modifiers.isStatic) {
90 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_STATIC); 90 reporter.reportErrorMessage(node, MessageKind.FORMAL_DECLARED_STATIC);
91 } 91 }
92 92
93 if (currentDefinitions != null) { 93 if (currentDefinitions != null) {
94 reporter.internalError(node, 'function type parameters not supported'); 94 reporter.internalError(node, 'function type parameters not supported');
95 } 95 }
96 currentDefinitions = node; 96 currentDefinitions = node;
97 FormalElementX element = definition.accept(this); 97 FormalElementX element = definition == new NoIdentifier()
Siggi Cherem (dart-lang) 2016/12/29 22:46:57 nit: this is more of a readability nit, than anyth
floitsch 2016/12/30 14:55:47 changed to NoIdentifier.singleton done.
98 ? createUnnamedParameter() // This happens in function types.
99 : definition.accept(this);
98 if (currentDefinitions.metadata != null) { 100 if (currentDefinitions.metadata != null) {
99 element.metadataInternal = 101 element.metadataInternal =
100 resolution.resolver.resolveMetadata(element, node); 102 resolution.resolver.resolveMetadata(element, node);
101 } 103 }
102 currentDefinitions = null; 104 currentDefinitions = null;
103 return element; 105 return element;
104 } 106 }
105 107
106 void validateName(Identifier node) { 108 void validateName(Identifier node) {
107 if (isOptionalParameter && 109 if (isOptionalParameter &&
108 optionalParametersAreNamed && 110 optionalParametersAreNamed &&
109 Name.isPrivateName(node.source)) { 111 Name.isPrivateName(node.source)) {
110 reporter.reportErrorMessage(node, MessageKind.PRIVATE_NAMED_PARAMETER); 112 reporter.reportErrorMessage(node, MessageKind.PRIVATE_NAMED_PARAMETER);
111 } 113 }
112 } 114 }
113 115
114 void computeParameterType(FormalElementX element, 116 void computeParameterType(FormalElementX element,
115 [VariableElement fieldElement]) { 117 [VariableElement fieldElement]) {
116 void computeFunctionType(FunctionExpression functionExpression) { 118 // Function-type as in `foo(int bar(String x))`
119 void computeInlineFunctionType(FunctionExpression functionExpression) {
117 FunctionSignature functionSignature = SignatureResolver.analyze( 120 FunctionSignature functionSignature = SignatureResolver.analyze(
118 resolution, 121 resolution,
119 scope, 122 scope,
120 functionExpression.typeVariables, 123 functionExpression.typeVariables,
121 functionExpression.parameters, 124 functionExpression.parameters,
122 functionExpression.returnType, 125 functionExpression.returnType,
123 element, 126 element,
124 registry, 127 registry,
125 defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT); 128 defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT);
126 element.functionSignature = functionSignature; 129 element.functionSignature = functionSignature;
127 } 130 }
128 131
129 if (currentDefinitions.type != null) { 132 if (currentDefinitions.type != null) {
130 element.typeCache = resolveTypeAnnotation(currentDefinitions.type); 133 element.typeCache = resolveTypeAnnotation(currentDefinitions.type);
131 } else { 134 } else {
132 // Is node.definitions exactly one FunctionExpression? 135 // Is node.definitions exactly one FunctionExpression?
133 Link<Node> link = currentDefinitions.definitions.nodes; 136 Link<Node> link = currentDefinitions.definitions.nodes;
134 assert(invariant(currentDefinitions, !link.isEmpty)); 137 assert(invariant(currentDefinitions, !link.isEmpty));
135 assert(invariant(currentDefinitions, link.tail.isEmpty)); 138 assert(invariant(currentDefinitions, link.tail.isEmpty));
136 if (link.head.asFunctionExpression() != null) { 139 if (link.head.asFunctionExpression() != null) {
137 // Inline function typed parameter, like `void m(int f(String s))`. 140 // Inline function typed parameter, like `void m(int f(String s))`.
138 computeFunctionType(link.head); 141 computeInlineFunctionType(link.head);
139 } else if (link.head.asSend() != null && 142 } else if (link.head.asSend() != null &&
140 link.head.asSend().selector.asFunctionExpression() != null) { 143 link.head.asSend().selector.asFunctionExpression() != null) {
141 // Inline function typed initializing formal or 144 // Inline function typed initializing formal or
142 // parameter with default value, like `C(int this.f(String s))` or 145 // parameter with default value, like `C(int this.f(String s))` or
143 // `void m([int f(String s) = null])`. 146 // `void m([int f(String s) = null])`.
144 computeFunctionType(link.head.asSend().selector.asFunctionExpression()); 147 computeInlineFunctionType(
148 link.head.asSend().selector.asFunctionExpression());
145 } else { 149 } else {
146 assert(invariant(currentDefinitions, 150 assert(invariant(currentDefinitions,
147 link.head.asIdentifier() != null || link.head.asSend() != null)); 151 link.head.asIdentifier() != null || link.head.asSend() != null));
148 if (fieldElement != null) { 152 if (fieldElement != null) {
149 element.typeCache = fieldElement.computeType(resolution); 153 element.typeCache = fieldElement.computeType(resolution);
150 } else { 154 } else {
151 element.typeCache = const DynamicType(); 155 element.typeCache = const DynamicType();
152 } 156 }
153 } 157 }
154 } 158 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 enclosingElement, currentDefinitions, name, initializer, 195 enclosingElement, currentDefinitions, name, initializer,
192 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed); 196 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed);
193 } else { 197 } else {
194 parameter = new FormalElementX( 198 parameter = new FormalElementX(
195 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name); 199 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name);
196 } 200 }
197 computeParameterType(parameter); 201 computeParameterType(parameter);
198 return parameter; 202 return parameter;
199 } 203 }
200 204
205 FormalElementX createUnnamedParameter() {
206 FormalElementX parameter;
207 assert(!createRealParameters);
208 parameter = new FormalElementX.unnamed(
209 ElementKind.PARAMETER, enclosingElement, currentDefinitions);
210 computeParameterType(parameter);
211 return parameter;
212 }
213
201 InitializingFormalElementX createFieldParameter( 214 InitializingFormalElementX createFieldParameter(
202 Send node, Expression initializer) { 215 Send node, Expression initializer) {
203 InitializingFormalElementX element; 216 InitializingFormalElementX element;
204 Identifier receiver = node.receiver.asIdentifier(); 217 Identifier receiver = node.receiver.asIdentifier();
205 if (receiver == null || !receiver.isThis()) { 218 if (receiver == null || !receiver.isThis()) {
206 reporter.reportErrorMessage(node, MessageKind.INVALID_PARAMETER); 219 reporter.reportErrorMessage(node, MessageKind.INVALID_PARAMETER);
207 return new ErroneousInitializingFormalElementX( 220 return new ErroneousInitializingFormalElementX(
208 getParameterName(node), enclosingElement); 221 getParameterName(node), enclosingElement);
209 } else { 222 } else {
210 if (!enclosingElement.isGenerativeConstructor) { 223 if (!enclosingElement.isGenerativeConstructor) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 LinkBuilder<DartType> parameterTypes = new LinkBuilder<DartType>(); 424 LinkBuilder<DartType> parameterTypes = new LinkBuilder<DartType>();
412 for (FormalElement parameter in parameters) { 425 for (FormalElement parameter in parameters) {
413 parameterTypes.addLast(parameter.type); 426 parameterTypes.addLast(parameter.type);
414 } 427 }
415 List<DartType> optionalParameterTypes = const <DartType>[]; 428 List<DartType> optionalParameterTypes = const <DartType>[];
416 List<String> namedParameters = const <String>[]; 429 List<String> namedParameters = const <String>[];
417 List<DartType> namedParameterTypes = const <DartType>[]; 430 List<DartType> namedParameterTypes = const <DartType>[];
418 List<Element> orderedOptionalParameters = 431 List<Element> orderedOptionalParameters =
419 visitor.optionalParameters.toList(); 432 visitor.optionalParameters.toList();
420 if (visitor.optionalParametersAreNamed) { 433 if (visitor.optionalParametersAreNamed) {
421 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List]. 434 // TODO(karlklose); replace when [visitor.optionalParameters] is a [List].
422 orderedOptionalParameters.sort((Element a, Element b) { 435 orderedOptionalParameters.sort((Element a, Element b) {
423 return a.name.compareTo(b.name); 436 return a.name.compareTo(b.name);
424 }); 437 });
425 LinkBuilder<String> namedParametersBuilder = new LinkBuilder<String>(); 438 LinkBuilder<String> namedParametersBuilder = new LinkBuilder<String>();
426 LinkBuilder<DartType> namedParameterTypesBuilder = 439 LinkBuilder<DartType> namedParameterTypesBuilder =
427 new LinkBuilder<DartType>(); 440 new LinkBuilder<DartType>();
428 for (FormalElement parameter in orderedOptionalParameters) { 441 for (FormalElement parameter in orderedOptionalParameters) {
429 namedParametersBuilder.addLast(parameter.name); 442 namedParametersBuilder.addLast(parameter.name);
430 namedParameterTypesBuilder.addLast(parameter.type); 443 namedParameterTypesBuilder.addLast(parameter.type);
431 } 444 }
432 namedParameters = namedParametersBuilder.toLink().toList(growable: false); 445 namedParameters = namedParametersBuilder.toLink().toList(growable: false);
433 namedParameterTypes = 446 namedParameterTypes =
434 namedParameterTypesBuilder.toLink().toList(growable: false); 447 namedParameterTypesBuilder.toLink().toList(growable: false);
435 } else { 448 } else {
436 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List]. 449 // TODO(karlklose); replace when [visitor.optionalParameters] is a [List].
437 LinkBuilder<DartType> optionalParameterTypesBuilder = 450 LinkBuilder<DartType> optionalParameterTypesBuilder =
438 new LinkBuilder<DartType>(); 451 new LinkBuilder<DartType>();
439 for (FormalElement parameter in visitor.optionalParameters) { 452 for (FormalElement parameter in visitor.optionalParameters) {
440 optionalParameterTypesBuilder.addLast(parameter.type); 453 optionalParameterTypesBuilder.addLast(parameter.type);
441 } 454 }
442 optionalParameterTypes = 455 optionalParameterTypes =
443 optionalParameterTypesBuilder.toLink().toList(growable: false); 456 optionalParameterTypesBuilder.toLink().toList(growable: false);
444 } 457 }
445 FunctionType type = new FunctionType( 458 FunctionType type = new FunctionType(
446 element.declaration, 459 element.declaration,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 /// variables of the function signature itself when its signature is analyzed. 495 /// variables of the function signature itself when its signature is analyzed.
483 class FunctionSignatureBuildingScope extends TypeVariablesScope { 496 class FunctionSignatureBuildingScope extends TypeVariablesScope {
484 @override 497 @override
485 final List<DartType> typeVariables; 498 final List<DartType> typeVariables;
486 499
487 FunctionSignatureBuildingScope(Scope parent, this.typeVariables) 500 FunctionSignatureBuildingScope(Scope parent, this.typeVariables)
488 : super(parent); 501 : super(parent);
489 502
490 String toString() => 'FunctionSignatureBuildingScope($typeVariables)'; 503 String toString() => 'FunctionSignatureBuildingScope($typeVariables)';
491 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698