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 final List<jsAst.Property> properties = <jsAst.Property>[]; | 11 final List<jsAst.Property> properties = <jsAst.Property>[]; |
12 final List<String> fields = <String>[]; | 12 final List<String> fields = <String>[]; |
13 | 13 |
14 String superName; | 14 String superName; |
15 String nativeName; | 15 String nativeName; |
16 String functionType; | 16 String functionType; |
17 List<jsAst.Node> fieldMetadata; | 17 List<jsAst.Node> fieldMetadata; |
18 | 18 |
| 19 final Namer namer; |
| 20 |
19 /// Set to true by user if class is indistinguishable from its superclass. | 21 /// Set to true by user if class is indistinguishable from its superclass. |
20 bool isTrivial = false; | 22 bool isTrivial = false; |
21 | 23 |
| 24 ClassBuilder(this.namer); |
| 25 |
22 // Has the same signature as [DefineStubFunction]. | 26 // Has the same signature as [DefineStubFunction]. |
23 void addProperty(String name, jsAst.Expression value) { | 27 void addProperty(String name, jsAst.Expression value) { |
24 properties.add(new jsAst.Property(js.string(name), value)); | 28 properties.add(new jsAst.Property(js.string(name), value)); |
25 } | 29 } |
26 | 30 |
27 void addField(String field) { | 31 void addField(String field) { |
28 fields.add(field); | 32 fields.add(field); |
29 } | 33 } |
30 | 34 |
31 jsAst.ObjectInitializer toObjectInitializer() { | 35 jsAst.ObjectInitializer toObjectInitializer() { |
(...skipping 11 matching lines...) Expand all Loading... |
43 buffer.writeAll(fields, ','); | 47 buffer.writeAll(fields, ','); |
44 var classData = js.string('$buffer'); | 48 var classData = js.string('$buffer'); |
45 if (fieldMetadata != null) { | 49 if (fieldMetadata != null) { |
46 // If we need to store fieldMetadata, classData is turned into an array, | 50 // 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, | 51 // and the field metadata is appended. So if classData is just a string, |
48 // there is no field metadata. | 52 // there is no field metadata. |
49 classData = | 53 classData = |
50 new jsAst.ArrayInitializer.from([classData]..addAll(fieldMetadata)); | 54 new jsAst.ArrayInitializer.from([classData]..addAll(fieldMetadata)); |
51 } | 55 } |
52 var fieldsAndProperties = | 56 var fieldsAndProperties = |
53 [new jsAst.Property(js.string(''), classData)] | 57 [new jsAst.Property(js.string(namer.classDescriptorProperty), |
| 58 classData)] |
54 ..addAll(properties); | 59 ..addAll(properties); |
55 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false); | 60 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false); |
56 } | 61 } |
57 | 62 |
58 } | 63 } |
OLD | NEW |