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

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

Issue 195983006: Constrain constant references from deferred libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 node, type, compiler.symbolConstructor, createArguments); 404 node, type, compiler.symbolConstructor, createArguments);
405 } 405 }
406 406
407 Constant makeTypeConstant(Element element) { 407 Constant makeTypeConstant(Element element) {
408 DartType elementType = element.computeType(compiler).asRaw(); 408 DartType elementType = element.computeType(compiler).asRaw();
409 DartType constantType = 409 DartType constantType =
410 compiler.backend.typeImplementation.computeType(compiler); 410 compiler.backend.typeImplementation.computeType(compiler);
411 return new TypeConstant(elementType, constantType); 411 return new TypeConstant(elementType, constantType);
412 } 412 }
413 413
414 /// Returns true if the prefix of the send resolves to a deferred import
415 /// prefix.
416 bool isDeferredUse(Send send) {
417 // We handle:
418 // 1. Send(Send(Send(null, Prefix), className), staticName)
419 // 2. Send(Send(Prefix, Classname), staticName)
420 // 3. Send(Send(null, Prefix), staticName | className)
421 // 4. Send(Send(Prefix), staticName | className)
422 // Nodes of the forms 2,4 occur in metadata.
423 if (send == null) return false;
424 while (send.receiver is Send) {
425 send = send.receiver;
426 }
427 Identifier prefixNode;
428 if (send.receiver is Identifier) {
429 prefixNode = send.receiver;
430 } else if (send.receiver == null &&
431 send.selector is Identifier) {
432 prefixNode = send.selector;
433 }
434 if (prefixNode != null) {
435 Element maybePrefix = elements[prefixNode.asIdentifier()];
436 if (maybePrefix != null && maybePrefix.isPrefix() &&
437 (maybePrefix as PrefixElement).isDeferred) {
438 return true;
439 }
440 }
441 return false;
442 }
443
414 // TODO(floitsch): provide better error-messages. 444 // TODO(floitsch): provide better error-messages.
415 Constant visitSend(Send send) { 445 Constant visitSend(Send send) {
416 Element element = elements[send]; 446 Element element = elements[send];
417 if (send.isPropertyAccess) { 447 if (send.isPropertyAccess) {
448 if (isDeferredUse(send)) {
449 return signalNotCompileTimeConstant(send,
450 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
451 }
418 if (Elements.isStaticOrTopLevelFunction(element)) { 452 if (Elements.isStaticOrTopLevelFunction(element)) {
419 return new FunctionConstant(element); 453 return new FunctionConstant(element);
420 } else if (Elements.isStaticOrTopLevelField(element)) { 454 } else if (Elements.isStaticOrTopLevelField(element)) {
421 Constant result; 455 Constant result;
422 if (element.modifiers.isConst()) { 456 if (element.modifiers.isConst()) {
423 result = handler.compileConstant(element); 457 result = handler.compileConstant(element);
424 } else if (element.modifiers.isFinal() && !isEvaluatingConstant) { 458 } else if (element.modifiers.isFinal() && !isEvaluatingConstant) {
425 result = handler.compileVariable(element); 459 result = handler.compileVariable(element);
426 } 460 }
427 if (result != null) return result; 461 if (result != null) return result;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 657 }
624 658
625 Send send = node.send; 659 Send send = node.send;
626 FunctionElement constructor = elements[send]; 660 FunctionElement constructor = elements[send];
627 if (Elements.isUnresolved(constructor)) { 661 if (Elements.isUnresolved(constructor)) {
628 return signalNotCompileTimeConstant(node); 662 return signalNotCompileTimeConstant(node);
629 } 663 }
630 664
631 // Deferred types can not be used in const instance creation expressions. 665 // Deferred types can not be used in const instance creation expressions.
632 // Check if the constructor comes from a deferred library. 666 // Check if the constructor comes from a deferred library.
633 Send selectorSend = node.send.selector.asSend(); 667 if (isDeferredUse(node.send.selector.asSend())) {
634 if (selectorSend != null) { 668 return signalNotCompileTimeConstant(node,
635 Identifier receiver = selectorSend.receiver.asIdentifier(); 669 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT_CONSTRUCTION);
636 if (receiver != null) {
637 Element element = elements[receiver];
638 if (element.isPrefix() && (element as PrefixElement).isDeferred) {
639 return signalNotCompileTimeConstant(node,
640 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
641 }
642 }
643 } 670 }
644 671
645 // TODO(ahe): This is nasty: we must eagerly analyze the 672 // TODO(ahe): This is nasty: we must eagerly analyze the
646 // constructor to ensure the redirectionTarget has been computed 673 // constructor to ensure the redirectionTarget has been computed
647 // correctly. Find a way to avoid this. 674 // correctly. Find a way to avoid this.
648 compiler.analyzeElement(constructor.declaration); 675 compiler.analyzeElement(constructor.declaration);
649 676
650 InterfaceType type = elements.getType(node); 677 InterfaceType type = elements.getType(node);
651 List<Constant> evaluateArguments(FunctionElement constructor) { 678 List<Constant> evaluateArguments(FunctionElement constructor) {
652 Selector selector = elements.getSelector(send); 679 Selector selector = elements.getSelector(send);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 if (fieldValue == null) { 1000 if (fieldValue == null) {
974 // Use the default value. 1001 // Use the default value.
975 fieldValue = handler.compileConstant(field); 1002 fieldValue = handler.compileConstant(field);
976 } 1003 }
977 jsNewArguments.add(fieldValue); 1004 jsNewArguments.add(fieldValue);
978 }, 1005 },
979 includeSuperAndInjectedMembers: true); 1006 includeSuperAndInjectedMembers: true);
980 return jsNewArguments; 1007 return jsNewArguments;
981 } 1008 }
982 } 1009 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698