Beispiel #1
0
 protected virtual string ToString(string constructName, HashSet <CFGBlockLogicalConstruct> printedCFGBlocks, LogicalFlowBuilderContext context)
 {
     V_0       = new StringBuilder();
     dummyVar0 = V_0.AppendLine(constructName);
     dummyVar1 = V_0.AppendLine("{");
     V_1       = this.GetSortedArrayFromCollection <CFGBlockLogicalConstruct>(this.get_CFGBlocks());
     V_2       = new Stack <CFGBlockLogicalConstruct>();
     V_4       = 0;
     while (V_4 < (int)V_1.Length)
     {
         V_5 = V_1[V_4] as CFGBlockLogicalConstruct;
         if (!printedCFGBlocks.Contains(V_5))
         {
             V_2.Push(V_5);
             while (V_2.get_Count() > 0)
             {
                 V_6 = V_2.Pop();
                 if (printedCFGBlocks.Contains(V_6) || !LogicalFlowUtilities.TryGetParentConstructWithGivenParent(V_6, this, out V_7))
                 {
                     continue;
                 }
                 stackVariable48    = ((LogicalConstructBase)V_7).ToString(V_7.GetType().get_Name(), printedCFGBlocks, context);
                 stackVariable50    = new String[1];
                 stackVariable50[0] = Environment.get_NewLine();
                 V_9  = stackVariable48.Split(stackVariable50, 1);
                 V_10 = 0;
                 while (V_10 < (int)V_9.Length)
                 {
                     V_11      = V_9[V_10];
                     dummyVar2 = V_0.AppendLine(String.Format("\t{0}", V_11));
                     V_10      = V_10 + 1;
                 }
                 V_8  = this.GetSortedArrayFromCollection <ISingleEntrySubGraph>(V_7.get_SameParentSuccessors());
                 V_12 = (int)V_8.Length - 1;
                 while (V_12 >= 0)
                 {
                     if (!printedCFGBlocks.Contains(V_8[V_12].get_FirstBlock()))
                     {
                         V_2.Push(V_8[V_12].get_FirstBlock());
                     }
                     V_12 = V_12 - 1;
                 }
             }
         }
         V_4 = V_4 + 1;
     }
     V_3       = String.Format("\tFollowNode: {0}", this.NodeILOffset(context, this.get_CFGFollowNode()));
     dummyVar3 = V_0.AppendLine(V_3);
     dummyVar4 = V_0.AppendLine("}");
     return(V_0.ToString());
 }
Beispiel #2
0
 private bool HasForParent(ILogicalConstruct supposedParent)
 {
     return(LogicalFlowUtilities.TryGetParentConstructWithGivenParent(this, supposedParent, out V_0));
 }
        /// <summary>
        /// Gets a string representation of this logical construct.
        /// </summary>
        /// <remarks>
        /// Used for testing purposes.
        /// </remarks>
        /// <param name="constructName">The name of the construct.</param>
        /// <param name="printedCFGBlocks">A set containing all of the CFG block logical constructs that are already traversed.</param>
        /// <param name="context">The current logical flow builder context.</param>
        /// <returns></returns>
        protected virtual string ToString(string constructName, HashSet <CFGBlockLogicalConstruct> printedCFGBlocks, LogicalFlowBuilderContext context)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(constructName);
            sb.AppendLine("{");

            ILogicalConstruct[] cfgBlocksArray = GetSortedArrayFromCollection(this.CFGBlocks);

            Stack <CFGBlockLogicalConstruct> printingStack = new Stack <CFGBlockLogicalConstruct>();

            for (int i = 0; i < cfgBlocksArray.Length; i++)
            {
                CFGBlockLogicalConstruct currentCFGBlock = cfgBlocksArray[i] as CFGBlockLogicalConstruct;

                //If the current node is already printed we skip it.
                if (printedCFGBlocks.Contains(currentCFGBlock))
                {
                    continue;
                }

                //We use a stack to print the constructs in preorder.
                printingStack.Push(currentCFGBlock);
                while (printingStack.Count > 0)
                {
                    CFGBlockLogicalConstruct blockToPrint = printingStack.Pop();
                    if (printedCFGBlocks.Contains(blockToPrint))
                    {
                        continue;
                    }

                    //Foreach CFG construct that is not printed we get the parent (not necessarily direct) logical construct that is child of this construct
                    //(i.e. childConstructToPrint is the child of this construct that contains the blockToPrint).
                    ILogicalConstruct childConstructToPrint;
                    if (!LogicalFlowUtilities.TryGetParentConstructWithGivenParent(blockToPrint, this, out childConstructToPrint))
                    {
                        continue;
                    }

                    string childString = ((LogicalConstructBase)childConstructToPrint).ToString(childConstructToPrint.GetType().Name, printedCFGBlocks, context);

                    //Indent each line of child's strings by one tab, so that they appear visually better
                    string[] childStringLines = childString.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string line in childStringLines)
                    {
                        sb.AppendLine(string.Format("\t{0}", line));
                    }

                    //We get a sorted array ot the child's same parent successors and we push their CFG logical construct entries in reverse order on the
                    //printing stack, so that the closest successor is going to be printed next.
                    ILogicalConstruct[] sameParentSuccessors = GetSortedArrayFromCollection(childConstructToPrint.SameParentSuccessors);

                    for (int j = sameParentSuccessors.Length - 1; j >= 0; j--)
                    {
                        if (!printedCFGBlocks.Contains(sameParentSuccessors[j].FirstBlock))
                        {
                            printingStack.Push(sameParentSuccessors[j].FirstBlock);
                        }
                    }
                }
            }

            string followNodeString = string.Format("\tFollowNode: {0}", NodeILOffset(context, CFGFollowNode));

            sb.AppendLine(followNodeString);
            sb.AppendLine("}");
            return(sb.ToString());
        }