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

Side by Side Diff: frog/gen.dart

Issue 8681027: Fix bug 578 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: prereviewed Created 9 years 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/lang.dart » ('j') | no next file with comments »
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // TODO(jimhug): Workaround for problems with reified generic Array. 196 // TODO(jimhug): Workaround for problems with reified generic Array.
197 if (type.name != null && type is ConcreteType && 197 if (type.name != null && type is ConcreteType &&
198 type.library == world.coreimpl && 198 type.library == world.coreimpl &&
199 type.name.startsWith('ListFactory')) { 199 type.name.startsWith('ListFactory')) {
200 writer.writeln('${type.jsname} = ${type.genericType.jsname};'); 200 writer.writeln('${type.jsname} = ${type.genericType.jsname};');
201 return; 201 return;
202 } 202 }
203 203
204 var typeName = type.jsname != null ? type.jsname : 'top level'; 204 var typeName = type.jsname != null ? type.jsname : 'top level';
205 writer.comment('// ********** Code for ${typeName} **************'); 205 writer.comment('// ********** Code for ${typeName} **************');
206 if (type.isNativeType && !type.isTop) { 206 if (type.isNative && !type.isTop) {
207 var nativeName = type.definition.nativeType.name; 207 var nativeName = type.definition.nativeType.name;
208 if (nativeName == '') { 208 if (nativeName == '') {
209 writer.writeln('function ${type.jsname}() {}'); 209 writer.writeln('function ${type.jsname}() {}');
210 } else if (type.jsname != nativeName) { 210 } else if (type.jsname != nativeName) {
211 writer.writeln('${type.jsname} = ${nativeName};'); 211 writer.writeln('${type.jsname} = ${nativeName};');
212 } 212 }
213 } 213 }
214 214
215 if (type.isTop) { 215 if (type.isTop) {
216 // no preludes for top type 216 // no preludes for top type
217 } else if (type.constructors.length == 0) { 217 } else if (type.constructors.length == 0) {
218 if (!type.isNativeType) { 218 if (!type.isNative) {
219 // TODO(jimhug): More guards to guarantee staticness 219 // TODO(jimhug): More guards to guarantee staticness
220 writer.writeln('function ${type.jsname}() {}'); 220 writer.writeln('function ${type.jsname}() {}');
221 } 221 }
222 } else { 222 } else {
223 Member standardConstructor = type.constructors['']; 223 Member standardConstructor = type.constructors[''];
224 if (standardConstructor == null || 224 if (standardConstructor == null ||
225 standardConstructor.generator == null) { 225 standardConstructor.generator == null) {
226 if (!type.isNativeType) { 226 if (!type.isNative) {
227 writer.writeln('function ${type.jsname}() {}'); 227 writer.writeln('function ${type.jsname}() {}');
228 } 228 }
229 } else { 229 } else {
230 standardConstructor.generator.writeDefinition(writer, null); 230 standardConstructor.generator.writeDefinition(writer, null);
231 } 231 }
232 232
233 for (var c in type.constructors.getValues()) { 233 for (var c in type.constructors.getValues()) {
234 if (c.generator != null && c != standardConstructor) { 234 if (c.generator != null && c != standardConstructor) {
235 c.generator.writeDefinition(writer, null); 235 c.generator.writeDefinition(writer, null);
236 } 236 }
237 } 237 }
238 } 238 }
239 239
240 if (!type.isTop) { 240 if (!type.isTop) {
241 if (type is ConcreteType) { 241 if (type is ConcreteType) {
242 ConcreteType c = type; 242 ConcreteType c = type;
243 _ensureInheritsHelper(); 243 _ensureInheritsHelper();
244 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});'); 244 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});');
245 245
246 // Mixin members from concrete specializations of base types too. 246 // Mixin members from concrete specializations of base types too.
247 // TODO(jmesserly): emit this sooner instead of at the end. 247 // TODO(jmesserly): emit this sooner instead of at the end.
248 // But it needs to come after we've emitted both types. 248 // But it needs to come after we've emitted both types.
249 // TODO(jmesserly): HACK: using _parent instead of parent so we don't 249 // TODO(jmesserly): HACK: using _parent instead of parent so we don't
250 // try to inherit things that we didn't actually use. 250 // try to inherit things that we didn't actually use.
251 for (var p = c._parent; p is ConcreteType; p = p._parent) { 251 for (var p = c._parent; p is ConcreteType; p = p._parent) {
252 _ensureInheritMembersHelper(); 252 _ensureInheritMembersHelper();
253 _mixins.writeln('\$inheritsMembers(${c.jsname}, ${p.jsname});'); 253 _mixins.writeln('\$inheritsMembers(${c.jsname}, ${p.jsname});');
254 } 254 }
255 } else if (!type.isNativeType) { 255 } else if (!type.isNative) {
256 if (type.parent != null && !type.parent.isObject) { 256 if (type.parent != null && !type.parent.isObject) {
257 _ensureInheritsHelper(); 257 _ensureInheritsHelper();
258 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});'); 258 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});');
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 // Concrete types (like List<String>) will have this already defined on 263 // Concrete types (like List<String>) will have this already defined on
264 // their prototype from the generic type (like List) 264 // their prototype from the generic type (like List)
265 if (type is! ConcreteType) { 265 if (type is! ConcreteType) {
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 _scope = new BlockScope(this, _scope, reentrant); 1118 _scope = new BlockScope(this, _scope, reentrant);
1119 } 1119 }
1120 1120
1121 _popBlock() { 1121 _popBlock() {
1122 _scope = _scope.parent; 1122 _scope = _scope.parent;
1123 } 1123 }
1124 1124
1125 MethodMember _makeLambdaMethod(String name, FunctionDefinition func) { 1125 MethodMember _makeLambdaMethod(String name, FunctionDefinition func) {
1126 var meth = new MethodMember(name, method.declaringType, func); 1126 var meth = new MethodMember(name, method.declaringType, func);
1127 meth.isLambda = true; 1127 meth.isLambda = true;
1128 meth.resolve(method.declaringType); 1128 meth.enclosingElement = method;
1129 meth.resolve();
1129 world.gen.genMethod(meth, this); 1130 world.gen.genMethod(meth, this);
1130 return meth; 1131 return meth;
1131 } 1132 }
1132 1133
1133 visitBool(Expression node) { 1134 visitBool(Expression node) {
1134 // Boolean conversions in if/while/do/for/conditions require non-null bool. 1135 // Boolean conversions in if/while/do/for/conditions require non-null bool.
1135 1136
1136 // TODO(jmesserly): why do we have this rule? It seems inconsistent with 1137 // TODO(jmesserly): why do we have this rule? It seems inconsistent with
1137 // the rest of the type system, and just causes bogus asserts unless all 1138 // the rest of the type system, and just causes bogus asserts unless all
1138 // bools are initialized to false. 1139 // bools are initialized to false.
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); 2398 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false));
2398 } 2399 }
2399 for (int i = bareCount; i < length; i++) { 2400 for (int i = bareCount; i < length; i++) {
2400 var name = getName(i); 2401 var name = getName(i);
2401 if (name == null) name = '\$$i'; 2402 if (name == null) name = '\$$i';
2402 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); 2403 result.add(new Value(world.varType, name, null, /*needsTemp:*/false));
2403 } 2404 }
2404 return new Arguments(nodes, result); 2405 return new Arguments(nodes, result);
2405 } 2406 }
2406 } 2407 }
OLDNEW
« no previous file with comments | « frog/frogsh ('k') | frog/lang.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698