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

Unified Diff: pkg/compiler/lib/src/elements/types.dart

Issue 2996723002: Support typedef type literals (Closed)
Patch Set: Updated cf. comments Created 3 years, 4 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
« no previous file with comments | « pkg/compiler/lib/src/elements/resolution_types.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/elements/types.dart
diff --git a/pkg/compiler/lib/src/elements/types.dart b/pkg/compiler/lib/src/elements/types.dart
index da83aaa80712886664b5675a5e55ac9f72e08fc1..26dfbc859a4f8ee4a3f000f2fcf1a98df3229a55 100644
--- a/pkg/compiler/lib/src/elements/types.dart
+++ b/pkg/compiler/lib/src/elements/types.dart
@@ -162,6 +162,85 @@ class InterfaceType extends DartType {
}
}
+class TypedefType extends DartType {
+ final TypedefEntity element;
+ final List<DartType> typeArguments;
+
+ TypedefType(this.element, this.typeArguments);
+
+ bool get isTypedef => true;
+
+ bool get containsTypeVariables =>
+ typeArguments.any((type) => type.containsTypeVariables);
+
+ void forEachTypeVariable(f(TypeVariableType variable)) {
+ typeArguments.forEach((type) => type.forEachTypeVariable(f));
+ }
+
+ TypedefType subst(List<DartType> arguments, List<DartType> parameters) {
+ if (typeArguments.isEmpty) {
+ // Return fast on non-generic types.
+ return this;
+ }
+ if (parameters.isEmpty) {
+ assert(arguments.isEmpty);
+ // Return fast on empty substitutions.
+ return this;
+ }
+ List<DartType> newTypeArguments =
+ _substTypes(typeArguments, arguments, parameters);
+ if (!identical(typeArguments, newTypeArguments)) {
+ // Create a new type only if necessary.
+ return new TypedefType(element, newTypeArguments);
+ }
+ return this;
+ }
+
+ bool get treatAsRaw {
+ for (DartType type in typeArguments) {
+ if (!type.treatAsDynamic) return false;
+ }
+ return true;
+ }
+
+ @override
+ R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
+ visitor.visitTypedefType(this, argument);
+
+ int get hashCode {
+ int hash = element.hashCode;
+ for (DartType argument in typeArguments) {
+ int argumentHash = argument != null ? argument.hashCode : 0;
+ hash = 17 * hash + 3 * argumentHash;
+ }
+ return hash;
+ }
+
+ bool operator ==(other) {
+ if (other is! TypedefType) return false;
+ return identical(element, other.element) &&
+ equalElements(typeArguments, other.typeArguments);
+ }
+
+ String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.write(element.name);
+ if (typeArguments.isNotEmpty) {
+ sb.write('<');
+ bool needsComma = false;
+ for (DartType typeArgument in typeArguments) {
+ if (needsComma) {
+ sb.write(',');
+ }
+ sb.write(typeArgument);
+ needsComma = true;
+ }
+ sb.write('>');
+ }
+ return sb.toString();
+ }
+}
+
class TypeVariableType extends DartType {
final TypeVariableEntity element;
@@ -421,6 +500,8 @@ abstract class DartTypeVisitor<R, A> {
R visitInterfaceType(covariant InterfaceType type, A argument) => null;
+ R visitTypedefType(covariant TypedefType type, A argument) => null;
+
R visitDynamicType(covariant DynamicType type, A argument) => null;
}
« no previous file with comments | « pkg/compiler/lib/src/elements/resolution_types.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698