Example #1
0
 private List <SerializableFLBuffer> ParseDefinedBuffers(DefineStatement[] defineStatements)
 {
     return(WorkItemRunner.RunInWorkItems(
                defineStatements.ToList(),
                ParseDefinedBuffersTask,
                parser.WorkItemRunnerSettings
                ));
 }
Example #2
0
 private List <SerializableFLFunction> ParseFunctions(List <StaticFunction> functionHeaders,
                                                      string[] definedBuffers,
                                                      string[] definedScripts)
 {
     return(WorkItemRunner.RunInWorkItems(functionHeaders.ToList(),
                                          (input, start, count) => ParseFunctionsTask(input, start, count, definedBuffers, definedScripts),
                                          parser.WorkItemRunnerSettings));
 }
Example #3
0
        public override StaticInspectionResult Process(LoadSourceStageResult input)
        {
            string[] definedScripts         = null;
            string[] definedBuffers         = null;
            List <StaticFunction> functions = null;


            Logger.Log(LogType.Log, "Statically Inspecting: " + input.Filename, 2);

            Task <string[]> scriptTask = new Task <string[]>(() => FLParser.FindDefineScriptsStatements(input.Source));
            Task <string[]> bufferTask = new Task <string[]>(() => FLParser.FindDefineStatements(input.Source));

            if (parser.WorkItemRunnerSettings.UseMultithread)
            {
                scriptTask.Start();
                bufferTask.Start();
            }
            else
            {
                scriptTask.RunSynchronously();
                bufferTask.RunSynchronously();
            }

            string[] functionsHeaders = FLParser.FindFunctionHeaders(input.Source);

            functions = WorkItemRunner.RunInWorkItems(functionsHeaders.ToList(),
                                                      (list, start, count) => ParseFunctionTask(list, start, count, input.Source),
                                                      parser.WorkItemRunnerSettings);


            Task.WaitAll(scriptTask, bufferTask);
            Logger.Log(LogType.Log, "Buffer And Script Task Finished.", 2);
            definedScripts = scriptTask.Result;
            definedBuffers = bufferTask.Result;


            Logger.Log(LogType.Log, "Tasks Completed.", 2);


            Logger.Log(LogType.Log, "Parsed Scripts: " + functions.Unpack(", "), 4);
            return(new StaticInspectionResult(input.Filename, input.Source, functions, definedBuffers,
                                              definedScripts));
        }
Example #4
0
        public override LoadSourceStageResult Process(LoadSourceStageResult input)
        {
            Logger.Log(LogType.Log, "Removing Comments.. ", 2);


            WorkItemRunner.RunInWorkItems(input.Source, RemoveCommentTask, parser.WorkItemRunnerSettings);


            Logger.Log(LogType.Log, $"Optimizing Script Length..", 2);
            for (int i = input.Source.Count - 1; i >= 0; i--)
            {
                if (string.IsNullOrWhiteSpace(input.Source[i]))
                {
                    input.Source.RemoveAt(i);
                    continue;
                }

                input.Source[i] = input.Source[i].Trim();
            }

            return(input);
        }
Example #5
0
        public override StaticInspectionResult Process(LoadSourceStageResult input)
        {
            ImportOptions options = new ImportOptions();
            Runner        runner  = new Runner();

            runner._AddCommand(
                SetSettingsCommand.CreateSettingsCommand(
                    "Import",
                    new[] { FLKeywords.SetParserOptionKey },
                    options
                    )
                );
            List <string> opts = FLParser.FindParserOptions(input.Source).ToList();

            opts.Insert(0, FLKeywords.SetParserOptionKey);
            runner._RunCommands(opts.ToArray());

            if (options.OnlyAllowImport && input.MainFile)
            {
                throw new InvalidOperationException(
                          $"The Script {input.Filename} can not be loaded as Entry point. As the Option: Import.OnlyAllowImport is set to true in the script"
                          );
            }

            if (options.NoImport && !input.MainFile)
            {
                throw new InvalidOperationException(
                          $"The Script {input.Filename} can not be imported. As the Option: Import.NoImport is set to true in the script"
                          );
            }


            DefineStatement[]     definedScripts = null;
            DefineStatement[]     definedBuffers = null;
            List <StaticFunction> functions      = null;


            Logger.Log(LogType.Log, "Statically Inspecting: " + input.Filename, 1);

            Task <DefineStatement[]> scriptTask =
                new Task <DefineStatement[]>(() => FLParser.FindDefineScriptsStatements(input.Source));
            Task <DefineStatement[]> bufferTask =
                new Task <DefineStatement[]>(() => FLParser.FindDefineStatements(input.Source));

            if (parser.WorkItemRunnerSettings.UseMultithread)
            {
                scriptTask.Start();
                bufferTask.Start();
            }
            else
            {
                scriptTask.RunSynchronously();
                bufferTask.RunSynchronously();
            }

            StaticFunctionHeader[] functionsHeaders = FLParser.FindFunctionHeaders(input.Source)
                                                      .Select(x => new StaticFunctionHeader(x)).ToArray();


            functions = WorkItemRunner.RunInWorkItems(
                functionsHeaders.ToList(),
                (list, start, count) =>
                ParseFunctionTask(list, start, count, input.Source),
                parser.WorkItemRunnerSettings
                );


            Task.WaitAll(scriptTask, bufferTask);
            Logger.Log(LogType.Log, "Buffer And Script Tasks Finished.", 1);
            definedScripts = scriptTask.Result;
            definedBuffers = bufferTask.Result;


            Logger.Log(LogType.Log, "Tasks Completed.", 1);


            Logger.Log(LogType.Log, "Parsed Scripts: " + functions.Unpack(", "), 4);
            return(new StaticInspectionResult(
                       input.Filename,
                       input.Source,
                       functions,
                       definedBuffers,
                       definedScripts,
                       options,
                       input.AdditionalKernels
                       ));
        }