Ejemplo n.º 1
0
        private ElseStatement TraverseElseStatement(ElsePartSyntax eps, ref int returnCnt, bool nested = false)
        {
            ElseStatement elseStm = new ElseStatement();
            elseStm.IsNested = nested;
            foreach (StatementSyntax ss in eps.Statements)
            {
                if (ss is AssignmentStatementSyntax)
                {
                    //TODO: need to look at more than just then name!
                    Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax);

                    elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is LocalDeclarationStatementSyntax)
                {
                    Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax);
                    elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is SingleLineIfStatementSyntax)
                {
                    Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true);
                    elseStm.Nested.AddRange(decision.IfStatements);
                    elseStm.Nested.AddRange(decision.ElseStatements);
                }
                else if (ss is MultiLineIfBlockSyntax)
                {
                    Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true);
                    elseStm.Nested.AddRange(decisions.IfStatements);
                    elseStm.Nested.AddRange(decisions.ElseStatements);
                }
                else if (ss is ElseStatementSyntax)
                {
                    elseStm.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true));
                }
                else if (ss is ForBlockSyntax)
                {
                    Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true);
                    elseStm.Nested.AddRange(tempDecision.IfStatements);
                    elseStm.Nested.AddRange(tempDecision.ElseStatements);
                    elseStm.Nested.AddRange(tempDecision.ForEachStatements);
                    elseStm.Nested.AddRange(tempDecision.ForStatements);
                    elseStm.Nested.AddRange(tempDecision.WhileLoops);
                    elseStm.Nested.AddRange(tempDecision.DoWhileLoops);
                    elseStm.Nested.AddRange(tempDecision.Catches);
                    elseStm.Nested.AddRange(tempDecision.SwitchStatements);
                }
                else if (ss is SelectBlockSyntax)
                {
                    elseStm.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true));
                }
                else if (ss is DoLoopBlockSyntax)
                {
                    elseStm.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true));
                }
                else if (ss is WhileBlockSyntax)
                {
                    elseStm.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true));
                }
                else if (ss is CallStatementSyntax)
                {
                    elseStm.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax));
                }
                else if (ss is ReturnStatementSyntax)
                {
                    Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax);
                    elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    returnCnt++;
                }
            }

            return elseStm;
        }
