public virtual TypeswitchCase GetClosestMatch(TypeswitchCase/*!*/ nd1, TypeswitchCaseList/*!*/ list1, TypeswitchCaseList list2, int list1pos, ref int list2start, TrivialHashtable/*!*/ matchedNodes, out Differences closestDifferences, out int list2pos) { closestDifferences = null; list2pos = -1; if (list2 == null) return null; if (nd1 == null || list1 == null || matchedNodes == null || list1pos < 0 || list1pos >= list1.Count || list2start < 0 || list2start >= list2.Count) { Debug.Assert(false); return null; } TypeswitchCase closest = null; Differences winnerSoFar = null; for (int j = list2start, m = list2.Count; j < m; j++){ TypeswitchCase nd2 = list2[j]; if (list2start == j) list2start++; if (nd2 == null) continue; if (matchedNodes[nd2.UniqueKey] != null) continue; Differences diff = this.GetDifferences(nd1, nd2); if (diff == null){Debug.Assert(false); continue;} if (diff.Similarity <= 0.5){ //Not a good enough match if (list2start == j+1) list2start--; //The next call to GetClosestMatch will start looking at list2start, so this node will be considered then continue; //ignore it for the rest of this call } if (winnerSoFar != null && winnerSoFar.Similarity >= diff.Similarity) continue; winnerSoFar = closestDifferences = diff; closest = nd2; list2pos = j; if (diff.NumberOfDifferences == 0) return closest; //Perfect match, no need to look for other matches } if (closest != null){ //^ assert winnerSoFar != null; //closest is closer to nd1 than any other node in list2, but this is no good if some other node in list1 has a better claim on closest for (int i = list1pos+1, n = list1.Count; i < n; i++){ TypeswitchCase nd1alt = list1[i]; if (nd1alt == null) continue; if (matchedNodes[nd1alt.UniqueKey] != null) continue; Differences diff = this.GetDifferences(nd1alt, closest); if (diff == null){Debug.Assert(false); continue;} if (diff.Similarity <= winnerSoFar.Similarity) continue; //nd1alt has a better claim on closest. See if it wants closest. Differences diff2; int j, k = list2start; TypeswitchCase nd2alt = this.GetClosestMatch(nd1alt, list1, list2, i, ref k, matchedNodes, out diff2, out j); if (nd2alt != closest){ Debug.Assert(nd2alt != null && diff2 != null && diff2.Similarity >= diff.Similarity); continue; //nd1alt prefers nd2alt to closest, so closest is still available } //nd1alt wants closest, take it out of the running matchedNodes[closest.UniqueKey] = nd1alt; //Now that closest is out of the running, try again k = list2start; TypeswitchCase newClosest = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out winnerSoFar, out list2pos); //put closest back in the running so that the next call to this routine will pick it up matchedNodes[closest.UniqueKey] = closest; closest = newClosest; break; } } closestDifferences = winnerSoFar; return closest; }
public virtual TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase, TypeswitchCase changes, TypeswitchCase deletions, TypeswitchCase insertions){ this.UpdateSourceContext(typeswitchCase, changes); if (typeswitchCase == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ } }else if (deletions != null) return null; return typeswitchCase; }
public virtual TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase){ if (typeswitchCase == null) return null; typeswitchCase.LabelType = this.VisitTypeReference(typeswitchCase.LabelType); typeswitchCase.LabelVariable = this.VisitTargetExpression(typeswitchCase.LabelVariable); typeswitchCase.Body = this.VisitBlock(typeswitchCase.Body); return typeswitchCase; }
public virtual Differences VisitTypeswitchCase(TypeswitchCase typeswitchCase1, TypeswitchCase typeswitchCase2){ Differences differences = new Differences(typeswitchCase1, typeswitchCase2); if (typeswitchCase1 == null || typeswitchCase2 == null){ if (typeswitchCase1 != typeswitchCase2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } TypeswitchCase changes = (TypeswitchCase)typeswitchCase2.Clone(); TypeswitchCase deletions = (TypeswitchCase)typeswitchCase2.Clone(); TypeswitchCase insertions = (TypeswitchCase)typeswitchCase2.Clone(); Differences diff = this.VisitBlock(typeswitchCase1.Body, typeswitchCase2.Body); if (diff == null){Debug.Assert(false); return differences;} changes.Body = diff.Changes as Block; deletions.Body = diff.Deletions as Block; insertions.Body = diff.Insertions as Block; Debug.Assert(diff.Changes == changes.Body && diff.Deletions == deletions.Body && diff.Insertions == insertions.Body); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitTypeNode(typeswitchCase1.LabelType, typeswitchCase2.LabelType); if (diff == null){Debug.Assert(false); return differences;} changes.LabelType = diff.Changes as TypeNode; deletions.LabelType = diff.Deletions as TypeNode; insertions.LabelType = diff.Insertions as TypeNode; //Debug.Assert(diff.Changes == changes.LabelType && diff.Deletions == deletions.LabelType && diff.Insertions == insertions.LabelType); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitExpression(typeswitchCase1.LabelVariable, typeswitchCase2.LabelVariable); if (diff == null){Debug.Assert(false); return differences;} changes.LabelVariable = diff.Changes as Expression; deletions.LabelVariable = diff.Deletions as Expression; insertions.LabelVariable = diff.Insertions as Expression; Debug.Assert(diff.Changes == changes.LabelVariable && diff.Deletions == deletions.LabelVariable && diff.Insertions == insertions.LabelVariable); 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 TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase){ if (typeswitchCase == null) return null; this.VisitResolvedTypeReference(typeswitchCase.LabelType, typeswitchCase.LabelTypeExpression); return base.VisitTypeswitchCase(typeswitchCase); }
public override TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase) { if (typeswitchCase == null) return null; this.switchCaseCount++; typeswitchCase.LabelType = this.VisitTypeReference(typeswitchCase.LabelType); typeswitchCase.LabelVariable = this.VisitTargetExpression(typeswitchCase.LabelVariable); typeswitchCase.Body = this.VisitBlock(typeswitchCase.Body); this.switchCaseCount--; return typeswitchCase; }
public override TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase) { throw new ApplicationException("unimplemented"); }
public override TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase) { if (typeswitchCase == null) return null; return base.VisitTypeswitchCase((TypeswitchCase)typeswitchCase.Clone()); }
public virtual TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase1, TypeswitchCase typeswitchCase2) { if (typeswitchCase1 == null) return null; if (typeswitchCase2 == null) { typeswitchCase1.LabelType = this.VisitTypeReference(typeswitchCase1.LabelType, null); typeswitchCase1.LabelVariable = this.VisitTargetExpression(typeswitchCase1.LabelVariable, null); typeswitchCase1.Body = this.VisitBlock(typeswitchCase1.Body, null); } else { typeswitchCase1.LabelType = this.VisitTypeReference(typeswitchCase1.LabelType, typeswitchCase2.LabelType); typeswitchCase1.LabelVariable = this.VisitTargetExpression(typeswitchCase1.LabelVariable, typeswitchCase2.LabelVariable); typeswitchCase1.Body = this.VisitBlock(typeswitchCase1.Body, typeswitchCase2.Body); } return typeswitchCase1; }
public override TypeswitchCase VisitTypeswitchCase(TypeswitchCase typeswitchCase){ if (typeswitchCase == null) return null; typeswitchCase.LabelType = this.VisitTypeReference(typeswitchCase.LabelType); Identifier targetId = typeswitchCase.LabelVariable as Identifier; if (targetId != null){ Field f = new Field(); f.DeclaringType = this.scope; f.Flags = FieldFlags.CompilerControlled|FieldFlags.InitOnly; f.Name = targetId; f.Type = typeswitchCase.LabelType; scope.Members.Add(f); typeswitchCase.LabelVariable = new MemberBinding(new ImplicitThis(this.scope, 0), f); typeswitchCase.LabelVariable.SourceContext = targetId.SourceContext; } typeswitchCase.Body = this.VisitBlock(typeswitchCase.Body); return typeswitchCase; }