예제 #1
0
        /// <summary>
        ///     Processes the file with the settings, definitions and the source manager specified.
        /// </summary>
        /// <param name="files">the file paths to be processed</param>
        /// <param name="settings">the settings that are used</param>
        /// <param name="defs">the definitions that are used</param>
        /// <returns>Returns a list of files that can be compiled in reverse order</returns>
        private ISourceScript[] Process(IFileContent[] files, Settings settings, IDefinitions defs)
        {
            Logger.Log(LogType.Log, "Preprocessing files: " + files.Unpack(", "), 1);
            Timer.GlobalTimer.Restart();
            IDefinitions definitions = defs ?? new Definitions();

            settings = settings ?? new Settings();
            SourceManager sm = new SourceManager(plugins);

            InitializePlugins(settings, definitions, sm);

            foreach (IFileContent file in files)
            {
                sm.SetLock(false);
                sm.TryCreateScript(out ISourceScript sss, sep, file, new ImportResult(), false);
                sm.SetLock(true);
                sm.AddToTodo(sss);
            }

            ISourceScript ss = sm.NextItem;

            do
            {
                Logger.Log(LogType.Log, "Selecting Current File: " + ss.GetFileInterface().GetFilePath(), 2);


                if (!(ss as SourceScript).IsSourceLoaded)
                {
                    RunStages(this, ProcessStage.OnLoadStage, ss, sm, definitions);
                }

                Logger.Log(LogType.Log, $"Selecting File: {Path.GetFileName(ss.GetFileInterface().GetKey())}", 3);

                //RUN MAIN
                sm.SetLock(false);
                RunStages(this, ProcessStage.OnMain, ss, sm, definitions);
                sm.SetLock(true);
                sm.SetState(ss, ProcessStage.OnFinishUp);
                ss = sm.NextItem;
            } while (ss != null);


            ISourceScript[] ret = sm.GetList().ToArray();

            foreach (ISourceScript finishedScript in ret)
            {
                Logger.Log(
                    LogType.Log,
                    $"Selecting File: {Path.GetFileName(finishedScript.GetFileInterface().GetKey())}",
                    3
                    );
                RunStages(this, ProcessStage.OnFinishUp, finishedScript, sm, definitions);
            }

            Logger.Log(LogType.Log, "Finished Processing Files.", 2);


            return(ret);
        }
