/**
  * @param TES5FragmentType $fragmentType
  * @param string $fragmentName
  * @param TES5GlobalScope $globalScope
  * @param TES4CodeChunks $chunks
  * @return TES5FunctionCodeBlock
  */
 public function createFragment(TES5FragmentType $fragmentType, $fragmentName, TES5GlobalScope $globalScope, TES5MultipleScriptsScope $multipleScriptsScope, TES4CodeChunks $chunks)
 {
     $fragmentLocalScope = $this->fragmentLocalScopeFactory->createFromFragmentType($fragmentType);
     $function = new TES5FunctionCodeBlock($fragmentName, new TES5VoidType(), $fragmentLocalScope, $this->codeScopeFactory->createCodeScope($this->fragmentLocalScopeFactory->createRecursiveScope($fragmentLocalScope)));
     foreach ($chunks->getCodeChunks() as $codeChunk) {
         $codeChunks = $this->codeChunkFactory->createCodeChunk($codeChunk, $function->getCodeScope(), $globalScope, $multipleScriptsScope);
         if ($codeChunks !== null) {
             foreach ($codeChunks as $newCodeChunk) {
                 $function->addChunk($newCodeChunk);
             }
         }
     }
     return $function;
 }
 /**
  * @param TES4SubBranch $branch
  * @param TES5CodeScope $outerCodeScope
  * @param TES5GlobalScope $globalScope
  * @return TES5SubBranch
  */
 private function convertSubBranch(TES4SubBranch $branch, TES5CodeScope $outerCodeScope, \Ormin\OBSLexicalParser\TES5\AST\Scope\TES5GlobalScope $globalScope, TES5MultipleScriptsScope $multipleScriptsScope)
 {
     $outerLocalScope = $outerCodeScope->getLocalScope();
     $expression = $this->valueFactory->createValue($branch->getExpression(), $outerCodeScope, $globalScope, $multipleScriptsScope);
     $newScope = $this->localScopeFactory->createRecursiveScope($outerLocalScope);
     $newCodeScope = $this->codeScopeFactory->createCodeScope($newScope);
     $branchChunks = $branch->getCodeChunks();
     if ($branchChunks !== null) {
         foreach ($branchChunks->getCodeChunks() as $codeChunk) {
             $codeChunks = $this->codeChunkFactory->createCodeChunk($codeChunk, $newCodeScope, $globalScope, $multipleScriptsScope);
             if ($codeChunks !== null) {
                 foreach ($codeChunks as $newCodeChunk) {
                     $newCodeScope->add($newCodeChunk);
                 }
             }
         }
     }
     return new TES5SubBranch($expression, $newCodeScope);
 }
 /**
  * @param TES5MultipleScriptsScope $multipleScriptsScope
  * @param TES5GlobalScope $globalScope
  * @param TES4CodeBlock $block
  * @return TES5EventBlockList
  */
 public function createBlock(TES5MultipleScriptsScope $multipleScriptsScope, TES5GlobalScope $globalScope, TES4CodeBlock $block)
 {
     $blockList = new TES5EventBlockList();
     $blockType = $block->getBlockType();
     if (strtolower($blockType) == "menumode") {
         return $blockList;
     }
     $newBlockType = $this->mapBlockType($blockType);
     $blockLocalScope = $this->blockLocalScopeFactory->createFromBlockType($newBlockType, $globalScope);
     $newBlock = new TES5EventCodeBlock($newBlockType, $blockLocalScope, $this->codeScopeFactory->createCodeScope($this->blockLocalScopeFactory->createRecursiveScope($blockLocalScope)));
     if ($block->getChunks() !== null) {
         foreach ($block->getChunks()->getCodeChunks() as $codeChunk) {
             $codeChunks = $this->codeChunkFactory->createCodeChunk($codeChunk, $newBlock->getCodeScope(), $globalScope, $multipleScriptsScope);
             if ($codeChunks !== null) {
                 foreach ($codeChunks as $newCodeChunk) {
                     $newBlock->addChunk($newCodeChunk);
                 }
             }
         }
         $this->changesPass->modify($block, $blockList, $newBlock, $globalScope, $multipleScriptsScope);
         $blockList->add($newBlock);
     }
     return $blockList;
 }