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

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

Issue 1146943002: Change Link to List in FunctionSignature. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 part of resolution; 5 part of resolution;
6 6
7 /** 7 /**
8 * [SignatureResolver] resolves function signatures. 8 * [SignatureResolver] resolves function signatures.
9 */ 9 */
10 class SignatureResolver extends MappingVisitor<FormalElementX> { 10 class SignatureResolver extends MappingVisitor<FormalElementX> {
11 final ResolverVisitor resolver; 11 final ResolverVisitor resolver;
12 final FunctionTypedElement enclosingElement; 12 final FunctionTypedElement enclosingElement;
13 final Scope scope; 13 final Scope scope;
14 final MessageKind defaultValuesError; 14 final MessageKind defaultValuesError;
15 final bool createRealParameters; 15 final bool createRealParameters;
16 Link<Element> optionalParameters = const Link<Element>(); 16 List<Element> optionalParameters = const <Element>[];
17 int optionalParameterCount = 0; 17 int optionalParameterCount = 0;
18 bool isOptionalParameter = false; 18 bool isOptionalParameter = false;
19 bool optionalParametersAreNamed = false; 19 bool optionalParametersAreNamed = false;
20 VariableDefinitions currentDefinitions; 20 VariableDefinitions currentDefinitions;
21 21
22 SignatureResolver(Compiler compiler, 22 SignatureResolver(Compiler compiler,
23 FunctionTypedElement enclosingElement, 23 FunctionTypedElement enclosingElement,
24 ResolutionRegistry registry, 24 ResolutionRegistry registry,
25 {this.defaultValuesError, 25 {this.defaultValuesError,
26 this.createRealParameters}) 26 this.createRealParameters})
27 : this.enclosingElement = enclosingElement, 27 : this.enclosingElement = enclosingElement,
28 this.scope = enclosingElement.buildScope(), 28 this.scope = enclosingElement.buildScope(),
29 this.resolver = 29 this.resolver =
30 new ResolverVisitor(compiler, enclosingElement, registry), 30 new ResolverVisitor(compiler, enclosingElement, registry),
31 super(compiler, registry); 31 super(compiler, registry);
32 32
33 bool get defaultValuesAllowed => defaultValuesError == null; 33 bool get defaultValuesAllowed => defaultValuesError == null;
34 34
35 visitNodeList(NodeList node) { 35 visitNodeList(NodeList node) {
36 // This must be a list of optional arguments. 36 // This must be a list of optional arguments.
37 String value = node.beginToken.stringValue; 37 String value = node.beginToken.stringValue;
38 if ((!identical(value, '[')) && (!identical(value, '{'))) { 38 if ((!identical(value, '[')) && (!identical(value, '{'))) {
39 internalError(node, "expected optional parameters"); 39 internalError(node, "expected optional parameters");
40 } 40 }
41 optionalParametersAreNamed = (identical(value, '{')); 41 optionalParametersAreNamed = (identical(value, '{'));
42 isOptionalParameter = true; 42 isOptionalParameter = true;
43 LinkBuilder<Element> elements = analyzeNodes(node.nodes); 43 LinkBuilder<Element> elements = analyzeNodes(node.nodes);
44 optionalParameterCount = elements.length; 44 optionalParameterCount = elements.length;
45 optionalParameters = elements.toLink(); 45 optionalParameters = elements.toList();
46 } 46 }
47 47
48 FormalElementX visitVariableDefinitions(VariableDefinitions node) { 48 FormalElementX visitVariableDefinitions(VariableDefinitions node) {
49 Link<Node> definitions = node.definitions.nodes; 49 Link<Node> definitions = node.definitions.nodes;
50 if (definitions.isEmpty) { 50 if (definitions.isEmpty) {
51 internalError(node, 'no parameter definition'); 51 internalError(node, 'no parameter definition');
52 return null; 52 return null;
53 } 53 }
54 if (!definitions.tail.isEmpty) { 54 if (!definitions.tail.isEmpty) {
55 internalError(definitions.tail.head, 'extra definition'); 55 internalError(definitions.tail.head, 'extra definition');
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 Node returnNode, 267 Node returnNode,
268 FunctionTypedElement element, 268 FunctionTypedElement element,
269 ResolutionRegistry registry, 269 ResolutionRegistry registry,
270 {MessageKind defaultValuesError, 270 {MessageKind defaultValuesError,
271 bool createRealParameters: false, 271 bool createRealParameters: false,
272 bool isFunctionExpression: false}) { 272 bool isFunctionExpression: false}) {
273 273
274 SignatureResolver visitor = new SignatureResolver(compiler, element, 274 SignatureResolver visitor = new SignatureResolver(compiler, element,
275 registry, defaultValuesError: defaultValuesError, 275 registry, defaultValuesError: defaultValuesError,
276 createRealParameters: createRealParameters); 276 createRealParameters: createRealParameters);
277 Link<Element> parameters = const Link<Element>(); 277 List<Element> parameters = const <Element>[];
278 int requiredParameterCount = 0; 278 int requiredParameterCount = 0;
279 if (formalParameters == null) { 279 if (formalParameters == null) {
280 if (!element.isGetter) { 280 if (!element.isGetter) {
281 if (element.isErroneous) { 281 if (element.isErroneous) {
282 // If the element is erroneous, an error should already have been 282 // If the element is erroneous, an error should already have been
283 // reported. In the case of parse errors, it is possible that there 283 // reported. In the case of parse errors, it is possible that there
284 // are formal parameters, but something else in the method failed to 284 // are formal parameters, but something else in the method failed to
285 // parse. So we suppress the message about missing formals. 285 // parse. So we suppress the message about missing formals.
286 assert(invariant(element, compiler.compilationFailed)); 286 assert(invariant(element, compiler.compilationFailed));
287 } else { 287 } else {
288 compiler.reportError(element, MessageKind.MISSING_FORMALS); 288 compiler.reportError(element, MessageKind.MISSING_FORMALS);
289 } 289 }
290 } 290 }
291 } else { 291 } else {
292 if (element.isGetter) { 292 if (element.isGetter) {
293 if (!identical(formalParameters.endToken.next.stringValue, 293 if (!identical(formalParameters.endToken.next.stringValue,
294 // TODO(ahe): Remove the check for native keyword. 294 // TODO(ahe): Remove the check for native keyword.
295 'native')) { 295 'native')) {
296 compiler.reportError(formalParameters, 296 compiler.reportError(formalParameters,
297 MessageKind.EXTRA_FORMALS); 297 MessageKind.EXTRA_FORMALS);
298 } 298 }
299 } 299 }
300 LinkBuilder<Element> parametersBuilder = 300 LinkBuilder<Element> parametersBuilder =
301 visitor.analyzeNodes(formalParameters.nodes); 301 visitor.analyzeNodes(formalParameters.nodes);
302 requiredParameterCount = parametersBuilder.length; 302 requiredParameterCount = parametersBuilder.length;
303 parameters = parametersBuilder.toLink(); 303 parameters = parametersBuilder.toList();
304 } 304 }
305 DartType returnType; 305 DartType returnType;
306 if (element.isFactoryConstructor) { 306 if (element.isFactoryConstructor) {
307 returnType = element.enclosingClass.thisType; 307 returnType = element.enclosingClass.thisType;
308 // Because there is no type annotation for the return type of 308 // Because there is no type annotation for the return type of
309 // this element, we explicitly add one. 309 // this element, we explicitly add one.
310 if (compiler.enableTypeAssertions) { 310 if (compiler.enableTypeAssertions) {
311 registry.registerIsCheck(returnType); 311 registry.registerIsCheck(returnType);
312 } 312 }
313 } else { 313 } else {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 403
404 DartType resolveReturnType(TypeAnnotation annotation) { 404 DartType resolveReturnType(TypeAnnotation annotation) {
405 if (annotation == null) return const DynamicType(); 405 if (annotation == null) return const DynamicType();
406 DartType result = resolver.resolveTypeAnnotation(annotation); 406 DartType result = resolver.resolveTypeAnnotation(annotation);
407 if (result == null) { 407 if (result == null) {
408 return const DynamicType(); 408 return const DynamicType();
409 } 409 }
410 return result; 410 return result;
411 } 411 }
412 } 412 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/members.dart ('k') | pkg/compiler/lib/src/universe/universe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698