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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_emitter/class_builder.dart

Issue 27524003: Generate tear-off closures dynamically. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r30954 Created 7 years 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) 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 11 final List<jsAst.Property> properties = <jsAst.Property>[];
12 final List<String> fields = <String>[];
12 13
13 final List<jsAst.Property> properties = <jsAst.Property>[]; 14 String superName;
15 String nativeName;
16 String functionType;
17 List<jsAst.Node> fieldMetadata;
14 18
15 /// Set to true by user if class is indistinguishable from its superclass. 19 /// Set to true by user if class is indistinguishable from its superclass.
16 bool isTrivial = false; 20 bool isTrivial = false;
17 21
18 // Has the same signature as [DefineStubFunction]. 22 // Has the same signature as [DefineStubFunction].
19 void addProperty(String name, jsAst.Expression value) { 23 void addProperty(String name, jsAst.Expression value) {
20 properties.add(new jsAst.Property(js.string(name), value)); 24 properties.add(new jsAst.Property(js.string(name), value));
21 } 25 }
22 26
23 jsAst.Expression toObjectInitializer() { 27 void addField(String field) {
24 return new jsAst.ObjectInitializer(properties, isOneLiner: false); 28 fields.add(field);
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);
25 } 56 }
26 57
27 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698