| Index: frog/type.dart
|
| diff --git a/frog/type.dart b/frog/type.dart
|
| index d479a067cf27e067be9c14f7b5b5280d5ffb1a9c..3b14af0923c285717d2f965097833d1f415862b7 100644
|
| --- a/frog/type.dart
|
| +++ b/frog/type.dart
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| @@ -24,7 +24,7 @@ class Type extends Element {
|
| Type(String name): _foundMembers = {}, varStubs = {}, super(name, null);
|
|
|
| void markUsed() {}
|
| - abstract void genMethod(Member method);
|
| + abstract void markUsedMethod(Member method);
|
|
|
| TypeMember get typeMember() {
|
| if (_typeMember == null) {
|
| @@ -171,7 +171,6 @@ class Type extends Element {
|
| return;
|
| }
|
| final ne = new MethodMember(':ne', this, eq.definition);
|
| - ne.isGenerated = true;
|
| ne.returnType = eq.returnType;
|
| ne.parameters = eq.parameters;
|
| ne.isStatic = eq.isStatic;
|
| @@ -240,8 +239,10 @@ class Type extends Element {
|
| return false;
|
| }
|
|
|
| + // TODO(jmesserly): does this function stick around once we have UnionValue?
|
| static Type union(Type x, Type y) {
|
| if (x == y) return x;
|
| +
|
| if (x.isNum && y.isNum) return world.numType;
|
| if (x.isString && y.isString) return world.stringType;
|
|
|
| @@ -277,6 +278,16 @@ class Type extends Element {
|
| }
|
| }
|
|
|
| + // TODO(jmesserly): this function isn't right. Should be based on the
|
| + // spec-matching isSubtypeOf. What we really need is either: implement both
|
| + // << and <:, and track the null type more precisely. OR: make sure our
|
| + // "subtypes" list precisely matches the spec notion of the "more specific"
|
| + // relation.
|
| + bool isMoreSpecific(Type other) {
|
| + if (other.subtypes == null) return false;
|
| + return other.subtypes.contains(this);
|
| + }
|
| +
|
| /**
|
| * This implements the subtype operator <: defined in "Interface Types"
|
| * of the language spec. It's implemented in terms of the << "more specific"
|
| @@ -427,9 +438,7 @@ class ParameterType extends Type {
|
|
|
| MethodMember getCallMethod() => extendsType.getCallMethod();
|
|
|
| - void genMethod(Member method) {
|
| - extendsType.genMethod(method);
|
| - }
|
| + void markUsedMethod(Member method) => extendsType.markUsedMethod(method);
|
|
|
| // TODO(jmesserly): should be like this:
|
| //bool isSubtypeOf(Type other) => extendsType.isSubtypeOf(other);
|
| @@ -493,7 +502,7 @@ class NonNullableType extends Type {
|
| Type resolveTypeParams(ConcreteType inType) => type.resolveTypeParams(inType);
|
| void addDirectSubtype(Type subtype) { type.addDirectSubtype(subtype); }
|
| void markUsed() { type.markUsed(); }
|
| - void genMethod(Member method) { type.genMethod(method); }
|
| + void markUsedMethod(Member method) => type.markUsedMethod(method);
|
| SourceSpan get span() => type.span;
|
| Member getMember(String name) => type.getMember(name);
|
| MethodMember getConstructor(String name) => type.getConstructor(name);
|
| @@ -628,7 +637,7 @@ class ConcreteType extends Type {
|
| genericType.markUsed();
|
| }
|
|
|
| - void genMethod(Member method) => genericType.genMethod(method);
|
| + void markUsedMethod(Member method) => genericType.markUsedMethod(method);
|
|
|
| getFactory(Type type, String constructorName) {
|
| return genericType.getFactory(type, constructorName);
|
| @@ -703,6 +712,7 @@ class ConcreteType extends Type {
|
| }
|
| }
|
|
|
| +typedef void Action();
|
|
|
| /** Represents a Dart type defined as source code. */
|
| class DefinedType extends Type {
|
| @@ -732,8 +742,11 @@ class DefinedType extends Type {
|
|
|
| Map<String, ConcreteType> _concreteTypes;
|
|
|
| - /** Methods to be generated once we know for sure that the type is used. */
|
| - Map<String, Member> _lazyGenMethods;
|
| + /**
|
| + * Functions that will be generated once we know for sure that the type is
|
| + * used in the program.
|
| + */
|
| + Map<String, Member> _lazyUsedMethods;
|
|
|
| bool isUsed = false;
|
| bool isNative = false;
|
| @@ -822,22 +835,22 @@ class DefinedType extends Type {
|
|
|
| _checkExtends();
|
|
|
| - if (_lazyGenMethods != null) {
|
| - for (var method in orderValuesByKeys(_lazyGenMethods)) {
|
| - world.gen.genMethod(method);
|
| + if (_lazyUsedMethods != null) {
|
| + for (var method in orderValuesByKeys(_lazyUsedMethods)) {
|
| + method.isUsed = true;
|
| }
|
| - _lazyGenMethods = null;
|
| + _lazyUsedMethods = null;
|
| }
|
|
|
| if (parent != null) parent.markUsed();
|
| }
|
|
|
| - void genMethod(Member method) {
|
| + void markUsedMethod(Member method) {
|
| if (isUsed) {
|
| - world.gen.genMethod(method);
|
| + method.isUsed = true;
|
| } else if (isClass) {
|
| - if (_lazyGenMethods == null) _lazyGenMethods = {};
|
| - _lazyGenMethods[method.name] = method;
|
| + if (_lazyUsedMethods == null) _lazyUsedMethods = <Member>{};
|
| + _lazyUsedMethods[method.name] = method;
|
| }
|
| }
|
|
|
|
|