Author: Elliot Levin (elliotlevin@hotmail.com)
Inheritance: implements Pinq\Expressions\IEvaluationContext
Example #1
0
 protected function assertTypeMatchesValue(ITypeAnalysis $analysis, O\Expression $expression, IType $metadataType = null)
 {
     $type = $this->typeSystem->getTypeFromValue($expression->evaluate(O\EvaluationContext::staticContext(__NAMESPACE__, __CLASS__)));
     $this->assertEqualTypes($type, $analysis->getReturnTypeOf($expression));
     if ($metadataType !== null) {
         $this->assertEqualTypes($metadataType, $type, $expression->compileDebug());
     }
 }
 public function __construct($namespace, $scopeType, $callableId, array $parameterScopedVariableMap, array $unusedParameterDefaultExpressionMap)
 {
     $this->callableId = $callableId;
     $this->namespace = $namespace;
     $this->parameterScopedVariableMap = $parameterScopedVariableMap;
     $this->scopeType = $scopeType;
     foreach ($unusedParameterDefaultExpressionMap as $parameter => $expression) {
         if ($expression !== null) {
             /** @var $expression O\Expression */
             $this->unusedParameterDefaultMap[$parameter] = $expression->asEvaluator(O\EvaluationContext::staticContext($this->namespace, $this->scopeType));
         }
     }
 }
Example #3
0
 public function testEmptyFunction()
 {
     $function = $this->emptyFunction();
     $this->assertSame('CALLABLE!!', $function->getCallableId());
     $this->assertSame(0, $function->getParameters()->count());
     $this->assertEquals([], $function->getParameters()->getAll());
     $this->assertEquals([], $function->getParameterScopedVariableMap());
     $this->assertSame(false, $function->hasScopeType());
     $this->assertSame(null, $function->getScopeType());
     $this->assertSame(false, $function->hasNamespace());
     $this->assertSame(null, $function->getNamespace());
     $this->assertSame(0, $function->countBodyExpressions());
     $this->assertSame(0, $function->countBodyExpressionsUntilReturn());
     $this->assertEquals([], $function->getBodyExpressions());
     $this->assertEquals([], $function->getBodyExpressionsUntilReturn());
     $this->assertEquals(['CALLABLE!!'], $function->getParameterIds());
     $this->assertEquals(O\EvaluationContext::globalScope(), $function->getEvaluationContextFactory()->getEvaluationContext(ResolvedParameterRegistry::none()));
 }
Example #4
0
 public function testVariableSuperGlobalExpressionSimplifiesCorrectly()
 {
     $this->assertEquals(O\Expression::value($_POST), O\Expression::variable(O\Expression::value('_POST'))->simplify(O\EvaluationContext::globalScope()));
 }
Example #5
0
 protected function __construct(IEvaluationContext $context = null)
 {
     $this->context = $context ?: EvaluationContext::globalScope();
     $this->requiredVariables = array_keys($this->context->getVariableTable());
 }
 public function testWithSpecialVariableNames()
 {
     $this->assertSame('1,2,3', O\CompiledEvaluator::fromExpressions([O\Expression::returnExpression(O\Expression::variable(O\Expression::value('a special var--')))], O\EvaluationContext::globalScope(null, ['a special var--' => '1,2,3']))->evaluate());
 }