/**
  * @param Stmt\ClassMethod $node
  *
  * @return string
  */
 public function convert(Stmt\ClassMethod $node)
 {
     $types = $this->typeFinder->getTypes($node, $this->dispatcher->getMetadata());
     foreach ($node->params as $param) {
         if ($param->byRef === true) {
             $this->logger->logIncompatibility('reference', sprintf('Reference not supported in parametter (var "%s")', $param->name), $param, $this->dispatcher->getMetadata()->getClass());
         }
     }
     if ($node->byRef) {
         $this->logger->logIncompatibility('reference', 'Reference not supported', $node, $this->dispatcher->getMetadata()->getClass());
     }
     $this->dispatcher->setLastMethod($node->name);
     $stmt = $this->dispatcher->pModifiers($node->type) . 'function ' . $node->name . '(';
     $varsInMethodSign = array();
     if (isset($types['params']) === true) {
         $params = array();
         foreach ($types['params'] as $type) {
             $varsInMethodSign[] = $type['name'];
             $stringType = $this->printType($type);
             $params[] = (!empty($stringType) ? $stringType . ' ' : '') . '' . $type['name'] . ($type['default'] === null ? '' : ' = ' . $this->dispatcher->p($type['default']));
         }
         $stmt .= implode(', ', $params);
     }
     $stmt .= ')';
     $stmt .= $this->printReturn($node, $types);
     $stmt .= (null !== $node->stmts ? "\n{" . $this->printVars($node, $varsInMethodSign) . $this->dispatcher->pStmts($node->stmts) . "\n}" : ';') . "\n";
     return $stmt;
 }
 /**
  * @param Expr\ClosureUse $node
  *
  * @return string
  */
 public function convert(Expr\ClosureUse $node)
 {
     if ($node->byRef) {
         $this->logger->logNode('Zephir not support reference parameters for now. Stay tuned for https://github.com/phalcon/zephir/issues/203', $node, $this->dispatcher->getMetadata()->getClass());
     }
     return $this->reservedWordReplacer->replace($node->var);
 }
Exemplo n.º 3
0
 /**
  * @param null|string $lastMethod
  * @param integer     $number
  */
 public function createClosureClass(Expr\Closure $node, $lastMethod, $number)
 {
     $this->logger->trace(__METHOD__ . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     $name = $this->dispatcher->getMetadata()->getClass() . $lastMethod . "Closure" . $this->N2L($number);
     $this->logger->logNode(sprintf('Closure does not exist in Zephir, class "%s" with __invoke is created', $name), $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     return array('name' => $name, 'code' => $this->createClass($name, $this->dispatcher->getMetadata()->getNamespace(), $node));
 }
Exemplo n.º 4
0
 /**
  * @param Stmt\If_ $node
  *
  * @return string
  */
 public function convert(Stmt\If_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     if (empty($node->stmts)) {
         $node->stmts = array(new Stmt\Echo_(array(new Scalar\String("not allowed"))));
         $this->logger->logNode('Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getClass());
     }
     return implode(";\n", $collected['extracted']) . "\n" . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node);
 }
Exemplo n.º 5
0
 /**
  * @param Stmt\If_ $node
  *
  * @return string
  */
 public function convert(Stmt\If_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     if (empty($node->stmts)) {
         $node->stmts = array(new Stmt\Echo_(array(new Scalar\String_('not allowed'))));
         $this->logger->logIncompatibility('Empty if', 'Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     }
     return $collected->getCollected() . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node);
 }
Exemplo n.º 6
0
 /**
  * @param Stmt\Property $node
  *
  * @return string
  */
 public function convert(Stmt\Property $node)
 {
     foreach ($node->props as $key => $prop) {
         $prop->name = $this->reservedWordReplacer->replace($prop->name);
         $node->props[$key] = $prop;
     }
     if ($node->props[0]->default instanceof Expr\Array_ && $node->isStatic() === true) {
         $node->type = $node->type - Stmt\Class_::MODIFIER_STATIC;
         $this->dispatcher->moveToNonStaticVar($node->props[0]->name);
         $this->logger->logNode("Static attribute default array not supported in zephir, (see #188). Changed into non static. ", $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     }
     return $this->dispatcher->pModifiers($node->type) . $this->dispatcher->pCommaSeparated($node->props) . ';';
 }
 public function convert(Stmt\Interface_ $node)
 {
     $node->name = $this->reservedWordReplacer->replace($node->name);
     $extendsStmt = '';
     if (!empty($node->extends)) {
         $extendsStmt = ' extends ';
         $extends = array();
         foreach ($node->extends as $extend) {
             $extends[] = $this->classManipulator->findRightClass($extend, $this->dispatcher->getMetadata());
         }
         $extendsStmt .= implode(', ', $extends);
     }
     return 'interface ' . $node->name . $extendsStmt . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}';
 }
Exemplo n.º 8
0
 /**
  * @param Assign $node
  * @param Expr   $leftNode
  * @param Expr   $rightNode
  * @param string $operatorString
  */
 private function arrayDimFetchCase($node, $leftNode, $rightNode, $operatorString, $precedence, $associativity)
 {
     $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     $head = '';
     if ($leftNode instanceof ArrayDimFetch) {
         if (false === ($splitedArray = $this->arrayManipulator->arrayNeedToBeSplit($leftNode))) {
             $leftString = $this->dispatcher->pPrec($leftNode, $precedence, $associativity, 1);
         } else {
             $result = $this->dispatcher->pExpr_ArrayDimFetch($leftNode, true);
             $head .= $result['head'];
             $leftString = $result['lastExpr'];
         }
     } else {
         $leftString = $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1);
     }
     if ($rightNode instanceof ArrayDimFetch) {
         if (false === ($splitedArray = $this->arrayManipulator->arrayNeedToBeSplit($rightNode))) {
             $rightString = $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1);
         } else {
             $result = $this->dispatcher->pExpr_ArrayDimFetch($rightNode, true);
             $head .= $result['head'];
             $rightString = $result['lastExpr'];
         }
     } elseif ($this->isSomething($rightNode)) {
         $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
         // @TODO add test case for each
         $rightString = $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1);
     } else {
         $head .= $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1) . ";\n";
         $rightString = $this->dispatcher->p($rightNode->var);
     }
     return $head . 'let ' . $leftString . $operatorString . $rightString;
 }
