public void AddType (TypeSpec ts)
{
if (types == null) {
types = new Dictionary<string, IList<TypeSpec>> (64);
}
var name = ts.Name;
IList<TypeSpec> existing;
if (types.TryGetValue (name, out existing)) {
TypeSpec better_type;
TypeSpec found;
if (existing.Count == 1) {
found = existing[0];
if (ts.Arity == found.Arity) {
better_type = IsImportedTypeOverride (ts, found);
if (better_type == found)
return;
if (better_type != null) {
existing [0] = better_type;
return;
}
}
existing = new List<TypeSpec> ();
existing.Add (found);
types[name] = existing;
} else {
for (int i = 0; i < existing.Count; ++i) {
found = existing[i];
if (ts.Arity != found.Arity)
continue;
better_type = IsImportedTypeOverride (ts, found);
if (better_type == found)
return;
if (better_type != null) {
existing.RemoveAt (i);
--i;
continue;
}
}
}
existing.Add (ts);
} else {
types.Add (name, new TypeSpec[] { ts });
}
}