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

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

Issue 363223003: Revert "Emit declarations for typedefs that are needed by reflection." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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) 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 MetadataEmitter extends CodeEmitterHelper { 7 class MetadataEmitter extends CodeEmitterHelper {
8 /// A list of JS expressions that represent metadata, parameter names and 8 /// A list of JS expressions that represent metadata, parameter names and
9 /// type, and return types. 9 /// type, and return types.
10 final List<String> globalMetadata = []; 10 final List<String> globalMetadata = [];
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 int addGlobalMetadata(String string) { 85 int addGlobalMetadata(String string) {
86 return globalMetadataMap.putIfAbsent(string, () { 86 return globalMetadataMap.putIfAbsent(string, () {
87 globalMetadata.add(string); 87 globalMetadata.add(string);
88 return globalMetadata.length - 1; 88 return globalMetadata.length - 1;
89 }); 89 });
90 } 90 }
91 91
92 void emitMetadata(CodeBuffer buffer) { 92 void emitMetadata(CodeBuffer buffer) {
93 buffer.write('init.metadata$_=$_['); 93 var literals = backend.typedefTypeLiterals.toList();
94 for (String metadata in globalMetadata) { 94 Elements.sortedByPosition(literals);
95 var properties = [];
96 for (TypedefElement literal in literals) {
97 var key = namer.getNameX(literal);
98 var value = js.number(reifyType(literal.rawType));
99 properties.add(new jsAst.Property(js.string(key), value));
100 }
101 var map = new jsAst.ObjectInitializer(properties);
102 buffer.write(
103 jsAst.prettyPrint(
104 js.statement('init.functionAliases = #', map), compiler));
105 buffer.write('${N}init.metadata$_=$_[');
106 for (var metadata in globalMetadata) {
95 if (metadata is String) { 107 if (metadata is String) {
96 if (metadata != 'null') { 108 if (metadata != 'null') {
97 buffer.write(metadata); 109 buffer.write(metadata);
98 } 110 }
99 } else { 111 } else {
100 throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}'; 112 throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}';
101 } 113 }
102 buffer.write(',$n'); 114 buffer.write(',$n');
103 } 115 }
104 buffer.write('];$n'); 116 buffer.write('];$n');
105 } 117 }
106 118
107 List<int> computeMetadata(FunctionElement element) { 119 List<int> computeMetadata(FunctionElement element) {
108 return compiler.withCurrentElement(element, () { 120 return compiler.withCurrentElement(element, () {
109 if (!backend.retainMetadataOf(element)) return const <int>[]; 121 if (!backend.retainMetadataOf(element)) return const <int>[];
110 List<int> metadata = <int>[]; 122 List<int> metadata = <int>[];
111 Link link = element.metadata; 123 Link link = element.metadata;
112 // TODO(ahe): Why is metadata sometimes null? 124 // TODO(ahe): Why is metadata sometimes null?
113 if (link != null) { 125 if (link != null) {
114 for (; !link.isEmpty; link = link.tail) { 126 for (; !link.isEmpty; link = link.tail) {
115 metadata.add(reifyMetadata(link.head)); 127 metadata.add(reifyMetadata(link.head));
116 } 128 }
117 } 129 }
118 return metadata; 130 return metadata;
119 }); 131 });
120 } 132 }
121 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698