public function createProperties(TES4VariableDeclarationList $variableList, TES5GlobalScope $globalScope) { /** * @var TES4VariableDeclaration[] $alreadyDefinedVariables */ $alreadyDefinedVariables = []; foreach ($variableList->getVariableList() as $variable) { $theVariableName = strtolower($variable->getVariableName()); if (isset($alreadyDefinedVariables[$theVariableName])) { if ($variable->getVariableType() == $alreadyDefinedVariables[$theVariableName]->getVariableType()) { continue; //Same variable defined twice, smack the original script developer and fallthrough silently. } throw new ConversionException("Double definition of variable named " . $variable->getVariableName() . " with different types ( " . $alreadyDefinedVariables[$theVariableName]->getVariableType()->value() . " and " . $variable->getVariableType()->value() . " )"); } switch ($variable->getVariableType()) { case TES4Type::T_FLOAT(): $property = new TES5Property($variable->getVariableName(), TES5BasicType::T_FLOAT(), null); break; case TES4Type::T_INT(): case TES4Type::T_SHORT(): case TES4Type::T_LONG(): $property = new TES5Property($variable->getVariableName(), TES5BasicType::T_INT(), null); break; case TES4Type::T_REF(): $property = $this->createPropertyFromReference($variable); break; default: throw new ConversionException("Unknown variable declaration type."); } $globalScope->add($property); $alreadyDefinedVariables[$theVariableName] = $variable; } }
/** * @param TES4Primitive $value * @return TES5Float|TES5Integer|TES5String * @throws \Ormin\OBSLexicalParser\TES5\Exception\ConversionException */ public function createValue(TES4Primitive $value) { switch ($value->getType()) { case TES4Type::T_INT(): return new TES5Integer($value->getData()); case TES4Type::T_STRING(): return new TES5String($value->getData()); case TES4Type::T_FLOAT(): return new TES5Float($value->getData()); } throw new ConversionException("Unknown value type to be factored from " . get_class($value)); }
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; }
public function getType() { return TES4Type::T_INT(); }