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

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

Issue 10876008: Remove most superfluous getter arguments from dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 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 Constant implements Hashable { 5 class Constant implements Hashable {
6 const Constant(); 6 const Constant();
7 7
8 bool isNull() => false; 8 bool isNull() => false;
9 bool isBool() => false; 9 bool isBool() => false;
10 bool isTrue() => false; 10 bool isTrue() => false;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 } 56 }
57 57
58 class NullConstant extends PrimitiveConstant { 58 class NullConstant extends PrimitiveConstant {
59 /** The value a Dart null is compiled to in JavaScript. */ 59 /** The value a Dart null is compiled to in JavaScript. */
60 static final String JsNull = "null"; 60 static final String JsNull = "null";
61 61
62 factory NullConstant() => const NullConstant._internal(); 62 factory NullConstant() => const NullConstant._internal();
63 const NullConstant._internal(); 63 const NullConstant._internal();
64 bool isNull() => true; 64 bool isNull() => true;
65 get value() => null; 65 get value => null;
66 66
67 void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) { 67 void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
68 buffer.add(JsNull); 68 buffer.add(JsNull);
69 } 69 }
70 70
71 // The magic constant has no meaning. It is just a random value. 71 // The magic constant has no meaning. It is just a random value.
72 int hashCode() => 785965825; 72 int hashCode() => 785965825;
73 DartString toDartString() => const LiteralDartString("null"); 73 DartString toDartString() => const LiteralDartString("null");
74 } 74 }
75 75
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 247 }
248 248
249 bool operator ==(var other) { 249 bool operator ==(var other) {
250 if (other is !StringConstant) return false; 250 if (other is !StringConstant) return false;
251 StringConstant otherString = other; 251 StringConstant otherString = other;
252 return (_hashCode == otherString._hashCode) && (value == otherString.value); 252 return (_hashCode == otherString._hashCode) && (value == otherString.value);
253 } 253 }
254 254
255 int hashCode() => _hashCode; 255 int hashCode() => _hashCode;
256 DartString toDartString() => value; 256 DartString toDartString() => value;
257 int get length() => value.length; 257 int get length => value.length;
258 } 258 }
259 259
260 class ObjectConstant extends Constant { 260 class ObjectConstant extends Constant {
261 final Type type; 261 final Type type;
262 262
263 ObjectConstant(this.type); 263 ObjectConstant(this.type);
264 bool isObject() => true; 264 bool isObject() => true;
265 265
266 // TODO(1603): The class should be marked as abstract, but the VM doesn't 266 // TODO(1603): The class should be marked as abstract, but the VM doesn't
267 // currently allow this. 267 // currently allow this.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 for (int i = 0; i < entries.length; i++) { 307 for (int i = 0; i < entries.length; i++) {
308 if (entries[i] != otherList.entries[i]) return false; 308 if (entries[i] != otherList.entries[i]) return false;
309 } 309 }
310 return true; 310 return true;
311 } 311 }
312 312
313 int hashCode() => _hashCode; 313 int hashCode() => _hashCode;
314 314
315 List<Constant> getDependencies() => entries; 315 List<Constant> getDependencies() => entries;
316 316
317 int get length() => entries.length; 317 int get length => entries.length;
318 } 318 }
319 319
320 class MapConstant extends ObjectConstant { 320 class MapConstant extends ObjectConstant {
321 /** 321 /**
322 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript 322 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript
323 * object. It would change the prototype chain. 323 * object. It would change the prototype chain.
324 */ 324 */
325 static final String PROTO_PROPERTY = "__proto__"; 325 static final String PROTO_PROPERTY = "__proto__";
326 326
327 /** The dart class implementing constant map literals. */ 327 /** The dart class implementing constant map literals. */
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 420 }
421 421
422 int hashCode() => _hashCode; 422 int hashCode() => _hashCode;
423 423
424 List<Constant> getDependencies() { 424 List<Constant> getDependencies() {
425 List<Constant> result = <Constant>[keys]; 425 List<Constant> result = <Constant>[keys];
426 result.addAll(values); 426 result.addAll(values);
427 return result; 427 return result;
428 } 428 }
429 429
430 int get length() => keys.length; 430 int get length => keys.length;
431 } 431 }
432 432
433 class ConstructedConstant extends ObjectConstant { 433 class ConstructedConstant extends ObjectConstant {
434 final List<Constant> fields; 434 final List<Constant> fields;
435 int _hashCode; 435 int _hashCode;
436 436
437 ConstructedConstant(Type type, this.fields) : super(type) { 437 ConstructedConstant(Type type, this.fields) : super(type) {
438 assert(type !== null); 438 assert(type !== null);
439 // TODO(floitsch): create a better hash. 439 // TODO(floitsch): create a better hash.
440 int hash = 0; 440 int hash = 0;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 final Map<Constant, String> compiledConstants; 489 final Map<Constant, String> compiledConstants;
490 490
491 // The set of variable elements that are in the process of being computed. 491 // The set of variable elements that are in the process of being computed.
492 final Set<VariableElement> pendingVariables; 492 final Set<VariableElement> pendingVariables;
493 493
494 ConstantHandler(Compiler compiler) 494 ConstantHandler(Compiler compiler)
495 : initialVariableValues = new Map<VariableElement, Dynamic>(), 495 : initialVariableValues = new Map<VariableElement, Dynamic>(),
496 compiledConstants = new Map<Constant, String>(), 496 compiledConstants = new Map<Constant, String>(),
497 pendingVariables = new Set<VariableElement>(), 497 pendingVariables = new Set<VariableElement>(),
498 super(compiler); 498 super(compiler);
499 String get name() => 'ConstantHandler'; 499 String get name => 'ConstantHandler';
500 500
501 void registerCompileTimeConstant(Constant constant) { 501 void registerCompileTimeConstant(Constant constant) {
502 Function ifAbsentThunk = (() => compiler.namer.getFreshGlobalName("CTC")); 502 Function ifAbsentThunk = (() => compiler.namer.getFreshGlobalName("CTC"));
503 compiledConstants.putIfAbsent(constant, ifAbsentThunk); 503 compiledConstants.putIfAbsent(constant, ifAbsentThunk);
504 } 504 }
505 505
506 /** 506 /**
507 * Compiles the initial value of the given field and stores it in an internal 507 * Compiles the initial value of the given field and stores it in an internal
508 * map. 508 * map.
509 * 509 *
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 Constant fieldValue = fieldValues[field]; 1169 Constant fieldValue = fieldValues[field];
1170 if (fieldValue === null) { 1170 if (fieldValue === null) {
1171 // Use the default value. 1171 // Use the default value.
1172 fieldValue = compiler.compileVariable(field); 1172 fieldValue = compiler.compileVariable(field);
1173 } 1173 }
1174 jsNewArguments.add(fieldValue); 1174 jsNewArguments.add(fieldValue);
1175 }); 1175 });
1176 return jsNewArguments; 1176 return jsNewArguments;
1177 } 1177 }
1178 } 1178 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/code_buffer.dart ('k') | dart/lib/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698