예제 #2
0
        private bool GetISourceScript(
            ISourceManager manager,
            string statement,
            string currentPath,
            bool isInline,
            out List <ISourceScript> scripts)
        {
            string[] vars = Utils.SplitAndRemoveFirst(statement, Separator);

            scripts = new List <ISourceScript>();

            if (vars.Length != 0)
            {
                ImportResult importInfo = manager.GetComputingScheme()(vars, currentPath);

                if (!importInfo)
                {
                    Logger.Log(LogType.Error, "Invalid Include Statement", 1);

                    return(false);
                }

                string filepath = importInfo.GetString("filename");
                importInfo.RemoveEntry("filename");
                string key = importInfo.GetString("key");
                importInfo.RemoveEntry("key");
                string originalDefinedName = importInfo.GetString("definedname");
                importInfo.RemoveEntry("definedname");

                IFileContent cont = new FilePathContent(filepath, originalDefinedName);
                cont.SetKey(key);

                if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo, isInline))
                {
                    scripts.Add(iss);
                }

                for (int index = scripts.Count - 1; index >= 0; index--)
                {
                    ISourceScript sourceScript = scripts[index];

                    if (sourceScript.GetFileInterface().HasValidFilepath&&
                        !Utils.FileExistsRelativeTo(currentPath, sourceScript.GetFileInterface()))
                    {
                        Logger.Log(LogType.Error, $"Could not find File: {sourceScript.GetFileInterface()}", 1);
                        scripts.RemoveAt(index);
                    }
                }

                return(true);
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fullScriptStage">The chain for this stage</param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">The script to operate on</param>
        /// <param name="sourceManager">The sourcemanager used.</param>
        /// <param name="defTable">The definitions used</param>
        /// <returns></returns>
        private bool RunFullScriptStage(List <AbstractPlugin> fullScriptStage, ProcessStage stage, ISourceScript script,
                                        ISourceManager sourceManager, IDefinitions defTable)
        {
            foreach (AbstractPlugin abstractPlugin in fullScriptStage)
            {
                bool ret = true;
                Logger.Log(PPLogType.Log, Verbosity.Level3, "Running Plugin: {0}: {1} on file {2}", abstractPlugin,
                           stage, Path.GetFileName(script.GetFileInterface().GetKey()));
                if (stage == ProcessStage.OnLoadStage)
                {
                    ret = abstractPlugin.OnLoad_FullScriptStage(script, sourceManager, defTable);
                }
                else if (stage == ProcessStage.OnMain)
                {
                    ret = abstractPlugin.OnMain_FullScriptStage(script, sourceManager, defTable);
                }

                if (!ret)
                {
                    Logger.Log(PPLogType.Error, Verbosity.Level1, "Processing was aborted by Plugin: {0}",
                               abstractPlugin);
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Sets the processing state of the script to done
        /// it will not be returned by the NextItem property.
        /// </summary>
        /// <param name="script">The script to set the stage for</param>
        public void SetState(ISourceScript script, ProcessStage stage)
        {
            if (IsIncluded(script))
            {
                doneState[IndexOfFile(script.GetKey())] = stage;

                Logger.Log(PPLogType.Log, Verbosity.Level3, "Finished Script: {0}",
                           Path.GetFileName(script.GetFileInterface().GetKey()));
            }
        }
예제 #5
0
 /// <summary>
 /// Adds a script to the to do list of the source manager.
 /// Will do nothing if already included
 /// </summary>
 /// <param name="script">The script to enqueue for computation</param>
 public void AddToTodo(ISourceScript script)
 {
     if (!IsIncluded(script))
     {
         Logger.Log(PPLogType.Log, Verbosity.Level3, "Adding Script to Todo List: {0}",
                    Path.GetFileName(script.GetFileInterface().GetKey()));
         AddFile(script, false);
         doneState.Add(ProcessStage.Queued);
     }
 }
예제 #6
0
        /// <summary>
        /// Fixes the order of the file tree if a script was being loaded and is now referenced (again)
        /// by removing it from the lower position and readding it at the top
        /// </summary>
        /// <param name="script">The script that got referenced.</param>
        public void FixOrder(ISourceScript script)
        {
            Logger.Log(PPLogType.Log, Verbosity.Level3, "Fixing Build Order of file: {0}",
                       Path.GetFileName(script.GetFileInterface().GetKey()));
            int           idx = IndexOfFile(script.GetKey());
            ISourceScript a   = sources[idx];
            ProcessStage  ab  = doneState[idx];

            doneState.RemoveAt(idx);
            doneState.Add(ab);
            sources.RemoveAt(idx);
            AddFile(a, true);
        }
예제 #7
0
        /// <summary>
        ///     Fixes the order of the file tree if a script was being loaded and is now referenced (again)
        ///     by removing it from the lower position and readding it at the top
        /// </summary>
        /// <param name="script">The script that got referenced.</param>
        public void FixOrder(ISourceScript script)
        {
            Logger.Log(
                LogType.Log,
                $"Fixing Build Order of file: {Path.GetFileName(script.GetFileInterface().GetKey())}",
                3
                );
            int           idx = IndexOfFile(script.GetKey());
            ISourceScript a   = sources[idx];

            ProcessStage ab = doneState[idx];

            if (!a.IsInline)
            {
                doneState.RemoveAt(idx);
                doneState.Add(ab);
                sources.RemoveAt(idx);
                AddFile(a, true);
            }
        }
예제 #8
0
        public override bool FullScriptStage(ISourceScript script, ISourceManager sourceManager, IDefinitions defs)
        {
            Logger.Log(LogType.Log, "Disovering Include Statments...", PLUGIN_MIN_SEVERITY);
            List <string> source      = script.GetSource().ToList();
            string        currentPath = Path.GetDirectoryName(script.GetFileInterface().GetFilePath());
            bool          hasIncludedInline;

            do
            {
                hasIncludedInline = false;
                for (int i = source.Count - 1; i >= 0; i--)
                {
                    if (Utils.IsStatement(source[i], IncludeInlineKeyword))
                    {
                        Logger.Log(LogType.Log, "Found Inline Include Statement...", PLUGIN_MIN_SEVERITY + 1);
                        string[] args = Utils.SplitAndRemoveFirst(source[i], Separator);
                        if (args.Length == 0)
                        {
                            Logger.Log(LogType.Error, "No File Specified", 1);
                            continue;
                        }

                        if (Utils.FileExistsRelativeTo(currentPath, args[0]))
                        {
                            Logger.Log(LogType.Log, "Replacing Inline Keyword with file content",
                                       PLUGIN_MIN_SEVERITY + 2);
                            source.RemoveAt(i);

                            source.InsertRange(i, IOManager.ReadAllLines(Path.Combine(currentPath, args[0])));
                            hasIncludedInline = true;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"File does not exist: {args[0]}", 1);
                        }
                    }
                }

                script.SetSource(source.ToArray());
            } while (hasIncludedInline);


            string[] incs = Utils.FindStatements(source.ToArray(), IncludeKeyword);

            foreach (string includes in incs)
            {
                Logger.Log(LogType.Log, $"Processing Statement: {includes}", PLUGIN_MIN_SEVERITY + 1);
                bool tmp = GetISourceScript(sourceManager, includes, currentPath, out List <ISourceScript> sources);
                if (tmp)
                {
                    foreach (ISourceScript sourceScript in sources)
                    {
                        Logger.Log(LogType.Log,
                                   $"Processing Include: {Path.GetFileName(sourceScript.GetFileInterface().GetKey())}",
                                   PLUGIN_MIN_SEVERITY + 2);

                        if (!sourceManager.IsIncluded(sourceScript))
                        {
                            sourceManager.AddToTodo(sourceScript);
                        }
                        else
                        {
                            sourceManager.FixOrder(sourceScript);
                        }
                    }
                }
                else
                {
                    return
                        (false); //We crash if we didnt find the file. but if the user forgets to specify the path we will just log the error
                }
            }

            Logger.Log(LogType.Log, "Inclusion of Files Finished", PLUGIN_MIN_SEVERITY);
            return(true);
        }
예제 #9
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            Logger.Log(LogType.Log,
                       $"Starting Condition Solver passes on file: {Path.GetFileName(file.GetFileInterface().GetKey())}",
                       PLUGIN_MIN_SEVERITY);
            bool          ret             = true;
            int           openIf          = 0;
            bool          foundConditions = false;
            bool          elseIsValid     = false;
            bool          expectEndOrIf   = false;
            List <string> lastPass        = file.GetSource().ToList();
            List <string> solvedFile      = new List <string>();
            int           passCount       = 0;

            do
            {
                passCount++;
                Logger.Log(LogType.Log, $"Starting Condition Solver pass: {passCount}", PLUGIN_MIN_SEVERITY + 1);

                foundConditions = false;
                elseIsValid     = false;
                for (int i = 0; i < lastPass.Count; i++)
                {
                    string line = lastPass[i].TrimStart();
                    if (IsKeyWord(line, StartCondition))
                    {
                        Logger.Log(LogType.Log, $"Found a {StartCondition} Statement", PLUGIN_MIN_SEVERITY + 2);
                        KeyValuePair <bool, int> prep = PrepareForConditionalEvaluation(line, defs,
                                                                                        lastPass, i,
                                                                                        solvedFile);

                        elseIsValid = prep.Key;
                        i          += prep.Value;

                        openIf++;
                        foundConditions = true;
                        expectEndOrIf   = false;
                    }
                    else if (elseIsValid && IsKeyWord(line, ElseIfCondition))
                    {
                        Logger.Log(LogType.Log, $"Found a {ElseIfCondition} Statement", PLUGIN_MIN_SEVERITY + 2);
                        if (!expectEndOrIf && openIf > 0)
                        {
                            KeyValuePair <bool, int> prep = PrepareForConditionalEvaluation(line, defs,
                                                                                            lastPass, i,
                                                                                            solvedFile);

                            elseIsValid     = prep.Key;
                            i              += prep.Value;
                            foundConditions = true;
                        }
                        else if (expectEndOrIf)
                        {
                            Logger.Log(LogType.Error, $"A {ElseCondition} can not be followed by an {ElseIfCondition}",
                                       1);
                            ret = false;
                            break;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"A {ElseIfCondition} should be preceeded by a {StartCondition}",
                                       1);
                            ret = false;
                            break;
                        }
                    }
                    else if (IsKeyWord(line, ElseCondition))
                    {
                        if (openIf > 0)
                        {
                            Logger.Log(LogType.Log, $"Found a {ElseCondition} Statement", PLUGIN_MIN_SEVERITY + 2);
                            int size = GetBlockSize(lastPass, i);
                            if (elseIsValid)
                            {
                                solvedFile.AddRange(lastPass.SubArray(i + 1, size));
                                Logger.Log(LogType.Log, "Adding Branch To Solved File.", PLUGIN_MIN_SEVERITY + 3);
                            }
                            else
                            {
                                Logger.Log(LogType.Log,
                                           "Ignored since a previous condition was true", PLUGIN_MIN_SEVERITY + 3);
                            }

                            i += size;
                            foundConditions = true;
                            expectEndOrIf   = true;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"A {ElseCondition} should be preceeded by a {StartCondition}",
                                       1);
                            ret = false;
                            break;
                        }
                    }
                    else if (IsKeyWord(line, EndCondition))
                    {
                        if (openIf > 0)
                        {
                            expectEndOrIf = false;
                            openIf--;
                        }
                        else
                        {
                            ret = false;

                            Logger.Log(LogType.Error, $"A {EndCondition} should be preceeded by a {StartCondition}", 1);
                            break;
                        }
                    }
                    else if (EnableDefine &&
                             line.StartsWith(DefineKeyword))
                    {
                        Logger.Log(LogType.Log, $"Found a {DefineKeyword} Statement", PLUGIN_MIN_SEVERITY + 2);
                        defs.Set(Utils.SplitAndRemoveFirst(line, Separator));
                        solvedFile.Add(lastPass[i]);
                    }
                    else if (EnableUndefine &&
                             line.StartsWith(UndefineKeyword))
                    {
                        Logger.Log(LogType.Log, $"Found a {UndefineKeyword} Statement", PLUGIN_MIN_SEVERITY + 2);
                        defs.Unset(Utils.SplitAndRemoveFirst(line, Separator));
                        solvedFile.Add(lastPass[i]);
                    }
                    else
                    {
                        solvedFile.Add(lastPass[i]);
                    }
                }

                if (ret)
                {
                    lastPass = solvedFile;
                }
                else
                {
                    break;
                }

                solvedFile = new List <string>();
            } while (foundConditions);

            file.SetSource(lastPass.ToArray());


            Logger.Log(LogType.Log, "Conditional Solver Finished", PLUGIN_MIN_SEVERITY);

            return(ret);
        }
