/**
  * @dataProvider provideBuiltin
  * @covers ::resolve
  */
 public function testResolveBuiltin($func, $return, array $params)
 {
     $signature = $this->resolver->resolve($func);
     $this->assertEquals(Type::normalizeType($return), $signature->getReturn());
     $this->assertEquals(count($params), count($signature->getParams()));
     foreach ($params as $key => $param) {
         $this->assertEquals(Type::normalizeType($param), $signature->getParam($key));
     }
 }
Example #2
0
 public function process(Vertex $vertex, Digraph $graph)
 {
     if ($vertex instanceof Vertex\Phi) {
         $types = [];
         foreach ($vertex->getValues() as $value) {
             $types[] = (string) $value->getType();
         }
         $types = array_unique($types);
         if ($vertex->getResult()->getType()->isUnknown()) {
             $type = null;
             $setAll = false;
             if (count($types) === 1 && $types[0] !== 'unknown') {
                 $type = Type::normalizeType($types[0]);
             } elseif (count($types) === 2 && in_array('long', $types) && in_array('numeric', $types)) {
                 $type = new Type(Type::TYPE_LONG);
                 $setAll = true;
             } elseif (count($types) === 2 && in_array('double', $types) && in_array('numeric', $types)) {
                 $type = new Type(Type::TYPE_DOUBLE);
                 $setAll = true;
             } elseif (count($types) === 2 && in_array('bool', $types) && in_array('numeric', $types)) {
                 $type = new Type(Type::TYPE_BOOLEAN);
             }
             if ($type) {
                 $vertex->getResult()->setType($type);
                 if ($setAll) {
                     foreach ($vertex->getValues() as $value) {
                         $value->setType($type);
                     }
                 }
                 return true;
             }
         }
         if (count($vertex->getValues()) === 1) {
             // remove phi node
             list($val) = iterator_to_array($vertex->getValues());
             $result = $vertex->getResult();
             foreach ($graph->vertices() as $vtx) {
                 $vtx->replaceVariable($result, $val);
                 if ($vtx instanceof Assignment && $vtx->getResult() === $result) {
                     $vtx->setResult($val);
                 }
             }
             Helper::remove($vertex, $graph);
             return true;
         }
     }
     return false;
 }
Example #3
0
 public function resolveSignature($comment)
 {
     $docblock = new DocBlock((string) $comment);
     $return = $docblock->getTagsByName("return");
     if (count($return) !== 1) {
         $returnType = new Type(Type::TYPE_UNKNOWN);
     } else {
         $returnType = Type::normalizeType($return[0]->getType());
     }
     $params = $docblock->getTagsByName("param");
     $paramTypes = [];
     foreach ($params as $key => $param) {
         $paramTypes[] = Type::normalizeType($params[$key]->getType());
     }
     return new Signature($returnType, $paramTypes);
 }
Example #4
0
 /**
  * @covers ::__construct
  * @covers ::isUnknown
  */
 public function testIsUnknownWithoutUnknown()
 {
     $type = new Type(Type::TYPE_LONG);
     $this->assertFalse($type->isUnknown());
 }