| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class TypeCheckerTask extends CompilerTask { | 5 class TypeCheckerTask extends CompilerTask { |
| 6 TypeCheckerTask(Compiler compiler) : super(compiler); | 6 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 7 String get name() => "Type checker"; | 7 String get name() => "Type checker"; |
| 8 | 8 |
| 9 void check(Node tree, TreeElements elements) { | 9 void check(Node tree, TreeElements elements) { |
| 10 measure(() { | 10 measure(() { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 /** Dart Programming Language Specification: 11.5.1 For Loop */ | 231 /** Dart Programming Language Specification: 11.5.1 For Loop */ |
| 232 Type visitFor(For node) { | 232 Type visitFor(For node) { |
| 233 analyzeWithDefault(node.initializer, StatementType.NOT_RETURNING); | 233 analyzeWithDefault(node.initializer, StatementType.NOT_RETURNING); |
| 234 checkCondition(node.condition); | 234 checkCondition(node.condition); |
| 235 analyzeWithDefault(node.update, StatementType.NOT_RETURNING); | 235 analyzeWithDefault(node.update, StatementType.NOT_RETURNING); |
| 236 StatementType bodyType = analyze(node.body); | 236 StatementType bodyType = analyze(node.body); |
| 237 return bodyType.join(StatementType.NOT_RETURNING); | 237 return bodyType.join(StatementType.NOT_RETURNING); |
| 238 } | 238 } |
| 239 | 239 |
| 240 Type visitFunctionExpression(FunctionExpression node) { | 240 Type visitFunctionExpression(FunctionExpression node) { |
| 241 Type type; |
| 242 Type returnType; |
| 243 Type previousType; |
| 241 final FunctionElement element = elements[node]; | 244 final FunctionElement element = elements[node]; |
| 242 FunctionType functionType = computeType(element); | 245 if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR || |
| 243 Type returnType = functionType.returnType; | 246 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 247 type = types.dynamicType; |
| 248 returnType = types.voidType; |
| 249 } else { |
| 250 FunctionType functionType = computeType(element); |
| 251 returnType = functionType.returnType; |
| 252 type = functionType; |
| 253 } |
| 244 Type previous = expectedReturnType; | 254 Type previous = expectedReturnType; |
| 245 expectedReturnType = returnType; | 255 expectedReturnType = returnType; |
| 246 if (element.isMember()) currentClass = element.enclosingElement; | 256 if (element.isMember()) currentClass = element.enclosingElement; |
| 247 StatementType bodyType = analyze(node.body); | 257 StatementType bodyType = analyze(node.body); |
| 248 if (returnType != types.voidType && returnType != types.dynamicType | 258 if (returnType != types.voidType && returnType != types.dynamicType |
| 249 && bodyType != StatementType.RETURNING) { | 259 && bodyType != StatementType.RETURNING) { |
| 250 MessageKind kind; | 260 MessageKind kind; |
| 251 if (bodyType == StatementType.MAYBE_RETURNING) { | 261 if (bodyType == StatementType.MAYBE_RETURNING) { |
| 252 kind = MessageKind.MAYBE_MISSING_RETURN; | 262 kind = MessageKind.MAYBE_MISSING_RETURN; |
| 253 } else { | 263 } else { |
| 254 kind = MessageKind.MISSING_RETURN; | 264 kind = MessageKind.MISSING_RETURN; |
| 255 } | 265 } |
| 256 reportTypeWarning(node.name, kind); | 266 reportTypeWarning(node.name, kind); |
| 257 } | 267 } |
| 258 expectedReturnType = previous; | 268 expectedReturnType = previous; |
| 259 return functionType; | 269 return type; |
| 260 } | 270 } |
| 261 | 271 |
| 262 Type visitIdentifier(Identifier node) { | 272 Type visitIdentifier(Identifier node) { |
| 263 if (node.isThis()) { | 273 if (node.isThis()) { |
| 264 return currentClass.computeType(compiler); | 274 return currentClass.computeType(compiler); |
| 265 } else { | 275 } else { |
| 266 fail(node, 'internal error: unexpected identifier'); | 276 fail(node, 'internal error: unexpected identifier'); |
| 267 } | 277 } |
| 268 } | 278 } |
| 269 | 279 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 } | 624 } |
| 615 | 625 |
| 616 visitCatchBlock(CatchBlock node) { | 626 visitCatchBlock(CatchBlock node) { |
| 617 compiler.unimplemented('visitCatchBlock', node: node); | 627 compiler.unimplemented('visitCatchBlock', node: node); |
| 618 } | 628 } |
| 619 | 629 |
| 620 visitTypedef(Typedef node) { | 630 visitTypedef(Typedef node) { |
| 621 compiler.unimplemented('visitTypedef', node: node); | 631 compiler.unimplemented('visitTypedef', node: node); |
| 622 } | 632 } |
| 623 } | 633 } |
| OLD | NEW |