Exemplo n.º 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;
 }
Exemplo n.º 2
0
Arquivo: DoSt.php Projeto: ovr/phpsa
 /**
  * @param \PhpParser\Node\Stmt\Do_ $stmt
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($stmt, Context $context)
 {
     $context->getExpressionCompiler()->compile($stmt->cond);
     foreach ($stmt->stmts as $statement) {
         \PHPSA\nodeVisitorFactory($statement, $context);
     }
 }
Exemplo n.º 3
0
 /**
  * @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);
     }
 }
Exemplo n.º 4
0
 /**
  * @param \PhpParser\Node\Stmt\Catch_ $statement
  * @param Context $context
  */
 public function compile($statement, Context $context)
 {
     $context->addVariable(new Variable($statement->var, null, CompiledExpression::OBJECT));
     foreach ($statement->stmts as $stmt) {
         \PHPSA\nodeVisitorFactory($stmt, $context);
     }
 }
Exemplo n.º 5
0
 /**
  * @param Context $context
  * @return boolean|null
  */
 public function compile(Context $context)
 {
     $this->compiled = true;
     $context->scopePointer = $this->getPointer();
     if ($this->statement->getDocComment() === null) {
         $context->notice('missing-docblock', sprintf('Missing docblock for %s() method', $this->name), $this->statement);
     }
     /**
      * 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 an abstract', $this->statement);
         }
         return true;
     }
     if (count($this->statement->stmts) == 0) {
         return $context->notice('not-implemented-method', sprintf('Method %s() is not implemented', $this->name), $this->statement);
     }
     if (count($this->statement->params) > 0) {
         /** @var  Node\Param $parameter */
         foreach ($this->statement->params as $parameter) {
             $context->addSymbol($parameter->name);
         }
     }
     foreach ($this->statement->stmts as $st) {
         \PHPSA\nodeVisitorFactory($st, $context);
     }
 }
Exemplo n.º 6
0
Arquivo: IfTest.php Projeto: ovr/phpsa
 /**
  * Tests if (1 == 1) { $stmtTest = 2; } creates the variable
  */
 public function testIfStatementCreatesVar()
 {
     $context = $this->getContext();
     $statement = new Node\Stmt\If_(new Node\Expr\BinaryOp\Equal($this->newScalarExpr(1), $this->newScalarExpr(1)), ["stmts" => [new Node\Expr\Assign(new Node\Expr\Variable(new Node\Name("stmtTest")), $this->newScalarExpr(2))]]);
     \PHPSA\nodeVisitorFactory($statement, $context);
     $variable = $context->getSymbol("stmtTest");
     parent::assertTrue($variable instanceof Variable);
 }
Exemplo n.º 7
0
 /**
  * Tests echo $stmtTest = 2; creates the variable
  */
 public function testEchoCreatesVar()
 {
     $context = $this->getContext();
     $statement = new Node\Stmt\Echo_([new Node\Expr\Assign(new Node\Expr\Variable(new Node\Name("stmtTest")), $this->newScalarExpr(2))]);
     \PHPSA\nodeVisitorFactory($statement, $context);
     $variable = $context->getSymbol("stmtTest");
     parent::assertTrue($variable instanceof Variable);
 }
Exemplo n.º 8
0
 /**
  * @param \PhpParser\Node\Stmt\Declare_ $stmt
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($stmt, Context $context)
 {
     $compiler = $context->getExpressionCompiler();
     foreach ($stmt->declares as $declare) {
         $compiler->compile($declare->value);
     }
     foreach ($stmt->stmts as $stmt) {
         \PHPSA\nodeVisitorFactory($stmt, $context);
     }
 }
Exemplo n.º 9
0
 /**
  * @param \PhpParser\Node\Stmt\Do_ $stmt
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($stmt, Context $context)
 {
     $expression = new Expression($context);
     $expression->compile($stmt->cond);
     if (count($stmt->stmts) > 0) {
         foreach ($stmt->stmts as $statement) {
             \PHPSA\nodeVisitorFactory($statement, $context);
         }
     } else {
         $context->notice('not-implemented-body', 'Missing body', $stmt);
     }
 }
Exemplo n.º 10
0
 /**
  * @param \PhpParser\Node\Stmt\Foreach_ $stmt
  * @param Context $context
  * @return null|boolean
  */
 public function compile($stmt, Context $context)
 {
     $context->getExpressionCompiler()->compile($stmt->expr);
     if ($stmt->keyVar) {
         $context->getExpressionCompiler()->declareVariable($stmt->keyVar, null, CompiledExpression::MIXED);
     }
     if ($stmt->valueVar) {
         $context->getExpressionCompiler()->declareVariable($stmt->valueVar, null, CompiledExpression::MIXED);
     }
     foreach ($stmt->stmts as $statement) {
         \PHPSA\nodeVisitorFactory($statement, $context);
     }
 }
