示例#1
0
        public static TES5StateCodeBlock CreateState(string name, bool auto)
        {
            TES5FunctionScope  functionScope = new TES5FunctionScope(name);
            TES5CodeScope      codeScope     = TES5CodeScopeFactory.CreateCodeScopeRoot(functionScope);
            TES5StateCodeBlock state         = new TES5StateCodeBlock(name, auto, functionScope, codeScope);

            return(state);
        }
示例#2
0
        public static TES5EventCodeBlock CreateEventCodeBlock(TES5FunctionScope functionScope, TES5GlobalScope globalScope)
        {
            InferEventBlockContainingType(functionScope.BlockName, globalScope);
            TES5CodeScope      codeScope = TES5CodeScopeFactory.CreateCodeScopeRoot(functionScope);
            TES5EventCodeBlock newBlock  = new TES5EventCodeBlock(functionScope, codeScope);

            return(newBlock);
        }
示例#3
0
        public TES5BlockList CreateBlock(TES4CodeBlock block, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, ref TES5EventCodeBlock?onUpdateBlockForNonQuestOrAME)
        {
            TES5BlockList  blockList    = new TES5BlockList();
            string         blockType    = block.BlockType;
            string         newBlockType = MapBlockType(blockType);
            TES4CodeChunks?chunks       = block.Chunks;

            if (chunks != null && chunks.Any())
            {
                TES5FunctionScope blockFunctionScope       = TES5FunctionScopeFactory.CreateFromBlockType(newBlockType);
                bool               onUpdateOfNonQuestOrAME = newBlockType == "OnUpdate" && globalScope.ScriptHeader.ScriptType.NativeType != TES5BasicType.T_QUEST && globalScope.ScriptHeader.ScriptType.NativeType != TES5BasicType.T_ACTIVEMAGICEFFECT;
                bool               onUpdateBlockOfNonQuestOrAMEAlreadyPresent = onUpdateBlockForNonQuestOrAME != null;
                TES5BlockList?     onUpdateAdditionalBlocksOfNonQuestOrAME    = null;
                TES5EventCodeBlock targetEventBlock;
                TES5CodeScope      targetCodeScope;
                if (onUpdateOfNonQuestOrAME)
                {
                    if (!onUpdateBlockOfNonQuestOrAMEAlreadyPresent)
                    {
                        CreateActivationStates(globalScope, out onUpdateAdditionalBlocksOfNonQuestOrAME, out targetEventBlock);
                        onUpdateBlockForNonQuestOrAME = targetEventBlock;
                    }
                    else
                    {
                        if (onUpdateBlockForNonQuestOrAME == null)
                        {
                            throw new NullableException(nameof(onUpdateBlockForNonQuestOrAME));
                        }
                        targetEventBlock = onUpdateBlockForNonQuestOrAME;
                    }
                    targetCodeScope = targetEventBlock.CodeScope;
                }
                else
                {
                    targetEventBlock = CreateEventCodeBlock(blockFunctionScope, globalScope);
                    targetCodeScope  = this.initialBlockCodeFactory.AddInitialCode(globalScope, targetEventBlock);
                }
                TES5CodeScope newScope           = TES5CodeScopeFactory.CreateCodeScopeRecursive(targetCodeScope.LocalScope);
                TES5CodeScope convertedCodeScope = this.ConvertTES4CodeChunksToTES5CodeScope(chunks, newScope, globalScope, multipleScriptsScope);
                TES5CodeScope modifiedCodeScope  = this.changesPass.Modify(block, blockList, blockFunctionScope, convertedCodeScope, globalScope, multipleScriptsScope);
                targetEventBlock.CodeScope.LocalScope.CopyVariablesFrom(modifiedCodeScope.LocalScope);
                targetEventBlock.CodeScope.AddChunks(modifiedCodeScope.CodeChunks);
                blockList.Add(targetEventBlock);
                if (onUpdateOfNonQuestOrAME)
                {
                    if (!onUpdateBlockOfNonQuestOrAMEAlreadyPresent)
                    {
                        if (onUpdateAdditionalBlocksOfNonQuestOrAME == null)
                        {
                            throw new NullableException(nameof(onUpdateAdditionalBlocksOfNonQuestOrAME));
                        }
                        return(onUpdateAdditionalBlocksOfNonQuestOrAME);
                    }
                    return(new TES5BlockList());
                }
            }
            return(blockList);
        }
