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

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

Issue 27251003: Generate onlyForRti class constructor for csp. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 class ClassEmitter extends CodeEmitterHelper { 7 class ClassEmitter extends CodeEmitterHelper {
8 /** 8 /**
9 * Documentation wanted -- johnniwinther 9 * Documentation wanted -- johnniwinther
10 * 10 *
(...skipping 17 matching lines...) Expand all
28 String runtimeName = 28 String runtimeName =
29 namer.getPrimitiveInterceptorRuntimeName(classElement); 29 namer.getPrimitiveInterceptorRuntimeName(classElement);
30 30
31 if (classElement.isMixinApplication) { 31 if (classElement.isMixinApplication) {
32 String mixinName = namer.getNameOfClass(computeMixinClass(classElement)); 32 String mixinName = namer.getNameOfClass(computeMixinClass(classElement));
33 superName = '$superName+$mixinName'; 33 superName = '$superName+$mixinName';
34 task.needsMixinSupport = true; 34 task.needsMixinSupport = true;
35 } 35 }
36 36
37 ClassBuilder builder = new ClassBuilder(); 37 ClassBuilder builder = new ClassBuilder();
38 if (!onlyForRti) { 38 emitClassConstructor(classElement, builder, runtimeName,
39 emitClassConstructor(classElement, builder, runtimeName); 39 onlyForRti: onlyForRti);
40 }
41 emitFields(classElement, builder, superName, onlyForRti: onlyForRti); 40 emitFields(classElement, builder, superName, onlyForRti: onlyForRti);
42 if (!onlyForRti) { 41 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti);
43 emitClassGettersSetters(classElement, builder); 42 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti);
44 if (!classElement.isMixinApplication) {
45 emitInstanceMembers(classElement, builder);
46 }
47 }
48 task.typeTestEmitter.emitIsTests(classElement, builder); 43 task.typeTestEmitter.emitIsTests(classElement, builder);
49 44
50 emitClassBuilderWithReflectionData( 45 emitClassBuilderWithReflectionData(
51 className, classElement, builder, buffer); 46 className, classElement, builder, buffer);
52 } 47 }
53 48
54 void emitClassConstructor(ClassElement classElement, 49 void emitClassConstructor(ClassElement classElement,
55 ClassBuilder builder, 50 ClassBuilder builder,
56 String runtimeName) { 51 String runtimeName,
52 {bool onlyForRti: false}) {
57 List<String> fields = <String>[]; 53 List<String> fields = <String>[];
58 if (!classElement.isNative()) { 54 if (!onlyForRti && !classElement.isNative()) {
59 visitFields(classElement, false, 55 visitFields(classElement, false,
60 (Element member, 56 (Element member,
61 String name, 57 String name,
62 String accessorName, 58 String accessorName,
63 bool needsGetter, 59 bool needsGetter,
64 bool needsSetter, 60 bool needsSetter,
65 bool needsCheckedSetter) { 61 bool needsCheckedSetter) {
66 fields.add(name); 62 fields.add(name);
67 }); 63 });
68 } 64 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 jsAst.Expression classDataNode = js.string(compactClassData); 218 jsAst.Expression classDataNode = js.string(compactClassData);
223 if (hasMetadata) { 219 if (hasMetadata) {
224 fieldMetadata.insert(0, classDataNode); 220 fieldMetadata.insert(0, classDataNode);
225 classDataNode = new jsAst.ArrayInitializer.from(fieldMetadata); 221 classDataNode = new jsAst.ArrayInitializer.from(fieldMetadata);
226 } 222 }
227 builder.addProperty('', classDataNode); 223 builder.addProperty('', classDataNode);
228 return fieldsAdded; 224 return fieldsAdded;
229 } 225 }
230 226
231 void emitClassGettersSetters(ClassElement classElement, 227 void emitClassGettersSetters(ClassElement classElement,
232 ClassBuilder builder) { 228 ClassBuilder builder,
229 {bool onlyForRti: false}) {
230 if (onlyForRti) return;
231
233 visitFields(classElement, false, 232 visitFields(classElement, false,
234 (VariableElement member, 233 (VariableElement member,
235 String name, 234 String name,
236 String accessorName, 235 String accessorName,
237 bool needsGetter, 236 bool needsGetter,
238 bool needsSetter, 237 bool needsSetter,
239 bool needsCheckedSetter) { 238 bool needsCheckedSetter) {
240 compiler.withCurrentElement(member, () { 239 compiler.withCurrentElement(member, () {
241 if (needsCheckedSetter) { 240 if (needsCheckedSetter) {
242 assert(!needsSetter); 241 assert(!needsSetter);
243 generateCheckedSetter(member, name, accessorName, builder); 242 generateCheckedSetter(member, name, accessorName, builder);
244 } 243 }
245 if (needsGetter) { 244 if (needsGetter) {
246 generateGetter(member, name, accessorName, builder); 245 generateGetter(member, name, accessorName, builder);
247 } 246 }
248 if (needsSetter) { 247 if (needsSetter) {
249 generateSetter(member, name, accessorName, builder); 248 generateSetter(member, name, accessorName, builder);
250 } 249 }
251 }); 250 });
252 }); 251 });
253 } 252 }
254 253
255 /** 254 /**
256 * Documentation wanted -- johnniwinther 255 * Documentation wanted -- johnniwinther
257 * 256 *
258 * Invariant: [classElement] must be a declaration element. 257 * Invariant: [classElement] must be a declaration element.
259 */ 258 */
260 void emitInstanceMembers(ClassElement classElement, 259 void emitInstanceMembers(ClassElement classElement,
261 ClassBuilder builder) { 260 ClassBuilder builder,
261 {bool onlyForRti: false}) {
262 assert(invariant(classElement, classElement.isDeclaration)); 262 assert(invariant(classElement, classElement.isDeclaration));
263 263
264 if (classElement.isMixinApplication) return;
kasperl 2013/10/16 08:23:51 Combine the two checks?
Johnni Winther 2013/10/16 08:30:10 Done.
265 if (onlyForRti) return;
266
264 void visitMember(ClassElement enclosing, Element member) { 267 void visitMember(ClassElement enclosing, Element member) {
265 assert(invariant(classElement, member.isDeclaration)); 268 assert(invariant(classElement, member.isDeclaration));
266 if (member.isInstanceMember()) { 269 if (member.isInstanceMember()) {
267 task.containerBuilder.addMember(member, builder); 270 task.containerBuilder.addMember(member, builder);
268 } 271 }
269 } 272 }
270 273
271 classElement.implementation.forEachMember( 274 classElement.implementation.forEachMember(
272 visitMember, 275 visitMember,
273 includeBackendMembers: true); 276 includeBackendMembers: true);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 ? new Selector.getter(member.name, member.getLibrary()) 594 ? new Selector.getter(member.name, member.getLibrary())
592 : new Selector.setter(member.name, member.getLibrary()); 595 : new Selector.setter(member.name, member.getLibrary());
593 String reflectionName = task.getReflectionName(selector, name); 596 String reflectionName = task.getReflectionName(selector, name);
594 if (reflectionName != null) { 597 if (reflectionName != null) {
595 var reflectable = 598 var reflectable =
596 js(backend.isAccessibleByReflection(member) ? '1' : '0'); 599 js(backend.isAccessibleByReflection(member) ? '1' : '0');
597 builder.addProperty('+$reflectionName', reflectable); 600 builder.addProperty('+$reflectionName', reflectable);
598 } 601 }
599 } 602 }
600 } 603 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698