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

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

Issue 11365170: Start new design for interceptors and implement String.charCodeAt with it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/compiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * The [ConstantHandler] keeps track of compile-time constants, 8 * The [ConstantHandler] keeps track of compile-time constants,
9 * initializations of global and static fields, and default values of 9 * initializations of global and static fields, and default values of
10 * optional parameters. 10 * optional parameters.
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 DartType keysType = new InterfaceType(compiler.listClass); 332 DartType keysType = new InterfaceType(compiler.listClass);
333 ListConstant keysList = new ListConstant(keysType, keys); 333 ListConstant keysList = new ListConstant(keysType, keys);
334 compiler.constantHandler.registerCompileTimeConstant(keysList); 334 compiler.constantHandler.registerCompileTimeConstant(keysList);
335 SourceString className = hasProtoKey 335 SourceString className = hasProtoKey
336 ? MapConstant.DART_PROTO_CLASS 336 ? MapConstant.DART_PROTO_CLASS
337 : MapConstant.DART_CLASS; 337 : MapConstant.DART_CLASS;
338 ClassElement classElement = compiler.jsHelperLibrary.find(className); 338 ClassElement classElement = compiler.jsHelperLibrary.find(className);
339 classElement.ensureResolved(compiler); 339 classElement.ensureResolved(compiler);
340 // TODO(floitsch): copy over the generic type. 340 // TODO(floitsch): copy over the generic type.
341 DartType type = new InterfaceType(classElement); 341 DartType type = new InterfaceType(classElement);
342 compiler.enqueuer.codegen.registerInstantiatedClass(classElement); 342 registerInstantiatedClass(classElement);
343 Constant constant = new MapConstant(type, keysList, values, protoValue); 343 Constant constant = new MapConstant(type, keysList, values, protoValue);
344 compiler.constantHandler.registerCompileTimeConstant(constant); 344 compiler.constantHandler.registerCompileTimeConstant(constant);
345 return constant; 345 return constant;
346 } 346 }
347 347
348 Constant visitLiteralNull(LiteralNull node) { 348 Constant visitLiteralNull(LiteralNull node) {
349 return constantSystem.createNull(); 349 return constantSystem.createNull();
350 } 350 }
351 351
352 void registerInstantiatedClass(ClassElement element) {
353 compiler.enqueuer.codegen.registerInstantiatedClass(element);
354 }
355
356 void registerStringInstance() {
357 registerInstantiatedClass(compiler.stringClass);
358 }
359
352 Constant visitLiteralString(LiteralString node) { 360 Constant visitLiteralString(LiteralString node) {
361 registerStringInstance();
353 return constantSystem.createString(node.dartString, node); 362 return constantSystem.createString(node.dartString, node);
354 } 363 }
355 364
356 Constant visitStringJuxtaposition(StringJuxtaposition node) { 365 Constant visitStringJuxtaposition(StringJuxtaposition node) {
357 StringConstant left = evaluate(node.first); 366 StringConstant left = evaluate(node.first);
358 StringConstant right = evaluate(node.second); 367 StringConstant right = evaluate(node.second);
359 if (left == null || right == null) return null; 368 if (left == null || right == null) return null;
369 registerStringInstance();
360 return constantSystem.createString( 370 return constantSystem.createString(
361 new DartString.concat(left.value, right.value), node); 371 new DartString.concat(left.value, right.value), node);
362 } 372 }
363 373
364 Constant visitStringInterpolation(StringInterpolation node) { 374 Constant visitStringInterpolation(StringInterpolation node) {
365 StringConstant initialString = evaluate(node.string); 375 StringConstant initialString = evaluate(node.string);
366 if (initialString == null) return null; 376 if (initialString == null) return null;
367 DartString accumulator = initialString.value; 377 DartString accumulator = initialString.value;
368 for (StringInterpolationPart part in node.parts) { 378 for (StringInterpolationPart part in node.parts) {
369 Constant expression = evaluate(part.expression); 379 Constant expression = evaluate(part.expression);
370 DartString expressionString; 380 DartString expressionString;
371 if (expression == null) { 381 if (expression == null) {
372 return signalNotCompileTimeConstant(part.expression); 382 return signalNotCompileTimeConstant(part.expression);
373 } else if (expression.isNum() || expression.isBool()) { 383 } else if (expression.isNum() || expression.isBool()) {
374 PrimitiveConstant primitive = expression; 384 PrimitiveConstant primitive = expression;
375 expressionString = new DartString.literal(primitive.value.toString()); 385 expressionString = new DartString.literal(primitive.value.toString());
376 } else if (expression.isString()) { 386 } else if (expression.isString()) {
377 PrimitiveConstant primitive = expression; 387 PrimitiveConstant primitive = expression;
378 expressionString = primitive.value; 388 expressionString = primitive.value;
379 } else { 389 } else {
380 return signalNotCompileTimeConstant(part.expression); 390 return signalNotCompileTimeConstant(part.expression);
381 } 391 }
382 accumulator = new DartString.concat(accumulator, expressionString); 392 accumulator = new DartString.concat(accumulator, expressionString);
383 StringConstant partString = evaluate(part.string); 393 StringConstant partString = evaluate(part.string);
384 if (partString == null) return null; 394 if (partString == null) return null;
385 accumulator = new DartString.concat(accumulator, partString.value); 395 accumulator = new DartString.concat(accumulator, partString.value);
386 }; 396 };
397 registerStringInstance();
387 return constantSystem.createString(accumulator, node); 398 return constantSystem.createString(accumulator, node);
388 } 399 }
389 400
390 // TODO(floitsch): provide better error-messages. 401 // TODO(floitsch): provide better error-messages.
391 Constant visitSend(Send send) { 402 Constant visitSend(Send send) {
392 Element element = elements[send]; 403 Element element = elements[send];
393 if (send.isPropertyAccess) { 404 if (send.isPropertyAccess) {
394 if (Elements.isStaticOrTopLevelFunction(element)) { 405 if (Elements.isStaticOrTopLevelFunction(element)) {
395 compiler.codegenWorld.staticFunctionsNeedingGetter.add(element); 406 compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
396 Constant constant = new FunctionConstant(element); 407 Constant constant = new FunctionConstant(element);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 // Use the default value. 820 // Use the default value.
810 fieldValue = compiler.compileConstant(field); 821 fieldValue = compiler.compileConstant(field);
811 } 822 }
812 jsNewArguments.add(fieldValue); 823 jsNewArguments.add(fieldValue);
813 }, 824 },
814 includeBackendMembers: true, 825 includeBackendMembers: true,
815 includeSuperMembers: true); 826 includeSuperMembers: true);
816 return jsNewArguments; 827 return jsNewArguments;
817 } 828 }
818 } 829 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698