Exemplo n.º 9
0
 /**
  * @param Stmt\ClassMethod $node
  *
  * @return string
  */
 public function convert(Stmt\ClassMethod $node)
 {
     $types = $this->typeFinder->getTypes($node, $this->dispatcher->getMetadata());
     $this->dispatcher->setLastMethod($node->name);
     $stmt = $this->dispatcher->pModifiers($node->type) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(';
     $varsInMethodSign = array();
     if (isset($types['params']) === true) {
         $params = array();
         foreach ($types['params'] as $type) {
             $varsInMethodSign[] = $type['name'];
             $stringType = $this->printType($type);
             $params[] = (!empty($stringType) ? $stringType . ' ' : '') . '' . $type['name'] . ($type['default'] === null ? '' : ' = ' . $this->dispatcher->p($type['default']));
         }
         $stmt .= implode(', ', $params);
     }
     $stmt .= ')';
     $stmt .= $this->printReturn($node, $types);
     $stmt .= (null !== $node->stmts ? "\n{" . $this->printVars($node, $varsInMethodSign) . $this->dispatcher->pStmts($node->stmts) . "\n}" : ';') . "\n";
     return $stmt;
 }
Exemplo n.º 10
0
 /**
  * @param Expr\ArrayDimFetch $node
  */
 private function findComplexArrayDimFetch($node, $collected = array())
 {
     if ($this->isInvalidInArrayDimFetch($node) === true) {
         if ($node->dim instanceof Expr\FuncCall) {
             $this->logger->trace(__METHOD__ . ' ' . __LINE__ . ' Non supported funccall in array', $node, $this->dispatcher->getMetadata()->getClass());
         } else {
             $collected[] = array('expr' => $this->dispatcher->p($node->dim) . ";\n", 'splitTab' => true, 'var' => $this->dispatcher->p($node->dim->var));
         }
     } else {
         if ($node->dim === null) {
             $collected[] = array('expr' => $this->dispatcher->p($node->var), 'splitTab' => false);
         } else {
             $collected[] = array('expr' => $this->dispatcher->p($node->dim), 'splitTab' => false);
         }
     }
     if ($node->var instanceof Expr\ArrayDimFetch) {
         $collected = $this->findComplexArrayDimFetch($node->var, $collected);
     } else {
         $collected[] = $node->var;
     }
     return $collected;
 }
Exemplo n.º 11
0
 /**
  * @param Name $node
  *
  * @return Ambigous <string, unknown>
  */
 public function convert(Name $node)
 {
     return $this->classManipulator->findRightClass($node, $this->dispatcher->getMetadata());
 }