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

Side by Side Diff: pkg/compiler/lib/src/js_backend/constant_emitter.dart

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 js_backend; 5 part of js_backend;
6 6
7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); 7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant);
8 8
9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array);
10 10
(...skipping 21 matching lines...) Expand all
32 * The given [constantReferenceGenerator] function must, when invoked with a 32 * The given [constantReferenceGenerator] function must, when invoked with a
33 * constant, either return a reference or return its literal expression if it 33 * constant, either return a reference or return its literal expression if it
34 * can be inlined. 34 * can be inlined.
35 */ 35 */
36 ConstantEmitter( 36 ConstantEmitter(
37 this.compiler, 37 this.compiler,
38 this.namer, 38 this.namer,
39 jsAst.Expression this.constantReferenceGenerator(ConstantValue constant), 39 jsAst.Expression this.constantReferenceGenerator(ConstantValue constant),
40 this.makeConstantList); 40 this.makeConstantList);
41 41
42 DiagnosticReporter get reporter => compiler.reporter;
43
42 /** 44 /**
43 * Constructs a literal expression that evaluates to the constant. Uses a 45 * Constructs a literal expression that evaluates to the constant. Uses a
44 * canonical name unless the constant can be emitted multiple times (as for 46 * canonical name unless the constant can be emitted multiple times (as for
45 * numbers and strings). 47 * numbers and strings).
46 */ 48 */
47 jsAst.Expression generate(ConstantValue constant) { 49 jsAst.Expression generate(ConstantValue constant) {
48 return _visit(constant); 50 return _visit(constant);
49 } 51 }
50 52
51 jsAst.Expression _visit(ConstantValue constant) { 53 jsAst.Expression _visit(ConstantValue constant) {
52 return constant.accept(this, null); 54 return constant.accept(this, null);
53 } 55 }
54 56
55 @override 57 @override
56 jsAst.Expression visitFunction(FunctionConstantValue constant, [_]) { 58 jsAst.Expression visitFunction(FunctionConstantValue constant, [_]) {
57 compiler.internalError(NO_LOCATION_SPANNABLE, 59 reporter.internalError(NO_LOCATION_SPANNABLE,
58 "The function constant does not need specific JS code."); 60 "The function constant does not need specific JS code.");
59 return null; 61 return null;
60 } 62 }
61 63
62 @override 64 @override
63 jsAst.Expression visitNull(NullConstantValue constant, [_]) { 65 jsAst.Expression visitNull(NullConstantValue constant, [_]) {
64 return new jsAst.LiteralNull(); 66 return new jsAst.LiteralNull();
65 } 67 }
66 68
67 static final _exponentialRE = new RegExp( 69 static final _exponentialRE = new RegExp(
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } else if (field.name == JavaScriptMapConstant.JS_OBJECT_NAME) { 215 } else if (field.name == JavaScriptMapConstant.JS_OBJECT_NAME) {
214 arguments.add(jsMap()); 216 arguments.add(jsMap());
215 } else if (field.name == JavaScriptMapConstant.KEYS_NAME) { 217 } else if (field.name == JavaScriptMapConstant.KEYS_NAME) {
216 arguments.add(constantReferenceGenerator(constant.keyList)); 218 arguments.add(constantReferenceGenerator(constant.keyList));
217 } else if (field.name == JavaScriptMapConstant.PROTO_VALUE) { 219 } else if (field.name == JavaScriptMapConstant.PROTO_VALUE) {
218 assert(constant.protoValue != null); 220 assert(constant.protoValue != null);
219 arguments.add(constantReferenceGenerator(constant.protoValue)); 221 arguments.add(constantReferenceGenerator(constant.protoValue));
220 } else if (field.name == JavaScriptMapConstant.JS_DATA_NAME) { 222 } else if (field.name == JavaScriptMapConstant.JS_DATA_NAME) {
221 arguments.add(jsGeneralMap()); 223 arguments.add(jsGeneralMap());
222 } else { 224 } else {
223 compiler.internalError(field, 225 reporter.internalError(field,
224 "Compiler has unexpected field ${field.name} for " 226 "Compiler has unexpected field ${field.name} for "
225 "${className}."); 227 "${className}.");
226 } 228 }
227 emittedArgumentCount++; 229 emittedArgumentCount++;
228 }, 230 },
229 includeSuperAndInjectedMembers: true); 231 includeSuperAndInjectedMembers: true);
230 if ((className == JavaScriptMapConstant.DART_STRING_CLASS && 232 if ((className == JavaScriptMapConstant.DART_STRING_CLASS &&
231 emittedArgumentCount != 3) || 233 emittedArgumentCount != 3) ||
232 (className == JavaScriptMapConstant.DART_PROTO_CLASS && 234 (className == JavaScriptMapConstant.DART_PROTO_CLASS &&
233 emittedArgumentCount != 4) || 235 emittedArgumentCount != 4) ||
234 (className == JavaScriptMapConstant.DART_GENERAL_CLASS && 236 (className == JavaScriptMapConstant.DART_GENERAL_CLASS &&
235 emittedArgumentCount != 1)) { 237 emittedArgumentCount != 1)) {
236 compiler.internalError(classElement, 238 reporter.internalError(classElement,
237 "Compiler and ${className} disagree on number of fields."); 239 "Compiler and ${className} disagree on number of fields.");
238 } 240 }
239 241
240 jsAst.Expression constructor = 242 jsAst.Expression constructor =
241 backend.emitter.constructorAccess(classElement); 243 backend.emitter.constructorAccess(classElement);
242 jsAst.Expression value = new jsAst.New(constructor, arguments); 244 jsAst.Expression value = new jsAst.New(constructor, arguments);
243 return maybeAddTypeArguments(constant.type, value); 245 return maybeAddTypeArguments(constant.type, value);
244 } 246 }
245 247
246 JavaScriptBackend get backend => compiler.backend; 248 JavaScriptBackend get backend => compiler.backend;
(...skipping 19 matching lines...) Expand all
266 @override 268 @override
267 jsAst.Expression visitSynthetic(SyntheticConstantValue constant, [_]) { 269 jsAst.Expression visitSynthetic(SyntheticConstantValue constant, [_]) {
268 switch (constant.kind) { 270 switch (constant.kind) {
269 case SyntheticConstantKind.DUMMY_INTERCEPTOR: 271 case SyntheticConstantKind.DUMMY_INTERCEPTOR:
270 case SyntheticConstantKind.EMPTY_VALUE: 272 case SyntheticConstantKind.EMPTY_VALUE:
271 return new jsAst.LiteralNumber('0'); 273 return new jsAst.LiteralNumber('0');
272 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: 274 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE:
273 case SyntheticConstantKind.NAME: 275 case SyntheticConstantKind.NAME:
274 return constant.payload; 276 return constant.payload;
275 default: 277 default:
276 compiler.internalError(NO_LOCATION_SPANNABLE, 278 reporter.internalError(NO_LOCATION_SPANNABLE,
277 "Unexpected DummyConstantKind ${constant.kind}"); 279 "Unexpected DummyConstantKind ${constant.kind}");
278 return null; 280 return null;
279 } 281 }
280 } 282 }
281 283
282 @override 284 @override
283 jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) { 285 jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) {
284 Element element = constant.type.element; 286 Element element = constant.type.element;
285 if (backend.isForeign(element) 287 if (backend.isForeign(element)
286 && element.name == 'JS_CONST') { 288 && element.name == 'JS_CONST') {
(...skipping 30 matching lines...) Expand all
317 [value, argumentList]); 319 [value, argumentList]);
318 } 320 }
319 return value; 321 return value;
320 } 322 }
321 323
322 @override 324 @override
323 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { 325 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) {
324 return constantReferenceGenerator(constant.referenced); 326 return constantReferenceGenerator(constant.referenced);
325 } 327 }
326 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698