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

Side by Side Diff: frog/leg/compile_time_constants.dart

Issue 9873012: Move member-iterating code into ClassElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
« no previous file with comments | « no previous file | frog/leg/elements/elements.dart » ('j') | frog/leg/elements/elements.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 "Compiler and ConstantMap disagree on number of fields."); 349 "Compiler and ConstantMap disagree on number of fields.");
350 } 350 }
351 351
352 ClassElement classElement = type.element; 352 ClassElement classElement = type.element;
353 buffer.add("new "); 353 buffer.add("new ");
354 buffer.add(handler.getJsConstructor(classElement)); 354 buffer.add(handler.getJsConstructor(classElement));
355 buffer.add("("); 355 buffer.add("(");
356 // The arguments of the JavaScript constructor for any given Dart class 356 // The arguments of the JavaScript constructor for any given Dart class
357 // are in the same order as the members of the class element. 357 // are in the same order as the members of the class element.
358 int emittedArgumentCount = 0; 358 int emittedArgumentCount = 0;
359 for (Element element in classElement.members) { 359 classElement.forEachInstanceField(
360 if (element.name == LENGTH_NAME) { 360 includeBackendMembers: true,
361 includeSuperMembers: true,
362 f: (ClassElement enclosing, Element field) {
363 if (emittedArgumentCount != 0) buffer.add(", ");
364 if (field.name == LENGTH_NAME) {
361 buffer.add(keys.entries.length); 365 buffer.add(keys.entries.length);
362 } else if (element.name == JS_OBJECT_NAME) { 366 } else if (field.name == JS_OBJECT_NAME) {
363 writeJsMap(); 367 writeJsMap();
364 } else if (element.name == KEYS_NAME) { 368 } else if (field.name == KEYS_NAME) {
365 keys.writeCanonicalizedJsCode(buffer, handler); 369 keys.writeCanonicalizedJsCode(buffer, handler);
366 } else { 370 } else {
367 // Skip methods. 371 badFieldCountError();
368 if (element.kind == ElementKind.FIELD) badFieldCountError();
369 continue;
370 } 372 }
371 emittedArgumentCount++; 373 emittedArgumentCount++;
372 if (emittedArgumentCount == 3) { 374 });
373 break; // All arguments have been emitted.
374 } else {
375 buffer.add(", ");
376 }
377 }
378 if (emittedArgumentCount != 3) badFieldCountError(); 375 if (emittedArgumentCount != 3) badFieldCountError();
379 buffer.add(")"); 376 buffer.add(")");
380 } 377 }
381 378
382 bool operator ==(var other) { 379 bool operator ==(var other) {
383 if (other is !MapConstant) return false; 380 if (other is !MapConstant) return false;
384 MapConstant otherMap = other; 381 MapConstant otherMap = other;
385 if (hashCode() != otherMap.hashCode()) return false; 382 if (hashCode() != otherMap.hashCode()) return false;
386 // TODO(floitsch): verify that the generic types are the same. 383 // TODO(floitsch): verify that the generic types are the same.
387 if (keys != otherMap.keys) return false; 384 if (keys != otherMap.keys) return false;
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 */ 1085 */
1089 void evaluateConstructorFieldValues(List<Constant> arguments) { 1086 void evaluateConstructorFieldValues(List<Constant> arguments) {
1090 compiler.withCurrentElement(constructor, () { 1087 compiler.withCurrentElement(constructor, () {
1091 assignArgumentsToParameters(arguments); 1088 assignArgumentsToParameters(arguments);
1092 evaluateConstructorInitializers(); 1089 evaluateConstructorInitializers();
1093 }); 1090 });
1094 } 1091 }
1095 1092
1096 List<Constant> buildJsNewArguments(ClassElement classElement) { 1093 List<Constant> buildJsNewArguments(ClassElement classElement) {
1097 List<Constant> jsNewArguments = <Constant>[]; 1094 List<Constant> jsNewArguments = <Constant>[];
1098 // TODO(floitsch): share this code with the emitter, so that we don't 1095 classElement.forEachInstanceField(
1099 // need to care about the order of fields here. 1096 includeBackendMembers: true,
1100 while (classElement != compiler.objectClass) { 1097 includeSuperMembers: true,
1101 for (Element member in classElement.members) { 1098 f: (ClassElement enclosing, Element field) {
1102 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { 1099 Constant fieldValue = fieldValues[field];
1103 Constant fieldValue = fieldValues[member]; 1100 if (fieldValue === null) {
1104 if (fieldValue === null) { 1101 // Use the default value.
1105 // Use the default value. 1102 fieldValue = compiler.compileVariable(field);
1106 fieldValue = compiler.compileVariable(member);
1107 }
1108 jsNewArguments.add(fieldValue);
1109 }
1110 } 1103 }
1111 classElement = classElement.superclass; 1104 jsNewArguments.add(fieldValue);
1112 } 1105 });
1113 return jsNewArguments; 1106 return jsNewArguments;
1114 } 1107 }
1115 } 1108 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/elements/elements.dart » ('j') | frog/leg/elements/elements.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698