| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A data structure for collecting fragments of a class definition. | 8 * A data structure for collecting fragments of a class definition. |
| 9 */ | 9 */ |
| 10 class ClassBuilder { | 10 class ClassBuilder { |
| 11 // TODO (sigurdm) this is just a bag of properties, rename this class |
| 12 |
| 11 final List<jsAst.Property> properties = <jsAst.Property>[]; | 13 final List<jsAst.Property> properties = <jsAst.Property>[]; |
| 12 final List<String> fields = <String>[]; | |
| 13 | |
| 14 String superName; | |
| 15 String nativeName; | |
| 16 String functionType; | |
| 17 List<jsAst.Node> fieldMetadata; | |
| 18 | 14 |
| 19 /// Set to true by user if class is indistinguishable from its superclass. | 15 /// Set to true by user if class is indistinguishable from its superclass. |
| 20 bool isTrivial = false; | 16 bool isTrivial = false; |
| 21 | 17 |
| 22 // Has the same signature as [DefineStubFunction]. | 18 // Has the same signature as [DefineStubFunction]. |
| 23 void addProperty(String name, jsAst.Expression value) { | 19 void addProperty(String name, jsAst.Expression value) { |
| 24 properties.add(new jsAst.Property(js.string(name), value)); | 20 properties.add(new jsAst.Property(js.string(name), value)); |
| 25 } | 21 } |
| 26 | 22 |
| 27 void addField(String field) { | 23 jsAst.Expression toObjectInitializer() { |
| 28 fields.add(field); | 24 return new jsAst.ObjectInitializer(properties, isOneLiner: false); |
| 29 } | |
| 30 | |
| 31 jsAst.ObjectInitializer toObjectInitializer() { | |
| 32 StringBuffer buffer = new StringBuffer(); | |
| 33 if (superName != null) { | |
| 34 if (nativeName != null) { | |
| 35 buffer.write('$nativeName/'); | |
| 36 } | |
| 37 buffer.write('$superName'); | |
| 38 if (functionType != null) { | |
| 39 buffer.write(':$functionType'); | |
| 40 } | |
| 41 buffer.write(';'); | |
| 42 } | |
| 43 buffer.writeAll(fields, ','); | |
| 44 var classData = js.string('$buffer'); | |
| 45 if (fieldMetadata != null) { | |
| 46 // If we need to store fieldMetadata, classData is turned into an array, | |
| 47 // and the field metadata is appended. So if classData is just a string, | |
| 48 // there is no field metadata. | |
| 49 classData = | |
| 50 new jsAst.ArrayInitializer.from([classData]..addAll(fieldMetadata)); | |
| 51 } | |
| 52 var fieldsAndProperties = | |
| 53 [new jsAst.Property(js.string(''), classData)] | |
| 54 ..addAll(properties); | |
| 55 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false); | |
| 56 } | 25 } |
| 57 | 26 |
| 58 } | 27 } |
| OLD | NEW |