| OLD | NEW |
| 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 ConstantEmitter implements ConstantVisitor { | 5 class ConstantEmitter implements ConstantVisitor { |
| 6 final Compiler compiler; | 6 final Compiler compiler; |
| 7 final Namer namer; | 7 final Namer namer; |
| 8 | 8 |
| 9 CodeBuffer buffer; | 9 CodeBuffer buffer; |
| 10 bool shouldEmitCanonicalVersion; | 10 bool shouldEmitCanonicalVersion; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 shouldEmitCanonicalVersion = true; | 200 shouldEmitCanonicalVersion = true; |
| 201 | 201 |
| 202 ClassElement classElement = constant.type.element; | 202 ClassElement classElement = constant.type.element; |
| 203 buffer.add("new "); | 203 buffer.add("new "); |
| 204 buffer.add(getJsConstructor(classElement)); | 204 buffer.add(getJsConstructor(classElement)); |
| 205 buffer.add("("); | 205 buffer.add("("); |
| 206 // The arguments of the JavaScript constructor for any given Dart class | 206 // The arguments of the JavaScript constructor for any given Dart class |
| 207 // are in the same order as the members of the class element. | 207 // are in the same order as the members of the class element. |
| 208 int emittedArgumentCount = 0; | 208 int emittedArgumentCount = 0; |
| 209 classElement.implementation.forEachInstanceField( | 209 classElement.implementation.forEachInstanceField( |
| 210 includeBackendMembers: true, | 210 (ClassElement enclosing, Element field) { |
| 211 includeSuperMembers: true, | |
| 212 f: (ClassElement enclosing, Element field) { | |
| 213 if (emittedArgumentCount != 0) buffer.add(", "); | 211 if (emittedArgumentCount != 0) buffer.add(", "); |
| 214 if (field.name == MapConstant.LENGTH_NAME) { | 212 if (field.name == MapConstant.LENGTH_NAME) { |
| 215 buffer.add(constant.keys.entries.length); | 213 buffer.add(constant.keys.entries.length); |
| 216 } else if (field.name == MapConstant.JS_OBJECT_NAME) { | 214 } else if (field.name == MapConstant.JS_OBJECT_NAME) { |
| 217 writeJsMap(); | 215 writeJsMap(); |
| 218 } else if (field.name == MapConstant.KEYS_NAME) { | 216 } else if (field.name == MapConstant.KEYS_NAME) { |
| 219 emitCanonicalVersionOfConstant(constant.keys, buffer); | 217 emitCanonicalVersionOfConstant(constant.keys, buffer); |
| 220 } else if (field.name == MapConstant.PROTO_VALUE) { | 218 } else if (field.name == MapConstant.PROTO_VALUE) { |
| 221 assert(constant.protoValue !== null); | 219 assert(constant.protoValue !== null); |
| 222 emitCanonicalVersionOfConstant(constant.protoValue, buffer); | 220 emitCanonicalVersionOfConstant(constant.protoValue, buffer); |
| 223 } else { | 221 } else { |
| 224 badFieldCountError(); | 222 badFieldCountError(); |
| 225 } | 223 } |
| 226 emittedArgumentCount++; | 224 emittedArgumentCount++; |
| 227 }); | 225 }, |
| 226 includeBackendMembers: true, |
| 227 includeSuperMembers: true); |
| 228 if ((constant.protoValue === null && emittedArgumentCount != 3) || | 228 if ((constant.protoValue === null && emittedArgumentCount != 3) || |
| 229 (constant.protoValue !== null && emittedArgumentCount != 4)) { | 229 (constant.protoValue !== null && emittedArgumentCount != 4)) { |
| 230 badFieldCountError(); | 230 badFieldCountError(); |
| 231 } | 231 } |
| 232 buffer.add(")"); | 232 buffer.add(")"); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 void visitConstructed(ConstructedConstant constant) { | 236 void visitConstructed(ConstructedConstant constant) { |
| 237 if (shouldEmitCanonicalVersion) { | 237 if (shouldEmitCanonicalVersion) { |
| 238 emitCanonicalVersion(constant); | 238 emitCanonicalVersion(constant); |
| 239 } else { | 239 } else { |
| 240 shouldEmitCanonicalVersion = true; | 240 shouldEmitCanonicalVersion = true; |
| 241 | 241 |
| 242 buffer.add("new "); | 242 buffer.add("new "); |
| 243 buffer.add(getJsConstructor(constant.type.element)); | 243 buffer.add(getJsConstructor(constant.type.element)); |
| 244 buffer.add("("); | 244 buffer.add("("); |
| 245 for (int i = 0; i < constant.fields.length; i++) { | 245 for (int i = 0; i < constant.fields.length; i++) { |
| 246 if (i != 0) buffer.add(", "); | 246 if (i != 0) buffer.add(", "); |
| 247 _visit(constant.fields[i]); | 247 _visit(constant.fields[i]); |
| 248 } | 248 } |
| 249 buffer.add(")"); | 249 buffer.add(")"); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| OLD | NEW |