Changeset View
Changeset View
Standalone View
Standalone View
src/parser/xhpast/api/XHPASTNode.php
Show All 25 Lines | public function getDocblockToken() { | ||||
return null; | return null; | ||||
} | } | ||||
public function evalStatic() { | public function evalStatic() { | ||||
switch ($this->getTypeName()) { | switch ($this->getTypeName()) { | ||||
case 'n_STATEMENT': | case 'n_STATEMENT': | ||||
return $this->getChildByIndex(0)->evalStatic(); | return $this->getChildByIndex(0)->evalStatic(); | ||||
break; | |||||
case 'n_STRING_SCALAR': | case 'n_STRING_SCALAR': | ||||
return phutil_string_cast($this->getStringLiteralValue()); | return phutil_string_cast($this->getStringLiteralValue()); | ||||
case 'n_HEREDOC': | case 'n_HEREDOC': | ||||
return phutil_string_cast($this->getStringLiteralValue()); | return phutil_string_cast($this->getStringLiteralValue()); | ||||
case 'n_NUMERIC_SCALAR': | case 'n_NUMERIC_SCALAR': | ||||
$value = $this->getSemanticString(); | $value = $this->getSemanticString(); | ||||
if (preg_match('/^0x/i', $value)) { | if (preg_match('/^0x/i', $value)) { | ||||
// Hex | // Hex | ||||
Show All 13 Lines | switch ($this->getTypeName()) { | ||||
return true; | return true; | ||||
case 'false': | case 'false': | ||||
return false; | return false; | ||||
case 'null': | case 'null': | ||||
return null; | return null; | ||||
default: | default: | ||||
throw new Exception(pht('Unrecognized symbol name.')); | throw new Exception(pht('Unrecognized symbol name.')); | ||||
} | } | ||||
break; | |||||
case 'n_UNARY_PREFIX_EXPRESSION': | case 'n_UNARY_PREFIX_EXPRESSION': | ||||
$operator = $this->getChildOfType(0, 'n_OPERATOR'); | $operator = $this->getChildOfType(0, 'n_OPERATOR'); | ||||
$operand = $this->getChildByIndex(1); | $operand = $this->getChildByIndex(1); | ||||
switch ($operator->getSemanticString()) { | switch ($operator->getSemanticString()) { | ||||
case '-': | case '-': | ||||
return -$operand->evalStatic(); | return -$operand->evalStatic(); | ||||
break; | |||||
case '+': | case '+': | ||||
return $operand->evalStatic(); | return $operand->evalStatic(); | ||||
break; | |||||
default: | default: | ||||
throw new Exception( | throw new Exception( | ||||
pht('Unexpected operator in static expression.')); | pht('Unexpected operator in static expression.')); | ||||
} | } | ||||
break; | |||||
case 'n_ARRAY_LITERAL': | case 'n_ARRAY_LITERAL': | ||||
$result = array(); | $result = array(); | ||||
$values = $this->getChildOfType(0, 'n_ARRAY_VALUE_LIST'); | $values = $this->getChildOfType(0, 'n_ARRAY_VALUE_LIST'); | ||||
foreach ($values->getChildren() as $child) { | foreach ($values->getChildren() as $child) { | ||||
$key = $child->getChildByIndex(0); | $key = $child->getChildByIndex(0); | ||||
$val = $child->getChildByIndex(1); | $val = $child->getChildByIndex(1); | ||||
if ($key->getTypeName() == 'n_EMPTY') { | if ($key->getTypeName() == 'n_EMPTY') { | ||||
$result[] = $val->evalStatic(); | $result[] = $val->evalStatic(); | ||||
▲ Show 20 Lines • Show All 254 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0