Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: lib/compiler/implementation/typechecker.dart

Issue 10232011: Implement simple dynamic type check. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor edits. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
27 interface Type { 27 interface Type {
28 SourceString get name(); 28 SourceString get name();
29 Element get element(); 29 Element get element();
30 } 30 }
31 31
32 class TypeVariableType implements Type { 32 class TypeVariableType implements Type {
33 final SourceString name; 33 final SourceString name;
34 Element element; 34 Element element;
35 TypeVariableType(this.name, [this.element]); 35 TypeVariableType(this.name, [this.element]);
36 36
37 toString() => name.toString(); 37 toString() => name.slowToString();
38 } 38 }
39 39
40 /** 40 /**
41 * A statement type tracks whether a statement returns or may return. 41 * A statement type tracks whether a statement returns or may return.
42 */ 42 */
43 class StatementType implements Type { 43 class StatementType implements Type {
44 final String stringName; 44 final String stringName;
45 Element get element() => null; 45 Element get element() => null;
46 46
47 SourceString get name() => new SourceString(stringName); 47 SourceString get name() => new SourceString(stringName);
48 48
49 const StatementType(this.stringName); 49 const StatementType(this.stringName);
50 50
51 static final RETURNING = const StatementType('<returning>'); 51 static final RETURNING = const StatementType('<returning>');
52 static final NOT_RETURNING = const StatementType('<not returning>'); 52 static final NOT_RETURNING = const StatementType('<not returning>');
53 static final MAYBE_RETURNING = const StatementType('<maybe returning>'); 53 static final MAYBE_RETURNING = const StatementType('<maybe returning>');
54 54
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 InterfaceType implements Type { 63 class InterfaceType implements Type {
64 final SourceString name; 64 final SourceString name;
65 final Element element; 65 final ClassElement element;
66 final Link<Type> arguments; 66 final Link<Type> arguments;
67 67
68 const InterfaceType(this.name, this.element, 68 const InterfaceType(this.name, this.element,
69 [this.arguments = const EmptyLink<Type>()]); 69 [this.arguments = const EmptyLink<Type>()]);
70 70
71 toString() { 71 toString() {
72 StringBuffer sb = new StringBuffer(); 72 StringBuffer sb = new StringBuffer();
73 sb.add(name.slowToString()); 73 sb.add(name.slowToString());
74 if (!arguments.isEmpty()) { 74 if (!arguments.isEmpty()) {
75 sb.add('<'); 75 sb.add('<');
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 } 727 }
728 728
729 visitCatchBlock(CatchBlock node) { 729 visitCatchBlock(CatchBlock node) {
730 fail(node); 730 fail(node);
731 } 731 }
732 732
733 visitTypedef(Typedef node) { 733 visitTypedef(Typedef node) {
734 fail(node); 734 fail(node);
735 } 735 }
736 } 736 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698