Example #1
0
        /// Function - RunAllChecks
        /// <summary>
        /// Thread starts all checks.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="pathes"></param>
        static void RunAllChecks(string filePath, string destPath, string [] pathes, ArrayList tools)
        {
            //variable declaration.
            Hashtable keywords = new Hashtable();
            Hashtable includes = new Hashtable();
            Dictionary <string, string>    defines       = new Dictionary <string, string>();
            Dictionary <string, ArrayList> funcVariables = new Dictionary <string, ArrayList>();
            ArrayList globalVariable = new ArrayList();

            //initialize
            try
            {
                GeneralCompilerFunctions.initializeKeywordsAndSyntext(ansiCFile, filePath, CSyntextFile, ignoreVariablesTypesPath, keywords, includes, defines, pathes);
            }
            catch (Exception e)
            {
                AddToLogString(filePath, "ERROR IN PREPROCESSOR");
                ConnectionServer.CloseConnection(threadNumber, "ERROR IN PREPROCESSOR " + e.ToString(), GeneralConsts.ERROR);
            }

            AddToLogString(filePath, keywords.Count.ToString());
            //Syntax Check.
            try
            {
                compileError = GeneralCompilerFunctions.SyntaxCheck(filePath, globalVariable, keywords, funcVariables, threadNumber);
            }
            catch (Exception e)
            {
                AddToLogString(filePath, "ERROR IN SyntaxCheck");
                ConnectionServer.CloseConnection(threadNumber, "ERROR IN SyntaxCheck " + e.ToString(), GeneralConsts.ERROR);
            }

            if (!compileError)
            {
                GeneralCompilerFunctions.printArrayList(filePath, keywords);
                AddToLogString(filePath, keywords.Count.ToString());
                //just tests.
                try
                {
                    GeneralRestApiServerMethods.CreateFinalJson(filePath, includes, globalVariable, funcVariables, defines, final_json);
                }
                catch (Exception e)
                {
                    AddToLogString(filePath, "ERROR Creating final json");
                    ConnectionServer.CloseConnection(threadNumber, "ERROR Creating final json " + e.ToString(), GeneralConsts.ERROR);
                }

                string dataJson = JsonConvert.SerializeObject(final_json[filePath]["codeInfo"]);
                AddToLogString(filePath, "new json " + dataJson);
                Thread threadOpenTools = new Thread(() => RunAllTasks(filePath, destPath, tools));
                threadOpenTools.Start();
                threadOpenTools.Join(GeneralConsts.TIMEOUT_JOIN);
                ConnectionServer.CloseConnection(threadNumber, FINISH_SUCCESFULL, GeneralConsts.FINISHED_SUCCESFULLY);
                AddToLogString(filePath, FINISH_SUCCESFULL);
                Console.WriteLine(logFiles[filePath]);
                Thread writeToFile = new Thread(() => File.AppendAllText(logFile, logFiles[filePath]));
                writeToFile.Start();
                writeToFile.Join(GeneralConsts.TIMEOUT_JOIN);
            }
        }
        /// Fubnction - CreateFunctionsJsonFile
        /// <summary>
        /// function is creating the json file for the "Function" GET request.
        /// </summary>
        /// <param name="path"> path of the file that is being checked.</param>
        /// <param name="pattern"></param>
        /// <param name="variables"> Dictionary that every key on him is the function LINE and every value is an arrayList
        /// type "ParameterType" of all of his variables.
        /// </param>
        /// <param name="final_json"> the final big json.</param>
        static void CreateFunctionsJsonFile(string path, Regex pattern, Dictionary <string, ArrayList> variables, Dictionary <string, Dictionary <string, Object> > final_json)
        {
            string codeLine = GeneralConsts.EMPTY_STRING;
            string fName;

            string[] temp;
            string   returnType             = GeneralConsts.EMPTY_STRING;
            bool     exitFlag               = false;
            string   firstLineDocumentation = GeneralConsts.EMPTY_STRING;
            uint     curPos;
            Object   tempDict    = new Dictionary <string, FunctionInfoJson>();
            MyStream sr          = new MyStream(path, System.Text.Encoding.UTF8);
            uint     documentPos = sr.Pos;

            while (codeLine != null)
            {
                //saves the last documentation.
                while (!exitFlag && !FunctionPatternInC.IsMatch(codeLine))
                {
                    if (codeLine != null)
                    {
                        codeLine = sr.ReadLine();
                    }
                    firstLineDocumentation = GeneralConsts.EMPTY_STRING;
                    if (codeLine == null)
                    {
                        exitFlag = true;
                        break;
                    }
                    if (codeLine.IndexOf("//") != NOT_FOUND_STRING)
                    {
                        documentPos            = sr.Pos;
                        firstLineDocumentation = codeLine;
                    }
                    while ((codeLine.IndexOf("//") != NOT_FOUND_STRING))
                    {
                        if (codeLine != null)
                        {
                            codeLine = sr.ReadLine();
                        }
                    }
                    if ((codeLine.IndexOf("/*") != NOT_FOUND_STRING))
                    {
                        documentPos            = sr.Pos;
                        firstLineDocumentation = codeLine;
                        while (!(codeLine.IndexOf("*/") != NOT_FOUND_STRING))
                        {
                            if (codeLine != null)
                            {
                                codeLine = sr.ReadLine();
                            }
                        }
                        if ((codeLine.IndexOf("*/") != NOT_FOUND_STRING))
                        {
                            if (codeLine != null)
                            {
                                codeLine = sr.ReadLine();
                            }
                        }
                    }
                    if (codeLine == null)
                    {
                        exitFlag = true;
                    }
                }
                if (codeLine == null)
                {
                    exitFlag = true;
                }
                if (!exitFlag)
                {
                    fName = codeLine;
                    if (fName != null)
                    {
                        temp = Regex.Split(fName, @"\*|\s");
                        if (fName.IndexOf("static") != NOT_FOUND_STRING)
                        {
                            returnType = takeSecondNotNullString(temp);
                        }
                        else
                        {
                            returnType = temp[0];
                        }

                        returnType = returnType.Trim();
                        //enter function to where i store it.
                        Object tempStorage = new FunctionInfoJson();
                        GeneralCompilerFunctions.NextScopeLength(sr, ref codeLine, ref ((FunctionInfoJson)tempStorage).codeLength, true);
                        ((FunctionInfoJson)tempStorage).content    = FunctionCode(sr, ref codeLine);
                        ((FunctionInfoJson)tempStorage).parameters = FindParameters(fName);
                        ((FunctionInfoJson)tempStorage).returnType = returnType;
                        ((FunctionInfoJson)tempStorage).variables  = FindVariables(variables[fName]);
                        curPos = sr.Pos;
                        ((FunctionInfoJson)tempStorage).documentation = FindDocumentation(sr, documentPos, firstLineDocumentation, curPos);
                        ((Dictionary <string, FunctionInfoJson>)tempDict).Add(fName, (FunctionInfoJson)tempStorage);
                    }
                    else
                    {
                        exitFlag = true;
                    }
                }
                //add it to where i store the function code.
            }
            //Serialize.
            Dictionary <string, Object> tempOuterDict = new Dictionary <string, Object>();

            tempOuterDict.Add("function", tempDict);
            final_json.Add(path, tempOuterDict);
            sr.Close();
        }