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

Side by Side Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 2669703003: Refactor ConstantExpression/ConstantConstructor to use entities. (Closed)
Patch Set: Created 3 years, 10 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 library dart2js.resolution.members; 5 library dart2js.resolution.members;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show Selectors; 8 import '../common/names.dart' show Selectors;
9 import '../common/resolution.dart' show Resolution; 9 import '../common/resolution.dart' show Resolution;
10 import '../compile_time_constants.dart'; 10 import '../compile_time_constants.dart';
(...skipping 2043 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 2054
2055 return handleUpdate(node, name, semantics); 2055 return handleUpdate(node, name, semantics);
2056 } 2056 }
2057 2057
2058 /// Handle access to a type literal of a typedef. Like `F` or 2058 /// Handle access to a type literal of a typedef. Like `F` or
2059 /// `F()` where 'F' is typedef. 2059 /// `F()` where 'F' is typedef.
2060 ResolutionResult handleTypedefTypeLiteralAccess( 2060 ResolutionResult handleTypedefTypeLiteralAccess(
2061 Send node, Name name, TypedefElement typdef) { 2061 Send node, Name name, TypedefElement typdef) {
2062 typdef.ensureResolved(resolution); 2062 typdef.ensureResolved(resolution);
2063 ResolutionDartType type = typdef.rawType; 2063 ResolutionDartType type = typdef.rawType;
2064 ConstantExpression constant = new TypeConstantExpression(type); 2064 ConstantExpression constant = new TypeConstantExpression(type, name.text);
2065 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant); 2065 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant);
2066 return handleConstantTypeLiteralAccess(node, name, typdef, type, semantics); 2066 return handleConstantTypeLiteralAccess(node, name, typdef, type, semantics);
2067 } 2067 }
2068 2068
2069 /// Handle access to a type literal of a typedef. Like `F = b`, `F++` or 2069 /// Handle access to a type literal of a typedef. Like `F = b`, `F++` or
2070 /// `F += b` where 'F' is typedef. 2070 /// `F += b` where 'F' is typedef.
2071 ResolutionResult handleTypedefTypeLiteralUpdate( 2071 ResolutionResult handleTypedefTypeLiteralUpdate(
2072 SendSet node, Name name, TypedefElement typdef) { 2072 SendSet node, Name name, TypedefElement typdef) {
2073 typdef.ensureResolved(resolution); 2073 typdef.ensureResolved(resolution);
2074 ResolutionDartType type = typdef.rawType; 2074 ResolutionDartType type = typdef.rawType;
2075 ConstantExpression constant = new TypeConstantExpression(type); 2075 ConstantExpression constant = new TypeConstantExpression(type, name.text);
2076 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant); 2076 AccessSemantics semantics = new ConstantAccess.typedefTypeLiteral(constant);
2077 return handleConstantTypeLiteralUpdate(node, name, typdef, type, semantics); 2077 return handleConstantTypeLiteralUpdate(node, name, typdef, type, semantics);
2078 } 2078 }
2079 2079
2080 /// Handle access to a type literal of the type 'dynamic'. Like `dynamic` or 2080 /// Handle access to a type literal of the type 'dynamic'. Like `dynamic` or
2081 /// `dynamic()`. 2081 /// `dynamic()`.
2082 ResolutionResult handleDynamicTypeLiteralAccess(Send node) { 2082 ResolutionResult handleDynamicTypeLiteralAccess(Send node) {
2083 ResolutionDartType type = const ResolutionDynamicType(); 2083 ResolutionDartType type = const ResolutionDynamicType();
2084 ConstantExpression constant = new TypeConstantExpression( 2084 ConstantExpression constant = new TypeConstantExpression(
2085 // TODO(johnniwinther): Use [type] when evaluation of constants is done 2085 // TODO(johnniwinther): Use [type] when evaluation of constants is done
2086 // directly on the constant expressions. 2086 // directly on the constant expressions.
2087 node.isCall ? commonElements.typeType : type); 2087 node.isCall ? commonElements.typeType : type,
2088 'dynamic');
2088 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); 2089 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant);
2089 ClassElement typeClass = commonElements.typeClass; 2090 ClassElement typeClass = commonElements.typeClass;
2090 return handleConstantTypeLiteralAccess( 2091 return handleConstantTypeLiteralAccess(
2091 node, const PublicName('dynamic'), typeClass, type, semantics); 2092 node, const PublicName('dynamic'), typeClass, type, semantics);
2092 } 2093 }
2093 2094
2094 /// Handle update to a type literal of the type 'dynamic'. Like `dynamic++` or 2095 /// Handle update to a type literal of the type 'dynamic'. Like `dynamic++` or
2095 /// `dynamic = 0`. 2096 /// `dynamic = 0`.
2096 ResolutionResult handleDynamicTypeLiteralUpdate(SendSet node) { 2097 ResolutionResult handleDynamicTypeLiteralUpdate(SendSet node) {
2097 ResolutionDartType type = const ResolutionDynamicType(); 2098 ResolutionDartType type = const ResolutionDynamicType();
2098 ConstantExpression constant = 2099 ConstantExpression constant =
2099 new TypeConstantExpression(const ResolutionDynamicType()); 2100 new TypeConstantExpression(const ResolutionDynamicType(), 'dynamic');
2100 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); 2101 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant);
2101 ClassElement typeClass = commonElements.typeClass; 2102 ClassElement typeClass = commonElements.typeClass;
2102 return handleConstantTypeLiteralUpdate( 2103 return handleConstantTypeLiteralUpdate(
2103 node, const PublicName('dynamic'), typeClass, type, semantics); 2104 node, const PublicName('dynamic'), typeClass, type, semantics);
2104 } 2105 }
2105 2106
2106 /// Handle access to a type literal of a class. Like `C` or 2107 /// Handle access to a type literal of a class. Like `C` or
2107 /// `C()` where 'C' is class. 2108 /// `C()` where 'C' is class.
2108 ResolutionResult handleClassTypeLiteralAccess( 2109 ResolutionResult handleClassTypeLiteralAccess(
2109 Send node, Name name, ClassElement cls) { 2110 Send node, Name name, ClassElement cls) {
2110 cls.ensureResolved(resolution); 2111 cls.ensureResolved(resolution);
2111 ResolutionDartType type = cls.rawType; 2112 ResolutionDartType type = cls.rawType;
2112 ConstantExpression constant = new TypeConstantExpression(type); 2113 ConstantExpression constant = new TypeConstantExpression(type, name.text);
2113 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); 2114 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant);
2114 return handleConstantTypeLiteralAccess(node, name, cls, type, semantics); 2115 return handleConstantTypeLiteralAccess(node, name, cls, type, semantics);
2115 } 2116 }
2116 2117
2117 /// Handle access to a type literal of a class. Like `C = b`, `C++` or 2118 /// Handle access to a type literal of a class. Like `C = b`, `C++` or
2118 /// `C += b` where 'C' is class. 2119 /// `C += b` where 'C' is class.
2119 ResolutionResult handleClassTypeLiteralUpdate( 2120 ResolutionResult handleClassTypeLiteralUpdate(
2120 SendSet node, Name name, ClassElement cls) { 2121 SendSet node, Name name, ClassElement cls) {
2121 cls.ensureResolved(resolution); 2122 cls.ensureResolved(resolution);
2122 ResolutionDartType type = cls.rawType; 2123 ResolutionDartType type = cls.rawType;
2123 ConstantExpression constant = new TypeConstantExpression(type); 2124 ConstantExpression constant = new TypeConstantExpression(type, name.text);
2124 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); 2125 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant);
2125 return handleConstantTypeLiteralUpdate(node, name, cls, type, semantics); 2126 return handleConstantTypeLiteralUpdate(node, name, cls, type, semantics);
2126 } 2127 }
2127 2128
2128 /// Handle a [Send] that resolves to a [prefix]. Like `prefix` in 2129 /// Handle a [Send] that resolves to a [prefix]. Like `prefix` in
2129 /// `prefix.Class` or `prefix` in `prefix()`, the latter being a compile time 2130 /// `prefix.Class` or `prefix` in `prefix()`, the latter being a compile time
2130 /// error. 2131 /// error.
2131 ResolutionResult handleClassSend(Send node, Name name, ClassElement cls) { 2132 ResolutionResult handleClassSend(Send node, Name name, ClassElement cls) {
2132 cls.ensureResolved(resolution); 2133 cls.ensureResolved(resolution);
2133 if (sendIsMemberAccess) { 2134 if (sendIsMemberAccess) {
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 .functionDeclaration.parameters 2545 .functionDeclaration.parameters
2545 .indexOf(parameter)), 2546 .indexOf(parameter)),
2546 element: element); 2547 element: element);
2547 } 2548 }
2548 } else { 2549 } else {
2549 result = new ElementResult(element); 2550 result = new ElementResult(element);
2550 } 2551 }
2551 break; 2552 break;
2552 case AccessKind.FINAL_LOCAL_VARIABLE: 2553 case AccessKind.FINAL_LOCAL_VARIABLE:
2553 if (element.isConst) { 2554 if (element.isConst) {
2555 LocalVariableElement local = element;
2554 result = new ConstantResult( 2556 result = new ConstantResult(
2555 node, new VariableConstantExpression(element), 2557 node, new LocalVariableConstantExpression(local),
2556 element: element); 2558 element: element);
2557 } else { 2559 } else {
2558 result = new ElementResult(element); 2560 result = new ElementResult(element);
2559 } 2561 }
2560 break; 2562 break;
2561 default: 2563 default:
2562 reporter.internalError(node, "Unexpected local access $semantics."); 2564 reporter.internalError(node, "Unexpected local access $semantics.");
2563 break; 2565 break;
2564 } 2566 }
2565 selector = new Selector.getter(name); 2567 selector = new Selector.getter(name);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER, {'name': name}); 2742 MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER, {'name': name});
2741 break; 2743 break;
2742 default: 2744 default:
2743 reporter.internalError( 2745 reporter.internalError(
2744 node, "Unexpected statically resolved access $semantics."); 2746 node, "Unexpected statically resolved access $semantics.");
2745 break; 2747 break;
2746 } 2748 }
2747 registry.registerSendStructure(node, new GetStructure(semantics)); 2749 registry.registerSendStructure(node, new GetStructure(semantics));
2748 if (member.isConst) { 2750 if (member.isConst) {
2749 FieldElement field = member; 2751 FieldElement field = member;
2750 result = new ConstantResult(node, new VariableConstantExpression(field), 2752 result = new ConstantResult(node, new FieldConstantExpression(field),
2751 element: field); 2753 element: field);
2752 } else { 2754 } else {
2753 result = new ElementResult(member); 2755 result = new ElementResult(member);
2754 } 2756 }
2755 } 2757 }
2756 2758
2757 // TODO(23998): Remove these when all information goes through 2759 // TODO(23998): Remove these when all information goes through
2758 // the [SendStructure]. 2760 // the [SendStructure].
2759 registry.useElement(node, member); 2761 registry.useElement(node, member);
2760 registry.setSelector(node, selector); 2762 registry.setSelector(node, selector);
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 // Callback hook for when the compile-time constant evaluator has 3976 // Callback hook for when the compile-time constant evaluator has
3975 // analyzed the constant. 3977 // analyzed the constant.
3976 // TODO(johnniwinther): Remove this when all constants are computed 3978 // TODO(johnniwinther): Remove this when all constants are computed
3977 // in resolution. 3979 // in resolution.
3978 Function onAnalyzed; 3980 Function onAnalyzed;
3979 if (isValidAsConstant && 3981 if (isValidAsConstant &&
3980 argumentsResult.isValidAsConstant && 3982 argumentsResult.isValidAsConstant &&
3981 // TODO(johnniwinther): Remove this when all constants are computed 3983 // TODO(johnniwinther): Remove this when all constants are computed
3982 // in resolution. 3984 // in resolution.
3983 !constructor.isFromEnvironmentConstructor) { 3985 !constructor.isFromEnvironmentConstructor) {
3986 ResolutionInterfaceType interfaceType = type;
3984 CallStructure callStructure = argumentsResult.callStructure; 3987 CallStructure callStructure = argumentsResult.callStructure;
3985 List<ConstantExpression> arguments = argumentsResult.constantArguments; 3988 List<ConstantExpression> arguments = argumentsResult.constantArguments;
3986 3989
3987 ConstructedConstantExpression constant = 3990 ConstructedConstantExpression constant =
3988 new ConstructedConstantExpression( 3991 new ConstructedConstantExpression(
3989 type, constructor, callStructure, arguments); 3992 interfaceType, constructor, callStructure, arguments);
3990 registry.registerNewStructure(node, 3993 registry.registerNewStructure(node,
3991 new ConstInvokeStructure(ConstantInvokeKind.CONSTRUCTED, constant)); 3994 new ConstInvokeStructure(ConstantInvokeKind.CONSTRUCTED, constant));
3992 resolutionResult = new ConstantResult(node, constant); 3995 resolutionResult = new ConstantResult(node, constant);
3993 } else if (isInvalid) { 3996 } else if (isInvalid) {
3994 // Known to be non-constant. 3997 // Known to be non-constant.
3995 kind == ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR; 3998 kind == ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR;
3996 registry.registerNewStructure( 3999 registry.registerNewStructure(
3997 node, 4000 node,
3998 new NewInvokeStructure( 4001 new NewInvokeStructure(
3999 new ConstructorAccessSemantics(kind, constructor, type), 4002 new ConstructorAccessSemantics(kind, constructor, type),
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
4782 } 4785 }
4783 return const NoneResult(); 4786 return const NoneResult();
4784 } 4787 }
4785 } 4788 }
4786 4789
4787 /// Looks up [name] in [scope] and unwraps the result. 4790 /// Looks up [name] in [scope] and unwraps the result.
4788 Element lookupInScope( 4791 Element lookupInScope(
4789 DiagnosticReporter reporter, Node node, Scope scope, String name) { 4792 DiagnosticReporter reporter, Node node, Scope scope, String name) {
4790 return Elements.unwrap(scope.lookup(name), reporter, node); 4793 return Elements.unwrap(scope.lookup(name), reporter, node);
4791 } 4794 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_adapter.dart ('k') | pkg/compiler/lib/src/resolution/resolution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698