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

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

Issue 226953003: Revert "Compute frontend/backend specific constants." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 = [];
11 11
12 /// A map used to canonicalize the entries of globalMetadata. 12 /// A map used to canonicalize the entries of globalMetadata.
13 final Map<String, int> globalMetadataMap = <String, int>{}; 13 final Map<String, int> globalMetadataMap = <String, int>{};
14 14
15 /// The metadata function returns the metadata associated with 15 /// The metadata function returns the metadata associated with
16 /// [element] in generated code. The metadata needs to be wrapped 16 /// [element] in generated code. The metadata needs to be wrapped
17 /// in a function as it refers to constants that may not have been 17 /// in a function as it refers to constants that may not have been
18 /// constructed yet. For example, a class is allowed to be 18 /// constructed yet. For example, a class is allowed to be
19 /// annotated with itself. The metadata function is used by 19 /// annotated with itself. The metadata function is used by
20 /// mirrors_patch to implement DeclarationMirror.metadata. 20 /// mirrors_patch to implement DeclarationMirror.metadata.
21 jsAst.Fun buildMetadataFunction(Element element) { 21 jsAst.Fun buildMetadataFunction(Element element) {
22 if (!backend.retainMetadataOf(element)) return null; 22 if (!backend.retainMetadataOf(element)) return null;
23 return compiler.withCurrentElement(element, () { 23 return compiler.withCurrentElement(element, () {
24 var metadata = []; 24 var metadata = [];
25 Link link = element.metadata; 25 Link link = element.metadata;
26 // TODO(ahe): Why is metadata sometimes null? 26 // TODO(ahe): Why is metadata sometimes null?
27 if (link != null) { 27 if (link != null) {
28 for (; !link.isEmpty; link = link.tail) { 28 for (; !link.isEmpty; link = link.tail) {
29 MetadataAnnotation annotation = link.head; 29 MetadataAnnotation annotation = link.head;
30 Constant value = 30 Constant value = annotation.value;
31 backend.constants.getConstantForMetadata(annotation);
32 if (value == null) { 31 if (value == null) {
33 compiler.internalError(annotation, 'Annotation value is null.'); 32 compiler.internalError(annotation, 'Annotation value is null.');
34 } else { 33 } else {
35 metadata.add(task.constantReference(value)); 34 metadata.add(task.constantReference(value));
36 } 35 }
37 } 36 }
38 } 37 }
39 if (metadata.isEmpty) return null; 38 if (metadata.isEmpty) return null;
40 return js.fun( 39 return js.fun(
41 [], [js.return_(new jsAst.ArrayInitializer.from(metadata))]); 40 [], [js.return_(new jsAst.ArrayInitializer.from(metadata))]);
42 }); 41 });
43 } 42 }
44 43
45 List<int> reifyDefaultArguments(FunctionElement function) { 44 List<int> reifyDefaultArguments(FunctionElement function) {
46 FunctionSignature signature = function.functionSignature; 45 FunctionSignature signature = function.functionSignature;
47 if (signature.optionalParameterCount == 0) return const []; 46 if (signature.optionalParameterCount == 0) return const [];
48 List<int> defaultValues = <int>[]; 47 List<int> defaultValues = <int>[];
49 for (Element element in signature.optionalParameters) { 48 for (Element element in signature.optionalParameters) {
50 Constant value = backend.constants.getConstantForVariable(element); 49 Constant value =
50 compiler.constantHandler.initialVariableValues[element];
51 String stringRepresentation = (value == null) 51 String stringRepresentation = (value == null)
52 ? "null" 52 ? "null"
53 : jsAst.prettyPrint(task.constantReference(value), compiler) 53 : jsAst.prettyPrint(task.constantReference(value), compiler)
54 .getText(); 54 .getText();
55 defaultValues.add(addGlobalMetadata(stringRepresentation)); 55 defaultValues.add(addGlobalMetadata(stringRepresentation));
56 } 56 }
57 return defaultValues; 57 return defaultValues;
58 } 58 }
59 59
60 int reifyMetadata(MetadataAnnotation annotation) { 60 int reifyMetadata(MetadataAnnotation annotation) {
61 Constant value = backend.constants.getConstantForMetadata(annotation); 61 Constant value = annotation.value;
62 if (value == null) { 62 if (value == null) {
63 compiler.internalError(annotation, 'Annotation value is null.'); 63 compiler.internalError(annotation, 'Annotation value is null.');
64 return -1; 64 return -1;
65 } 65 }
66 return addGlobalMetadata( 66 return addGlobalMetadata(
67 jsAst.prettyPrint(task.constantReference(value), compiler).getText()); 67 jsAst.prettyPrint(task.constantReference(value), compiler).getText());
68 } 68 }
69 69
70 int reifyType(DartType type) { 70 int reifyType(DartType type) {
71 jsAst.Expression representation = 71 jsAst.Expression representation =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // TODO(ahe): Why is metadata sometimes null? 124 // TODO(ahe): Why is metadata sometimes null?
125 if (link != null) { 125 if (link != null) {
126 for (; !link.isEmpty; link = link.tail) { 126 for (; !link.isEmpty; link = link.tail) {
127 metadata.add(reifyMetadata(link.head)); 127 metadata.add(reifyMetadata(link.head));
128 } 128 }
129 } 129 }
130 return metadata; 130 return metadata;
131 }); 131 });
132 } 132 }
133 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698