Skip to content

Commit

Permalink
Merge pull request #1602 from sergeyklay/development
Browse files Browse the repository at this point in the history
 Deal with types
  • Loading branch information
sergeyklay authored Nov 11, 2017
2 parents 04eb328 + 0352562 commit 6b069ad
Show file tree
Hide file tree
Showing 18 changed files with 596 additions and 236 deletions.
10 changes: 7 additions & 3 deletions Library/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Zephir;

use Zephir\Statements\StatementAbstract;

/**
* Branch
*
Expand All @@ -24,6 +26,7 @@ class Branch

protected $level = -1;

/** @var StatementAbstract|null */
protected $relatedStatement;

protected $type;
Expand Down Expand Up @@ -139,15 +142,16 @@ public function getUniqueId()
}

/**
* @param $relatedStatement
* @param StatementAbstract $relatedStatement
* @return void
*/
public function setRelatedStatement($relatedStatement)
public function setRelatedStatement(StatementAbstract $relatedStatement)
{
$this->relatedStatement = $relatedStatement;
}

/**
* @return mixed
* @return StatementAbstract|null
*/
public function getRelatedStatement()
{
Expand Down
2 changes: 1 addition & 1 deletion Library/CompiledExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* This represent a compiled expression, the object can be used to check
* if the expression type is able to be used in certain types of the application
*/
class CompiledExpression
class CompiledExpression implements TypeAwareInterface
{
protected $type;

Expand Down
2 changes: 1 addition & 1 deletion Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
class Compiler
{
const VERSION = '0.10.5';
const VERSION = '0.10.6';

public $parserCompiled = false;

Expand Down
42 changes: 42 additions & 0 deletions Library/Compiler/IllegalOperationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir |
| Copyright (c) 2013-present Zephir Team (https://zephir-lang.com/) |
| |
| This source file is subject the MIT license, that is bundled with this |
| package in the file LICENSE, and is available through the world-wide-web |
| at the following url: https://zephir-lang.com/license.html |
+--------------------------------------------------------------------------+
*/

namespace Zephir\Compiler;

use Zephir\TypeAwareInterface;

/**
* Zephir\Compiler\IllegalOperationException
*
* @package Zephir\Compiler
*/
class IllegalOperationException extends CompilerException
{
/**
* IllegalOperationException constructor.
*
* @param array $statement The statement
* @param TypeAwareInterface $type Oprator type
* @param array|null $extra Extra info [optional].
*/
public function __construct(array $statement, TypeAwareInterface $type, array $extra = null)
{
$message = sprintf(
"Operator '%s' is not supported for variable type: %s",
$statement['operator'],
$type->getType()
);

parent::__construct($message, $extra ?: $statement);
}
}
7 changes: 1 addition & 6 deletions Library/Passes/StaticTypeInference.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,10 @@ public function passExpression(array $expression)
case 'null':
case 'char':
case 'uchar':
case 'string':
case 'istring':
return $expression['type'];

case 'string':
if (ctype_digit($expression['value'])) {
return 'long';
}
return 'string';

case 'closure':
case 'closure-arrow':
case 'static-constant-access':
Expand Down
6 changes: 4 additions & 2 deletions Library/Statements/Let/StaticProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Zephir\ClassProperty;
use Zephir\CompilationContext;
use Zephir\Compiler\CompilerException;
use Zephir\Compiler\IllegalOperationException;
use Zephir\Expression;
use Zephir\CompiledExpression;

Expand All @@ -36,6 +37,7 @@ class StaticProperty
* @param array $statement
*
* @throws CompilerException
* @throws IllegalOperationException
* @internal param string $variable
*/
public function assignStatic($className, $property, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
Expand Down Expand Up @@ -141,7 +143,7 @@ public function assignStatic($className, $property, CompiledExpression $resolved
}
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for variable type: string", $statement);
throw new IllegalOperationException($statement, $resolvedExpr);
}

$compilationContext->backend->updateStaticProperty($classEntry, $property, $tempVariable, $compilationContext);
Expand Down Expand Up @@ -261,7 +263,7 @@ public function assignStatic($className, $property, CompiledExpression $resolved
}
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for variable type: string", $statement);
throw new IllegalOperationException($statement, $variableVariable);
}
break;
case 'variable':
Expand Down
Loading

0 comments on commit 6b069ad

Please sign in to comment.