OLD | NEW |
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 '../compiler.dart' show | 8 import '../compiler.dart' show Compiler; |
9 Compiler; | |
10 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
11 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
12 import '../elements/modelx.dart' show | 11 import '../elements/modelx.dart' |
13 ErroneousFieldElementX, | 12 show |
14 ErroneousInitializingFormalElementX, | 13 ErroneousFieldElementX, |
15 FormalElementX, | 14 ErroneousInitializingFormalElementX, |
16 FunctionElementX, | 15 FormalElementX, |
17 FunctionSignatureX, | 16 FunctionElementX, |
18 InitializingFormalElementX, | 17 FunctionSignatureX, |
19 LocalParameterElementX; | 18 InitializingFormalElementX, |
| 19 LocalParameterElementX; |
20 import '../tree/tree.dart'; | 20 import '../tree/tree.dart'; |
21 import '../universe/use.dart' show | 21 import '../universe/use.dart' show TypeUse; |
22 TypeUse; | 22 import '../util/util.dart' show Link, LinkBuilder; |
23 import '../util/util.dart' show | |
24 Link, | |
25 LinkBuilder; | |
26 | 23 |
27 import 'members.dart' show | 24 import 'members.dart' show ResolverVisitor; |
28 ResolverVisitor; | 25 import 'registry.dart' show ResolutionRegistry; |
29 import 'registry.dart' show | 26 import 'resolution_common.dart' show MappingVisitor; |
30 ResolutionRegistry; | 27 import 'scope.dart' show Scope; |
31 import 'resolution_common.dart' show | |
32 MappingVisitor; | |
33 import 'scope.dart' show | |
34 Scope; | |
35 | 28 |
36 /** | 29 /** |
37 * [SignatureResolver] resolves function signatures. | 30 * [SignatureResolver] resolves function signatures. |
38 */ | 31 */ |
39 class SignatureResolver extends MappingVisitor<FormalElementX> { | 32 class SignatureResolver extends MappingVisitor<FormalElementX> { |
40 final ResolverVisitor resolver; | 33 final ResolverVisitor resolver; |
41 final FunctionTypedElement enclosingElement; | 34 final FunctionTypedElement enclosingElement; |
42 final Scope scope; | 35 final Scope scope; |
43 final MessageKind defaultValuesError; | 36 final MessageKind defaultValuesError; |
44 final bool createRealParameters; | 37 final bool createRealParameters; |
45 List<Element> optionalParameters = const <Element>[]; | 38 List<Element> optionalParameters = const <Element>[]; |
46 int optionalParameterCount = 0; | 39 int optionalParameterCount = 0; |
47 bool isOptionalParameter = false; | 40 bool isOptionalParameter = false; |
48 bool optionalParametersAreNamed = false; | 41 bool optionalParametersAreNamed = false; |
49 VariableDefinitions currentDefinitions; | 42 VariableDefinitions currentDefinitions; |
50 | 43 |
51 SignatureResolver(Compiler compiler, | 44 SignatureResolver(Compiler compiler, FunctionTypedElement enclosingElement, |
52 FunctionTypedElement enclosingElement, | 45 ResolutionRegistry registry, |
53 ResolutionRegistry registry, | 46 {this.defaultValuesError, this.createRealParameters}) |
54 {this.defaultValuesError, | |
55 this.createRealParameters}) | |
56 : this.enclosingElement = enclosingElement, | 47 : this.enclosingElement = enclosingElement, |
57 this.scope = enclosingElement.buildScope(), | 48 this.scope = enclosingElement.buildScope(), |
58 this.resolver = | 49 this.resolver = |
59 new ResolverVisitor(compiler, enclosingElement, registry), | 50 new ResolverVisitor(compiler, enclosingElement, registry), |
60 super(compiler, registry); | 51 super(compiler, registry); |
61 | 52 |
62 bool get defaultValuesAllowed => defaultValuesError == null; | 53 bool get defaultValuesAllowed => defaultValuesError == null; |
63 | 54 |
64 visitNodeList(NodeList node) { | 55 visitNodeList(NodeList node) { |
65 // This must be a list of optional arguments. | 56 // This must be a list of optional arguments. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 101 |
111 void validateName(Identifier node) { | 102 void validateName(Identifier node) { |
112 if (isOptionalParameter && | 103 if (isOptionalParameter && |
113 optionalParametersAreNamed && | 104 optionalParametersAreNamed && |
114 Name.isPrivateName(node.source)) { | 105 Name.isPrivateName(node.source)) { |
115 reporter.reportErrorMessage(node, MessageKind.PRIVATE_NAMED_PARAMETER); | 106 reporter.reportErrorMessage(node, MessageKind.PRIVATE_NAMED_PARAMETER); |
116 } | 107 } |
117 } | 108 } |
118 | 109 |
119 void computeParameterType(FormalElementX element, | 110 void computeParameterType(FormalElementX element, |
120 [VariableElement fieldElement]) { | 111 [VariableElement fieldElement]) { |
121 void computeFunctionType(FunctionExpression functionExpression) { | 112 void computeFunctionType(FunctionExpression functionExpression) { |
122 FunctionSignature functionSignature = SignatureResolver.analyze( | 113 FunctionSignature functionSignature = SignatureResolver.analyze( |
123 compiler, functionExpression.parameters, | 114 compiler, |
124 functionExpression.returnType, element, registry, | 115 functionExpression.parameters, |
| 116 functionExpression.returnType, |
| 117 element, |
| 118 registry, |
125 defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT); | 119 defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT); |
126 element.functionSignature = functionSignature; | 120 element.functionSignature = functionSignature; |
127 } | 121 } |
128 | 122 |
129 if (currentDefinitions.type != null) { | 123 if (currentDefinitions.type != null) { |
130 element.typeCache = resolveTypeAnnotation(currentDefinitions.type); | 124 element.typeCache = resolveTypeAnnotation(currentDefinitions.type); |
131 } else { | 125 } else { |
132 // Is node.definitions exactly one FunctionExpression? | 126 // Is node.definitions exactly one FunctionExpression? |
133 Link<Node> link = currentDefinitions.definitions.nodes; | 127 Link<Node> link = currentDefinitions.definitions.nodes; |
134 assert(invariant(currentDefinitions, !link.isEmpty)); | 128 assert(invariant(currentDefinitions, !link.isEmpty)); |
135 assert(invariant(currentDefinitions, link.tail.isEmpty)); | 129 assert(invariant(currentDefinitions, link.tail.isEmpty)); |
136 if (link.head.asFunctionExpression() != null) { | 130 if (link.head.asFunctionExpression() != null) { |
137 // Inline function typed parameter, like `void m(int f(String s))`. | 131 // Inline function typed parameter, like `void m(int f(String s))`. |
138 computeFunctionType(link.head); | 132 computeFunctionType(link.head); |
139 } else if (link.head.asSend() != null && | 133 } else if (link.head.asSend() != null && |
140 link.head.asSend().selector.asFunctionExpression() != null) { | 134 link.head.asSend().selector.asFunctionExpression() != null) { |
141 // Inline function typed initializing formal or | 135 // Inline function typed initializing formal or |
142 // parameter with default value, like `C(int this.f(String s))` or | 136 // parameter with default value, like `C(int this.f(String s))` or |
143 // `void m([int f(String s) = null])`. | 137 // `void m([int f(String s) = null])`. |
144 computeFunctionType(link.head.asSend().selector.asFunctionExpression()); | 138 computeFunctionType(link.head.asSend().selector.asFunctionExpression()); |
145 } else { | 139 } else { |
146 assert(invariant(currentDefinitions, | 140 assert(invariant(currentDefinitions, |
147 link.head.asIdentifier() != null || link.head.asSend() != null)); | 141 link.head.asIdentifier() != null || link.head.asSend() != null)); |
148 if (fieldElement != null) { | 142 if (fieldElement != null) { |
149 element.typeCache = fieldElement.computeType(resolution); | 143 element.typeCache = fieldElement.computeType(resolution); |
150 } else { | 144 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
163 if (identifier != null) { | 157 if (identifier != null) { |
164 // Normal parameter: [:Type name:]. | 158 // Normal parameter: [:Type name:]. |
165 return identifier; | 159 return identifier; |
166 } else { | 160 } else { |
167 // Function type parameter: [:void name(DartType arg):]. | 161 // Function type parameter: [:void name(DartType arg):]. |
168 var functionExpression = node.selector.asFunctionExpression(); | 162 var functionExpression = node.selector.asFunctionExpression(); |
169 if (functionExpression != null && | 163 if (functionExpression != null && |
170 functionExpression.name.asIdentifier() != null) { | 164 functionExpression.name.asIdentifier() != null) { |
171 return functionExpression.name.asIdentifier(); | 165 return functionExpression.name.asIdentifier(); |
172 } else { | 166 } else { |
173 reporter.internalError(node, | 167 reporter.internalError( |
174 'internal error: unimplemented receiver on parameter send'); | 168 node, 'internal error: unimplemented receiver on parameter send'); |
175 return null; | 169 return null; |
176 } | 170 } |
177 } | 171 } |
178 } | 172 } |
179 | 173 |
180 // The only valid [Send] can be in constructors and must be of the form | 174 // The only valid [Send] can be in constructors and must be of the form |
181 // [:this.x:] (where [:x:] represents an instance field). | 175 // [:this.x:] (where [:x:] represents an instance field). |
182 InitializingFormalElementX visitSend(Send node) { | 176 InitializingFormalElementX visitSend(Send node) { |
183 return createFieldParameter(node, null); | 177 return createFieldParameter(node, null); |
184 } | 178 } |
185 | 179 |
186 FormalElementX createParameter(Identifier name, Expression initializer) { | 180 FormalElementX createParameter(Identifier name, Expression initializer) { |
187 validateName(name); | 181 validateName(name); |
188 FormalElementX parameter; | 182 FormalElementX parameter; |
189 if (createRealParameters) { | 183 if (createRealParameters) { |
190 parameter = new LocalParameterElementX( | 184 parameter = new LocalParameterElementX( |
191 enclosingElement, currentDefinitions, name, initializer, | 185 enclosingElement, currentDefinitions, name, initializer, |
192 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed); | 186 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed); |
193 } else { | 187 } else { |
194 parameter = new FormalElementX( | 188 parameter = new FormalElementX( |
195 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name); | 189 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name); |
196 } | 190 } |
197 computeParameterType(parameter); | 191 computeParameterType(parameter); |
198 return parameter; | 192 return parameter; |
199 } | 193 } |
200 | 194 |
201 InitializingFormalElementX createFieldParameter(Send node, | 195 InitializingFormalElementX createFieldParameter( |
202 Expression initializer) { | 196 Send node, Expression initializer) { |
203 InitializingFormalElementX element; | 197 InitializingFormalElementX element; |
204 Identifier receiver = node.receiver.asIdentifier(); | 198 Identifier receiver = node.receiver.asIdentifier(); |
205 if (receiver == null || !receiver.isThis()) { | 199 if (receiver == null || !receiver.isThis()) { |
206 reporter.reportErrorMessage(node, MessageKind.INVALID_PARAMETER); | 200 reporter.reportErrorMessage(node, MessageKind.INVALID_PARAMETER); |
207 return new ErroneousInitializingFormalElementX( | 201 return new ErroneousInitializingFormalElementX( |
208 getParameterName(node), enclosingElement); | 202 getParameterName(node), enclosingElement); |
209 } else { | 203 } else { |
210 if (!enclosingElement.isGenerativeConstructor) { | 204 if (!enclosingElement.isGenerativeConstructor) { |
211 reporter.reportErrorMessage( | 205 reporter.reportErrorMessage( |
212 node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED); | 206 node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED); |
213 return new ErroneousInitializingFormalElementX( | 207 return new ErroneousInitializingFormalElementX( |
214 getParameterName(node), enclosingElement); | 208 getParameterName(node), enclosingElement); |
215 } | 209 } |
216 Identifier name = getParameterName(node); | 210 Identifier name = getParameterName(node); |
217 validateName(name); | 211 validateName(name); |
218 Element fieldElement = | 212 Element fieldElement = |
219 enclosingElement.enclosingClass.lookupLocalMember(name.source); | 213 enclosingElement.enclosingClass.lookupLocalMember(name.source); |
220 if (fieldElement == null || | 214 if (fieldElement == null || |
221 !identical(fieldElement.kind, ElementKind.FIELD)) { | 215 !identical(fieldElement.kind, ElementKind.FIELD)) { |
222 reporter.reportErrorMessage( | 216 reporter.reportErrorMessage( |
223 node, MessageKind.NOT_A_FIELD, {'fieldName': name}); | 217 node, MessageKind.NOT_A_FIELD, {'fieldName': name}); |
224 fieldElement = new ErroneousFieldElementX( | 218 fieldElement = |
225 name, enclosingElement.enclosingClass); | 219 new ErroneousFieldElementX(name, enclosingElement.enclosingClass); |
226 } else if (!fieldElement.isInstanceMember) { | 220 } else if (!fieldElement.isInstanceMember) { |
227 reporter.reportErrorMessage( | 221 reporter.reportErrorMessage( |
228 node, MessageKind.NOT_INSTANCE_FIELD, {'fieldName': name}); | 222 node, MessageKind.NOT_INSTANCE_FIELD, {'fieldName': name}); |
229 fieldElement = new ErroneousFieldElementX( | 223 fieldElement = |
230 name, enclosingElement.enclosingClass); | 224 new ErroneousFieldElementX(name, enclosingElement.enclosingClass); |
231 } | 225 } |
232 element = new InitializingFormalElementX(enclosingElement, | 226 element = new InitializingFormalElementX( |
233 currentDefinitions, name, initializer, fieldElement, | 227 enclosingElement, currentDefinitions, name, initializer, fieldElement, |
234 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed); | 228 isOptional: isOptionalParameter, isNamed: optionalParametersAreNamed); |
235 computeParameterType(element, fieldElement); | 229 computeParameterType(element, fieldElement); |
236 } | 230 } |
237 return element; | 231 return element; |
238 } | 232 } |
239 | 233 |
240 /// A [SendSet] node is an optional parameter with a default value. | 234 /// A [SendSet] node is an optional parameter with a default value. |
241 Element visitSendSet(SendSet node) { | 235 Element visitSendSet(SendSet node) { |
242 FormalElementX element; | 236 FormalElementX element; |
243 if (node.receiver != null) { | 237 if (node.receiver != null) { |
244 element = createFieldParameter(node, node.arguments.first); | 238 element = createFieldParameter(node, node.arguments.first); |
245 } else if (node.selector.asIdentifier() != null || | 239 } else if (node.selector.asIdentifier() != null || |
246 node.selector.asFunctionExpression() != null) { | 240 node.selector.asFunctionExpression() != null) { |
247 element = createParameter(getParameterName(node), node.arguments.first); | 241 element = createParameter(getParameterName(node), node.arguments.first); |
248 } | 242 } |
249 Node defaultValue = node.arguments.head; | 243 Node defaultValue = node.arguments.head; |
250 if (!defaultValuesAllowed) { | 244 if (!defaultValuesAllowed) { |
251 reporter.reportErrorMessage(defaultValue, defaultValuesError); | 245 reporter.reportErrorMessage(defaultValue, defaultValuesError); |
252 } | 246 } |
253 return element; | 247 return element; |
254 } | 248 } |
255 | 249 |
256 Element visitFunctionExpression(FunctionExpression node) { | 250 Element visitFunctionExpression(FunctionExpression node) { |
257 // This is a function typed parameter. | 251 // This is a function typed parameter. |
258 Modifiers modifiers = currentDefinitions.modifiers; | 252 Modifiers modifiers = currentDefinitions.modifiers; |
259 if (modifiers.isFinal) { | 253 if (modifiers.isFinal) { |
260 reporter.reportErrorMessage( | 254 reporter.reportErrorMessage( |
261 modifiers, | 255 modifiers, MessageKind.FINAL_FUNCTION_TYPE_PARAMETER); |
262 MessageKind.FINAL_FUNCTION_TYPE_PARAMETER); | |
263 } | 256 } |
264 if (modifiers.isVar) { | 257 if (modifiers.isVar) { |
265 reporter.reportErrorMessage( | 258 reporter.reportErrorMessage( |
266 modifiers, MessageKind.VAR_FUNCTION_TYPE_PARAMETER); | 259 modifiers, MessageKind.VAR_FUNCTION_TYPE_PARAMETER); |
267 } | 260 } |
268 | 261 |
269 return createParameter(node.name, null); | 262 return createParameter(node.name, null); |
270 } | 263 } |
271 | 264 |
272 LinkBuilder<Element> analyzeNodes(Link<Node> link) { | 265 LinkBuilder<Element> analyzeNodes(Link<Node> link) { |
273 LinkBuilder<Element> elements = new LinkBuilder<Element>(); | 266 LinkBuilder<Element> elements = new LinkBuilder<Element>(); |
274 for (; !link.isEmpty; link = link.tail) { | 267 for (; !link.isEmpty; link = link.tail) { |
275 Element element = link.head.accept(this); | 268 Element element = link.head.accept(this); |
276 if (element != null) { | 269 if (element != null) { |
277 elements.addLast(element); | 270 elements.addLast(element); |
278 } else { | 271 } else { |
279 // If parameter is null, the current node should be the last, | 272 // If parameter is null, the current node should be the last, |
280 // and a list of optional named parameters. | 273 // and a list of optional named parameters. |
281 if (!link.tail.isEmpty || (link.head is !NodeList)) { | 274 if (!link.tail.isEmpty || (link.head is! NodeList)) { |
282 reporter.internalError(link.head, "expected optional parameters"); | 275 reporter.internalError(link.head, "expected optional parameters"); |
283 } | 276 } |
284 } | 277 } |
285 } | 278 } |
286 return elements; | 279 return elements; |
287 } | 280 } |
288 | 281 |
289 /** | 282 /** |
290 * Resolves formal parameters and return type of a [FunctionExpression] | 283 * Resolves formal parameters and return type of a [FunctionExpression] |
291 * to a [FunctionSignature]. | 284 * to a [FunctionSignature]. |
292 * | 285 * |
293 * If [createRealParameters] is `true`, the parameters will be | 286 * If [createRealParameters] is `true`, the parameters will be |
294 * real parameters implementing the [ParameterElement] interface. Otherwise, | 287 * real parameters implementing the [ParameterElement] interface. Otherwise, |
295 * the parameters will only implement [FormalElement]. | 288 * the parameters will only implement [FormalElement]. |
296 */ | 289 */ |
297 static FunctionSignature analyze( | 290 static FunctionSignature analyze( |
298 Compiler compiler, | 291 Compiler compiler, |
299 NodeList formalParameters, | 292 NodeList formalParameters, |
300 Node returnNode, | 293 Node returnNode, |
301 FunctionTypedElement element, | 294 FunctionTypedElement element, |
302 ResolutionRegistry registry, | 295 ResolutionRegistry registry, |
303 {MessageKind defaultValuesError, | 296 {MessageKind defaultValuesError, |
304 bool createRealParameters: false, | 297 bool createRealParameters: false, |
305 bool isFunctionExpression: false}) { | 298 bool isFunctionExpression: false}) { |
306 DiagnosticReporter reporter = compiler.reporter; | 299 DiagnosticReporter reporter = compiler.reporter; |
307 | 300 |
308 SignatureResolver visitor = new SignatureResolver(compiler, element, | 301 SignatureResolver visitor = new SignatureResolver( |
309 registry, defaultValuesError: defaultValuesError, | 302 compiler, element, registry, |
| 303 defaultValuesError: defaultValuesError, |
310 createRealParameters: createRealParameters); | 304 createRealParameters: createRealParameters); |
311 List<Element> parameters = const <Element>[]; | 305 List<Element> parameters = const <Element>[]; |
312 int requiredParameterCount = 0; | 306 int requiredParameterCount = 0; |
313 if (formalParameters == null) { | 307 if (formalParameters == null) { |
314 if (!element.isGetter) { | 308 if (!element.isGetter) { |
315 if (element.isMalformed) { | 309 if (element.isMalformed) { |
316 // If the element is erroneous, an error should already have been | 310 // If the element is erroneous, an error should already have been |
317 // reported. In the case of parse errors, it is possible that there | 311 // reported. In the case of parse errors, it is possible that there |
318 // are formal parameters, but something else in the method failed to | 312 // are formal parameters, but something else in the method failed to |
319 // parse. So we suppress the message about missing formals. | 313 // parse. So we suppress the message about missing formals. |
320 assert(invariant(element, compiler.compilationFailed)); | 314 assert(invariant(element, compiler.compilationFailed)); |
321 } else { | 315 } else { |
322 reporter.reportErrorMessage(element, MessageKind.MISSING_FORMALS); | 316 reporter.reportErrorMessage(element, MessageKind.MISSING_FORMALS); |
323 } | 317 } |
324 } | 318 } |
325 } else { | 319 } else { |
326 if (element.isGetter) { | 320 if (element.isGetter) { |
327 if (!identical(formalParameters.endToken.next.stringValue, | 321 if (!identical( |
328 // TODO(ahe): Remove the check for native keyword. | 322 formalParameters.endToken.next.stringValue, |
329 'native')) { | 323 // TODO(ahe): Remove the check for native keyword. |
| 324 'native')) { |
330 reporter.reportErrorMessage( | 325 reporter.reportErrorMessage( |
331 formalParameters, | 326 formalParameters, MessageKind.EXTRA_FORMALS); |
332 MessageKind.EXTRA_FORMALS); | |
333 } | 327 } |
334 } | 328 } |
335 LinkBuilder<Element> parametersBuilder = | 329 LinkBuilder<Element> parametersBuilder = |
336 visitor.analyzeNodes(formalParameters.nodes); | 330 visitor.analyzeNodes(formalParameters.nodes); |
337 requiredParameterCount = parametersBuilder.length; | 331 requiredParameterCount = parametersBuilder.length; |
338 parameters = parametersBuilder.toList(); | 332 parameters = parametersBuilder.toList(); |
339 } | 333 } |
340 DartType returnType; | 334 DartType returnType; |
341 if (element.isFactoryConstructor) { | 335 if (element.isFactoryConstructor) { |
342 returnType = element.enclosingClass.thisType; | 336 returnType = element.enclosingClass.thisType; |
343 // Because there is no type annotation for the return type of | 337 // Because there is no type annotation for the return type of |
344 // this element, we explicitly add one. | 338 // this element, we explicitly add one. |
345 if (compiler.options.enableTypeAssertions) { | 339 if (compiler.options.enableTypeAssertions) { |
346 registry.registerTypeUse(new TypeUse.checkedModeCheck(returnType)); | 340 registry.registerTypeUse(new TypeUse.checkedModeCheck(returnType)); |
347 } | 341 } |
348 } else { | 342 } else { |
349 AsyncMarker asyncMarker = AsyncMarker.SYNC; | 343 AsyncMarker asyncMarker = AsyncMarker.SYNC; |
350 if (isFunctionExpression) { | 344 if (isFunctionExpression) { |
351 // Use async marker to determine the return type of function | 345 // Use async marker to determine the return type of function |
352 // expressions. | 346 // expressions. |
353 FunctionElement function = element; | 347 FunctionElement function = element; |
354 asyncMarker = function.asyncMarker; | 348 asyncMarker = function.asyncMarker; |
355 } | 349 } |
356 switch (asyncMarker) { | 350 switch (asyncMarker) { |
357 case AsyncMarker.SYNC: | 351 case AsyncMarker.SYNC: |
358 returnType = visitor.resolveReturnType(returnNode); | 352 returnType = visitor.resolveReturnType(returnNode); |
359 break; | 353 break; |
360 case AsyncMarker.SYNC_STAR: | 354 case AsyncMarker.SYNC_STAR: |
361 returnType = compiler.coreTypes.iterableType(); | 355 returnType = compiler.coreTypes.iterableType(); |
362 break; | 356 break; |
363 case AsyncMarker.ASYNC: | 357 case AsyncMarker.ASYNC: |
364 returnType = compiler.coreTypes.futureType(); | 358 returnType = compiler.coreTypes.futureType(); |
365 break; | 359 break; |
366 case AsyncMarker.ASYNC_STAR: | 360 case AsyncMarker.ASYNC_STAR: |
367 returnType = compiler.coreTypes.streamType(); | 361 returnType = compiler.coreTypes.streamType(); |
368 break; | 362 break; |
369 } | 363 } |
370 } | 364 } |
371 | 365 |
372 if (element.isSetter && (requiredParameterCount != 1 || | 366 if (element.isSetter && |
373 visitor.optionalParameterCount != 0)) { | 367 (requiredParameterCount != 1 || visitor.optionalParameterCount != 0)) { |
374 // If there are no formal parameters, we already reported an error above. | 368 // If there are no formal parameters, we already reported an error above. |
375 if (formalParameters != null) { | 369 if (formalParameters != null) { |
376 reporter.reportErrorMessage( | 370 reporter.reportErrorMessage( |
377 formalParameters, | 371 formalParameters, MessageKind.ILLEGAL_SETTER_FORMALS); |
378 MessageKind.ILLEGAL_SETTER_FORMALS); | |
379 } | 372 } |
380 } | 373 } |
381 LinkBuilder<DartType> parameterTypes = new LinkBuilder<DartType>(); | 374 LinkBuilder<DartType> parameterTypes = new LinkBuilder<DartType>(); |
382 for (FormalElement parameter in parameters) { | 375 for (FormalElement parameter in parameters) { |
383 parameterTypes.addLast(parameter.type); | 376 parameterTypes.addLast(parameter.type); |
384 } | 377 } |
385 List<DartType> optionalParameterTypes = const <DartType>[]; | 378 List<DartType> optionalParameterTypes = const <DartType>[]; |
386 List<String> namedParameters = const <String>[]; | 379 List<String> namedParameters = const <String>[]; |
387 List<DartType> namedParameterTypes = const <DartType>[]; | 380 List<DartType> namedParameterTypes = const <DartType>[]; |
388 List<Element> orderedOptionalParameters = | 381 List<Element> orderedOptionalParameters = |
389 visitor.optionalParameters.toList(); | 382 visitor.optionalParameters.toList(); |
390 if (visitor.optionalParametersAreNamed) { | 383 if (visitor.optionalParametersAreNamed) { |
391 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List]. | 384 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List]. |
392 orderedOptionalParameters.sort((Element a, Element b) { | 385 orderedOptionalParameters.sort((Element a, Element b) { |
393 return a.name.compareTo(b.name); | 386 return a.name.compareTo(b.name); |
394 }); | 387 }); |
395 LinkBuilder<String> namedParametersBuilder = new LinkBuilder<String>(); | 388 LinkBuilder<String> namedParametersBuilder = new LinkBuilder<String>(); |
396 LinkBuilder<DartType> namedParameterTypesBuilder = | 389 LinkBuilder<DartType> namedParameterTypesBuilder = |
397 new LinkBuilder<DartType>(); | 390 new LinkBuilder<DartType>(); |
398 for (FormalElement parameter in orderedOptionalParameters) { | 391 for (FormalElement parameter in orderedOptionalParameters) { |
399 namedParametersBuilder.addLast(parameter.name); | 392 namedParametersBuilder.addLast(parameter.name); |
400 namedParameterTypesBuilder.addLast(parameter.type); | 393 namedParameterTypesBuilder.addLast(parameter.type); |
401 } | 394 } |
402 namedParameters = namedParametersBuilder.toLink().toList(growable: false); | 395 namedParameters = namedParametersBuilder.toLink().toList(growable: false); |
403 namedParameterTypes = namedParameterTypesBuilder.toLink() | 396 namedParameterTypes = |
404 .toList(growable: false); | 397 namedParameterTypesBuilder.toLink().toList(growable: false); |
405 } else { | 398 } else { |
406 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List]. | 399 // TODO(karlklose); replace when [visitor.optinalParameters] is a [List]. |
407 LinkBuilder<DartType> optionalParameterTypesBuilder = | 400 LinkBuilder<DartType> optionalParameterTypesBuilder = |
408 new LinkBuilder<DartType>(); | 401 new LinkBuilder<DartType>(); |
409 for (FormalElement parameter in visitor.optionalParameters) { | 402 for (FormalElement parameter in visitor.optionalParameters) { |
410 optionalParameterTypesBuilder.addLast(parameter.type); | 403 optionalParameterTypesBuilder.addLast(parameter.type); |
411 } | 404 } |
412 optionalParameterTypes = optionalParameterTypesBuilder.toLink() | 405 optionalParameterTypes = |
413 .toList(growable: false); | 406 optionalParameterTypesBuilder.toLink().toList(growable: false); |
414 } | 407 } |
415 FunctionType type = new FunctionType( | 408 FunctionType type = new FunctionType( |
416 element.declaration, | 409 element.declaration, |
417 returnType, | 410 returnType, |
418 parameterTypes.toLink().toList(growable: false), | 411 parameterTypes.toLink().toList(growable: false), |
419 optionalParameterTypes, | 412 optionalParameterTypes, |
420 namedParameters, | 413 namedParameters, |
421 namedParameterTypes); | 414 namedParameterTypes); |
422 return new FunctionSignatureX( | 415 return new FunctionSignatureX( |
423 requiredParameters: parameters, | 416 requiredParameters: parameters, |
(...skipping 15 matching lines...) Expand all Loading... |
439 | 432 |
440 DartType resolveReturnType(TypeAnnotation annotation) { | 433 DartType resolveReturnType(TypeAnnotation annotation) { |
441 if (annotation == null) return const DynamicType(); | 434 if (annotation == null) return const DynamicType(); |
442 DartType result = resolver.resolveTypeAnnotation(annotation); | 435 DartType result = resolver.resolveTypeAnnotation(annotation); |
443 if (result == null) { | 436 if (result == null) { |
444 return const DynamicType(); | 437 return const DynamicType(); |
445 } | 438 } |
446 return result; | 439 return result; |
447 } | 440 } |
448 } | 441 } |
OLD | NEW |