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

Implement new static analysis tools and infrastructure for expression trees #16

Merged
merged 20 commits into from
Sep 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
085ae8b
Implement new static analysis tools and infrastructure for expression…
Sep 13, 2014
0d22272
Implement type inference in the analysis context from values in the v…
Sep 13, 2014
b0a8936
Add more tests for expression analyser
Sep 13, 2014
0c4c14b
Add test for instanceof operator expression analysis
Sep 13, 2014
6d7470d
Add tests for comparison operator expression analysis
Sep 13, 2014
6099b52
Add missing ** binary operator in Analysis\PhpTypeSystem
Sep 13, 2014
206da29
Add tests for and fix assignment operator to binary operator conversi…
Sep 13, 2014
374f971
Remove duplicate type data from Analysis\TypeData\InternalTypes
Sep 13, 2014
8023eea
Fix formatting in Analysis\TypeData\InternalFunctions
Sep 14, 2014
b2dbcd8
Fix formatting in Analysis\IExpressionAnalyser
Sep 14, 2014
91b8e64
Extract interface from Analysis\TypeData\TypeDataModule
Sep 14, 2014
2e00592
Make Analysis\TypeData\TypeDataModule non abstract
Sep 14, 2014
4c340dd
Added Countable interface to Analysis\TypeData\InternalTypes type dat…
Sep 19, 2014
4d2875e
Fix variable name in Analysis\TypeId::getComposedTypeIds and add comp…
Sep 19, 2014
a5b73b5
Renamed Analysis\TypeId::getClassType to getClassTypeFromId and Analy…
Sep 19, 2014
f95fd0d
Extract method to generate PINQ API type data in Analysis\TypeData\Pi…
Sep 20, 2014
d81b795
Add more informative exception messages for unknown type operations
Sep 20, 2014
77aee82
Fix docblocks in Analysis\PhpTypeSystem
Sep 20, 2014
9362cc3
Allow instance calls to static methods and add tests
Sep 20, 2014
2574642
Implement methods to add type data modules to Analysis\PhpTypeSystem …
Sep 20, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading