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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_types.dart

Issue 22903036: Use predicates to check simple function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Small updates. Created 7 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
Index: sdk/lib/_internal/compiler/implementation/dart_types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_types.dart b/sdk/lib/_internal/compiler/implementation/dart_types.dart
index f49028849b7759bee049eb9f94cc9defad44314b..a17fa0ba88b6c987b53dc2539079afad565c22ea 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -83,7 +83,7 @@ abstract class DartType {
/**
* If this type is malformed or a generic type created with the wrong number
* of type arguments then [userProvidedBadType] holds the bad type provided
- * by the user.
+ * by the user.
*/
DartType get userProvidedBadType => null;
@@ -105,7 +105,7 @@ abstract class DartType {
/// Returns an occurrence of a type variable within this type, if any.
TypeVariableType get typeVariableOccurrence => null;
- /// Applies [f] to each occurence of a [TypeVariableType] within this type.
+ /// Applies [f] to each occurence of a [TypeVariableType] within this type.
void forEachTypeVariable(f(TypeVariableType variable)) {}
TypeVariableType _findTypeVariableOccurrence(Link<DartType> types) {
@@ -487,10 +487,10 @@ class InterfaceType extends GenericType {
Element member = classElement.implementation.lookupLocalMember(name);
if (member == null) return null;
if (member.isConstructor() || member.isPrefix()) return null;
- assert(member.isFunction() ||
- member.isAbstractField() ||
+ assert(member.isFunction() ||
+ member.isAbstractField() ||
member.isField());
-
+
if (member.isAbstractField()) {
AbstractFieldElement abstractFieldElement = member;
if (fallbackAbstractField == null) {
@@ -505,7 +505,7 @@ class InterfaceType extends GenericType {
member = null;
}
}
- return member != null
+ return member != null
? new Member(receiver, declarer, member, isSetter: isSetter) : null;
}
@@ -544,7 +544,7 @@ class InterfaceType extends GenericType {
/**
* Special subclass of [InterfaceType] used for generic interface types created
* with the wrong number of type arguments.
- *
+ *
* The type uses [:dynamic:] for all it s type arguments.
*/
class BadInterfaceType extends InterfaceType {
@@ -563,7 +563,7 @@ class BadInterfaceType extends InterfaceType {
/**
* Special subclass of [TypedefType] used for generic typedef types created
* with the wrong number of type arguments.
- *
+ *
* The type uses [:dynamic:] for all it s type arguments.
*/
class BadTypedefType extends TypedefType {
@@ -579,6 +579,7 @@ class BadTypedefType extends TypedefType {
}
class FunctionType extends DartType {
+ final bool isSimple;
final Element element;
final DartType returnType;
final Link<DartType> parameterTypes;
@@ -595,12 +596,35 @@ class FunctionType extends DartType {
*/
final Link<DartType> namedParameterTypes;
- FunctionType(Element this.element,
- DartType this.returnType,
- Link<DartType> this.parameterTypes,
- Link<DartType> this.optionalParameterTypes,
- Link<SourceString> this.namedParameters,
- Link<DartType> this.namedParameterTypes) {
+ factory FunctionType(Element element,
+ DartType returnType,
+ Link<DartType> parameterTypes,
+ Link<DartType> optionalParameterTypes,
+ Link<SourceString> namedParameters,
+ Link<DartType> namedParameterTypes) {
+ bool isSimple() {
karlklose 2013/08/23 09:13:50 Could we move this check to a predicate in Runtime
Johnni Winther 2013/08/23 10:06:57 Done.
+ if (!returnType.isDynamic) return false;
+ if (!optionalParameterTypes.isEmpty) return false;
+ if (!namedParameterTypes.isEmpty) return false;
+ for (Link<DartType> link = parameterTypes;
+ !link.isEmpty;
+ link = link.tail) {
+ if (!link.head.isDynamic) return false;
+ }
+ return true;
+ }
+ bool simple = isSimple();
+ return new FunctionType.internal(element, returnType, parameterTypes,
+ optionalParameterTypes, namedParameters, namedParameterTypes, simple);
+ }
+
+ FunctionType.internal(Element this.element,
+ DartType this.returnType,
+ Link<DartType> this.parameterTypes,
+ Link<DartType> this.optionalParameterTypes,
+ Link<SourceString> this.namedParameters,
+ Link<DartType> this.namedParameterTypes,
+ bool this.isSimple) {
assert(invariant(element, element.isDeclaration));
// Assert that optional and named parameters are not used at the same time.
assert(optionalParameterTypes.isEmpty || namedParameterTypes.isEmpty);
@@ -851,7 +875,7 @@ class Member {
if (element.isAbstractField()) {
AbstractFieldElement abstractFieldElement = element;
// Use setter if present and required or if no getter is available.
- if ((isSetter && abstractFieldElement.setter != null) ||
+ if ((isSetter && abstractFieldElement.setter != null) ||
abstractFieldElement.getter == null) {
// TODO(johnniwinther): Add check of read of field with no getter.
FunctionType functionType =
@@ -934,8 +958,8 @@ class SubtypeVisitor extends DartTypeVisitor<bool, DartType> {
bool isSubtype(DartType t, DartType s) {
if (identical(t, s) ||
- t.treatAsDynamic ||
- s.treatAsDynamic ||
+ t.treatAsDynamic ||
+ s.treatAsDynamic ||
identical(s.element, compiler.objectClass) ||
identical(t.element, compiler.nullClass)) {
return true;

Powered by Google App Engine
This is Rietveld 408576698