Exemplo n.º 11
0
Arquivo: ForSt.php Projeto: ovr/phpsa
 /**
  * @param \PhpParser\Node\Stmt\For_ $stmt
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($stmt, Context $context)
 {
     foreach ($stmt->init as $init) {
         $context->getExpressionCompiler()->compile($init);
     }
     foreach ($stmt->cond as $cond) {
         $context->getExpressionCompiler()->compile($cond);
     }
     foreach ($stmt->loop as $loop) {
         $context->getExpressionCompiler()->compile($loop);
     }
     foreach ($stmt->stmts as $statement) {
         \PHPSA\nodeVisitorFactory($statement, $context);
     }
 }
Exemplo n.º 12
0
 /**
  * @param \PhpParser\Node\Stmt\TryCatch $statement
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($statement, Context $context)
 {
     foreach ($statement->stmts as $stmt) {
         \PHPSA\nodeVisitorFactory($stmt, $context);
     }
     foreach ($statement->catches as $stmt) {
         \PHPSA\nodeVisitorFactory($stmt, $context);
     }
     if ($statement->finallyStmts !== null) {
         if (count($statement->finallyStmts) > 0) {
             foreach ($statement->finallyStmts as $stmt) {
                 \PHPSA\nodeVisitorFactory($stmt, $context);
             }
         }
     }
 }
Exemplo n.º 13
0
Arquivo: IfSt.php Projeto: ovr/phpsa
 /**
  * @param \PhpParser\Node\Stmt\If_ $ifStatement
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($ifStatement, Context $context)
 {
     $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_TRUE);
     $context->getExpressionCompiler()->compile($ifStatement->cond);
     foreach ($ifStatement->stmts as $stmt) {
         \PHPSA\nodeVisitorFactory($stmt, $context);
     }
     $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_EXTERNAL);
     foreach ($ifStatement->elseifs as $elseIfStatement) {
         \PHPSA\nodeVisitorFactory($elseIfStatement, $context);
     }
     $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_FALSE);
     if ($ifStatement->else) {
         \PHPSA\nodeVisitorFactory($ifStatement->else, $context);
     }
     $context->setCurrentBranch(Variable::BRANCH_ROOT);
 }
Exemplo n.º 14
0
 /**
  * @param Context $context
  * @return bool
  */
 public function compile(Context $context)
 {
     if ($this->st->getDocComment() === null) {
         return $context->notice('missing-docblock', sprintf('Missing docblock for %s() method', $this->name), $this->st);
     }
     if (count($this->ast) == 0) {
         return $context->notice('not-implemented-method', sprintf('Method %s() is not implemented', $this->name), $this->st);
     }
     if (count($this->st->params) > 0) {
         /** @var  Node\Param $parameter */
         foreach ($this->st->params as $parameter) {
             $context->addSymbol($parameter->name);
         }
     }
     foreach ($this->ast as $st) {
         $result = \PHPSA\nodeVisitorFactory($st, $context);
     }
 }
Exemplo n.º 15
0
 /**
  * Compile function to check it
  *
  * @param Context $context
  * @return bool
  */
 public function compile(Context $context)
 {
     $this->compiled = true;
     $context->scopePointer = $this->getPointer();
     $context->setScope(null);
     if (count($this->statement->stmts) == 0) {
         return $context->notice('not-implemented-function', sprintf('Function %s() is not implemented', $this->name), $this->statement);
     }
     if (count($this->statement->params) > 0) {
         /** @var  Node\Param $parameter */
         foreach ($this->statement->params as $parameter) {
             $context->addSymbol($parameter->name);
         }
     }
     foreach ($this->statement->stmts as $st) {
         \PHPSA\nodeVisitorFactory($st, $context);
     }
     return true;
 }
