| 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 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 /** Combine the information about two control-flow edges that are joined. */ | 55 /** Combine the information about two control-flow edges that are joined. */ |
| 56 StatementType join(StatementType other) { | 56 StatementType join(StatementType other) { |
| 57 return (this === other) ? this : MAYBE_RETURNING; | 57 return (this === other) ? this : MAYBE_RETURNING; |
| 58 } | 58 } |
| 59 | 59 |
| 60 String toString() => stringName; | 60 String toString() => stringName; |
| 61 } | 61 } |
| 62 | 62 |
| 63 class VoidType implements Type { | 63 class VoidType implements Type { |
| 64 const VoidType(this.element); | 64 const VoidType(this.element); |
| 65 SourceString get name() => Types.VOID; | 65 SourceString get name() => element.name; |
| 66 final VoidElement element; | 66 final VoidElement element; |
| 67 | 67 |
| 68 toString() => name.slowToString(); | 68 toString() => name.slowToString(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 class InterfaceType implements Type { | 71 class InterfaceType implements Type { |
| 72 final Element element; | 72 final Element element; |
| 73 final Link<Type> arguments; | 73 final Link<Type> arguments; |
| 74 | 74 |
| 75 const InterfaceType(this.element, | 75 const InterfaceType(this.element, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 SourceString get name() => const SourceString('Function'); | 109 SourceString get name() => const SourceString('Function'); |
| 110 | 110 |
| 111 int computeArity() { | 111 int computeArity() { |
| 112 int arity = 0; | 112 int arity = 0; |
| 113 parameterTypes.forEach((_) { arity++; }); | 113 parameterTypes.forEach((_) { arity++; }); |
| 114 return arity; | 114 return arity; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 class Types { | 118 class Types { |
| 119 static final VOID = const SourceString('void'); | |
| 120 static final INT = const SourceString('int'); | |
| 121 static final DOUBLE = const SourceString('double'); | |
| 122 static final DYNAMIC = const SourceString('Dynamic'); | |
| 123 static final STRING = const SourceString('String'); | |
| 124 static final BOOL = const SourceString('bool'); | |
| 125 static final OBJECT = const SourceString('Object'); | |
| 126 static final LIST = const SourceString('List'); | |
| 127 | |
| 128 final VoidType voidType; | 119 final VoidType voidType; |
| 129 final InterfaceType dynamicType; | 120 final InterfaceType dynamicType; |
| 130 | 121 |
| 131 Types(Element dynamicElement) | 122 Types(Element dynamicElement) |
| 132 : this.with(dynamicElement, new LibraryElement(new Script(null, null))); | 123 : this.with(dynamicElement, new LibraryElement(new Script(null, null))); |
| 133 | 124 |
| 134 // TODO(karlklose): should we have a class Void? | 125 // TODO(karlklose): should we have a class Void? |
| 135 Types.with(Element dynamicElement, LibraryElement library) | 126 Types.with(Element dynamicElement, LibraryElement library) |
| 136 : voidType = new VoidType(new VoidElement(library)), | 127 : voidType = new VoidType(new VoidElement(library)), |
| 137 dynamicType = new InterfaceType(dynamicElement); | 128 dynamicType = new InterfaceType(dynamicElement); |
| 138 | 129 |
| 139 Type lookup(SourceString s) { | |
| 140 if (VOID == s) { | |
| 141 return voidType; | |
| 142 } else if (DYNAMIC == s || s.stringValue === 'var') { | |
| 143 return dynamicType; | |
| 144 } | |
| 145 return null; | |
| 146 } | |
| 147 | |
| 148 /** Returns true if t is a subtype of s */ | 130 /** Returns true if t is a subtype of s */ |
| 149 bool isSubtype(Type t, Type s) { | 131 bool isSubtype(Type t, Type s) { |
| 150 if (t === s || t === dynamicType || s === dynamicType || | 132 if (t === s || t === dynamicType || s === dynamicType || |
| 151 s.name == OBJECT) return true; | 133 // TODO(karlklose): Test for s.element === compiler.objectClass. |
| 134 s.name == const SourceString('Object')) return true; |
| 152 if (t is VoidType) { | 135 if (t is VoidType) { |
| 153 return false; | 136 return false; |
| 154 } else if (t is InterfaceType) { | 137 } else if (t is InterfaceType) { |
| 155 if (s is !InterfaceType) return false; | 138 if (s is !InterfaceType) return false; |
| 156 ClassElement tc = t.element; | 139 ClassElement tc = t.element; |
| 157 if (tc === s.element) return true; | 140 if (tc === s.element) return true; |
| 158 for (Link<Type> supertypes = tc.allSupertypes; | 141 for (Link<Type> supertypes = tc.allSupertypes; |
| 159 supertypes != null && !supertypes.isEmpty(); | 142 supertypes != null && !supertypes.isEmpty(); |
| 160 supertypes = supertypes.tail) { | 143 supertypes = supertypes.tail) { |
| 161 Type supertype = supertypes.head; | 144 Type supertype = supertypes.head; |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 } | 768 } |
| 786 | 769 |
| 787 visitCatchBlock(CatchBlock node) { | 770 visitCatchBlock(CatchBlock node) { |
| 788 return unhandledStatement(); | 771 return unhandledStatement(); |
| 789 } | 772 } |
| 790 | 773 |
| 791 visitTypedef(Typedef node) { | 774 visitTypedef(Typedef node) { |
| 792 return unhandledStatement(); | 775 return unhandledStatement(); |
| 793 } | 776 } |
| 794 } | 777 } |
| OLD | NEW |