예제 #10
0
        /// <summary>
        /// Processes the file with the settings, definitions and the source manager specified.
        /// </summary>
        /// <param name="files">the file paths to be processed</param>
        /// <param name="settings">the settings that are used</param>
        /// <param name="defs">the definitions that are used</param>
        /// <returns>Returns a list of files that can be compiled in reverse order</returns>
        private ISourceScript[] Process(IFileContent[] files, Settings settings, IDefinitions defs)
        {
            Timer.GlobalTimer.Restart();
            //string dir = Directory.GetCurrentDirectory();
            IDefinitions definitions = defs ?? new Definitions();

            settings = settings ?? new Settings();
            SourceManager sm = new SourceManager(plugins);

            long old = Timer.MS;

            InitializePlugins(settings, definitions, sm);
            Logger.Log(PPLogType.Progress, Verbosity.Level1, "Finished Initializing {1} Plugins({0}ms)", Timer.MS - old,
                       plugins.Count);

            old = Timer.MS;
            foreach (IFileContent file in files)
            {
                sm.SetLock(false);
                sm.TryCreateScript(out ISourceScript sss, sep, file, new ImportResult());
                sm.SetLock(true);
                sm.AddToTodo(sss);
            }

            Logger.Log(PPLogType.Progress, Verbosity.Level1, "Loaded {1} Files in {0}ms", Timer.MS - old,
                       sm.GetTodoCount());

            Logger.Log(PPLogType.Log, Verbosity.Level1, "Starting Processing of Files: {0}", files.Unpack(", "));

            old = Timer.MS;
            ISourceScript ss = sm.NextItem;

            do
            {
                if (!(ss as SourceScript).IsSourceLoaded)
                {
                    RunStages(this, ProcessStage.OnLoadStage, ss, sm, definitions);
                }

                Logger.Log(PPLogType.Progress, Verbosity.Level1, "Remaining Files: {0}", sm.GetTodoCount());
                Logger.Log(PPLogType.Log, Verbosity.Level2, "Selecting File: {0}",
                           Path.GetFileName(ss.GetFileInterface().GetKey()));
                //RUN MAIN
                sm.SetLock(false);
                RunStages(this, ProcessStage.OnMain, ss, sm, definitions);
                sm.SetLock(true);
                sm.SetState(ss, ProcessStage.OnFinishUp);
                ss = sm.NextItem;
            } while (ss != null);


            //Directory.SetCurrentDirectory(dir);
            ISourceScript[] ret = sm.GetList().ToArray();
            Logger.Log(PPLogType.Log, Verbosity.Level1, "Finishing Up...");
            foreach (ISourceScript finishedScript in ret)
            {
                Logger.Log(PPLogType.Log, Verbosity.Level2, "Selecting File: {0}",
                           Path.GetFileName(finishedScript.GetFileInterface().GetKey()));
                RunStages(this, ProcessStage.OnFinishUp, finishedScript, sm, definitions);
            }
            Logger.Log(PPLogType.Log, Verbosity.Level1, "Finished Processing Files.");

            Logger.Log(PPLogType.Progress, Verbosity.Level1, "Processed {1} Files into {2} scripts in {0}ms",
                       Timer.MS - old, sm.GetList().Count, ret.Length);

            return(ret);
        }
