This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TimeToogo/feature/static-analysis
Implement static analysis tools and infrastructure for expression trees under the Analysis namespace
- Loading branch information
Showing
51 changed files
with
5,238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Pinq\Analysis; | ||
|
||
use Pinq\Expressions as O; | ||
|
||
/** | ||
* Implementation of the analysis context. | ||
* | ||
* @author Elliot Levin <elliotlevin@hotmail.com> | ||
*/ | ||
class AnalysisContext extends Typed implements IAnalysisContext | ||
{ | ||
/** | ||
* @var O\IEvaluationContext | ||
*/ | ||
protected $evaluationContext; | ||
|
||
/** | ||
* @var IType[] | ||
*/ | ||
protected $expressionTypes = []; | ||
|
||
public function __construct(ITypeSystem $typeSystem, O\IEvaluationContext $evaluationContext) | ||
{ | ||
parent::__construct($typeSystem); | ||
$this->evaluationContext = $evaluationContext; | ||
foreach($evaluationContext->getVariableTable() as $variable => $value) { | ||
$this->setExpressionType(O\Expression::variable(O\Expression::value($variable)), $typeSystem->getTypeFromValue($value)); | ||
} | ||
} | ||
|
||
public function getEvaluationContext() | ||
{ | ||
return $this->evaluationContext; | ||
} | ||
|
||
public function getExpressionType(O\Expression $expression) | ||
{ | ||
$hash = $expression->hash(); | ||
return isset($this->expressionTypes[$hash]) ? $this->expressionTypes[$hash] : null; | ||
} | ||
|
||
public function setExpressionType(O\Expression $expression, IType $type) | ||
{ | ||
$this->expressionTypes[$expression->hash()] = $type; | ||
} | ||
|
||
public function removeExpressionType(O\Expression $expression) | ||
{ | ||
unset($this->expressionTypes[$expression->hash()]); | ||
} | ||
|
||
public function createReference(O\Expression $expression, O\Expression $referencedExpression) | ||
{ | ||
$this->expressionTypes[$expression->hash()] =& $this->expressionTypes[$referencedExpression->hash()]; | ||
} | ||
|
||
public function inNewScope() | ||
{ | ||
return new self($this->typeSystem, $this->evaluationContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Pinq\Analysis\BinaryOperations; | ||
|
||
use Pinq\Analysis\IBinaryOperation; | ||
use Pinq\Analysis\ITypeSystem; | ||
use Pinq\Analysis\Typed; | ||
use Pinq\Expressions as O; | ||
|
||
/** | ||
* Implementation of the binary operation. | ||
* | ||
* @author Elliot Levin <elliotlevin@hotmail.com> | ||
*/ | ||
class BinaryOperation extends Typed implements IBinaryOperation | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $leftOperandType; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $operator; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $rightOperandType; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $returnType; | ||
|
||
public function __construct(ITypeSystem $typeSystem, $leftOperandType, $operator, $rightOperandType, $returnType) | ||
{ | ||
parent::__construct($typeSystem); | ||
$this->leftOperandType = $leftOperandType; | ||
$this->operator = $operator; | ||
$this->rightOperandType = $rightOperandType; | ||
$this->returnType = $returnType; | ||
} | ||
|
||
public function getLeftOperandType() | ||
{ | ||
return $this->typeSystem->getType($this->leftOperandType); | ||
} | ||
|
||
public function getOperator() | ||
{ | ||
return $this->operator; | ||
} | ||
|
||
public function getRightOperandType() | ||
{ | ||
return $this->typeSystem->getType($this->rightOperandType); | ||
} | ||
|
||
public function getReturnType() | ||
{ | ||
return $this->typeSystem->getType($this->returnType); | ||
} | ||
} |
Oops, something went wrong.