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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/metadata_emitter.dart

Issue 869513003: dart2js: Move metadata from old_emitter to shared directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return addGlobalMetadata('"$name"'); 96 return addGlobalMetadata('"$name"');
97 } 97 }
98 98
99 int addGlobalMetadata(String string) { 99 int addGlobalMetadata(String string) {
100 return globalMetadataMap.putIfAbsent(string, () { 100 return globalMetadataMap.putIfAbsent(string, () {
101 globalMetadata.add(string); 101 globalMetadata.add(string);
102 return globalMetadata.length - 1; 102 return globalMetadata.length - 1;
103 }); 103 });
104 } 104 }
105 105
106 void emitMetadata(CodeOutput output) {
floitsch 2015/01/29 14:36:30 Moved to the oldEmitter.
107 String metadataAccess = emitter.generateEmbeddedGlobalAccessString(
108 embeddedNames.METADATA);
109 output.add('$metadataAccess$_=$_[');
110 for (String metadata in globalMetadata) {
111 if (metadata is String) {
112 if (metadata != 'null') {
113 output.add(metadata);
114 }
115 } else {
116 throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}';
117 }
118 output.add(',$n');
119 }
120 output.add('];$n');
121 }
122
123 List<int> computeMetadata(FunctionElement element) { 106 List<int> computeMetadata(FunctionElement element) {
124 return compiler.withCurrentElement(element, () { 107 return compiler.withCurrentElement(element, () {
125 if (!mustEmitMetadataFor(element)) return const <int>[]; 108 if (!mustEmitMetadataFor(element)) return const <int>[];
126 List<int> metadata = <int>[]; 109 List<int> metadata = <int>[];
127 Link link = element.metadata; 110 Link link = element.metadata;
128 // TODO(ahe): Why is metadata sometimes null? 111 // TODO(ahe): Why is metadata sometimes null?
129 if (link != null) { 112 if (link != null) {
130 for (; !link.isEmpty; link = link.tail) { 113 for (; !link.isEmpty; link = link.tail) {
131 metadata.add(reifyMetadata(link.head)); 114 metadata.add(reifyMetadata(link.head));
132 } 115 }
133 } 116 }
134 return metadata; 117 return metadata;
135 }); 118 });
136 } 119 }
137 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698