public function createCodeChunk(TES4VariableDeclarationList $chunk, TES5CodeScope $codeScope) { foreach ($chunk->getVariableList() as $variable) { switch ($variable->getVariableType()) { case TES4Type::T_FLOAT(): $property = new TES5LocalVariable($variable->getVariableName(), TES5BasicType::T_FLOAT()); break; case TES4Type::T_INT(): case TES4Type::T_SHORT(): case TES4Type::T_LONG(): $property = new TES5LocalVariable($variable->getVariableName(), TES5BasicType::T_INT()); break; case TES4Type::T_REF(): //most basic one, if something from inherited class is used, we will set to the inheriting class $property = new TES5LocalVariable($variable->getVariableName(), TES5BasicType::T_FORM()); break; default: throw new ConversionException("Unknown local variable declaration type."); } $codeScope->getLocalScope()->addVariable($property); } return null; }
/** * @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); }
/** * Returns a called-on reference for the called function. * @param TES4Callable $chunk * @param TES5CodeScope $codeScope * @param TES5GlobalScope $globalScope * @param TES5MultipleScriptsScope $multipleScriptsScope * @return \Ormin\OBSLexicalParser\TES5\AST\Object\TES5Referencer * @throws \Ormin\OBSLexicalParser\TES5\Exception\ConversionException */ private function createCalledOnReferenceOfCalledFunction(TES4Callable $chunk, TES5CodeScope $codeScope, TES5GlobalScope $globalScope, TES5MultipleScriptsScope $multipleScriptsScope) { if (($calledOn = $chunk->getCalledOn()) !== null) { $reference = $this->referenceFactory->createReference($calledOn->getData(), $globalScope, $multipleScriptsScope, $codeScope->getLocalScope()); } else { $reference = $this->extractImplicitReference($globalScope, $multipleScriptsScope, $codeScope->getLocalScope()); } return $reference; }