Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from TimeToogo/feature/static-analysis
Browse files Browse the repository at this point in the history
Implement static analysis tools and infrastructure for expression trees under the Analysis namespace
  • Loading branch information
TimeToogo committed Sep 20, 2014
2 parents b01d9f8 + 2574642 commit c1f07be
Show file tree
Hide file tree
Showing 51 changed files with 5,238 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ dev-master
- Extracted interfaces from `Request`/`Operation`/`Segment` visitor classes.
- Removed obsolete query providers (`Loadable`, `Caching`) in favour of a new integrated helper `Providers\Utilities\IQueryResultCollection`
- Implemented new DSL query provider under `Providers\DSL`.
- Implemented new static analysis tools and infrastructure for expression trees under the `Analysis` namespace.
- New structure of query providers
- `RepositoryProvider` decorates the `QueryProvider`
- New configuration classes (under `Providers\Configuration` namespace)
Expand Down
63 changes: 63 additions & 0 deletions Source/Analysis/AnalysisContext.php
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);
}
}
65 changes: 65 additions & 0 deletions Source/Analysis/BinaryOperations/BinaryOperation.php
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);
}
}

0 comments on commit c1f07be

Please sign in to comment.