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; } }
public function buildVariableDeclarationList($path) { $list = new TES4VariableDeclarationList(); if (!file_exists($path)) { return $list; } $references = file($path); foreach ($references as $reference) { $reference = trim($reference); if (empty($reference)) { continue; } $list->add(new TES4VariableDeclaration(trim($reference), TES4Type::T_REF())); } return $list; }
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; }