예제 #1
0
        private void McClureRepeat(ref string sourceCode, Parser.Program ownerProgram)
        {
            string code           = sourceCode.Substring(sourceCode.IndexOf("repeat")).Trim();
            var    clureVariables = new List <McClureVariable>();
            string untilString    = code.Substring(McCabeMetrics.GetIndexEndOfRepeat(code));

            sourceCode  = sourceCode.Substring(McCabeMetrics.GetIndexEndOfRepeat(sourceCode));
            sourceCode  = sourceCode.Substring(sourceCode.IndexOf(";") + 1);
            untilString =
                untilString.Remove(untilString.IndexOf(";")).Substring(untilString.IndexOf("until") + 5);
            string[] variablesNames = GetNamesVariables(untilString);
            foreach (string name in variablesNames)
            {
                var variable = new McClureVariable();
                variable.OwnerProgram = ownerProgram;
                variable.Name         = name;
                clureVariables.Add(variable);
                variables.Add(variable);
            }
            foreach (McClureVariable variable in clureVariables)
            {
                AnalyzeBlock(code.Substring(6).Remove(McCabeMetrics.GetIndexEndOfRepeat(code)), variable, variable.Name,
                             0,
                             ownerProgram);
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Parser.Program program  = Parser.FindProgram(textBoxSourceCode.Text.ToLower());
            var            programs = new List <Parser.Program>();

            AddProgramToList(ref programs, program);
            programs.Remove(program);
            var mcCabe = new McCabeMetrics();

            mcCabe.SetSubprograms(programs);
            int mc = mcCabe.CalculateMcCabeMetrics(program.BlockBeginEnd) + 1;

            MessageBox.Show("Цикломатическая сложность программы = " + mc);
        }