public function getType()
 {
     if ($this->leftValue->getType() == TES5BasicType::T_FLOAT() || $this->rightValue->getType() == TES5BasicType::T_FLOAT()) {
         return TES5BasicType::T_FLOAT();
     }
     return TES5BasicType::T_INT();
 }
 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 __construct(TES5ObjectPropertyFactory $objectPropertyFactory)
 {
     $this->objectPropertyFactory = $objectPropertyFactory;
     //Those are used to hook in the internal Skyblivion systems.
     $special_conversions = ['TES4AttrStrength' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrIntelligence' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrWillpower' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrAgility' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrSpeed' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrEndurance' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrPersonality' => TES5BasicType::T_GLOBALVARIABLE(), 'TES4AttrLuck' => TES5BasicType::T_GLOBALVARIABLE(), 'tContainer' => TES5TypeFactory::memberByValue("TES4Container", TES5BasicType::T_QUEST()), 'tTimer' => TES5TypeFactory::memberByValue("TES4TimerHelper", TES5BasicType::T_QUEST()), 'tGSPLocalTimer' => TES5BasicType::T_FLOAT(), 'TES4CyrodiilCrimeFaction' => TES5BasicType::T_FACTION(), self::MESSAGEBOX_VARIABLE_CONST => TES5BasicType::T_INT()];
     $this->special_conversions = $special_conversions;
 }
 private function inferenceTypeOfMethodArguments(TES5ObjectCall $objectCall, TES5MultipleScriptsScope $multipleScriptsScope)
 {
     /**
      * Inference the arguments
      */
     $arguments = $objectCall->getArguments();
     $argumentNumber = 0;
     $calledOnType = $objectCall->getAccessedObject()->getType()->getNativeType();
     foreach ($arguments->getArguments() as $argument) {
         /**
          * Get the argument type according to TES5Inheritance graph.
          */
         $argumentTargetType = TES5InheritanceGraphAnalyzer::findTypeByMethodParameter($calledOnType, $objectCall->getFunctionName(), $argumentNumber);
         if ($argument->getType() == $argumentTargetType) {
             ++$argumentNumber;
             continue;
             //Same type matched. We do not need to do anything :)
         }
         /**
          * todo - maybe we should move getReferencesTo() to TES5Value and make all of the rest TES5Values just have null references as they do not reference anything? :)
          */
         if (TES5InheritanceGraphAnalyzer::isExtending($argumentTargetType, $argument->getType()->getNativeType()) && $argument instanceof TES5Referencer) {
             //HACKY!
             $this->inferenceType($argument->getReferencesTo(), $argumentTargetType, $multipleScriptsScope);
         } else {
             //So there's one , one special case where we actually have to cast a var from one to another even though they are not ,,inheriting" from themselves, because they are primitives.
             //Scenario: there's an T_INT argument, and we feed it with a T_FLOAT variable reference. It won't work :(
             //We need to cast it on call level ( NOT inference it ) to make it work and not break other possible scenarios ( more specifically, when a float would be inferenced to int and there's a
             //float assigment somewhere in the code )
             if ($argumentTargetType == TES5BasicType::T_INT() && $argument->getType() == TES5BasicType::T_FLOAT()) {
                 if ($argument instanceof TES5Reference) {
                     //HACKY! When we'll clean up this interface, it will dissapear :)
                     $argument->setManualCastTo(TES5BasicType::T_INT());
                 }
             }
         }
         ++$argumentNumber;
     }
 }
 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;
 }
Ejemplo n.º 6
0
 public function getType()
 {
     return TES5BasicType::T_FLOAT();
 }