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

Side by Side Diff: pkg/compiler/lib/src/constants/expressions.dart

Issue 1192103002: Support serialization of the compiler backbone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library dart2js.constants.expressions; 5 library dart2js.constants.expressions;
6 6
7 import '../constants/constant_system.dart'; 7 import '../constants/constant_system.dart';
8 import '../core_types.dart'; 8 import '../core_types.dart';
9 import '../dart2jslib.dart' show assertDebugMode, Compiler; 9 import '../dart2jslib.dart' show assertDebugMode, Compiler;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 /// Computes the type of the instance created in a const constructor 101 /// Computes the type of the instance created in a const constructor
102 /// invocation with type [newType]. 102 /// invocation with type [newType].
103 InterfaceType computeInstanceType(InterfaceType newType); 103 InterfaceType computeInstanceType(InterfaceType newType);
104 104
105 /// Computes the constant expressions of the fields of the created instance 105 /// Computes the constant expressions of the fields of the created instance
106 /// in a const constructor invocation with [arguments]. 106 /// in a const constructor invocation with [arguments].
107 Map<FieldElement, ConstantExpression> computeInstanceFields( 107 Map<FieldElement, ConstantExpression> computeInstanceFields(
108 List<ConstantExpression> arguments, 108 List<ConstantExpression> arguments,
109 CallStructure callStructure); 109 CallStructure callStructure);
110
111 accept(ConstantConstructorVisitor visitor, arg);
112 }
113
114 abstract class ConstantConstructorVisitor<R, A> {
115 const ConstantConstructorVisitor();
116
117 R visit(ConstantConstructor constantConstructor, A context) {
118 return constantConstructor.accept(this, context);
119 }
120
121 R visitGenerative(GenerativeConstantConstructor constructor, A arg);
122 R visitRedirectingGenerative(
123 RedirectingGenerativeConstantConstructor constructor, A arg);
124 R visitRedirectingFactory(
125 RedirectingFactoryConstantConstructor constructor, A arg);
110 } 126 }
111 127
112 /// A generative constant constructor. 128 /// A generative constant constructor.
113 class GenerativeConstantConstructor implements ConstantConstructor{ 129 class GenerativeConstantConstructor implements ConstantConstructor{
114 final InterfaceType type; 130 final InterfaceType type;
115 final Map<dynamic/*int|String*/, ConstantExpression> defaultValues; 131 final Map<dynamic/*int|String*/, ConstantExpression> defaultValues;
116 final Map<FieldElement, ConstantExpression> fieldMap; 132 final Map<FieldElement, ConstantExpression> fieldMap;
117 final ConstructedConstantExpression superConstructorInvocation; 133 final ConstructedConstantExpression superConstructorInvocation;
118 134
119 GenerativeConstantConstructor( 135 GenerativeConstantConstructor(
(...skipping 14 matching lines...) Expand all
134 NormalizedArguments args = new NormalizedArguments( 150 NormalizedArguments args = new NormalizedArguments(
135 defaultValues, callStructure, arguments); 151 defaultValues, callStructure, arguments);
136 Map<FieldElement, ConstantExpression> appliedFieldMap = 152 Map<FieldElement, ConstantExpression> appliedFieldMap =
137 applyFields(args, superConstructorInvocation); 153 applyFields(args, superConstructorInvocation);
138 fieldMap.forEach((FieldElement field, ConstantExpression constant) { 154 fieldMap.forEach((FieldElement field, ConstantExpression constant) {
139 appliedFieldMap[field] = constant.apply(args); 155 appliedFieldMap[field] = constant.apply(args);
140 }); 156 });
141 return appliedFieldMap; 157 return appliedFieldMap;
142 } 158 }
143 159
160 accept(ConstantConstructorVisitor visitor, arg) {
161 return visitor.visitGenerative(this, arg);
162 }
163
144 String toString() { 164 String toString() {
145 StringBuffer sb = new StringBuffer(); 165 StringBuffer sb = new StringBuffer();
146 sb.write("{'type': $type"); 166 sb.write("{'type': $type");
147 defaultValues.forEach((key, ConstantExpression expression) { 167 defaultValues.forEach((key, ConstantExpression expression) {
148 sb.write(",\n 'default:${key}': ${expression.getText()}"); 168 sb.write(",\n 'default:${key}': ${expression.getText()}");
149 }); 169 });
150 fieldMap.forEach((FieldElement field, ConstantExpression expression) { 170 fieldMap.forEach((FieldElement field, ConstantExpression expression) {
151 sb.write(",\n 'field:${field}': ${expression.getText()}"); 171 sb.write(",\n 'field:${field}': ${expression.getText()}");
152 }); 172 });
153 if (superConstructorInvocation != null) { 173 if (superConstructorInvocation != null) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 List<ConstantExpression> arguments, 218 List<ConstantExpression> arguments,
199 CallStructure callStructure) { 219 CallStructure callStructure) {
200 NormalizedArguments args = 220 NormalizedArguments args =
201 new NormalizedArguments(defaultValues, callStructure, arguments); 221 new NormalizedArguments(defaultValues, callStructure, arguments);
202 Map<FieldElement, ConstantExpression> appliedFieldMap = 222 Map<FieldElement, ConstantExpression> appliedFieldMap =
203 GenerativeConstantConstructor.applyFields( 223 GenerativeConstantConstructor.applyFields(
204 args, thisConstructorInvocation); 224 args, thisConstructorInvocation);
205 return appliedFieldMap; 225 return appliedFieldMap;
206 } 226 }
207 227
228 accept(ConstantConstructorVisitor visitor, arg) {
229 return visitor.visitRedirectingGenerative(this, arg);
230 }
231
208 String toString() { 232 String toString() {
209 StringBuffer sb = new StringBuffer(); 233 StringBuffer sb = new StringBuffer();
210 sb.write("{'type': ${thisConstructorInvocation.type}"); 234 sb.write("{'type': ${thisConstructorInvocation.type}");
211 defaultValues.forEach((key, ConstantExpression expression) { 235 defaultValues.forEach((key, ConstantExpression expression) {
212 sb.write(",\n 'default:${key}': ${expression.getText()}"); 236 sb.write(",\n 'default:${key}': ${expression.getText()}");
213 }); 237 });
214 sb.write(",\n 'constructor': ${thisConstructorInvocation.getText()}"); 238 sb.write(",\n 'constructor': ${thisConstructorInvocation.getText()}");
215 sb.write("}"); 239 sb.write("}");
216 return sb.toString(); 240 return sb.toString();
217 } 241 }
(...skipping 15 matching lines...) Expand all
233 } 257 }
234 258
235 Map<FieldElement, ConstantExpression> computeInstanceFields( 259 Map<FieldElement, ConstantExpression> computeInstanceFields(
236 List<ConstantExpression> arguments, 260 List<ConstantExpression> arguments,
237 CallStructure callStructure) { 261 CallStructure callStructure) {
238 ConstantConstructor constantConstructor = 262 ConstantConstructor constantConstructor =
239 targetConstructorInvocation.target.constantConstructor; 263 targetConstructorInvocation.target.constantConstructor;
240 return constantConstructor.computeInstanceFields(arguments, callStructure); 264 return constantConstructor.computeInstanceFields(arguments, callStructure);
241 } 265 }
242 266
267 accept(ConstantConstructorVisitor visitor, arg) {
268 return visitor.visitRedirectingFactory(this, arg);
269 }
270
243 String toString() { 271 String toString() {
244 StringBuffer sb = new StringBuffer(); 272 StringBuffer sb = new StringBuffer();
245 sb.write("{"); 273 sb.write("{");
246 sb.write("'constructor': ${targetConstructorInvocation.getText()}"); 274 sb.write("'constructor': ${targetConstructorInvocation.getText()}");
247 sb.write("}"); 275 sb.write("}");
248 return sb.toString(); 276 return sb.toString();
249 } 277 }
250 } 278 }
251 279
252 /// An expression that is a compile-time constant. 280 /// An expression that is a compile-time constant.
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 visit(exp.name); 1823 visit(exp.name);
1796 if (exp.defaultValue != null) { 1824 if (exp.defaultValue != null) {
1797 sb.write(', defaultValue: '); 1825 sb.write(', defaultValue: ');
1798 visit(exp.defaultValue); 1826 visit(exp.defaultValue);
1799 } 1827 }
1800 sb.write(')'); 1828 sb.write(')');
1801 } 1829 }
1802 1830
1803 String toString() => sb.toString(); 1831 String toString() => sb.toString();
1804 } 1832 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698