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

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

Issue 16101007: Implement LibraryMirror.metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix issues found during testing. 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 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 ..addAll(buildDefineClassAndFinishClassFunctionsIfNecessary()) 2933 ..addAll(buildDefineClassAndFinishClassFunctionsIfNecessary())
2934 ..addAll(buildLazyInitializerFunctionIfNecessary()) 2934 ..addAll(buildLazyInitializerFunctionIfNecessary())
2935 ..addAll(buildFinishIsolateConstructor()) 2935 ..addAll(buildFinishIsolateConstructor())
2936 ); 2936 );
2937 jsAst.FunctionDeclaration decl = new jsAst.FunctionDeclaration( 2937 jsAst.FunctionDeclaration decl = new jsAst.FunctionDeclaration(
2938 new jsAst.VariableDeclaration('init'), fun); 2938 new jsAst.VariableDeclaration('init'), fun);
2939 buffer.write(jsAst.prettyPrint(decl, compiler).getText()); 2939 buffer.write(jsAst.prettyPrint(decl, compiler).getText());
2940 if (compiler.enableMinification) buffer.write('\n'); 2940 if (compiler.enableMinification) buffer.write('\n');
2941 } 2941 }
2942 2942
2943 /// The metadata function returns the metadata associated with
2944 /// [element] in generated code. The metadata needs to be wrapped
2945 /// in a function as it refers to constants that may not have been
2946 /// constructed yet. For example, a class is allowed to be
2947 /// annotated with itself. The metadata function is used by
2948 /// mirrors_patch to implement DeclarationMirror.metadata.
2949 jsAst.Expression buildMetadataFunction(Element element) {
2950 if (compiler.mirrorSystemClass == null) return new jsAst.LiteralString('');
kasperl 2013/05/30 13:16:39 Add comment.
ahe 2013/05/30 13:28:45 Done.
2951 var metadata = [];
2952 for (Link link = element.metadata;
2953 // TODO(ahe): Why is metadata sometimes null?
kasperl 2013/05/30 13:16:39 Maybe move this check out of the loop so it sticks
ahe 2013/05/30 13:28:45 Done.
2954 link != null && !link.isEmpty;
2955 link = link.tail) {
2956 metadata.add(constantReference(link.head.value));
2957 }
2958 return js.fun([], [js.return_(new jsAst.ArrayInitializer.from(metadata))]);
2959 }
2960
2943 String assembleProgram() { 2961 String assembleProgram() {
2944 measure(() { 2962 measure(() {
2945 // Compute the required type checks to know which classes need a 2963 // Compute the required type checks to know which classes need a
2946 // 'is$' method. 2964 // 'is$' method.
2947 computeRequiredTypeChecks(); 2965 computeRequiredTypeChecks();
2948 2966
2949 computeNeededClasses(); 2967 computeNeededClasses();
2950 2968
2951 mainBuffer.add(GENERATED_BY); 2969 mainBuffer.add(GENERATED_BY);
2952 addComment(HOOKS_API_USAGE, mainBuffer); 2970 addComment(HOOKS_API_USAGE, mainBuffer);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 // TODO(ahe): It is a hack to use compiler.sourceMapUri 3056 // TODO(ahe): It is a hack to use compiler.sourceMapUri
3039 // here. It should be relative to the main JavaScript 3057 // here. It should be relative to the main JavaScript
3040 // output file. 3058 // output file.
3041 uri = relativize( 3059 uri = relativize(
3042 compiler.sourceMapUri, library.canonicalUri, false); 3060 compiler.sourceMapUri, library.canonicalUri, false);
3043 } 3061 }
3044 if (buffer != null) { 3062 if (buffer != null) {
3045 mainBuffer 3063 mainBuffer
3046 ..write('["${library.getLibraryOrScriptName()}",$_') 3064 ..write('["${library.getLibraryOrScriptName()}",$_')
3047 ..write('"${uri}",$_') 3065 ..write('"${uri}",$_')
3066 ..write(
3067 jsAst.prettyPrint(buildMetadataFunction(library), compiler))
3068 ..write(',$_')
3048 ..write('{$n') 3069 ..write('{$n')
3049 ..addBuffer(buffer) 3070 ..addBuffer(buffer)
3050 ..write('}],$n'); 3071 ..write('}],$n');
3051 } 3072 }
3052 buffer = buffers[1]; 3073 buffer = buffers[1];
3053 if (buffer != null) { 3074 if (buffer != null) {
3054 deferredBuffer 3075 deferredBuffer
3055 ..write('["${library.getLibraryOrScriptName()}",$_') 3076 ..write('["${library.getLibraryOrScriptName()}",$_')
3056 ..write('"${uri}",$_') 3077 ..write('"${uri}",$_')
3078 ..write('[],$_')
3057 ..write('{$n') 3079 ..write('{$n')
3058 ..addBuffer(buffer) 3080 ..addBuffer(buffer)
3059 ..write('}],$n'); 3081 ..write('}],$n');
3060 } 3082 }
3061 libraryBuffers[library] = const []; 3083 libraryBuffers[library] = const [];
3062 } 3084 }
3063 mainBuffer.write('])$N'); 3085 mainBuffer.write('])$N');
3064 3086
3065 deferredBuffer.write('])$N'); 3087 deferredBuffer.write('])$N');
3066 if (!deferredClasses.isEmpty) { 3088 if (!deferredClasses.isEmpty) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3233 const String REFLECTION_DATA_PARSER = r''' 3255 const String REFLECTION_DATA_PARSER = r'''
3234 (function (reflectionData) { 3256 (function (reflectionData) {
3235 if (!init.libraries) init.libraries = []; 3257 if (!init.libraries) init.libraries = [];
3236 var libraries = init.libraries; 3258 var libraries = init.libraries;
3237 var hasOwnProperty = Object.prototype.hasOwnProperty; 3259 var hasOwnProperty = Object.prototype.hasOwnProperty;
3238 var length = reflectionData.length; 3260 var length = reflectionData.length;
3239 for (var i = 0; i < length; i++) { 3261 for (var i = 0; i < length; i++) {
3240 var data = reflectionData[i]; 3262 var data = reflectionData[i];
3241 var name = data[0]; 3263 var name = data[0];
3242 var uri = data[1]; 3264 var uri = data[1];
3243 var descriptor = data[2]; 3265 var metadata = data[2];
3266 var descriptor = data[3];
3244 var classes = []; 3267 var classes = [];
3245 var functions = []; 3268 var functions = [];
3246 for (var property in descriptor) { 3269 for (var property in descriptor) {
3247 if (!hasOwnProperty.call(descriptor, property)) continue; 3270 if (!hasOwnProperty.call(descriptor, property)) continue;
3248 var element = descriptor[property]; 3271 var element = descriptor[property];
3249 if (typeof element === "function") { 3272 if (typeof element === "function") {
3250 $[property] = element; 3273 $[property] = element;
3251 functions.push(property); 3274 functions.push(property);
3252 } else { 3275 } else {
3253 $$[property] = element; 3276 $$[property] = element;
3254 classes.push(property); 3277 classes.push(property);
3255 classes.push(element[""]); 3278 classes.push(element[""]);
3256 } 3279 }
3257 } 3280 }
3258 libraries.push([name, uri, classes, functions]); 3281 libraries.push([name, uri, classes, functions, metadata]);
3259 } 3282 }
3260 })'''; 3283 })''';
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698