| 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 final bool LOG_FAILURES = false; | 9 static final bool LOG_FAILURES = false; |
| 10 | 10 |
| 11 void check(Node tree, TreeElements elements) { | 11 void check(Node tree, TreeElements elements) { |
| 12 measure(() { | 12 measure(() { |
| 13 Visitor visitor = | 13 Visitor visitor = |
| 14 new TypeCheckerVisitor(compiler, elements, compiler.types); | 14 new TypeCheckerVisitor(compiler, elements, compiler.types); |
| 15 try { | 15 try { |
| 16 tree.accept(visitor); | 16 tree.accept(visitor); |
| 17 } catch (CancelTypeCheckException e) { | 17 } catch (CancelTypeCheckException e) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 39 * [: Func<int,String> :] is the function type [: (String) -> int :]. | 39 * [: Func<int,String> :] is the function type [: (String) -> int :]. |
| 40 */ | 40 */ |
| 41 Type unalias(Compiler compiler); | 41 Type unalias(Compiler compiler); |
| 42 } | 42 } |
| 43 | 43 |
| 44 class TypeVariableType implements Type { | 44 class TypeVariableType implements Type { |
| 45 final TypeVariableElement element; | 45 final TypeVariableElement element; |
| 46 | 46 |
| 47 TypeVariableType(this.element); | 47 TypeVariableType(this.element); |
| 48 | 48 |
| 49 SourceString get name() => element.name; | 49 SourceString get name => element.name; |
| 50 | 50 |
| 51 Type unalias(Compiler compiler) => this; | 51 Type unalias(Compiler compiler) => this; |
| 52 | 52 |
| 53 String toString() => name.slowToString(); | 53 String toString() => name.slowToString(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * A statement type tracks whether a statement returns or may return. | 57 * A statement type tracks whether a statement returns or may return. |
| 58 */ | 58 */ |
| 59 class StatementType implements Type { | 59 class StatementType implements Type { |
| 60 final String stringName; | 60 final String stringName; |
| 61 Element get element() => null; | 61 Element get element => null; |
| 62 | 62 |
| 63 SourceString get name() => new SourceString(stringName); | 63 SourceString get name => new SourceString(stringName); |
| 64 | 64 |
| 65 const StatementType(this.stringName); | 65 const StatementType(this.stringName); |
| 66 | 66 |
| 67 static final RETURNING = const StatementType('<returning>'); | 67 static final RETURNING = const StatementType('<returning>'); |
| 68 static final NOT_RETURNING = const StatementType('<not returning>'); | 68 static final NOT_RETURNING = const StatementType('<not returning>'); |
| 69 static final MAYBE_RETURNING = const StatementType('<maybe returning>'); | 69 static final MAYBE_RETURNING = const StatementType('<maybe returning>'); |
| 70 | 70 |
| 71 /** Combine the information about two control-flow edges that are joined. */ | 71 /** Combine the information about two control-flow edges that are joined. */ |
| 72 StatementType join(StatementType other) { | 72 StatementType join(StatementType other) { |
| 73 return (this === other) ? this : MAYBE_RETURNING; | 73 return (this === other) ? this : MAYBE_RETURNING; |
| 74 } | 74 } |
| 75 | 75 |
| 76 Type unalias(Compiler compiler) => this; | 76 Type unalias(Compiler compiler) => this; |
| 77 | 77 |
| 78 String toString() => stringName; | 78 String toString() => stringName; |
| 79 } | 79 } |
| 80 | 80 |
| 81 class VoidType implements Type { | 81 class VoidType implements Type { |
| 82 const VoidType(this.element); | 82 const VoidType(this.element); |
| 83 SourceString get name() => element.name; | 83 SourceString get name => element.name; |
| 84 final VoidElement element; | 84 final VoidElement element; |
| 85 | 85 |
| 86 Type unalias(Compiler compiler) => this; | 86 Type unalias(Compiler compiler) => this; |
| 87 | 87 |
| 88 String toString() => name.slowToString(); | 88 String toString() => name.slowToString(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 class InterfaceType implements Type { | 91 class InterfaceType implements Type { |
| 92 final Element element; | 92 final Element element; |
| 93 final Link<Type> arguments; | 93 final Link<Type> arguments; |
| 94 | 94 |
| 95 const InterfaceType(this.element, | 95 const InterfaceType(this.element, |
| 96 [this.arguments = const EmptyLink<Type>()]); | 96 [this.arguments = const EmptyLink<Type>()]); |
| 97 | 97 |
| 98 SourceString get name() => element.name; | 98 SourceString get name => element.name; |
| 99 | 99 |
| 100 Type unalias(Compiler compiler) => this; | 100 Type unalias(Compiler compiler) => this; |
| 101 | 101 |
| 102 String toString() { | 102 String toString() { |
| 103 StringBuffer sb = new StringBuffer(); | 103 StringBuffer sb = new StringBuffer(); |
| 104 sb.add(name.slowToString()); | 104 sb.add(name.slowToString()); |
| 105 if (!arguments.isEmpty()) { | 105 if (!arguments.isEmpty()) { |
| 106 sb.add('<'); | 106 sb.add('<'); |
| 107 arguments.printOn(sb, ', '); | 107 arguments.printOn(sb, ', '); |
| 108 sb.add('>'); | 108 sb.add('>'); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 | 123 |
| 124 String toString() { | 124 String toString() { |
| 125 StringBuffer sb = new StringBuffer(); | 125 StringBuffer sb = new StringBuffer(); |
| 126 bool first = true; | 126 bool first = true; |
| 127 sb.add('('); | 127 sb.add('('); |
| 128 parameterTypes.printOn(sb, ', '); | 128 parameterTypes.printOn(sb, ', '); |
| 129 sb.add(') -> ${returnType}'); | 129 sb.add(') -> ${returnType}'); |
| 130 return sb.toString(); | 130 return sb.toString(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 SourceString get name() => const SourceString('Function'); | 133 SourceString get name => const SourceString('Function'); |
| 134 | 134 |
| 135 int computeArity() { | 135 int computeArity() { |
| 136 int arity = 0; | 136 int arity = 0; |
| 137 parameterTypes.forEach((_) { arity++; }); | 137 parameterTypes.forEach((_) { arity++; }); |
| 138 return arity; | 138 return arity; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void initializeFrom(FunctionType other) { | 141 void initializeFrom(FunctionType other) { |
| 142 assert(returnType === null); | 142 assert(returnType === null); |
| 143 assert(parameterTypes === null); | 143 assert(parameterTypes === null); |
| 144 returnType = other.returnType; | 144 returnType = other.returnType; |
| 145 parameterTypes = other.parameterTypes; | 145 parameterTypes = other.parameterTypes; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 class TypedefType implements Type { | 149 class TypedefType implements Type { |
| 150 final TypedefElement element; | 150 final TypedefElement element; |
| 151 final Link<Type> typeArguments; | 151 final Link<Type> typeArguments; |
| 152 | 152 |
| 153 const TypedefType(this.element, | 153 const TypedefType(this.element, |
| 154 [this.typeArguments = const EmptyLink<Type>()]); | 154 [this.typeArguments = const EmptyLink<Type>()]); |
| 155 | 155 |
| 156 SourceString get name() => element.name; | 156 SourceString get name => element.name; |
| 157 | 157 |
| 158 Type unalias(Compiler compiler) { | 158 Type unalias(Compiler compiler) { |
| 159 // TODO(ahe): This should be [ensureResolved]. | 159 // TODO(ahe): This should be [ensureResolved]. |
| 160 compiler.resolveTypedef(element); | 160 compiler.resolveTypedef(element); |
| 161 return element.alias.unalias(compiler); | 161 return element.alias.unalias(compiler); |
| 162 } | 162 } |
| 163 | 163 |
| 164 String toString() { | 164 String toString() { |
| 165 StringBuffer sb = new StringBuffer(); | 165 StringBuffer sb = new StringBuffer(); |
| 166 sb.add(name.slowToString()); | 166 sb.add(name.slowToString()); |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 } | 843 } |
| 844 | 844 |
| 845 visitCatchBlock(CatchBlock node) { | 845 visitCatchBlock(CatchBlock node) { |
| 846 return unhandledStatement(); | 846 return unhandledStatement(); |
| 847 } | 847 } |
| 848 | 848 |
| 849 visitTypedef(Typedef node) { | 849 visitTypedef(Typedef node) { |
| 850 return unhandledStatement(); | 850 return unhandledStatement(); |
| 851 } | 851 } |
| 852 } | 852 } |
| OLD | NEW |