Lines Matching refs:expr
42 $this->fallbackEvaluator = $fallbackEvaluator ?? function (Expr $expr) {
44 "Expression of type {$expr->getType()} cannot be evaluated"
61 * @param Expr $expr Constant expression to evaluate
66 public function evaluateSilently(Expr $expr) { argument
72 return $this->evaluate($expr);
96 * @param Expr $expr Constant expression to evaluate
101 public function evaluateDirectly(Expr $expr) { argument
102 return $this->evaluate($expr);
106 private function evaluate(Expr $expr) { argument
107 if ($expr instanceof Scalar\Int_
108 || $expr instanceof Scalar\Float_
109 || $expr instanceof Scalar\String_
111 return $expr->value;
114 if ($expr instanceof Expr\Array_) {
115 return $this->evaluateArray($expr);
119 if ($expr instanceof Expr\UnaryPlus) {
120 return +$this->evaluate($expr->expr);
122 if ($expr instanceof Expr\UnaryMinus) {
123 return -$this->evaluate($expr->expr);
125 if ($expr instanceof Expr\BooleanNot) {
126 return !$this->evaluate($expr->expr);
128 if ($expr instanceof Expr\BitwiseNot) {
129 return ~$this->evaluate($expr->expr);
132 if ($expr instanceof Expr\BinaryOp) {
133 return $this->evaluateBinaryOp($expr);
136 if ($expr instanceof Expr\Ternary) {
137 return $this->evaluateTernary($expr);
140 if ($expr instanceof Expr\ArrayDimFetch && null !== $expr->dim) {
141 return $this->evaluate($expr->var)[$this->evaluate($expr->dim)];
144 if ($expr instanceof Expr\ConstFetch) {
145 return $this->evaluateConstFetch($expr);
148 return ($this->fallbackEvaluator)($expr);
151 private function evaluateArray(Expr\Array_ $expr): array { argument
153 foreach ($expr->items as $item) {
166 private function evaluateTernary(Expr\Ternary $expr) { argument
167 if (null === $expr->if) {
168 return $this->evaluate($expr->cond) ?: $this->evaluate($expr->else);
171 return $this->evaluate($expr->cond)
172 ? $this->evaluate($expr->if)
173 : $this->evaluate($expr->else);
177 private function evaluateBinaryOp(Expr\BinaryOp $expr) { argument
178 if ($expr instanceof Expr\BinaryOp\Coalesce
179 && $expr->left instanceof Expr\ArrayDimFetch
182 return $this->evaluate($expr->left->var)[$this->evaluate($expr->left->dim)]
183 ?? $this->evaluate($expr->right);
188 $l = $expr->left;
189 $r = $expr->right;
190 switch ($expr->getOperatorSigil()) {
224 private function evaluateConstFetch(Expr\ConstFetch $expr) { argument
225 $name = $expr->name->toLowerString();
232 return ($this->fallbackEvaluator)($expr);