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

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

Issue 1148343004: Remove ConstantExpression.value (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update comments. Created 5 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
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 MetadataCollector { 7 class MetadataCollector {
8 final Compiler _compiler; 8 final Compiler _compiler;
9 final Emitter _emitter; 9 final Emitter _emitter;
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 /// mirrors_patch to implement DeclarationMirror.metadata. 42 /// mirrors_patch to implement DeclarationMirror.metadata.
43 jsAst.Fun buildMetadataFunction(Element element) { 43 jsAst.Fun buildMetadataFunction(Element element) {
44 if (!_mustEmitMetadataFor(element)) return null; 44 if (!_mustEmitMetadataFor(element)) return null;
45 return _compiler.withCurrentElement(element, () { 45 return _compiler.withCurrentElement(element, () {
46 List<jsAst.Expression> metadata = <jsAst.Expression>[]; 46 List<jsAst.Expression> metadata = <jsAst.Expression>[];
47 Link link = element.metadata; 47 Link link = element.metadata;
48 // TODO(ahe): Why is metadata sometimes null? 48 // TODO(ahe): Why is metadata sometimes null?
49 if (link != null) { 49 if (link != null) {
50 for (; !link.isEmpty; link = link.tail) { 50 for (; !link.isEmpty; link = link.tail) {
51 MetadataAnnotation annotation = link.head; 51 MetadataAnnotation annotation = link.head;
52 ConstantExpression constant = 52 ConstantValue constant =
53 _backend.constants.getConstantForMetadata(annotation); 53 _backend.constants.getConstantValueForMetadata(annotation);
54 if (constant == null) { 54 if (constant == null) {
55 _compiler.internalError(annotation, 'Annotation value is null.'); 55 _compiler.internalError(annotation, 'Annotation value is null.');
56 } else { 56 } else {
57 metadata.add(_emitter.constantReference(constant.value)); 57 metadata.add(_emitter.constantReference(constant));
58 } 58 }
59 } 59 }
60 } 60 }
61 if (metadata.isEmpty) return null; 61 if (metadata.isEmpty) return null;
62 return js('function() { return # }', 62 return js('function() { return # }',
63 new jsAst.ArrayInitializer(metadata)); 63 new jsAst.ArrayInitializer(metadata));
64 }); 64 });
65 } 65 }
66 66
67 List<int> reifyDefaultArguments(FunctionElement function) { 67 List<int> reifyDefaultArguments(FunctionElement function) {
68 FunctionSignature signature = function.functionSignature; 68 FunctionSignature signature = function.functionSignature;
69 if (signature.optionalParameterCount == 0) return const []; 69 if (signature.optionalParameterCount == 0) return const [];
70 List<int> defaultValues = <int>[]; 70 List<int> defaultValues = <int>[];
71 for (ParameterElement element in signature.optionalParameters) { 71 for (ParameterElement element in signature.optionalParameters) {
72 ConstantExpression constant = 72 ConstantValue constant =
73 _backend.constants.getConstantForVariable(element); 73 _backend.constants.getConstantValueForVariable(element);
74 jsAst.Expression expression = (constant == null) 74 jsAst.Expression expression = (constant == null)
75 ? null 75 ? null
76 : _emitter.constantReference(constant.value); 76 : _emitter.constantReference(constant);
77 defaultValues.add(addGlobalMetadata(expression)); 77 defaultValues.add(addGlobalMetadata(expression));
78 } 78 }
79 return defaultValues; 79 return defaultValues;
80 } 80 }
81 81
82 int reifyMetadata(MetadataAnnotation annotation) { 82 int reifyMetadata(MetadataAnnotation annotation) {
83 ConstantExpression constant = 83 ConstantValue constant =
84 _backend.constants.getConstantForMetadata(annotation); 84 _backend.constants.getConstantValueForMetadata(annotation);
85 if (constant == null) { 85 if (constant == null) {
86 _compiler.internalError(annotation, 'Annotation value is null.'); 86 _compiler.internalError(annotation, 'Annotation value is null.');
87 return -1; 87 return -1;
88 } 88 }
89 return addGlobalMetadata(_emitter.constantReference(constant.value)); 89 return addGlobalMetadata(_emitter.constantReference(constant));
90 } 90 }
91 91
92 int reifyType(DartType type, {bool ignoreTypeVariables: false}) { 92 int reifyType(DartType type, {bool ignoreTypeVariables: false}) {
93 return reifyTypeForOutputUnit(type, 93 return reifyTypeForOutputUnit(type,
94 _compiler.deferredLoadTask.mainOutputUnit, 94 _compiler.deferredLoadTask.mainOutputUnit,
95 ignoreTypeVariables: ignoreTypeVariables); 95 ignoreTypeVariables: ignoreTypeVariables);
96 } 96 }
97 97
98 int reifyTypeForOutputUnit(DartType type, OutputUnit outputUnit, 98 int reifyTypeForOutputUnit(DartType type, OutputUnit outputUnit,
99 {bool ignoreTypeVariables: false}) { 99 {bool ignoreTypeVariables: false}) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // TODO(ahe): Why is metadata sometimes null? 157 // TODO(ahe): Why is metadata sometimes null?
158 if (link != null) { 158 if (link != null) {
159 for (; !link.isEmpty; link = link.tail) { 159 for (; !link.isEmpty; link = link.tail) {
160 metadata.add(reifyMetadata(link.head)); 160 metadata.add(reifyMetadata(link.head));
161 } 161 }
162 } 162 }
163 return metadata; 163 return metadata;
164 }); 164 });
165 } 165 }
166 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698