protected function renderOperand(Operand $var)
{
$type = isset($var->type) ? "<{$var->type}>" : "";
if ($var instanceof Literal) {
return "LITERAL{$type}(" . var_export($var->value, true) . ")";
} elseif ($var instanceof Variable) {
assert($var->name instanceof Literal);
$prefix = "{$type}\$";
if ($var instanceof BoundVariable) {
if ($var->byRef) {
$prefix = "&\$";
}
switch ($var->scope) {
case BoundVariable::SCOPE_GLOBAL:
return "global<{$prefix}{$var->name->value}>";
case BoundVariable::SCOPE_LOCAL:
return "local<{$prefix}{$var->name->value}>";
case BoundVariable::SCOPE_OBJECT:
return "this<{$prefix}{$var->name->value}>";
case BoundVariable::SCOPE_FUNCTION:
return "static<{$prefix}{$var->name->value}>";
default:
throw new \LogicException("Unknown bound variable scope");
}
}
return $prefix . $var->name->value . $type;
} elseif ($var instanceof Temporary) {
$id = $this->getVarId($var);
if ($var->original) {
return "Var{$type}#{$id}" . "<" . $this->renderOperand($var->original) . ">";
}
return "Var{$type}#" . $this->getVarId($var);
} elseif (is_array($var)) {
$result = "array" . $type;
foreach ($var as $k => $v) {
$result .= "\n {$k}: " . $this->indent($this->renderOperand($v));
}
return $result;
}
return 'UNKNOWN';
}