Exemplo n.º 1
0
 /// <summary>
 /// True if the containers match, ignoring the statements in their bodies.
 /// </summary>
 /// <param name="st1"></param>
 /// <param name="st2"></param>
 /// <param name="allowBrokenLoops"></param>
 /// <param name="ignoreLoopDirection"></param>
 /// <returns></returns>
 internal static bool ContainersAreEqual(IStatement st1, IStatement st2, bool allowBrokenLoops = false, bool ignoreLoopDirection = false)
 {
     if (ReferenceEquals(st1, st2))
     {
         return(true);
     }
     if (st1 is IForStatement)
     {
         IForStatement ifs1 = (IForStatement)st1;
         if (st2 is IForStatement)
         {
             IForStatement ifs2 = (IForStatement)st2;
             if (ignoreLoopDirection && Recognizer.IsForwardLoop(ifs1) != Recognizer.IsForwardLoop(ifs2))
             {
                 ifs2 = (IForStatement)CreateContainer(ifs2);
                 Recognizer.ReverseLoopDirection(ifs2);
             }
             return(ifs1.Initializer.Equals(ifs2.Initializer) &&
                    ifs1.Condition.Equals(ifs2.Condition) &&
                    ifs1.Increment.Equals(ifs2.Increment) &&
                    (allowBrokenLoops || ((ifs1 is IBrokenForStatement) == (ifs2 is IBrokenForStatement))));
         }
         else
         {
             return(false);
         }
     }
     else if (st1 is IConditionStatement)
     {
         IConditionStatement ics1 = (IConditionStatement)st1;
         if (st2 is IConditionStatement)
         {
             IConditionStatement ics2 = (IConditionStatement)st2;
             return(ics1.Condition.Equals(ics2.Condition));
         }
         else
         {
             return(false);
         }
     }
     else if (st1 is IRepeatStatement)
     {
         IRepeatStatement irs1 = (IRepeatStatement)st1;
         if (st2 is IRepeatStatement)
         {
             IRepeatStatement irs2 = (IRepeatStatement)st2;
             return(irs1.Count.Equals(irs2.Count));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(st1 == st2);
     }
 }