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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 15979020: Implement InstanceMirror.invoke (minified). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
OLDNEW
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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 // uninstantiated classes, that have been overwritten by subclasses. 1165 // uninstantiated classes, that have been overwritten by subclasses.
1166 1166
1167 if (member.isFunction() 1167 if (member.isFunction()
1168 || member.isGenerativeConstructorBody() 1168 || member.isGenerativeConstructorBody()
1169 || member.isAccessor()) { 1169 || member.isAccessor()) {
1170 if (member.isAbstract(compiler)) return; 1170 if (member.isAbstract(compiler)) return;
1171 jsAst.Expression code = backend.generatedCode[member]; 1171 jsAst.Expression code = backend.generatedCode[member];
1172 if (code == null) return; 1172 if (code == null) return;
1173 String name = namer.getName(member); 1173 String name = namer.getName(member);
1174 builder.addProperty(name, code); 1174 builder.addProperty(name, code);
1175 var metadata = buildMetadataFunction(member);
1176 if (metadata != null) {
1177 builder.addProperty('@$name', metadata);
1178 }
1179 String reflectionName = reflectionName(member);
1180 if (reflectionName != null) {
1181 builder.addProperty('+$reflectionName', js('0'));
1182 }
1175 code = backend.generatedBailoutCode[member]; 1183 code = backend.generatedBailoutCode[member];
1176 if (code != null) { 1184 if (code != null) {
1177 builder.addProperty(namer.getBailoutName(member), code); 1185 builder.addProperty(namer.getBailoutName(member), code);
1178 } 1186 }
1179 FunctionElement function = member; 1187 FunctionElement function = member;
1180 FunctionSignature parameters = function.computeSignature(compiler); 1188 FunctionSignature parameters = function.computeSignature(compiler);
1181 if (!parameters.optionalParameters.isEmpty) { 1189 if (!parameters.optionalParameters.isEmpty) {
1182 addParameterStubs(member, builder.addProperty); 1190 addParameterStubs(member, builder.addProperty);
1183 } 1191 }
1184 var metadata = buildMetadataFunction(member);
1185 if (metadata != null) {
1186 builder.addProperty('@$name', metadata);
1187 }
1188 } else if (!member.isField()) { 1192 } else if (!member.isField()) {
1189 compiler.internalError('unexpected kind: "${member.kind}"', 1193 compiler.internalError('unexpected kind: "${member.kind}"',
1190 element: member); 1194 element: member);
1191 } 1195 }
1192 emitExtraAccessors(member, builder); 1196 emitExtraAccessors(member, builder);
1193 } 1197 }
1194 1198
1199 String reflectionName(Element element) {
1200 if (!compiler.mirrorsEnabled) return null;
1201 String name = element.name.slowToString();
1202 if (element.isGetter()) return name;
1203 if (element.isSetter()) return '$name=';
1204 if (element.isFunction()) {
1205 FunctionElement function = element;
1206 int requiredParameterCount = function.requiredParameterCount(compiler);
1207 int optionalParameterCount = function.optionalParameterCount(compiler);
1208 if (function.isConstructor()) {
1209 return 'new $name:$requiredParameterCount:$optionalParameterCount';
kasperl 2013/06/04 14:05:55 Maybe share the suffix (compute it and stuff it in
ahe 2013/06/04 14:21:01 Done.
1210 } else {
1211 return '$name:$requiredParameterCount:$optionalParameterCount';
1212 }
1213 }
1214 if (element.isGenerativeConstructorBody()) {
1215 return null;
1216 }
1217 throw compiler.internalErrorOnElement(
1218 element, 'Do not know how to reflect on this');
1219 }
1220
1195 /** 1221 /**
1196 * Documentation wanted -- johnniwinther 1222 * Documentation wanted -- johnniwinther
1197 * 1223 *
1198 * Invariant: [classElement] must be a declaration element. 1224 * Invariant: [classElement] must be a declaration element.
1199 */ 1225 */
1200 void emitInstanceMembers(ClassElement classElement, 1226 void emitInstanceMembers(ClassElement classElement,
1201 ClassBuilder builder) { 1227 ClassBuilder builder) {
1202 assert(invariant(classElement, classElement.isDeclaration)); 1228 assert(invariant(classElement, classElement.isDeclaration));
1203 1229
1204 void visitMember(ClassElement enclosing, Element member) { 1230 void visitMember(ClassElement enclosing, Element member) {
(...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after
3266 compiler.reportMessage(compiler.spanFromSpannable(element), 3292 compiler.reportMessage(compiler.spanFromSpannable(element),
3267 MessageKind.GENERIC.error({'text': message}), 3293 MessageKind.GENERIC.error({'text': message}),
3268 api.Diagnostic.WARNING); 3294 api.Diagnostic.WARNING);
3269 } 3295 }
3270 3296
3271 // TODO(ahe): This code should be integrated in finishClasses. 3297 // TODO(ahe): This code should be integrated in finishClasses.
3272 String getReflectionDataParser() { 3298 String getReflectionDataParser() {
3273 return ''' 3299 return '''
3274 (function (reflectionData) { 3300 (function (reflectionData) {
3275 if (!init.libraries) init.libraries = []; 3301 if (!init.libraries) init.libraries = [];
3302 if (!init.mangledNames) init.mangledNames = {};
3276 var libraries = init.libraries; 3303 var libraries = init.libraries;
3304 var mangledNames = init.mangledNames;
3277 var hasOwnProperty = Object.prototype.hasOwnProperty; 3305 var hasOwnProperty = Object.prototype.hasOwnProperty;
3278 var length = reflectionData.length; 3306 var length = reflectionData.length;
3279 for (var i = 0; i < length; i++) { 3307 for (var i = 0; i < length; i++) {
3280 var data = reflectionData[i]; 3308 var data = reflectionData[i];
3281 var name = data[0]; 3309 var name = data[0];
3282 var uri = data[1]; 3310 var uri = data[1];
3283 var metadata = data[2]; 3311 var metadata = data[2];
3284 var descriptor = data[3]; 3312 var descriptor = data[3];
3285 var classes = []; 3313 var classes = [];
3286 var functions = []; 3314 var functions = [];
3287 for (var property in descriptor) { 3315 for (var property in descriptor) {
3288 if (!hasOwnProperty.call(descriptor, property)) continue; 3316 if (!hasOwnProperty.call(descriptor, property)) continue;
3289 var element = descriptor[property]; 3317 var element = descriptor[property];
3290 if (property.substring(0, 1) == "@") { 3318 if (property.substring(0, 1) == "@") {
3291 property = property.substring(1); 3319 property = property.substring(1);
3292 ${namer.CURRENT_ISOLATE}[property]["${namer.metadataField}"] = element; 3320 ${namer.CURRENT_ISOLATE}[property]["${namer.metadataField}"] = element;
3293 } else if (typeof element === "function") { 3321 } else if (typeof element === "function") {
3294 ${namer.CURRENT_ISOLATE}[property] = element; 3322 ${namer.CURRENT_ISOLATE}[property] = element;
3295 functions.push(property); 3323 functions.push(property);
3296 } else { 3324 } else {
3297 var newDesc = {} 3325 var newDesc = {};
3326 var previousProp;
3298 for (var prop in element) { 3327 for (var prop in element) {
3299 if (!hasOwnProperty.call(element, prop)) continue; 3328 if (!hasOwnProperty.call(element, prop)) continue;
3300 if (prop.substring(0, 1) == "@" && prop != "@") { 3329 var firstChar = prop.substring(0, 1);
3330 if (firstChar == "+") {
3331 mangledNames[previousProp] = prop.substring(1);
3332 } else if (firstChar == "@" && prop != "@") {
3301 newDesc[prop.substring(1)]["${namer.metadataField}"] =''' 3333 newDesc[prop.substring(1)]["${namer.metadataField}"] ='''
3302 '''element[prop]; 3334 '''element[prop];
3303 } else { 3335 } else {
3304 newDesc[prop] = element[prop]; 3336 newDesc[previousProp = prop] = element[prop];
3305 } 3337 }
3306 } 3338 }
3307 $classesCollector[property] = newDesc; 3339 $classesCollector[property] = newDesc;
3308 classes.push(property); 3340 classes.push(property);
3309 } 3341 }
3310 } 3342 }
3311 libraries.push([name, uri, classes, functions, metadata]); 3343 libraries.push([name, uri, classes, functions, metadata]);
3312 } 3344 }
3313 })'''; 3345 })''';
3314 } 3346 }
3315 } 3347 }
3316 3348
3317 const String GENERATED_BY = """ 3349 const String GENERATED_BY = """
3318 // Generated by dart2js, the Dart to JavaScript compiler. 3350 // Generated by dart2js, the Dart to JavaScript compiler.
3319 """; 3351 """;
3320 3352
3321 const String HOOKS_API_USAGE = """ 3353 const String HOOKS_API_USAGE = """
3322 // The code supports the following hooks: 3354 // The code supports the following hooks:
3323 // dartPrint(message) - if this function is defined it is called 3355 // dartPrint(message) - if this function is defined it is called
3324 // instead of the Dart [print] method. 3356 // instead of the Dart [print] method.
3325 // dartMainRunner(main) - if this function is defined, the Dart [main] 3357 // dartMainRunner(main) - if this function is defined, the Dart [main]
3326 // method will not be invoked directly. 3358 // method will not be invoked directly.
3327 // Instead, a closure that will invoke [main] is 3359 // Instead, a closure that will invoke [main] is
3328 // passed to [dartMainRunner]. 3360 // passed to [dartMainRunner].
3329 """; 3361 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698