static public Dictionary <string, int> FindFunctions(List <string> code) { foreach (var item in code) { string temp = Analyze.FindMethodName(item); _functionNames.Add(temp); _functions.Add(temp, Analyze.FindCode(item)); } _usedFunctions.Add("main()", 1); RecFind("main()"); return(_usedFunctions); }
static public Box NotMain(string filePath) { List <string> functions; List <string> analisisCode; List <string> methodNames; var box = new Box(); string fileCode = System.IO.File.ReadAllText(filePath); fileCode = Refactoring(fileCode); fileCode = RemoveString(fileCode, '"', '\''); var _functions = Analyze.GetFunctions(fileCode); var _functionNames = new List <string>(); foreach (var item in _functions) { _functionNames.Add(Analyze.FindMethodName(item)); } var _uselesNames = new List <string>(); methodNames = GetMethodName(GetFunctionContents(fileCode)); foreach (var name in methodNames) { if (!_functionNames.Contains(name + "()")) { _uselesNames.Add(name); } } foreach (var item in GetMethodName(GetFunctionContents(fileCode))) // Подготавливаем код проги { fileCode = fileCode.Replace(item + "(", " "); } functions = GetFunctionContents(fileCode); // Список функций foreach (var functionCode in functions) { var tempDict = new Dictionary <string, int>(); var alilya = new Dictionary <string, int>(); var variableSet = GetVariables(functionCode); // Список уникальных переменных foreach (var item in variableSet) { if (!alilya.ContainsKey(item)) { alilya.Add(item, GetCount(variableSet, item) * GetCount(methodNames, methodNames[functions.IndexOf(functionCode)]) - GetCount(methodNames, methodNames[functions.IndexOf(functionCode)])); } } box.FirstMetric.Add(methodNames[functions.IndexOf(functionCode)], alilya); } fileCode = RemoveString(fileCode, '[', ']'); functions = GetFunctionContents(fileCode); foreach (var functionCode in functions) { analisisCode = GetCodeForAnalysis(functionCode); // Список для ИИ var variableSet = GetVariables(functionCode).Distinct(); string functionName = methodNames[functions.IndexOf(functionCode)]; var tempVariableGroup = GetVariablesGroup(variableSet, analisisCode); var secondDick = new Dictionary <string, Dictionary <string, int> >(); foreach (var item in tempVariableGroup.Keys) // Получает Словарь переменных и в нем перебирает значения { var firstDick = new Dictionary <string, int>(); var variables = tempVariableGroup[item]; foreach (var vari in variables) { firstDick.Add(vari, GetCount(variables, vari) * GetCount(methodNames, functionName) - GetCount(methodNames, functionName)); } secondDick.Add(item, firstDick); } box.SecondMetric.Add(functionName, secondDick); } foreach (var functionCode in functions) { analisisCode = GetCodeForAnalysis(functionCode); var variableSet = GetVariables(functionCode).Distinct(); string functionName = methodNames[functions.IndexOf(functionCode)]; var tempVariableGroup = GetVariablesGroupIO(variableSet, analisisCode); var secondDick = new Dictionary <string, Dictionary <string, int> >(); foreach (var item in tempVariableGroup.Keys) // Получает Словарь переменных и в нем перебирает значения { var firstDick = new Dictionary <string, int>(); var variables = tempVariableGroup[item]; foreach (var vari in variables) { firstDick.Add(vari, GetCount(variables, vari) * GetCount(methodNames, functionName) - GetCount(methodNames, functionName)); } secondDick.Add(item, firstDick); } box.ThirdMetric.Add(functionName, secondDick); } foreach (var name in _uselesNames) { box.FirstMetric.Remove(name); box.SecondMetric.Remove(name); box.ThirdMetric.Remove(name); } return(box); }