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

Side by Side Diff: frog/gen.dart

Issue 8457007: Better runtime type checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleaner output Created 9 years, 1 month 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
« no previous file with comments | « frog/frogsh ('k') | frog/lib/core.js » ('j') | frog/library.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * Top level generator object for writing code and keeping track of 6 * Top level generator object for writing code and keeping track of
7 * dependencies. 7 * dependencies.
8 * 8 *
9 * Should have two compilation models, but only one implemented so far. 9 * Should have two compilation models, but only one implemented so far.
10 * 10 *
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 for (var type in _orderValues(lib.types)) { 100 for (var type in _orderValues(lib.types)) {
101 if (type.isUsed && type.isClass) { 101 if (type.isUsed && type.isClass) {
102 writeType(type); 102 writeType(type);
103 103
104 if (type.isGeneric) { 104 if (type.isGeneric) {
105 for (var ct in _orderValues(type._concreteTypes)) { 105 for (var ct in _orderValues(type._concreteTypes)) {
106 writeType(ct); 106 writeType(ct);
107 } 107 }
108 } 108 }
109 } 109 }
110 // Type check functions for builtin JS types
111 if (type.typeCheckCode != null) {
112 writer.writeln(type.typeCheckCode);
113 }
110 } 114 }
111 } 115 }
112 116
113 genMethod(Member meth, [MethodGenerator enclosingMethod=null]) { 117 genMethod(Member meth, [MethodGenerator enclosingMethod=null]) {
114 if (!meth.isGenerated && meth.declaringType.isClass 118 if (!meth.isGenerated && meth.declaringType.isClass
115 && meth.definition != null && !meth.isAbstract) { 119 && meth.definition != null && !meth.isAbstract) {
116 new MethodGenerator(meth, enclosingMethod).run(); 120 new MethodGenerator(meth, enclosingMethod).run();
117 } 121 }
118 } 122 }
119 123
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (type is ConcreteType) { 182 if (type is ConcreteType) {
179 writer.writeln( 183 writer.writeln(
180 '\$inherits(${type.jsname}, ${type.genericType.jsname});'); 184 '\$inherits(${type.jsname}, ${type.genericType.jsname});');
181 } else if (!type.isNativeType) { 185 } else if (!type.isNativeType) {
182 if (type.parent != null && !type.parent.isObject) { 186 if (type.parent != null && !type.parent.isObject) {
183 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});'); 187 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});');
184 } 188 }
185 } 189 }
186 } 190 }
187 191
188 // Concrete types (like List<String>) will this already defined on their 192 // Concrete types (like List<String>) will have this already defined on
189 // prototype from the generic type (like List) 193 // their prototype from the generic type (like List)
190 if (type is! ConcreteType) { 194 if (type is! ConcreteType) {
191 _maybeIsTest(type, type); 195 _maybeIsTest(type, type);
192 } 196 }
193 if (type.genericType._concreteTypes != null) { 197 if (type.genericType._concreteTypes != null) {
194 for (var ct in _orderValues(type.genericType._concreteTypes)) { 198 for (var ct in _orderValues(type.genericType._concreteTypes)) {
195 _maybeIsTest(type, ct); 199 _maybeIsTest(type, ct);
196 } 200 }
197 } 201 }
198 202
199 if (type.interfaces != null) { 203 if (type.interfaces != null) {
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 945
942 MethodMember _makeLambdaMethod(String name, FunctionDefinition func) { 946 MethodMember _makeLambdaMethod(String name, FunctionDefinition func) {
943 var meth = new MethodMember(name, method.declaringType, func); 947 var meth = new MethodMember(name, method.declaringType, func);
944 meth.isLambda = true; 948 meth.isLambda = true;
945 meth.resolve(method.declaringType); 949 meth.resolve(method.declaringType);
946 world.gen.genMethod(meth, this); 950 world.gen.genMethod(meth, this);
947 return meth; 951 return meth;
948 } 952 }
949 953
950 visitBool(Expression node) { 954 visitBool(Expression node) {
951 return visitTypedValue(node, world.boolType); 955 // Boolean conversions in if/while/do/for/conditions require non-null bool.
956
957 // TODO(jmesserly): why do we have this rule? It seems inconsistent with
958 // the rest of the type system, and just causes bogus asserts unless all
959 // bools are initialized to false.
960 return visitValue(node).convertToNonNullBool(this, node);
952 } 961 }
953 962
954 visitValue(Expression node) { 963 visitValue(Expression node) {
955 if (node == null) return null; 964 if (node == null) return null;
956 965
957 var value = node.visit(this); 966 var value = node.visit(this);
958 value.checkFirstClass(node.span); 967 value.checkFirstClass(node.span);
959 return value; 968 return value;
960 } 969 }
961 970
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 result.add(new Value(world.varType, '\$$i', false, /*needsTemp:*/false)); 2169 result.add(new Value(world.varType, '\$$i', false, /*needsTemp:*/false));
2161 } 2170 }
2162 for (int i = bareCount; i < length; i++) { 2171 for (int i = bareCount; i < length; i++) {
2163 var name = getName(i); 2172 var name = getName(i);
2164 if (name == null) name = '\$$i'; 2173 if (name == null) name = '\$$i';
2165 result.add(new Value(world.varType, name, false, /*needsTemp:*/false)); 2174 result.add(new Value(world.varType, name, false, /*needsTemp:*/false));
2166 } 2175 }
2167 return new Arguments(nodes, result); 2176 return new Arguments(nodes, result);
2168 } 2177 }
2169 } 2178 }
OLDNEW
« no previous file with comments | « frog/frogsh ('k') | frog/lib/core.js » ('j') | frog/library.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698