Chris@0: lexer = $lexer; Chris@0: $this->errors = array(); Chris@0: Chris@0: if (isset($options['throwOnError'])) { Chris@0: throw new \LogicException( Chris@0: '"throwOnError" is no longer supported, use "errorHandler" instead'); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Parses PHP code into a node tree. Chris@0: * Chris@0: * If a non-throwing error handler is used, the parser will continue parsing after an error Chris@0: * occurred and attempt to build a partial AST. Chris@0: * Chris@0: * @param string $code The source code to parse Chris@0: * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults Chris@0: * to ErrorHandler\Throwing. Chris@0: * Chris@0: * @return Node[]|null Array of statements (or null if the 'throwOnError' option is disabled and the parser was Chris@0: * unable to recover from an error). Chris@0: */ Chris@0: public function parse($code, ErrorHandler $errorHandler = null) { Chris@0: $this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing; Chris@0: Chris@0: // Initialize the lexer Chris@0: $this->lexer->startLexing($code, $this->errorHandler); Chris@0: Chris@0: // We start off with no lookahead-token Chris@0: $symbol = self::SYMBOL_NONE; Chris@0: Chris@0: // The attributes for a node are taken from the first and last token of the node. Chris@0: // From the first token only the startAttributes are taken and from the last only Chris@0: // the endAttributes. Both are merged using the array union operator (+). Chris@0: $startAttributes = '*POISON'; Chris@0: $endAttributes = '*POISON'; Chris@0: $this->endAttributes = $endAttributes; Chris@0: Chris@0: // Keep stack of start and end attributes Chris@0: $this->startAttributeStack = array(); Chris@0: $this->endAttributeStack = array($endAttributes); Chris@0: Chris@0: // Start off in the initial state and keep a stack of previous states Chris@0: $state = 0; Chris@0: $stateStack = array($state); Chris@0: Chris@0: // Semantic value stack (contains values of tokens and semantic action results) Chris@0: $this->semStack = array(); Chris@0: Chris@0: // Current position in the stack(s) Chris@0: $this->stackPos = 0; Chris@0: Chris@0: $this->errorState = 0; Chris@0: Chris@0: for (;;) { Chris@0: //$this->traceNewState($state, $symbol); Chris@0: Chris@0: if ($this->actionBase[$state] == 0) { Chris@0: $rule = $this->actionDefault[$state]; Chris@0: } else { Chris@0: if ($symbol === self::SYMBOL_NONE) { Chris@0: // Fetch the next token id from the lexer and fetch additional info by-ref. Chris@0: // The end attributes are fetched into a temporary variable and only set once the token is really Chris@0: // shifted (not during read). Otherwise you would sometimes get off-by-one errors, when a rule is Chris@0: // reduced after a token was read but not yet shifted. Chris@0: $tokenId = $this->lexer->getNextToken($tokenValue, $startAttributes, $endAttributes); Chris@0: Chris@0: // map the lexer token id to the internally used symbols Chris@0: $symbol = $tokenId >= 0 && $tokenId < $this->tokenToSymbolMapSize Chris@0: ? $this->tokenToSymbol[$tokenId] Chris@0: : $this->invalidSymbol; Chris@0: Chris@0: if ($symbol === $this->invalidSymbol) { Chris@0: throw new \RangeException(sprintf( Chris@0: 'The lexer returned an invalid token (id=%d, value=%s)', Chris@0: $tokenId, $tokenValue Chris@0: )); Chris@0: } Chris@0: Chris@0: // This is necessary to assign some meaningful attributes to /* empty */ productions. They'll get Chris@0: // the attributes of the next token, even though they don't contain it themselves. Chris@0: $this->startAttributeStack[$this->stackPos+1] = $startAttributes; Chris@0: $this->endAttributeStack[$this->stackPos+1] = $endAttributes; Chris@0: $this->lookaheadStartAttributes = $startAttributes; Chris@0: Chris@0: //$this->traceRead($symbol); Chris@0: } Chris@0: Chris@0: $idx = $this->actionBase[$state] + $symbol; Chris@0: if ((($idx >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] == $symbol) Chris@0: || ($state < $this->YY2TBLSTATE Chris@0: && ($idx = $this->actionBase[$state + $this->YYNLSTATES] + $symbol) >= 0 Chris@0: && $idx < $this->actionTableSize && $this->actionCheck[$idx] == $symbol)) Chris@0: && ($action = $this->action[$idx]) != $this->defaultAction) { Chris@0: /* Chris@0: * >= YYNLSTATES: shift and reduce Chris@0: * > 0: shift Chris@0: * = 0: accept Chris@0: * < 0: reduce Chris@0: * = -YYUNEXPECTED: error Chris@0: */ Chris@0: if ($action > 0) { Chris@0: /* shift */ Chris@0: //$this->traceShift($symbol); Chris@0: Chris@0: ++$this->stackPos; Chris@0: $stateStack[$this->stackPos] = $state = $action; Chris@0: $this->semStack[$this->stackPos] = $tokenValue; Chris@0: $this->startAttributeStack[$this->stackPos] = $startAttributes; Chris@0: $this->endAttributeStack[$this->stackPos] = $endAttributes; Chris@0: $this->endAttributes = $endAttributes; Chris@0: $symbol = self::SYMBOL_NONE; Chris@0: Chris@0: if ($this->errorState) { Chris@0: --$this->errorState; Chris@0: } Chris@0: Chris@0: if ($action < $this->YYNLSTATES) { Chris@0: continue; Chris@0: } Chris@0: Chris@0: /* $yyn >= YYNLSTATES means shift-and-reduce */ Chris@0: $rule = $action - $this->YYNLSTATES; Chris@0: } else { Chris@0: $rule = -$action; Chris@0: } Chris@0: } else { Chris@0: $rule = $this->actionDefault[$state]; Chris@0: } Chris@0: } Chris@0: Chris@0: for (;;) { Chris@0: if ($rule === 0) { Chris@0: /* accept */ Chris@0: //$this->traceAccept(); Chris@0: return $this->semValue; Chris@0: } elseif ($rule !== $this->unexpectedTokenRule) { Chris@0: /* reduce */ Chris@0: //$this->traceReduce($rule); Chris@0: Chris@0: try { Chris@0: $this->{'reduceRule' . $rule}(); Chris@0: } catch (Error $e) { Chris@0: if (-1 === $e->getStartLine() && isset($startAttributes['startLine'])) { Chris@0: $e->setStartLine($startAttributes['startLine']); Chris@0: } Chris@0: Chris@0: $this->emitError($e); Chris@0: // Can't recover from this type of error Chris@0: return null; Chris@0: } Chris@0: Chris@0: /* Goto - shift nonterminal */ Chris@0: $lastEndAttributes = $this->endAttributeStack[$this->stackPos]; Chris@0: $this->stackPos -= $this->ruleToLength[$rule]; Chris@0: $nonTerminal = $this->ruleToNonTerminal[$rule]; Chris@0: $idx = $this->gotoBase[$nonTerminal] + $stateStack[$this->stackPos]; Chris@0: if ($idx >= 0 && $idx < $this->gotoTableSize && $this->gotoCheck[$idx] == $nonTerminal) { Chris@0: $state = $this->goto[$idx]; Chris@0: } else { Chris@0: $state = $this->gotoDefault[$nonTerminal]; Chris@0: } Chris@0: Chris@0: ++$this->stackPos; Chris@0: $stateStack[$this->stackPos] = $state; Chris@0: $this->semStack[$this->stackPos] = $this->semValue; Chris@0: $this->endAttributeStack[$this->stackPos] = $lastEndAttributes; Chris@0: } else { Chris@0: /* error */ Chris@0: switch ($this->errorState) { Chris@0: case 0: Chris@0: $msg = $this->getErrorMessage($symbol, $state); Chris@0: $this->emitError(new Error($msg, $startAttributes + $endAttributes)); Chris@0: // Break missing intentionally Chris@0: case 1: Chris@0: case 2: Chris@0: $this->errorState = 3; Chris@0: Chris@0: // Pop until error-expecting state uncovered Chris@0: while (!( Chris@0: (($idx = $this->actionBase[$state] + $this->errorSymbol) >= 0 Chris@0: && $idx < $this->actionTableSize && $this->actionCheck[$idx] == $this->errorSymbol) Chris@0: || ($state < $this->YY2TBLSTATE Chris@0: && ($idx = $this->actionBase[$state + $this->YYNLSTATES] + $this->errorSymbol) >= 0 Chris@0: && $idx < $this->actionTableSize && $this->actionCheck[$idx] == $this->errorSymbol) Chris@0: ) || ($action = $this->action[$idx]) == $this->defaultAction) { // Not totally sure about this Chris@0: if ($this->stackPos <= 0) { Chris@0: // Could not recover from error Chris@0: return null; Chris@0: } Chris@0: $state = $stateStack[--$this->stackPos]; Chris@0: //$this->tracePop($state); Chris@0: } Chris@0: Chris@0: //$this->traceShift($this->errorSymbol); Chris@0: ++$this->stackPos; Chris@0: $stateStack[$this->stackPos] = $state = $action; Chris@0: Chris@0: // We treat the error symbol as being empty, so we reset the end attributes Chris@0: // to the end attributes of the last non-error symbol Chris@0: $this->endAttributeStack[$this->stackPos] = $this->endAttributeStack[$this->stackPos - 1]; Chris@0: $this->endAttributes = $this->endAttributeStack[$this->stackPos - 1]; Chris@0: break; Chris@0: Chris@0: case 3: Chris@0: if ($symbol === 0) { Chris@0: // Reached EOF without recovering from error Chris@0: return null; Chris@0: } Chris@0: Chris@0: //$this->traceDiscard($symbol); Chris@0: $symbol = self::SYMBOL_NONE; Chris@0: break 2; Chris@0: } Chris@0: } Chris@0: Chris@0: if ($state < $this->YYNLSTATES) { Chris@0: break; Chris@0: } Chris@0: Chris@0: /* >= YYNLSTATES means shift-and-reduce */ Chris@0: $rule = $state - $this->YYNLSTATES; Chris@0: } Chris@0: } Chris@0: Chris@0: throw new \RuntimeException('Reached end of parser loop'); Chris@0: } Chris@0: Chris@0: protected function emitError(Error $error) { Chris@0: $this->errorHandler->handleError($error); Chris@0: } Chris@0: Chris@0: protected function getErrorMessage($symbol, $state) { Chris@0: $expectedString = ''; Chris@0: if ($expected = $this->getExpectedTokens($state)) { Chris@0: $expectedString = ', expecting ' . implode(' or ', $expected); Chris@0: } Chris@0: Chris@0: return 'Syntax error, unexpected ' . $this->symbolToName[$symbol] . $expectedString; Chris@0: } Chris@0: Chris@0: protected function getExpectedTokens($state) { Chris@0: $expected = array(); Chris@0: Chris@0: $base = $this->actionBase[$state]; Chris@0: foreach ($this->symbolToName as $symbol => $name) { Chris@0: $idx = $base + $symbol; Chris@0: if ($idx >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol Chris@0: || $state < $this->YY2TBLSTATE Chris@0: && ($idx = $this->actionBase[$state + $this->YYNLSTATES] + $symbol) >= 0 Chris@0: && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol Chris@0: ) { Chris@0: if ($this->action[$idx] != $this->unexpectedTokenRule Chris@0: && $this->action[$idx] != $this->defaultAction Chris@0: && $symbol != $this->errorSymbol Chris@0: ) { Chris@0: if (count($expected) == 4) { Chris@0: /* Too many expected tokens */ Chris@0: return array(); Chris@0: } Chris@0: Chris@0: $expected[] = $name; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: return $expected; Chris@0: } Chris@0: Chris@0: /* Chris@0: * Tracing functions used for debugging the parser. Chris@0: */ Chris@0: Chris@0: /* Chris@0: protected function traceNewState($state, $symbol) { Chris@0: echo '% State ' . $state Chris@0: . ', Lookahead ' . ($symbol == self::SYMBOL_NONE ? '--none--' : $this->symbolToName[$symbol]) . "\n"; Chris@0: } Chris@0: Chris@0: protected function traceRead($symbol) { Chris@0: echo '% Reading ' . $this->symbolToName[$symbol] . "\n"; Chris@0: } Chris@0: Chris@0: protected function traceShift($symbol) { Chris@0: echo '% Shift ' . $this->symbolToName[$symbol] . "\n"; Chris@0: } Chris@0: Chris@0: protected function traceAccept() { Chris@0: echo "% Accepted.\n"; Chris@0: } Chris@0: Chris@0: protected function traceReduce($n) { Chris@0: echo '% Reduce by (' . $n . ') ' . $this->productions[$n] . "\n"; Chris@0: } Chris@0: Chris@0: protected function tracePop($state) { Chris@0: echo '% Recovering, uncovered state ' . $state . "\n"; Chris@0: } Chris@0: Chris@0: protected function traceDiscard($symbol) { Chris@0: echo '% Discard ' . $this->symbolToName[$symbol] . "\n"; Chris@0: } Chris@0: */ Chris@0: Chris@0: /* Chris@0: * Helper functions invoked by semantic actions Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions. Chris@0: * Chris@0: * @param Node[] $stmts Chris@0: * @return Node[] Chris@0: */ Chris@0: protected function handleNamespaces(array $stmts) { Chris@0: $hasErrored = false; Chris@0: $style = $this->getNamespacingStyle($stmts); Chris@0: if (null === $style) { Chris@0: // not namespaced, nothing to do Chris@0: return $stmts; Chris@0: } elseif ('brace' === $style) { Chris@0: // For braced namespaces we only have to check that there are no invalid statements between the namespaces Chris@0: $afterFirstNamespace = false; Chris@0: foreach ($stmts as $stmt) { Chris@0: if ($stmt instanceof Node\Stmt\Namespace_) { Chris@0: $afterFirstNamespace = true; Chris@0: } elseif (!$stmt instanceof Node\Stmt\HaltCompiler Chris@0: && !$stmt instanceof Node\Stmt\Nop Chris@0: && $afterFirstNamespace && !$hasErrored) { Chris@0: $this->emitError(new Error( Chris@0: 'No code may exist outside of namespace {}', $stmt->getAttributes())); Chris@0: $hasErrored = true; // Avoid one error for every statement Chris@0: } Chris@0: } Chris@0: return $stmts; Chris@0: } else { Chris@0: // For semicolon namespaces we have to move the statements after a namespace declaration into ->stmts Chris@0: $resultStmts = array(); Chris@0: $targetStmts =& $resultStmts; Chris@0: foreach ($stmts as $stmt) { Chris@0: if ($stmt instanceof Node\Stmt\Namespace_) { Chris@0: if ($stmt->stmts === null) { Chris@0: $stmt->stmts = array(); Chris@0: $targetStmts =& $stmt->stmts; Chris@0: $resultStmts[] = $stmt; Chris@0: } else { Chris@0: // This handles the invalid case of mixed style namespaces Chris@0: $resultStmts[] = $stmt; Chris@0: $targetStmts =& $resultStmts; Chris@0: } Chris@0: } elseif ($stmt instanceof Node\Stmt\HaltCompiler) { Chris@0: // __halt_compiler() is not moved into the namespace Chris@0: $resultStmts[] = $stmt; Chris@0: } else { Chris@0: $targetStmts[] = $stmt; Chris@0: } Chris@0: } Chris@0: return $resultStmts; Chris@0: } Chris@0: } Chris@0: Chris@0: private function getNamespacingStyle(array $stmts) { Chris@0: $style = null; Chris@0: $hasNotAllowedStmts = false; Chris@0: foreach ($stmts as $i => $stmt) { Chris@0: if ($stmt instanceof Node\Stmt\Namespace_) { Chris@0: $currentStyle = null === $stmt->stmts ? 'semicolon' : 'brace'; Chris@0: if (null === $style) { Chris@0: $style = $currentStyle; Chris@0: if ($hasNotAllowedStmts) { Chris@0: $this->emitError(new Error( Chris@0: 'Namespace declaration statement has to be the very first statement in the script', Chris@0: $stmt->getLine() // Avoid marking the entire namespace as an error Chris@0: )); Chris@0: } Chris@0: } elseif ($style !== $currentStyle) { Chris@0: $this->emitError(new Error( Chris@0: 'Cannot mix bracketed namespace declarations with unbracketed namespace declarations', Chris@0: $stmt->getLine() // Avoid marking the entire namespace as an error Chris@0: )); Chris@0: // Treat like semicolon style for namespace normalization Chris@0: return 'semicolon'; Chris@0: } Chris@0: continue; Chris@0: } Chris@0: Chris@0: /* declare(), __halt_compiler() and nops can be used before a namespace declaration */ Chris@0: if ($stmt instanceof Node\Stmt\Declare_ Chris@0: || $stmt instanceof Node\Stmt\HaltCompiler Chris@0: || $stmt instanceof Node\Stmt\Nop) { Chris@0: continue; Chris@0: } Chris@0: Chris@0: /* There may be a hashbang line at the very start of the file */ Chris@0: if ($i == 0 && $stmt instanceof Node\Stmt\InlineHTML && preg_match('/\A#!.*\r?\n\z/', $stmt->value)) { Chris@0: continue; Chris@0: } Chris@0: Chris@0: /* Everything else if forbidden before namespace declarations */ Chris@0: $hasNotAllowedStmts = true; Chris@0: } Chris@0: return $style; Chris@0: } Chris@0: Chris@0: protected function handleBuiltinTypes(Name $name) { Chris@0: $scalarTypes = [ Chris@0: 'bool' => true, Chris@0: 'int' => true, Chris@0: 'float' => true, Chris@0: 'string' => true, Chris@0: 'iterable' => true, Chris@0: 'void' => true, Chris@0: 'object' => true, Chris@0: ]; Chris@0: Chris@0: if (!$name->isUnqualified()) { Chris@0: return $name; Chris@0: } Chris@0: Chris@0: $lowerName = strtolower($name->toString()); Chris@0: return isset($scalarTypes[$lowerName]) ? $lowerName : $name; Chris@0: } Chris@0: Chris@0: protected static $specialNames = array( Chris@0: 'self' => true, Chris@0: 'parent' => true, Chris@0: 'static' => true, Chris@0: ); Chris@0: Chris@0: protected function getAttributesAt($pos) { Chris@0: return $this->startAttributeStack[$pos] + $this->endAttributeStack[$pos]; Chris@0: } Chris@0: Chris@0: protected function parseLNumber($str, $attributes, $allowInvalidOctal = false) { Chris@0: try { Chris@0: return LNumber::fromString($str, $attributes, $allowInvalidOctal); Chris@0: } catch (Error $error) { Chris@0: $this->emitError($error); Chris@0: // Use dummy value Chris@0: return new LNumber(0, $attributes); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function parseNumString($str, $attributes) { Chris@0: if (!preg_match('/^(?:0|-?[1-9][0-9]*)$/', $str)) { Chris@0: return new String_($str, $attributes); Chris@0: } Chris@0: Chris@0: $num = +$str; Chris@0: if (!is_int($num)) { Chris@0: return new String_($str, $attributes); Chris@0: } Chris@0: Chris@0: return new LNumber($num, $attributes); Chris@0: } Chris@0: Chris@0: protected function checkModifier($a, $b, $modifierPos) { Chris@0: // Jumping through some hoops here because verifyModifier() is also used elsewhere Chris@0: try { Chris@0: Class_::verifyModifier($a, $b); Chris@0: } catch (Error $error) { Chris@0: $error->setAttributes($this->getAttributesAt($modifierPos)); Chris@0: $this->emitError($error); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkParam(Param $node) { Chris@0: if ($node->variadic && null !== $node->default) { Chris@0: $this->emitError(new Error( Chris@0: 'Variadic parameter cannot have a default value', Chris@0: $node->default->getAttributes() Chris@0: )); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkTryCatch(TryCatch $node) { Chris@0: if (empty($node->catches) && null === $node->finally) { Chris@0: $this->emitError(new Error( Chris@0: 'Cannot use try without catch or finally', $node->getAttributes() Chris@0: )); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkNamespace(Namespace_ $node) { Chris@0: if (isset(self::$specialNames[strtolower($node->name)])) { Chris@0: $this->emitError(new Error( Chris@0: sprintf('Cannot use \'%s\' as namespace name', $node->name), Chris@0: $node->name->getAttributes() Chris@0: )); Chris@0: } Chris@0: Chris@0: if (null !== $node->stmts) { Chris@0: foreach ($node->stmts as $stmt) { Chris@0: if ($stmt instanceof Namespace_) { Chris@0: $this->emitError(new Error( Chris@0: 'Namespace declarations cannot be nested', $stmt->getAttributes() Chris@0: )); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkClass(Class_ $node, $namePos) { Chris@0: if (null !== $node->name && isset(self::$specialNames[strtolower($node->name)])) { Chris@0: $this->emitError(new Error( Chris@0: sprintf('Cannot use \'%s\' as class name as it is reserved', $node->name), Chris@0: $this->getAttributesAt($namePos) Chris@0: )); Chris@0: } Chris@0: Chris@0: if (isset(self::$specialNames[strtolower($node->extends)])) { Chris@0: $this->emitError(new Error( Chris@0: sprintf('Cannot use \'%s\' as class name as it is reserved', $node->extends), Chris@0: $node->extends->getAttributes() Chris@0: )); Chris@0: } Chris@0: Chris@0: foreach ($node->implements as $interface) { Chris@0: if (isset(self::$specialNames[strtolower($interface)])) { Chris@0: $this->emitError(new Error( Chris@0: sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), Chris@0: $interface->getAttributes() Chris@0: )); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkInterface(Interface_ $node, $namePos) { Chris@0: if (null !== $node->name && isset(self::$specialNames[strtolower($node->name)])) { Chris@0: $this->emitError(new Error( Chris@0: sprintf('Cannot use \'%s\' as class name as it is reserved', $node->name), Chris@0: $this->getAttributesAt($namePos) Chris@0: )); Chris@0: } Chris@0: Chris@0: foreach ($node->extends as $interface) { Chris@0: if (isset(self::$specialNames[strtolower($interface)])) { Chris@0: $this->emitError(new Error( Chris@0: sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), Chris@0: $interface->getAttributes() Chris@0: )); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkClassMethod(ClassMethod $node, $modifierPos) { Chris@0: if ($node->flags & Class_::MODIFIER_STATIC) { Chris@0: switch (strtolower($node->name)) { Chris@0: case '__construct': Chris@0: $this->emitError(new Error( Chris@0: sprintf('Constructor %s() cannot be static', $node->name), Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: break; Chris@0: case '__destruct': Chris@0: $this->emitError(new Error( Chris@0: sprintf('Destructor %s() cannot be static', $node->name), Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: break; Chris@0: case '__clone': Chris@0: $this->emitError(new Error( Chris@0: sprintf('Clone method %s() cannot be static', $node->name), Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: break; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkClassConst(ClassConst $node, $modifierPos) { Chris@0: if ($node->flags & Class_::MODIFIER_STATIC) { Chris@0: $this->emitError(new Error( Chris@0: "Cannot use 'static' as constant modifier", Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: } Chris@0: if ($node->flags & Class_::MODIFIER_ABSTRACT) { Chris@0: $this->emitError(new Error( Chris@0: "Cannot use 'abstract' as constant modifier", Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: } Chris@0: if ($node->flags & Class_::MODIFIER_FINAL) { Chris@0: $this->emitError(new Error( Chris@0: "Cannot use 'final' as constant modifier", Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkProperty(Property $node, $modifierPos) { Chris@0: if ($node->flags & Class_::MODIFIER_ABSTRACT) { Chris@0: $this->emitError(new Error('Properties cannot be declared abstract', Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: } Chris@0: Chris@0: if ($node->flags & Class_::MODIFIER_FINAL) { Chris@0: $this->emitError(new Error('Properties cannot be declared final', Chris@0: $this->getAttributesAt($modifierPos))); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function checkUseUse(UseUse $node, $namePos) { Chris@0: if ('self' == strtolower($node->alias) || 'parent' == strtolower($node->alias)) { Chris@0: $this->emitError(new Error( Chris@0: sprintf( Chris@0: 'Cannot use %s as %s because \'%2$s\' is a special class name', Chris@0: $node->name, $node->alias Chris@0: ), Chris@0: $this->getAttributesAt($namePos) Chris@0: )); Chris@0: } Chris@0: } Chris@0: }