Exemplo n.º 16
0
 /**
  * @param \PhpParser\Node\Stmt\Foreach_ $stmt
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($stmt, Context $context)
 {
     $expression = new Expression($context);
     $expression->compile($stmt->expr);
     if ($stmt->keyVar) {
         $keyExpression = new Expression($context);
         $keyExpression->declareVariable($stmt->keyVar);
     }
     if ($stmt->valueVar) {
         $valueExpression = new Expression($context);
         $valueExpression->declareVariable($stmt->valueVar);
     }
     if (count($stmt->stmts) > 0) {
         foreach ($stmt->stmts as $statement) {
             \PHPSA\nodeVisitorFactory($statement, $context);
         }
     } else {
         return $context->notice('not-implemented-body', 'Missing body', $stmt);
     }
 }
Exemplo n.º 17
0
 /**
  * @param Node\Stmt\If_ $st
  */
 public function passIf(Node\Stmt\If_ $ifStatement)
 {
     $expression = new Expression($this->context);
     $compiledExpression = $expression->compile($ifStatement->cond);
     if (count($ifStatement->stmts) > 0) {
         foreach ($ifStatement->stmts as $st) {
             $result = \PHPSA\nodeVisitorFactory($st, $this->context);
         }
     } else {
         //@todo implement
     }
     if (count($ifStatement->elseifs) > 0) {
         foreach ($ifStatement->elseifs as $elseIfStatement) {
             $expression = new Expression($this->context);
             $compiledExpression = $expression->compile($elseIfStatement->cond);
             if (count($elseIfStatement->stmts) > 0) {
                 foreach ($elseIfStatement->stmts as $st) {
                     $result = \PHPSA\nodeVisitorFactory($st, $this->context);
                 }
             } else {
                 //@todo implement
             }
         }
     } else {
         //@todo implement
     }
     if ($ifStatement->else) {
         if (count($ifStatement->else->stmts) > 0) {
             foreach ($ifStatement->else->stmts as $st) {
                 $result = \PHPSA\nodeVisitorFactory($st, $this->context);
             }
         } else {
             //@todo implement
         }
     }
 }
Exemplo n.º 18
0
 /**
  * @param \PhpParser\Node\Stmt\If_ $ifStatement
  * @param Context $context
  * @return CompiledExpression
  */
 public function compile($ifStatement, Context $context)
 {
     $expression = new Expression($context);
     $expression->compile($ifStatement->cond);
     if (count($ifStatement->stmts) > 0) {
         foreach ($ifStatement->stmts as $stmt) {
             \PHPSA\nodeVisitorFactory($stmt, $context);
         }
     } else {
         $context->notice('not-implemented-body', 'Missing body', $ifStatement);
     }
     if (count($ifStatement->elseifs) > 0) {
         foreach ($ifStatement->elseifs as $elseIfStatement) {
             $expression = new Expression($context);
             $expression->compile($elseIfStatement->cond);
             if (count($elseIfStatement->stmts) > 0) {
                 foreach ($elseIfStatement->stmts as $stmt) {
                     \PHPSA\nodeVisitorFactory($stmt, $context);
                 }
             } else {
                 $context->notice('not-implemented-body', 'Missing body', $elseIfStatement);
             }
         }
     } else {
         //@todo implement
     }
     if ($ifStatement->else) {
         if (count($ifStatement->else->stmts) > 0) {
             foreach ($ifStatement->else->stmts as $stmt) {
                 \PHPSA\nodeVisitorFactory($stmt, $context);
             }
         } else {
             $context->notice('not-implemented-body', 'Missing body', $ifStatement->else);
         }
     }
 }
Exemplo n.º 19
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;
 }
Exemplo n.º 20
0
Arquivo: ElseSt.php Projeto: ovr/phpsa
 /**
  * @param \PhpParser\Node\Stmt\Else_ $elseStatement
  * @param Context $context
  */
 public function compile($elseStatement, Context $context)
 {
     foreach ($elseStatement->stmts as $stmt) {
         \PHPSA\nodeVisitorFactory($stmt, $context);
     }
 }