示例#1
0
 /**
  * Compile function to check it
  *
  * @param Context $context
  * @return bool
  */
 public function compile(Context $context)
 {
     if ($this->compiled) {
         return true;
     }
     $context->setFilepath($this->filepath);
     $this->compiled = true;
     $context->scopePointer = $this->getPointer();
     $context->setScope(null);
     $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($this->statement, $context));
     if (count($this->statement->params) > 0) {
         /** @var  Node\Param $parameter */
         foreach ($this->statement->params as $parameter) {
             $type = CompiledExpression::UNKNOWN;
             if ($parameter->type) {
                 if (is_string($parameter->type)) {
                     $type = Types::getType($parameter->type);
                 } elseif ($parameter->type instanceof Node\Name) {
                     $type = CompiledExpression::OBJECT;
                 }
             }
             $context->addVariable(new Parameter($parameter->name, null, $type, $parameter->byRef));
         }
     }
     foreach ($this->statement->stmts as $st) {
         \PHPSA\nodeVisitorFactory($st, $context);
     }
     return true;
 }
示例#2
0
文件: ClassMethod.php 项目: ovr/phpsa
 /**
  * @param Context $context
  * @return boolean|null
  */
 public function compile(Context $context)
 {
     $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($this->statement, $context));
     $this->compiled = true;
     $context->scopePointer = $this->getPointer();
     /**
      * It's not needed to compile empty method via it's abstract
      */
     if ($this->isAbstract()) {
         /** @var ClassDefinition $scope */
         $scope = $context->scope;
         if (!$scope->isAbstract()) {
             $context->notice('not-abstract-class-with-abstract-method', 'Class must be abstract', $this->statement);
         }
         return true;
     }
     if ($this->statement->params) {
         foreach ($this->statement->params as $parameter) {
             $type = CompiledExpression::UNKNOWN;
             if ($parameter->type) {
                 if (is_string($parameter->type)) {
                     $type = Types::getType($parameter->type);
                 } elseif ($parameter->type instanceof Node\Name) {
                     $type = CompiledExpression::OBJECT;
                 }
             }
             $context->addVariable(new Parameter($parameter->name, null, $type, $parameter->byRef));
         }
     }
     foreach ($this->statement->stmts as $st) {
         \PHPSA\nodeVisitorFactory($st, $context);
     }
 }
示例#3
0
 /**
  * @return string
  */
 public function getTypeName()
 {
     return Types::getTypeName($this->type);
 }
示例#4
0
 /**
  * Returns debug info.
  *
  * @return array
  */
 public function __debugInfo()
 {
     return ['type' => \PHPSA\Compiler\Types::getTypeName($this->type), 'value' => $this->value];
 }
示例#5
0
文件: TypesTest.php 项目: ovr/phpsa
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Type 'not a valid type' is not supported
  */
 public function testGetTypeWithAnUnknownTypeThrows()
 {
     Types::getType('not a valid type');
 }
示例#6
0
 /**
  * If we don't know $type but know $value
  *
  * @param $value
  * @throws RuntimeException
  * @return CompiledExpression
  */
 public static function fromZvalValue($value)
 {
     return new CompiledExpression(CompilerTypes::getType($value), $value);
 }
示例#7
0
 /**
  * Compile function to check it
  *
  * @param Context $context
  * @return bool
  */
 public function compile(Context $context)
 {
     if ($this->compiled) {
         return true;
     }
     $context->setFilepath($this->filepath);
     $this->compiled = true;
     $context->clearSymbols();
     $context->scopePointer = $this->getPointer();
     $context->setScope(null);
     if (count($this->statement->stmts) == 0) {
         return $context->notice('not-implemented-function', sprintf('Closure %s() is not implemented', $this->name), $this->statement);
     }
     if (count($this->statement->params) > 0) {
         /** @var  Node\Param $parameter */
         foreach ($this->statement->params as $parameter) {
             $type = CompiledExpression::UNKNOWN;
             if ($parameter->type) {
                 if (is_string($parameter->type)) {
                     $type = Types::getType($parameter->type);
                 } elseif ($parameter->type instanceof Node\Name) {
                     $type = CompiledExpression::OBJECT;
                 }
             }
             $context->addVariable(new Parameter($parameter->name, null, $type, $parameter->byRef));
         }
     }
     foreach ($this->statement->stmts as $st) {
         \PHPSA\nodeVisitorFactory($st, $context);
     }
     return true;
 }