| 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 static const bool LOG_FAILURES = false; | 9 static const bool LOG_FAILURES = false; |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 * The unaliased type of a typedef'd type is the unaliased type to which its | 44 * The unaliased type of a typedef'd type is the unaliased type to which its |
| 45 * name is bound. The unaliased version of any other type is the type itself. | 45 * name is bound. The unaliased version of any other type is the type itself. |
| 46 * | 46 * |
| 47 * For example, the unaliased type of [: typedef A Func<A,B>(B b) :] is the | 47 * For example, the unaliased type of [: typedef A Func<A,B>(B b) :] is the |
| 48 * function type [: (B) -> A :] and the unaliased type of | 48 * function type [: (B) -> A :] and the unaliased type of |
| 49 * [: Func<int,String> :] is the function type [: (String) -> int :]. | 49 * [: Func<int,String> :] is the function type [: (String) -> int :]. |
| 50 */ | 50 */ |
| 51 abstract DartType unalias(Compiler compiler); | 51 abstract DartType unalias(Compiler compiler); |
| 52 | 52 |
| 53 abstract bool operator ==(other); | 53 abstract bool operator ==(other); |
| 54 |
| 55 DartType asRaw() => this; |
| 54 } | 56 } |
| 55 | 57 |
| 56 class TypeVariableType implements DartType { | 58 class TypeVariableType implements DartType { |
| 57 final TypeVariableElement element; | 59 final TypeVariableElement element; |
| 58 | 60 |
| 59 TypeVariableType(this.element); | 61 TypeVariableType(this.element); |
| 60 | 62 |
| 61 SourceString get name => element.name; | 63 SourceString get name => element.name; |
| 62 | 64 |
| 63 DartType unalias(Compiler compiler) => this; | 65 DartType unalias(Compiler compiler) => this; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 hash = 17 * hash + 3 * argumentHash; | 151 hash = 17 * hash + 3 * argumentHash; |
| 150 } | 152 } |
| 151 return hash; | 153 return hash; |
| 152 } | 154 } |
| 153 | 155 |
| 154 bool operator ==(other) { | 156 bool operator ==(other) { |
| 155 if (other is !InterfaceType) return false; | 157 if (other is !InterfaceType) return false; |
| 156 if (!identical(element, other.element)) return false; | 158 if (!identical(element, other.element)) return false; |
| 157 return arguments == other.arguments; | 159 return arguments == other.arguments; |
| 158 } | 160 } |
| 161 |
| 162 InterfaceType asRaw() { |
| 163 if (arguments.isEmpty()) return this; |
| 164 return new InterfaceType(element); |
| 165 } |
| 159 } | 166 } |
| 160 | 167 |
| 161 class FunctionType implements DartType { | 168 class FunctionType implements DartType { |
| 162 final Element element; | 169 final Element element; |
| 163 DartType returnType; | 170 DartType returnType; |
| 164 Link<DartType> parameterTypes; | 171 Link<DartType> parameterTypes; |
| 165 | 172 |
| 166 FunctionType(DartType this.returnType, Link<DartType> this.parameterTypes, | 173 FunctionType(DartType this.returnType, Link<DartType> this.parameterTypes, |
| 167 Element this.element) { | 174 Element this.element) { |
| 168 assert(element == null || invariant(element, element.isDeclaration)); | 175 assert(element == null || invariant(element, element.isDeclaration)); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 } | 753 } |
| 747 | 754 |
| 748 /** Dart Programming Language Specification: 11.10 Return */ | 755 /** Dart Programming Language Specification: 11.10 Return */ |
| 749 DartType visitReturn(Return node) { | 756 DartType visitReturn(Return node) { |
| 750 if (identical(node.getBeginToken().stringValue, 'native')) { | 757 if (identical(node.getBeginToken().stringValue, 'native')) { |
| 751 return StatementType.RETURNING; | 758 return StatementType.RETURNING; |
| 752 } | 759 } |
| 753 if (node.isRedirectingFactoryBody) { | 760 if (node.isRedirectingFactoryBody) { |
| 754 // TODO(lrn): Typecheck the body. It must refer to the constructor | 761 // TODO(lrn): Typecheck the body. It must refer to the constructor |
| 755 // of a subtype. | 762 // of a subtype. |
| 756 return elements.getType(node); | 763 return StatementType.RETURNING; |
| 757 } | 764 } |
| 758 | 765 |
| 759 final expression = node.expression; | 766 final expression = node.expression; |
| 760 final isVoidFunction = (identical(expectedReturnType, types.voidType)); | 767 final isVoidFunction = (identical(expectedReturnType, types.voidType)); |
| 761 | 768 |
| 762 // Executing a return statement return e; [...] It is a static type warning | 769 // Executing a return statement return e; [...] It is a static type warning |
| 763 // if the type of e may not be assigned to the declared return type of the | 770 // if the type of e may not be assigned to the declared return type of the |
| 764 // immediately enclosing function. | 771 // immediately enclosing function. |
| 765 if (expression != null) { | 772 if (expression != null) { |
| 766 final expressionType = analyze(expression); | 773 final expressionType = analyze(expression); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 } | 990 } |
| 984 | 991 |
| 985 DartType visitStatement(Statement node) { | 992 DartType visitStatement(Statement node) { |
| 986 compiler.unimplemented('visitNode', node: node); | 993 compiler.unimplemented('visitNode', node: node); |
| 987 } | 994 } |
| 988 | 995 |
| 989 DartType visitStringNode(StringNode node) { | 996 DartType visitStringNode(StringNode node) { |
| 990 compiler.unimplemented('visitNode', node: node); | 997 compiler.unimplemented('visitNode', node: node); |
| 991 } | 998 } |
| 992 } | 999 } |
| OLD | NEW |