Esempio n. 1
0
        public static BuildTarget Get(string target, Build build, BuildLogServices buildLogServices, bool includeQFWriteCommand = true)
        {
            switch (target)
            {
            case BuildTarget.BUILD_TARGET_STANDALONE:
            {
                StandaloneParsingService standaloneParsingService = new StandaloneParsingService(new SyntaxErrorCleanParser(new TES4OBScriptGrammar()));
                return(new BuildTarget(BuildTarget.BUILD_TARGET_STANDALONE, TES5TypeFactory.TES4Prefix, build, buildLogServices.MetadataLogService, new Standalone.TranspileCommand(standaloneParsingService, build, buildLogServices.MetadataLogService), new Standalone.CompileCommand(), new Standalone.ASTCommand(), new Standalone.BuildScopeCommand(standaloneParsingService), new Standalone.WriteCommand()));
            }

            case BuildTarget.BUILD_TARGET_TIF:
            {
                FragmentsParsingService fragmentsParsingService = new FragmentsParsingService(new SyntaxErrorCleanParser(new TES4ObscriptCodeGrammar()));
                return(new BuildTarget(BuildTarget.BUILD_TARGET_TIF, "", build, buildLogServices.MetadataLogService, new TIF.TranspileCommand(fragmentsParsingService, build, buildLogServices.MetadataLogService), new TIF.CompileCommand(), new TIF.ASTCommand(), new TIF.BuildScopeCommand(), new TIF.WriteCommand()));
            }

            case BuildTarget.BUILD_TARGET_PF:
            {
                return(new BuildTarget(BuildTarget.BUILD_TARGET_PF, "", build, buildLogServices.MetadataLogService, new PF.TranspileCommand(), new PF.CompileCommand(), new PF.ASTCommand(), new PF.BuildScopeCommand(), new PF.WriteCommand()));
            }

            case BuildTarget.BUILD_TARGET_QF:
            {
                FragmentsParsingService fragmentsParsingService = new FragmentsParsingService(new SyntaxErrorCleanParser(new TES4ObscriptCodeGrammar()));
                QF.WriteCommand         writeCommand;
                if (includeQFWriteCommand)
                {        //Allows for skipping TES4 file loading when using BuildFileDeleteCommand
                    ESMAnalyzer                    analyzer                   = new ESMAnalyzer(DataDirectory.TES4GameFileName);
                    TES5TypeInferencer             typeInferencer             = new TES5TypeInferencer(analyzer, BuildTarget.StandaloneSourcePath);
                    TES5ObjectCallFactory          objectCallFactory          = new TES5ObjectCallFactory(typeInferencer);
                    TES5ObjectPropertyFactory      objectPropertyFactory      = new TES5ObjectPropertyFactory(typeInferencer);
                    TES5ReferenceFactory           referenceFactory           = new TES5ReferenceFactory(objectCallFactory, objectPropertyFactory);
                    TES5ValueFactory               valueFactory               = new TES5ValueFactory(objectCallFactory, referenceFactory, objectPropertyFactory, analyzer, typeInferencer, buildLogServices.MetadataLogService);
                    TES5ObjectCallArgumentsFactory objectCallArgumentsFactory = new TES5ObjectCallArgumentsFactory(valueFactory);
                    TES5ValueFactoryFunctionFiller.FillFunctions(valueFactory, objectCallFactory, objectCallArgumentsFactory, referenceFactory, objectPropertyFactory, analyzer, typeInferencer, buildLogServices.MetadataLogService);
                    ObjectiveHandlingFactory objectiveHandlingFactory = new ObjectiveHandlingFactory(referenceFactory);
                    QFFragmentFactory        qfFragmentFactory        = new QFFragmentFactory(buildLogServices.MappedTargetsLogService, objectiveHandlingFactory);
                    writeCommand = new QF.WriteCommand(qfFragmentFactory);
                }
                else
                {
                    writeCommand = null;
                }
                return(new BuildTarget(BuildTarget.BUILD_TARGET_QF, "", build, buildLogServices.MetadataLogService, new QF.TranspileCommand(fragmentsParsingService, build, buildLogServices.MetadataLogService), new QF.CompileCommand(), new QF.ASTCommand(), new QF.BuildScopeCommand(), writeCommand));
            }

            default:
            {
                throw new InvalidOperationException("Unknown target " + target);
            }
            }
        }
        public static BuildTargetAdvanced ConstructAdvanced(BuildTargetSimple buildTarget, BuildLogServiceCollection buildLogServices, ESMAnalyzer esmAnalyzer, TES5TypeInferencer typeInferencer)
        {
            switch (buildTarget.Name)
            {
            case StandaloneName:
            {
                StandaloneParsingService standaloneParsingService = new StandaloneParsingService(new SyntaxErrorCleanParser(new TES4OBScriptGrammar()));
                return(new BuildTargetAdvanced(buildTarget, new Standalone.TranspileCommand(standaloneParsingService, buildLogServices.MetadataLogService, esmAnalyzer), new Standalone.BuildScopeCommand(standaloneParsingService, esmAnalyzer, new TES5PropertyFactory(esmAnalyzer)), new Standalone.WriteCommand()));
            }

            case TIFName:
            {
                FragmentsParsingService fragmentsParsingService = new FragmentsParsingService(new SyntaxErrorCleanParser(new TES4ObscriptCodeGrammar()));
                return(new BuildTargetAdvanced(buildTarget, new TIF.TranspileCommand(fragmentsParsingService, buildLogServices.MetadataLogService, esmAnalyzer), new TIF.BuildScopeCommand(new TES5PropertyFactory(esmAnalyzer), new FragmentsReferencesBuilder(esmAnalyzer)), new TIF.WriteCommand()));
            }

            case PFName:
            {
                return(new BuildTargetAdvanced(buildTarget, new PF.TranspileCommand(), new PF.BuildScopeCommand(), new PF.WriteCommand()));
            }

            case QFName:
            {
                FragmentsParsingService        fragmentsParsingService    = new FragmentsParsingService(new SyntaxErrorCleanParser(new TES4ObscriptCodeGrammar()));
                TES5ObjectCallFactory          objectCallFactory          = new TES5ObjectCallFactory(typeInferencer);
                TES5ObjectPropertyFactory      objectPropertyFactory      = new TES5ObjectPropertyFactory(typeInferencer);
                TES5ReferenceFactory           referenceFactory           = new TES5ReferenceFactory(objectCallFactory, objectPropertyFactory, esmAnalyzer);
                TES5ValueFactory               valueFactory               = new TES5ValueFactory(objectCallFactory, referenceFactory, esmAnalyzer);
                TES5ObjectCallArgumentsFactory objectCallArgumentsFactory = new TES5ObjectCallArgumentsFactory(valueFactory);
                TES5ValueFactoryFunctionFiller.FillFunctions(valueFactory, objectCallFactory, objectCallArgumentsFactory, referenceFactory, objectPropertyFactory, buildLogServices.MetadataLogService, esmAnalyzer);
                TES5VariableAssignationConversionFactory assignationConversionFactory = new TES5VariableAssignationConversionFactory(objectCallFactory, referenceFactory, valueFactory, typeInferencer);
                TES5ReturnFactory           returnFactory            = new TES5ReturnFactory(objectCallFactory);
                TES5ChainedCodeChunkFactory chainedCodeChunkFactory  = new TES5ChainedCodeChunkFactory(valueFactory, returnFactory, assignationConversionFactory);
                TES5FragmentFactory         fragmentFactory          = new TES5FragmentFactory(chainedCodeChunkFactory);
                ObjectiveHandlingFactory    objectiveHandlingFactory = new ObjectiveHandlingFactory(objectCallFactory);
                QFFragmentFactory           qfFragmentFactory        = new QFFragmentFactory(buildLogServices.MappedTargetsLogService, objectiveHandlingFactory, esmAnalyzer);
                QF.WriteCommand             writeCommand             = new QF.WriteCommand(qfFragmentFactory);
                return(new BuildTargetAdvanced(buildTarget, new QF.TranspileCommand(fragmentsParsingService, fragmentFactory), new QF.BuildScopeCommand(new TES5PropertyFactory(esmAnalyzer), new FragmentsReferencesBuilder(esmAnalyzer)), writeCommand));
            }

            default:
            {
                throw new InvalidOperationException("Unknown target " + buildTarget.Name);
            }
            }
        }
        public override void Execute()
        {
            if (!PreExecutionChecks(false, false, false, false))
            {
                return;
            }
            Build build = new Build(Build.DEFAULT_BUILD_PATH);
            Dictionary <int, List <int> > originalStageMap;

            using (BuildLogServices buildLogServices = new BuildLogServices(build))
            {
                BuildTarget buildTarget = BuildTargetFactory.Get(BuildTarget.BUILD_TARGET_QF, build, buildLogServices);
                originalStageMap = QFFragmentFactory.BuildStageMapDictionary(buildTarget, "QF_FGC01Rats_01035713");
            }
            StageMap      stageMap = new StageMap(originalStageMap.ToDictionary(m => m.Key, m => m.Value.ToList()));//Copy dictionary
            StringBuilder output   = new StringBuilder();

            foreach (var stageId in stageMap.StageIDs)
            {
                output.AppendLine(stageId.ToString() + " - " + string.Join(" ", originalStageMap[stageId]));
                output.Append(stageId.ToString() + " -");
                List <int> map = stageMap.GetStageTargetsMap(stageId);
                foreach (var val in map)
                {
                    output.Append(" " + val);
                }

                output.AppendLine();
            }

            output.Append("Mapping index print");
            foreach (var kvp in stageMap.MappedTargetsIndex)
            {
                var originalTargetIndex = kvp.Key;
                var mappedTargetIndexes = kvp.Value;
                output.AppendLine();
                output.Append(originalTargetIndex + " - " + string.Join(" ", mappedTargetIndexes));
            }

            string outputString = output.ToString();

            Console.WriteLine(outputString);
            const string fgc01RatsResultFromPHP =
                @"10 - 0 0 0 1
10 - 0 0 0 1 0 0 0 0 0 0
20 - 1 0 0 0
20 - 1 0 0 0 0 0 0 0 0 0
30 - 0 0 0 1
30 - 0 0 0 0 1 0 0 0 0 0
40 - 0 0 1 0
40 - 0 0 1 0 0 0 0 0 0 0
50 - 0 0 1 0
50 - 0 0 1 0 0 0 0 0 0 0
55 - 0 0 0 1
55 - 0 0 0 0 0 1 0 0 0 0
60 - 1 0 0 0
60 - 0 0 0 0 0 0 1 0 0 0
65 - 0 0 0 1
65 - 0 0 0 0 0 0 0 1 0 0
70 - 0 1 0 0
70 - 0 1 0 0 0 0 0 0 0 0
80 - 0 1 0 0
80 - 0 1 0 0 0 0 0 0 0 0
90 - 0 0 0 1
90 - 0 0 0 0 0 0 0 0 1 0
100 - 0 0 0 0
100 - 0 0 0 0 0 0 0 0 0 0
105 - 0 1 0 0
105 - 0 0 0 0 0 0 0 0 0 1
110 - 0 0 0 0
110 - 0 0 0 0 0 0 0 0 0 0
200 - 0 0 0 0
200 - 0 0 0 0 0 0 0 0 0 0
Mapping index print
3 - 4 5 7 8
0 - 6
1 - 9";
            bool match = fgc01RatsResultFromPHP.Replace("\r\n", "\n") == outputString.Replace("\r\n", "\n");

            Console.WriteLine("Output " + (match ? "matched" : "did not match") + " the output of the PHP version.");
        }
 public WriteCommand(QFFragmentFactory QFFragmentFactory)
 {
     this.QFFragmentFactory = QFFragmentFactory;
 }