示例#4
0
        private TES5CodeScope ConvertTES4CodeChunksToTES5CodeScope(TES4CodeChunks chunks, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES5CodeScope newCodeScope = TES5CodeScopeFactory.CreateCodeScope(codeScope.LocalScope);

            foreach (ITES4CodeChunk codeChunk in chunks)
            {
                TES5CodeChunkCollection codeChunks = this.codeChunkFactory.CreateCodeChunk(codeChunk, codeScope, globalScope, multipleScriptsScope);
                newCodeScope.AddChunk(codeChunks);
            }
            return(newCodeScope);
        }
示例#5
0
        public static TES5EventCodeBlock CreateEventCodeBlock(string blockType, TES5FunctionScope functionScope = null)
        {
            if (functionScope == null)
            {
                functionScope = new TES5FunctionScope(blockType);
            }
            TES5CodeScope      codeScope = TES5CodeScopeFactory.CreateCodeScopeRoot(functionScope);
            TES5EventCodeBlock newBlock  = new TES5EventCodeBlock(functionScope, codeScope);

            return(newBlock);
        }
示例#6
0
        private static TES5ElseSubBranch ConvertElseBranch(TES4ElseSubBranch branch, TES5CodeScope outerCodeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, TES5ChainedCodeChunkFactory codeChunkFactory)
        {
            TES5CodeScope  newCodeScope = TES5CodeScopeFactory.CreateCodeScopeRecursive(outerCodeScope.LocalScope);
            TES4CodeChunks?branchChunks = branch.CodeChunks;

            if (branchChunks != null)
            {
                foreach (ITES4CodeChunk codeChunk in branchChunks)
                {
                    TES5CodeChunkCollection codeChunks = codeChunkFactory.CreateCodeChunk(codeChunk, newCodeScope, globalScope, multipleScriptsScope);
                    foreach (ITES5CodeChunk newCodeChunk in codeChunks)
                    {
                        newCodeScope.AddChunk(newCodeChunk);
                    }
                }
            }
            return(new TES5ElseSubBranch(newCodeScope));
        }
示例#7
0
        private static TES5SubBranch ConvertSubBranch(TES4SubBranch branch, TES5CodeScope outerCodeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, TES5ChainedCodeChunkFactory codeChunkFactory, TES5ValueFactory valueFactory)
        {
            ITES5Value     expression   = valueFactory.CreateValue(branch.Expression, outerCodeScope, globalScope, multipleScriptsScope);
            TES5CodeScope  newCodeScope = TES5CodeScopeFactory.CreateCodeScopeRecursive(outerCodeScope.LocalScope);
            TES4CodeChunks branchChunks = branch.CodeChunks;

            if (branchChunks != null)
            {
                foreach (ITES4CodeChunk codeChunk in branchChunks)
                {
                    TES5CodeChunkCollection codeChunks = codeChunkFactory.createCodeChunk(codeChunk, newCodeScope, globalScope, multipleScriptsScope);
                    if (codeChunks != null)
                    {
                        foreach (ITES5CodeChunk newCodeChunk in codeChunks)
                        {
                            newCodeScope.AddChunk(newCodeChunk);
                        }
                    }
                }
            }

            return(new TES5SubBranch(expression, newCodeScope));
        }
        public TES5FunctionCodeBlock CreateFragment(TES5FragmentType fragmentType, string fragmentName, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, TES4CodeChunks chunks)
        {
            TES5FunctionScope     fragmentLocalScope = TES5FragmentFunctionScopeFactory.CreateFromFragmentType(fragmentName, fragmentType);
            TES5FunctionCodeBlock function           = new TES5FunctionCodeBlock(fragmentLocalScope, TES5CodeScopeFactory.CreateCodeScopeRoot(fragmentLocalScope), TES5VoidType.Instance, false, fragmentType == TES5FragmentType.T_QF || fragmentType == TES5FragmentType.T_TIF);

            foreach (var codeChunk in chunks)
            {
                TES5CodeChunkCollection codeChunks = this.codeChunkFactory.CreateCodeChunk(codeChunk, function.CodeScope, globalScope, multipleScriptsScope);
                foreach (var newCodeChunk in codeChunks)
                {
                    function.AddChunk(newCodeChunk);
                }
            }
            return(function);
        }
示例#9
0
 public static TES5SubBranch CreateSubBranch(ITES5Expression expression, TES5LocalScope parentScope)
 {
     return(new TES5SubBranch(expression, TES5CodeScopeFactory.CreateCodeScopeRecursive(parentScope)));
 }
示例#10
0
        public static TES5EventCodeBlock CreateOnInit()
        {
            TES5FunctionScope  onInitFunctionScope = TES5FunctionScopeFactory.CreateFromBlockType("OnInit");
            TES5EventCodeBlock newInitBlock        = new TES5EventCodeBlock(onInitFunctionScope, TES5CodeScopeFactory.CreateCodeScopeRoot(onInitFunctionScope));

            return(newInitBlock);
        }