Ejemplo n.º 2
0
        //TODO: Make sure we recursively go through each decision
        private Decisions TraverseIfStatement(SingleLineIfStatementSyntax sliss, ref int returnCnt, bool nested = false)
        {
            Decisions retDecision = new Decisions();
            IfStatement ifStm = new IfStatement();
            ifStm.IsNested = nested;
            //!!!!!!!!!!!!!!!!!!!!Start Here!!!!!!!!!!!!!!!!!!!
            SingleLineIfPartSyntax ifPart = sliss.IfPart;

            IfStatementSyntax iss = ifPart.Begin;

            BinaryExpressionSyntax bes = iss.Condition as BinaryExpressionSyntax;

            if (bes != null)
            {
                foreach (SyntaxNode sn in bes.DescendantNodesAndSelf())
                {
                    if (sn is BinaryExpressionSyntax)
                    {
                        ifStm.ConditionCount++;
                    }
                    else if (sn is IdentifierNameSyntax)
                    {
                        Variables variable = new Variables();
                        variable.IsReferenced = true;

                        variable.Name = (sn as IdentifierNameSyntax).Identifier.ValueText;
                        ifStm.AccessedVars.Add(variable);
                    }
                }
            }

            foreach (StatementSyntax ss in ifPart.Statements)
            {
                if (ss is AssignmentStatementSyntax)
                {
                    //TODO: need to look at more than just then name!
                    Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax);

                    ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is LocalDeclarationStatementSyntax)
                {
                    Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax);
                    ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is SingleLineIfStatementSyntax)
                {
                    Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true);
                    ifStm.Nested.AddRange(decision.IfStatements);
                    ifStm.Nested.AddRange(decision.ElseStatements);
                }
                else if (ss is MultiLineIfBlockSyntax)
                {
                    Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true);
                    ifStm.Nested.AddRange(decisions.IfStatements);
                    ifStm.Nested.AddRange(decisions.ElseStatements);
                }
                else if (ss is ElseStatementSyntax)
                {
                    ifStm.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true));
                }
                else if (ss is ForBlockSyntax)
                {
                    Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true);
                    ifStm.Nested.AddRange(tempDecision.IfStatements);
                    ifStm.Nested.AddRange(tempDecision.ElseStatements);
                    ifStm.Nested.AddRange(tempDecision.ForEachStatements);
                    ifStm.Nested.AddRange(tempDecision.ForStatements);
                    ifStm.Nested.AddRange(tempDecision.WhileLoops);
                    ifStm.Nested.AddRange(tempDecision.DoWhileLoops);
                    ifStm.Nested.AddRange(tempDecision.Catches);
                    ifStm.Nested.AddRange(tempDecision.SwitchStatements);
                }
                else if (ss is SelectBlockSyntax)
                {
                    ifStm.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true));
                }
                else if (ss is DoLoopBlockSyntax)
                {
                    ifStm.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true));
                }
                else if (ss is WhileBlockSyntax)
                {
                    ifStm.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true));
                }
                else if (ss is CallStatementSyntax)
                {
                    ifStm.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax));
                }
                else if (ss is ReturnStatementSyntax)
                {
                    Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax);
                    ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    returnCnt++;
                }
            }

            retDecision.IfStatements.Add(ifStm);

            if (sliss.ElsePart != null)
            {
                SingleLineElsePartSyntax sleps = sliss.ElsePart;
                ElseStatement elseStm = new ElseStatement();

                foreach (StatementSyntax ss in sleps.Statements)
                {
                    if (ss is AssignmentStatementSyntax)
                    {
                        //TODO: need to look at more than just then name!
                        Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax);

                        elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                        elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    }
                    else if (ss is LocalDeclarationStatementSyntax)
                    {
                        Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax);
                        elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                        elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    }
                    else if (ss is SingleLineIfStatementSyntax)
                    {
                        Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true);
                        elseStm.Nested.AddRange(decision.IfStatements);
                        elseStm.Nested.AddRange(decision.ElseStatements);
                    }
                    else if (ss is MultiLineIfBlockSyntax)
                    {
                        Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true);
                        elseStm.Nested.AddRange(decisions.IfStatements);
                        elseStm.Nested.AddRange(decisions.ElseStatements);
                    }
                    else if (ss is ElseStatementSyntax)
                    {
                        elseStm.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true));
                    }
                    else if (ss is ForBlockSyntax)
                    {
                        Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true);
                        ifStm.Nested.AddRange(tempDecision.IfStatements);
                        ifStm.Nested.AddRange(tempDecision.ElseStatements);
                        ifStm.Nested.AddRange(tempDecision.ForEachStatements);
                        ifStm.Nested.AddRange(tempDecision.ForStatements);
                        ifStm.Nested.AddRange(tempDecision.WhileLoops);
                        ifStm.Nested.AddRange(tempDecision.DoWhileLoops);
                        ifStm.Nested.AddRange(tempDecision.Catches);
                        ifStm.Nested.AddRange(tempDecision.SwitchStatements);
                    }
                    else if (ss is SelectBlockSyntax)
                    {
                        elseStm.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true));
                    }
                    else if (ss is DoLoopBlockSyntax)
                    {
                        elseStm.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true));
                    }
                    else if (ss is WhileBlockSyntax)
                    {
                        elseStm.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true));
                    }
                    else if (ss is CallStatementSyntax)
                    {
                        elseStm.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax));
                    }
                    else if (ss is ReturnStatementSyntax)
                    {
                        Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax);
                        elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                        elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                        returnCnt++;
                    }
                }
                retDecision.Add(elseStm);
            }

            return retDecision;
        }
Ejemplo n.º 3
0
        private ElseStatement TravsereElseStatement(ElseStatementSyntax ess, ref int returnCnt, bool nested = false)
        {
            ElseStatement elseStm = new ElseStatement();
            elseStm.IsNested = true;

            return elseStm;
        }