예제 #11
0
        /// <summary>
        ///
        /// </summary>

        /// <param name="fullScriptStage">The chain for this stage</param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">The script to operate on</param>
        /// <param name="sourceManager">The sourcemanager used.</param>
        /// <param name="defTable">The definitions used</param>
        /// <returns></returns>
        private bool RunFullScriptStage(List <AbstractPlugin> fullScriptStage, ProcessStage stage, ISourceScript script, ISourceManager sourceManager, IDefinitions defTable)
        {
            foreach (var abstractPlugin in fullScriptStage)
            {
                bool ret = true;
                this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Running Plugin: {0}: {1} on file {2}", abstractPlugin, stage, Path.GetFileName(script.GetFileInterface().GetKey()));
                if (stage == ProcessStage.ON_LOAD_STAGE)
                {
                    ret = abstractPlugin.OnLoad_FullScriptStage(script, sourceManager, defTable);
                }
                else if (stage == ProcessStage.ON_MAIN)
                {
                    ret = abstractPlugin.OnMain_FullScriptStage(script, sourceManager, defTable);
                }

                if (!ret)
                {
                    this.Error("Processing was aborted by Plugin: {0}", abstractPlugin);
                    return(false);
                }
            }

            return(true);
        }
예제 #12
0
        /// <summary>
        /// Sets the processing state of the script to done
        /// it will not be returned by the NextItem property.
        /// </summary>
        /// <param name="script">The script to set the stage for</param>
        public void SetState(ISourceScript script, ProcessStage stage)
        {
            if (IsIncluded(script))
            {
                _doneState[IndexOfFile(script.GetKey())] = stage;

                this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Finished Script: {0}", Path.GetFileName(script.GetFileInterface().GetKey()));
            }
        }
