1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php declare(strict_types=1);
- namespace PhpParser;
- if (!\function_exists('PhpParser\defineCompatibilityTokens')) {
- function defineCompatibilityTokens(): void {
- $compatTokens = [
-
- 'T_NAME_QUALIFIED',
- 'T_NAME_FULLY_QUALIFIED',
- 'T_NAME_RELATIVE',
- 'T_MATCH',
- 'T_NULLSAFE_OBJECT_OPERATOR',
- 'T_ATTRIBUTE',
-
- 'T_ENUM',
- 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
- 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
- 'T_READONLY',
- ];
-
-
-
- $usedTokenIds = [];
- foreach ($compatTokens as $token) {
- if (\defined($token)) {
- $tokenId = \constant($token);
- $clashingToken = $usedTokenIds[$tokenId] ?? null;
- if ($clashingToken !== null) {
- throw new \Error(sprintf(
- 'Token %s has same ID as token %s, ' .
- 'you may be using a library with broken token emulation',
- $token, $clashingToken
- ));
- }
- $usedTokenIds[$tokenId] = $token;
- }
- }
-
-
- $newTokenId = -1;
- foreach ($compatTokens as $token) {
- if (!\defined($token)) {
- while (isset($usedTokenIds[$newTokenId])) {
- $newTokenId--;
- }
- \define($token, $newTokenId);
- $newTokenId--;
- }
- }
- }
- defineCompatibilityTokens();
- }
|