public virtual Differences VisitFaultHandlerList(FaultHandlerList list1, FaultHandlerList list2,
   out FaultHandlerList changes, out FaultHandlerList deletions, out FaultHandlerList insertions){
   changes = list1 == null ? null : list1.Clone();
   deletions = list1 == null ? null : list1.Clone();
   insertions = list1 == null ? new FaultHandlerList() : list1.Clone();
   //^ assert insertions != null;
   Differences differences = new Differences();
   for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
     //^ assert list2 != null;
     FaultHandler nd2 = list2[j];
     if (nd2 == null) continue;
     insertions.Add(null);
   }
   TrivialHashtable savedDifferencesMapFor = this.differencesMapFor;
   this.differencesMapFor = null;
   TrivialHashtable matchedNodes = new TrivialHashtable();
   for (int i = 0, k = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     FaultHandler nd1 = list1[i]; 
     if (nd1 == null) continue;
     Differences diff;
     int j;
     FaultHandler nd2 = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out diff, out j);
     if (nd2 == null || diff == null){Debug.Assert(nd2 == null && diff == null); continue;}
     matchedNodes[nd1.UniqueKey] = nd1;
     matchedNodes[nd2.UniqueKey] = nd2;
     changes[i] = diff.Changes as FaultHandler;
     deletions[i] = diff.Deletions as FaultHandler;
     insertions[i] = diff.Insertions as FaultHandler;
     insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
     Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
     differences.NumberOfDifferences += diff.NumberOfDifferences;
     differences.NumberOfSimilarities += diff.NumberOfSimilarities;
   }
   //Find deletions
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     FaultHandler nd1 = list1[i]; 
     if (nd1 == null) continue;
     if (matchedNodes[nd1.UniqueKey] != null) continue;
     changes[i] = null;
     deletions[i] = nd1;
     insertions[i] = null;
     differences.NumberOfDifferences += 1;
   }
   //Find insertions
   for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
     //^ assert list2 != null;
     FaultHandler nd2 = list2[j]; 
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     insertions[n+j] = nd2;  //Records nd2 as an insertion into list1, along with its position in list2
     differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
   }
   if (differences.NumberOfDifferences == 0){
     changes = null;
     deletions = null;
     insertions = null;
   }
   this.differencesMapFor = savedDifferencesMapFor;
   return differences;
 }
Beispiel #2
0
 public virtual FaultHandlerList VisitFaultHandlerList(FaultHandlerList faultHandlers, FaultHandlerList changes, FaultHandlerList deletions, FaultHandlerList insertions){
   if (changes == null || deletions == null || insertions == null) return faultHandlers;
   int n = faultHandlers == null ? 0 : faultHandlers.Count;
   if (n > changes.Count){Debug.Assert(false); n = changes.Count;}
   if (n > deletions.Count){Debug.Assert(false); n = deletions.Count;}
   if (n > insertions.Count){Debug.Assert(false); n = insertions.Count;}
   if (faultHandlers != null)
     for (int i = 0; i < n; i++)
       faultHandlers[i] = this.VisitFaultHandler(faultHandlers[i], changes[i], deletions[i], insertions[i]);
   FaultHandlerList result = new FaultHandlerList(insertions.Count-n);
   for (int i = n, m = insertions.Count; i < m; i++)
     result.Add(insertions[i]);
   return result;
 }
Beispiel #3
0
 public virtual FaultHandlerList VisitFaultHandlerList(FaultHandlerList faultHandlers){
   if (faultHandlers == null) return null;
   for (int i = 0, n = faultHandlers.Count; i < n; i++)
     faultHandlers[i] = (FaultHandler)this.VisitFaultHandler(faultHandlers[i]);
   return faultHandlers;
 }
 public virtual FaultHandler GetClosestMatch(FaultHandler/*!*/ nd1, FaultHandlerList/*!*/ list1, FaultHandlerList 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;
   }
   FaultHandler closest = null;
   Differences winnerSoFar = null;
   for (int j = list2start, m = list2.Count; j < m; j++){
     FaultHandler 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++){
       FaultHandler 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;
       FaultHandler 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;
       FaultHandler 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;
 }
Beispiel #5
0
 public virtual void VisitFaultHandlerList(FaultHandlerList faultHandlers)
 {
   if (faultHandlers == null) return;
   for (int i = 0, n = faultHandlers.Count; i < n; i++)
     this.VisitFaultHandler(faultHandlers[i]);
 }
Beispiel #6
0
 public override FaultHandlerList VisitFaultHandlerList(FaultHandlerList faultHandlers)
 {
     if (faultHandlers == null) return null;
     return base.VisitFaultHandlerList(faultHandlers.Clone());
 }
 public virtual FaultHandlerList VisitFaultHandlerList(FaultHandlerList faultHandlers1, FaultHandlerList faultHandlers2)
 {
     if (faultHandlers1 == null) return null;
     for (int i = 0, n = faultHandlers1.Count, m = faultHandlers2 == null ? 0 : faultHandlers2.Count; i < n; i++)
     {
         //^ assert faultHandlers2 != null;
         if (i >= m)
             faultHandlers1[i] = (FaultHandler)this.VisitFaultHandler(faultHandlers1[i], null);
         else
             faultHandlers1[i] = (FaultHandler)this.VisitFaultHandler(faultHandlers1[i], faultHandlers2[i]);
     }
     return faultHandlers1;
 }
Beispiel #8
0
 public Try(Block tryBlock, CatchList catchers, FilterList filters, FaultHandlerList faultHandlers, Finally Finally)
     : base(NodeType.Try)
 {
     this.catchers = catchers;
     this.faultHandlers = faultHandlers;
     this.filters = filters;
     this.finallyClause = Finally;
     this.tryBlock = tryBlock;
 }
 public EventingVisitor(Action<FaultHandlerList> visitFaultHandlerList) { VisitedFaultHandlerList += visitFaultHandlerList; } public event Action<FaultHandlerList> VisitedFaultHandlerList; public override FaultHandlerList VisitFaultHandlerList(FaultHandlerList faultHandlers) { if (VisitedFaultHandlerList != null) VisitedFaultHandlerList(faultHandlers); return base.VisitFaultHandlerList(faultHandlers); }