예제 #13
0
 /// <summary>
 /// Adds a script to the to do list of the source manager.
 /// Will do nothing if already included
 /// </summary>
 /// <param name="script">The script to enqueue for computation</param>
 public void AddToTodo(ISourceScript script)
 {
     if (!IsIncluded(script))
     {
         this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Adding Script to Todo List: {0}", Path.GetFileName(script.GetFileInterface().GetKey()));
         AddFile(script, false);
         _doneState.Add(ProcessStage.QUEUED);
     }
 }
예제 #14
0
        /// <summary>
        /// Fixes the order of the file tree if a script was being loaded and is now referenced (again)
        /// by removing it from the lower position and readding it at the top
        /// </summary>
        /// <param name="script">The script that got referenced.</param>
        public void FixOrder(ISourceScript script)
        {
            this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Fixing Build Order of file: {0}", Path.GetFileName(script.GetFileInterface().GetKey()));
            int idx = IndexOfFile(script.GetKey());
            var a   = _sources[idx];
            var ab  = _doneState[idx];

            _doneState.RemoveAt(idx);
            _doneState.Add(ab);
            _sources.RemoveAt(idx);
            AddFile(a, true);
        }
예제 #15
0
        private bool GetISourceScript(ISourceManager manager, string statement, string currentPath,
                                      out List <ISourceScript> scripts)
        {
            string[] vars = Utils.SplitAndRemoveFirst(statement, Separator);

            scripts = new List <ISourceScript>();
            if (vars.Length != 0)
            {
                ImportResult importInfo = manager.GetComputingScheme()(vars, currentPath);
                if (!importInfo)
                {
                    Logger.Log(PPLogType.Error, Verbosity.Level1, "Invalid Include Statement");
                    return(false);
                }

                string filepath = importInfo.GetString("filename");
                importInfo.RemoveEntry("filename");
                string key = importInfo.GetString("key");
                importInfo.RemoveEntry("key");


                if (filepath.EndsWith("\\*") || filepath.EndsWith("/*"))
                {
                    string[] files = IOManager.GetFiles(filepath.Substring(0, filepath.Length - 2));
                    foreach (string file in files)
                    {
                        IFileContent cont = new FilePathContent(file);
                        cont.SetKey(key);
                        if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo))
                        {
                            scripts.Add(iss);
                        }
                    }
                }
                else
                {
                    IFileContent cont = new FilePathContent(filepath);
                    cont.SetKey(key);
                    if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo))
                    {
                        scripts.Add(iss);
                    }
                }


                for (int index = scripts.Count - 1; index >= 0; index--)
                {
                    ISourceScript sourceScript = scripts[index];
                    if (sourceScript.GetFileInterface().HasValidFilepath&&
                        !Utils.FileExistsRelativeTo(currentPath, sourceScript.GetFileInterface()))
                    {
                        Logger.Log(PPLogType.Error, Verbosity.Level1, "Could not find File: {0}",
                                   sourceScript.GetFileInterface());
                        scripts.RemoveAt(index);
                    }
                }


                return(true);
            }


            return(false);
        }