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

Unified Diff: pkg/compiler/lib/src/constants/constructors.dart

Issue 2669703003: Refactor ConstantExpression/ConstantConstructor to use entities. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/constants/constructors.dart
diff --git a/pkg/compiler/lib/src/constants/constructors.dart b/pkg/compiler/lib/src/constants/constructors.dart
index 8199bbcf982cdbabd1496eb591ef7e2b7cd2522b..f5d5ab7ca3acac9e8c1327c5215185737ef08dce 100644
--- a/pkg/compiler/lib/src/constants/constructors.dart
+++ b/pkg/compiler/lib/src/constants/constructors.dart
@@ -4,8 +4,8 @@
library dart2js.constants.constructors;
-import '../elements/resolution_types.dart';
-import '../elements/elements.dart' show FieldElement;
+import '../elements/entities.dart' show FieldEntity;
+import '../elements/types.dart';
import '../universe/call_structure.dart' show CallStructure;
import '../util/util.dart';
import 'evaluation.dart';
@@ -23,12 +23,15 @@ abstract class ConstantConstructor {
/// Computes the type of the instance created in a const constructor
/// invocation with type [newType].
- ResolutionInterfaceType computeInstanceType(ResolutionInterfaceType newType);
+ InterfaceType computeInstanceType(
+ Environment environment, InterfaceType newType);
/// Computes the constant expressions of the fields of the created instance
/// in a const constructor invocation with [arguments].
- Map<FieldElement, ConstantExpression> computeInstanceFields(
- List<ConstantExpression> arguments, CallStructure callStructure);
+ Map<FieldEntity, ConstantExpression> computeInstanceFields(
+ Environment environment,
+ List<ConstantExpression> arguments,
+ CallStructure callStructure);
accept(ConstantConstructorVisitor visitor, arg);
}
@@ -49,9 +52,9 @@ abstract class ConstantConstructorVisitor<R, A> {
/// A generative constant constructor.
class GenerativeConstantConstructor implements ConstantConstructor {
- final ResolutionInterfaceType type;
+ final InterfaceType type;
final Map<dynamic /*int|String*/, ConstantExpression> defaultValues;
- final Map<FieldElement, ConstantExpression> fieldMap;
+ final Map<FieldEntity, ConstantExpression> fieldMap;
final ConstructedConstantExpression superConstructorInvocation;
GenerativeConstantConstructor(this.type, this.defaultValues, this.fieldMap,
@@ -59,17 +62,20 @@ class GenerativeConstantConstructor implements ConstantConstructor {
ConstantConstructorKind get kind => ConstantConstructorKind.GENERATIVE;
- ResolutionInterfaceType computeInstanceType(ResolutionInterfaceType newType) {
- return type.substByContext(newType);
+ InterfaceType computeInstanceType(
+ Environment environment, InterfaceType newType) {
+ return environment.substByContext(type, newType);
}
- Map<FieldElement, ConstantExpression> computeInstanceFields(
- List<ConstantExpression> arguments, CallStructure callStructure) {
+ Map<FieldEntity, ConstantExpression> computeInstanceFields(
+ Environment environment,
+ List<ConstantExpression> arguments,
+ CallStructure callStructure) {
NormalizedArguments args =
new NormalizedArguments(defaultValues, callStructure, arguments);
- Map<FieldElement, ConstantExpression> appliedFieldMap =
- applyFields(args, superConstructorInvocation);
- fieldMap.forEach((FieldElement field, ConstantExpression constant) {
+ Map<FieldEntity, ConstantExpression> appliedFieldMap =
+ applyFields(environment, args, superConstructorInvocation);
+ fieldMap.forEach((FieldEntity field, ConstantExpression constant) {
appliedFieldMap[field] = constant.apply(args);
});
return appliedFieldMap;
@@ -101,7 +107,7 @@ class GenerativeConstantConstructor implements ConstantConstructor {
defaultValues.forEach((key, ConstantExpression expression) {
sb.write(",\n 'default:${key}': ${expression.toDartText()}");
});
- fieldMap.forEach((FieldElement field, ConstantExpression expression) {
+ fieldMap.forEach((FieldEntity field, ConstantExpression expression) {
sb.write(",\n 'field:${field}': ${expression.toDartText()}");
});
if (superConstructorInvocation != null) {
@@ -124,15 +130,16 @@ class GenerativeConstantConstructor implements ConstantConstructor {
/// Creates the field-to-constant map from applying [args] to
/// [constructorInvocation]. If [constructorInvocation] is `null`, an empty
/// map is created.
- static Map<FieldElement, ConstantExpression> applyFields(
+ static Map<FieldEntity, ConstantExpression> applyFields(
+ Environment environment,
NormalizedArguments args,
ConstructedConstantExpression constructorInvocation) {
- Map<FieldElement, ConstantExpression> appliedFieldMap =
- <FieldElement, ConstantExpression>{};
+ Map<FieldEntity, ConstantExpression> appliedFieldMap =
+ <FieldEntity, ConstantExpression>{};
if (constructorInvocation != null) {
- Map<FieldElement, ConstantExpression> fieldMap =
- constructorInvocation.computeInstanceFields();
- fieldMap.forEach((FieldElement field, ConstantExpression constant) {
+ Map<FieldEntity, ConstantExpression> fieldMap =
+ constructorInvocation.computeInstanceFields(environment);
+ fieldMap.forEach((FieldEntity field, ConstantExpression constant) {
appliedFieldMap[field] = constant.apply(args);
});
}
@@ -152,19 +159,21 @@ class RedirectingGenerativeConstantConstructor implements ConstantConstructor {
return ConstantConstructorKind.REDIRECTING_GENERATIVE;
}
- ResolutionInterfaceType computeInstanceType(ResolutionInterfaceType newType) {
- return thisConstructorInvocation
- .computeInstanceType()
- .substByContext(newType);
+ InterfaceType computeInstanceType(
+ Environment environment, InterfaceType newType) {
+ return environment.substByContext(
+ thisConstructorInvocation.computeInstanceType(environment), newType);
}
- Map<FieldElement, ConstantExpression> computeInstanceFields(
- List<ConstantExpression> arguments, CallStructure callStructure) {
+ Map<FieldEntity, ConstantExpression> computeInstanceFields(
+ Environment environment,
+ List<ConstantExpression> arguments,
+ CallStructure callStructure) {
NormalizedArguments args =
new NormalizedArguments(defaultValues, callStructure, arguments);
- Map<FieldElement, ConstantExpression> appliedFieldMap =
+ Map<FieldEntity, ConstantExpression> appliedFieldMap =
GenerativeConstantConstructor.applyFields(
- args, thisConstructorInvocation);
+ environment, args, thisConstructorInvocation);
return appliedFieldMap;
}
@@ -207,17 +216,20 @@ class RedirectingFactoryConstantConstructor implements ConstantConstructor {
return ConstantConstructorKind.REDIRECTING_FACTORY;
}
- ResolutionInterfaceType computeInstanceType(ResolutionInterfaceType newType) {
- return targetConstructorInvocation
- .computeInstanceType()
- .substByContext(newType);
+ InterfaceType computeInstanceType(
+ Environment environment, InterfaceType newType) {
+ return environment.substByContext(
+ targetConstructorInvocation.computeInstanceType(environment), newType);
}
- Map<FieldElement, ConstantExpression> computeInstanceFields(
- List<ConstantExpression> arguments, CallStructure callStructure) {
+ Map<FieldEntity, ConstantExpression> computeInstanceFields(
+ Environment environment,
+ List<ConstantExpression> arguments,
+ CallStructure callStructure) {
ConstantConstructor constantConstructor =
- targetConstructorInvocation.target.constantConstructor;
- return constantConstructor.computeInstanceFields(arguments, callStructure);
+ environment.getConstructorConstant(targetConstructorInvocation.target);
+ return constantConstructor.computeInstanceFields(
+ environment, arguments, callStructure);
}
accept(ConstantConstructorVisitor visitor, arg) {
« no previous file with comments | « pkg/compiler/lib/src/constants/constant_constructors.dart ('k') | pkg/compiler/lib/src/constants/evaluation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698