public virtual TypeIntersection VisitTypeIntersection(TypeIntersection typeIntersection, TypeIntersection changes, TypeIntersection deletions, TypeIntersection insertions){ return (TypeIntersection)this.VisitTypeNode(typeIntersection, changes, deletions, insertions); }
public virtual TypeIntersection VisitTypeIntersection(TypeIntersection typeIntersection){ return (TypeIntersection)this.VisitTypeNode(typeIntersection); }
public virtual Differences VisitTypeIntersection(TypeIntersection typeIntersection1, TypeIntersection typeIntersection2){ Differences differences = this.GetMemberDifferences(typeIntersection1, typeIntersection2); if (differences == null){Debug.Assert(false); differences = new Differences(typeIntersection1, typeIntersection2);} if (differences.NumberOfDifferences > 0 || differences.NumberOfSimilarities > 0) return differences; if (typeIntersection1 == null || typeIntersection2 == null){ if (typeIntersection1 != typeIntersection2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } TypeIntersection changes = (TypeIntersection)typeIntersection2.Clone(); TypeIntersection deletions = (TypeIntersection)typeIntersection2.Clone(); TypeIntersection insertions = (TypeIntersection)typeIntersection2.Clone(); AttributeList attrChanges, attrDeletions, attrInsertions; Differences diff = this.VisitAttributeList(typeIntersection1.Attributes, typeIntersection2.Attributes, out attrChanges, out attrDeletions, out attrInsertions); if (diff == null){Debug.Assert(false); return differences;} changes.Attributes = attrChanges; deletions.Attributes = attrDeletions; insertions.Attributes = attrInsertions; differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (typeIntersection1.Flags == typeIntersection2.Flags) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++; diff = this.VisitIdentifier(typeIntersection1.Name, typeIntersection2.Name); if (diff == null){Debug.Assert(false); return differences;} changes.Name = diff.Changes as Identifier; deletions.Name = diff.Deletions as Identifier; insertions.Name = diff.Insertions as Identifier; Debug.Assert(diff.Changes == changes.Name && diff.Deletions == deletions.Name && diff.Insertions == insertions.Name); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; TypeNodeList typeChanges, typeDeletions, typeInsertions; diff = this.VisitTypeNodeList(typeIntersection1.TemplateParameters, typeIntersection2.TemplateParameters, out typeChanges, out typeDeletions, out typeInsertions); if (diff == null){Debug.Assert(false); return differences;} changes.TemplateParameters = typeChanges; deletions.TemplateParameters = typeDeletions; insertions.TemplateParameters = typeInsertions; differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitTypeNodeList(typeIntersection1.Types, typeIntersection2.Types, out typeChanges, out typeDeletions, out typeInsertions); if (diff == null){Debug.Assert(false); return differences;} changes.Types = typeChanges; deletions.Types = typeDeletions; insertions.Types = typeInsertions; differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
public override TypeNode VisitTypeReference(TypeNode type) { if (type == null) { return(null); } Class cl = type as Class; if (cl != null) { this.VisitTypeReference(cl.BaseClass); } if (this.MembersToFind[type.UniqueKey] != null) { this.FoundMembers[type.UniqueKey] = type; if (!this.insideMethodBody) { this.AllReferencesAreConfinedToMethodBodies = false; } return(type); } switch (type.NodeType) { case NodeType.ArrayType: ArrayType arrType = (ArrayType)type; this.VisitTypeReference(arrType.ElementType); return(type); case NodeType.DelegateNode: { FunctionType ftype = type as FunctionType; if (ftype == null) { goto default; } this.VisitTypeReference(ftype.ReturnType); this.VisitParameterList(ftype.Parameters); return(type); } case NodeType.Pointer: Pointer pType = (Pointer)type; this.VisitTypeReference(pType.ElementType); return(type); case NodeType.Reference: Reference rType = (Reference)type; this.VisitTypeReference(rType.ElementType); return(type); case NodeType.TupleType: { TupleType tType = (TupleType)type; MemberList members = tType.Members; int n = members == null ? 0 : members.Count; for (int i = 0; i < n; i++) { Field f = members[i] as Field; if (f == null) { continue; } this.VisitTypeReference(f.Type); } return(type); } case NodeType.TypeIntersection: TypeIntersection tIntersect = (TypeIntersection)type; this.VisitTypeReferenceList(tIntersect.Types); return(type); case NodeType.TypeUnion: TypeUnion tUnion = (TypeUnion)type; this.VisitTypeReferenceList(tUnion.Types); return(type); case NodeType.ArrayTypeExpression: ArrayTypeExpression aExpr = (ArrayTypeExpression)type; this.VisitTypeReference(aExpr.ElementType); return(type); case NodeType.BoxedTypeExpression: BoxedTypeExpression bExpr = (BoxedTypeExpression)type; this.VisitTypeReference(bExpr.ElementType); return(type); case NodeType.ClassExpression: ClassExpression cExpr = (ClassExpression)type; this.VisitExpression(cExpr.Expression); this.VisitTypeReferenceList(cExpr.TemplateArguments); return(type); case NodeType.ClassParameter: case NodeType.TypeParameter: return(type); case NodeType.ConstrainedType: ConstrainedType conType = (ConstrainedType)type; this.VisitTypeReference(conType.UnderlyingType); this.VisitExpression(conType.Constraint); return(type); case NodeType.FlexArrayTypeExpression: FlexArrayTypeExpression flExpr = (FlexArrayTypeExpression)type; this.VisitTypeReference(flExpr.ElementType); return(type); case NodeType.FunctionTypeExpression: FunctionTypeExpression ftExpr = (FunctionTypeExpression)type; this.VisitParameterList(ftExpr.Parameters); this.VisitTypeReference(ftExpr.ReturnType); return(type); case NodeType.InvariantTypeExpression: InvariantTypeExpression invExpr = (InvariantTypeExpression)type; this.VisitTypeReference(invExpr.ElementType); return(type); case NodeType.InterfaceExpression: InterfaceExpression iExpr = (InterfaceExpression)type; this.VisitExpression(iExpr.Expression); this.VisitTypeReferenceList(iExpr.TemplateArguments); return(type); case NodeType.NonEmptyStreamTypeExpression: NonEmptyStreamTypeExpression neExpr = (NonEmptyStreamTypeExpression)type; this.VisitTypeReference(neExpr.ElementType); return(type); case NodeType.NonNullTypeExpression: NonNullTypeExpression nnExpr = (NonNullTypeExpression)type; this.VisitTypeReference(nnExpr.ElementType); return(type); case NodeType.NonNullableTypeExpression: NonNullableTypeExpression nbExpr = (NonNullableTypeExpression)type; this.VisitTypeReference(nbExpr.ElementType); return(type); case NodeType.NullableTypeExpression: NullableTypeExpression nuExpr = (NullableTypeExpression)type; this.VisitTypeReference(nuExpr.ElementType); return(type); case NodeType.OptionalModifier: case NodeType.RequiredModifier: TypeModifier modType = (TypeModifier)type; this.VisitTypeReference(modType.ModifiedType); this.VisitTypeReference(modType.Modifier); return(type); case NodeType.PointerTypeExpression: PointerTypeExpression pExpr = (PointerTypeExpression)type; this.VisitTypeReference(pExpr.ElementType); return(type); case NodeType.ReferenceTypeExpression: ReferenceTypeExpression rExpr = (ReferenceTypeExpression)type; this.VisitTypeReference(rExpr.ElementType); return(type); case NodeType.StreamTypeExpression: StreamTypeExpression sExpr = (StreamTypeExpression)type; this.VisitTypeReference(sExpr.ElementType); return(type); case NodeType.TupleTypeExpression: TupleTypeExpression tuExpr = (TupleTypeExpression)type; this.VisitFieldList(tuExpr.Domains); return(type); case NodeType.TypeExpression: TypeExpression tExpr = (TypeExpression)type; this.VisitExpression(tExpr.Expression); this.VisitTypeReferenceList(tExpr.TemplateArguments); return(type); case NodeType.TypeIntersectionExpression: TypeIntersectionExpression tiExpr = (TypeIntersectionExpression)type; this.VisitTypeReferenceList(tiExpr.Types); return(type); case NodeType.TypeUnionExpression: TypeUnionExpression tyuExpr = (TypeUnionExpression)type; this.VisitTypeReferenceList(tyuExpr.Types); return(type); default: if (type.Template != null && type.TemplateArguments != null) { this.VisitTypeReference(type.Template); this.VisitTypeReferenceList(type.TemplateArguments); } return(type); } }
public virtual void VisitTypeIntersection(TypeIntersection typeIntersection){ this.VisitTypeNode(typeIntersection); }
public virtual Expression CoerceToTypeIntersection(Expression source, TypeNode sourceType, TypeIntersection targetType, bool explicitCoercion, TypeViewer typeViewer){ if (source == null || sourceType == null || targetType == null) return null; if (!explicitCoercion){ TypeNodeList types = targetType.Types; for (int i = 0, n = types == null ? 0 : types.Count; i < n; i++){ TypeNode t = types[i]; if (t == null) continue; if (!TypeViewer.GetTypeView(typeViewer, sourceType).IsAssignableTo(t)) return null; } } Method fromObject = TypeViewer.GetTypeView(typeViewer, targetType).GetMethod(StandardIds.FromObject, SystemTypes.Object); Method getType = Runtime.GetType; MethodCall fromObjectCall = new MethodCall(new MemberBinding(null, fromObject), new ExpressionList(source), NodeType.Call); fromObjectCall.Type = targetType; return fromObjectCall; }
public virtual bool ImplicitCoercionToIntersection(TypeNode sourceType, TypeIntersection intersect, TypeViewer typeViewer){ if (intersect == null) return false; TypeNodeList types = intersect.Types; for (int i = 0, n = types == null ? 0 : types.Count; i < n; i++){ TypeNode t = types[i]; if (t == null) continue; if (!this.ImplicitCoercionFromTo(sourceType, t, typeViewer)) return false; } return true; }
public EventingVisitor(Action<TypeIntersection> visitTypeIntersection) { VisitedTypeIntersection += visitTypeIntersection; } public event Action<TypeIntersection> VisitedTypeIntersection; public override TypeIntersection VisitTypeIntersection(TypeIntersection typeIntersection) { if (VisitedTypeIntersection != null) VisitedTypeIntersection(typeIntersection); return base.VisitTypeIntersection(typeIntersection); }