Ejemplo n.º 4
0
        private Decisions TraverseElseClauses(ElseClauseSyntax ecs, ref int exitPoints, bool nested = false)
        {
            Decisions retDecision = new Decisions();
            ElseStatement elseStm = new ElseStatement();

            if (ecs.HasLeadingTrivia)
            {
                SetOuterComments(elseStm, ecs.GetLeadingTrivia().ToFullString());
            }

            if (ecs.HasTrailingTrivia)
            {
                SetInnerComments(elseStm, ecs.GetTrailingTrivia().ToFullString());
            }

            elseStm.IsNested = nested;
            var binaryExpressions = from aBinaryExpression in ecs.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpression;
            foreach (BinaryExpressionSyntax bes in binaryExpressions)
            {
                Method tempMethod = TraverseBinaryExpression(bes);
                elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
            }
            var catches = from aCatch in ecs.ChildNodes().OfType<CatchClauseSyntax>() select aCatch;
            foreach (CatchClauseSyntax ccs in catches)
            {
                Decisions tempCatch = TraverseCatchClauses(ccs, ref exitPoints, true);
                elseStm.Nested.AddRange(tempCatch.Catches);
            }
            var elses = from aElse in ecs.ChildNodes().OfType<ElseClauseSyntax>() select aElse;
            foreach (ElseClauseSyntax ecs2 in elses)
            {
                Decisions tempElse = TraverseElseClauses(ecs2, ref exitPoints, true);
                elseStm.Nested.AddRange(tempElse.ElseStatements);
            }
            #region nested stuff
            var statements = from aStatement in ecs.ChildNodes().OfType<StatementSyntax>() select aStatement;
            foreach (StatementSyntax ss in statements)
            {
                if (ss is DoStatementSyntax)
                {
                    Decisions dwl = TraverseDoStatements(ss as DoStatementSyntax, ref exitPoints, true);
                    elseStm.Nested.AddRange(dwl.DoWhileLoops);
                }
                else if (ss is ExpressionStatementSyntax)
                {
                    Method tempMethod = TraverseExpressionStatementSyntax(ss as ExpressionStatementSyntax);
                    elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is ForEachStatementSyntax)
                {
                    Decisions fes = TraverseForEachStatements(ss as ForEachStatementSyntax, ref exitPoints, true);
                    elseStm.Nested.AddRange(fes.ForEachStatements);
                }
                else if (ss is ForStatementSyntax)
                {
                    Decisions fs = TraverseForStatements(ss as ForStatementSyntax, ref exitPoints, true);
                    elseStm.Nested.AddRange(fs.ForStatements);
                }
                else if (ss is IfStatementSyntax)
                {
                    Decisions decision = TraverseIfStatements(ss as IfStatementSyntax, ref exitPoints, true);
                    elseStm.Nested.AddRange(decision.IfStatements);
                }
                else if (ss is LocalDeclarationStatementSyntax)
                {
                    Model.Type tempType = new Model.Type();
                    LocalDeclarationStatementSyntax ldss = ss as LocalDeclarationStatementSyntax;
                    if (ldss.Declaration != null)
                    {
                        VariableDeclarationSyntax vds = ldss.Declaration;
                        tempType.Name = vds.Type.ToString();
                        tempType.IsKnownType = true;
                        tempType.IsNotUserDefined = true;
                    }
                    Method tempMethod = TransverseAccessVars(ss as LocalDeclarationStatementSyntax);
                    //NOT SURE if this will work but here goes
                    tempMethod.AccessedVariables[0].Type = tempType;
                    elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is ReturnStatementSyntax)
                {
                    exitPoints++;
                }
                else if (ss is SwitchStatementSyntax)
                {
                    Decisions switchStm = TraverseSwitchStatements(ss as SwitchStatementSyntax, ref exitPoints, true);
                    elseStm.Nested.AddRange(switchStm.SwitchStatements);
                }
                else if (ss is WhileStatementSyntax)
                {
                    Decisions wl = TraverseWhileLoops(ss as WhileStatementSyntax, ref exitPoints, true);
                    elseStm.Nested.AddRange(wl.WhileLoops);
                }
            }
            #endregion
            retDecision.ElseStatements.Add(elseStm);
            return retDecision;
        }