Skip to content

Commit f5dcd34

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 7c909e3 + 29d3742 commit f5dcd34

File tree

3 files changed

+129
-8
lines changed

3 files changed

+129
-8
lines changed

cmake/ext/tokenizer/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ project(
3030

3131
include(CMakeDependentOption)
3232
include(FeatureSummary)
33-
include(PHP/AddCustomCommand)
3433

3534
option(PHP_EXT_TOKENIZER "Enable the tokenizer extension" ON)
3635

@@ -71,17 +70,17 @@ target_sources(
7170
add_dependencies(php_ext_tokenizer Zend::Zend)
7271

7372
# Generate tokenizer data source files.
74-
if(PHP_SOURCE_DIR)
75-
php_add_custom_command(
76-
php_ext_tokenizer_generate_data
73+
if(EXISTS ${PHP_SOURCE_DIR}/Zend/zend_language_parser.y)
74+
add_custom_command(
7775
OUTPUT
7876
${CMAKE_CURRENT_SOURCE_DIR}/tokenizer_data.stub.php
7977
${CMAKE_CURRENT_SOURCE_DIR}/tokenizer_data.c
8078
DEPENDS
81-
${CMAKE_CURRENT_SOURCE_DIR}/tokenizer_data_gen.php
8279
${PHP_SOURCE_DIR}/Zend/zend_language_parser.y
83-
PHP_COMMAND
84-
${CMAKE_CURRENT_SOURCE_DIR}/tokenizer_data_gen.php
80+
COMMAND
81+
${CMAKE_COMMAND}
82+
-D PHP_SOURCE_DIR=${PHP_SOURCE_DIR}
83+
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateTokenizerData.cmake
8584
COMMENT
8685
"[ext/tokenizer] Regenerating tokenizer_data.c and tokenizer_data.stub.php"
8786
VERBATIM
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# This is CMake-based alternative of ext/tokenizer/tokenizer_data_gen.php
2+
#
3+
# Run as:
4+
# cmake -D PHP_SOURCE_DIR=<php-src> -P GenerateTokenizerData.cmake
5+
6+
cmake_minimum_required(VERSION 3.25...3.31)
7+
8+
if(NOT CMAKE_SCRIPT_MODE_FILE)
9+
message(FATAL_ERROR "This is a command-line script.")
10+
endif()
11+
12+
if(NOT PHP_SOURCE_DIR)
13+
message(FATAL_ERROR "PHP_SOURCE_DIR variable is required.")
14+
endif()
15+
16+
set(regex "^%token [^T]*(T_[^ \n]+)")
17+
18+
file(
19+
STRINGS
20+
"${PHP_SOURCE_DIR}/Zend/zend_language_parser.y"
21+
lines
22+
REGEX "${regex}"
23+
)
24+
25+
# Bypass the [ and ] characters issue in lists:
26+
# https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-lists
27+
string(REPLACE "[" "LEFT_BRACKET" lines "${lines}")
28+
string(REPLACE "]" "RIGHT_BRACKET" lines "${lines}")
29+
30+
# Get a list of tokens.
31+
set(tokens "")
32+
foreach(line IN LISTS lines)
33+
if(line MATCHES "${regex}")
34+
set(token "${CMAKE_MATCH_1}")
35+
36+
if(token MATCHES "^T_(NOELSE|ERROR)$")
37+
continue()
38+
endif()
39+
40+
list(APPEND tokens "${token}")
41+
endif()
42+
endforeach()
43+
44+
set(content "")
45+
foreach(token IN LISTS tokens)
46+
string(
47+
APPEND
48+
content
49+
"/**\n * @var int\n * @cvalue ${token}\n */\n"
50+
"const ${token} = UNKNOWN;\n"
51+
)
52+
endforeach()
53+
string(STRIP "${content}" content)
54+
55+
file(
56+
CONFIGURE
57+
OUTPUT "${PHP_SOURCE_DIR}/ext/tokenizer/tokenizer_data.stub.php"
58+
CONTENT [[
59+
<?php
60+
61+
/** @generate-class-entries */
62+
63+
@content@
64+
/**
65+
* @var int
66+
* @cvalue T_PAAMAYIM_NEKUDOTAYIM
67+
*/
68+
const T_DOUBLE_COLON = UNKNOWN;
69+
]] @ONLY)
70+
71+
set(content "")
72+
foreach(token IN LISTS tokens)
73+
if(token STREQUAL "T_PAAMAYIM_NEKUDOTAYIM")
74+
string(
75+
APPEND
76+
content
77+
"\t\tcase T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";\n"
78+
)
79+
else()
80+
string(APPEND content "\t\tcase ${token}: return \"${token}\";\n")
81+
endif()
82+
endforeach()
83+
84+
set(tab "\t")
85+
86+
file(
87+
CONFIGURE
88+
OUTPUT "${PHP_SOURCE_DIR}/ext/tokenizer/tokenizer_data.c"
89+
CONTENT [[
90+
/*
91+
+----------------------------------------------------------------------+
92+
| Copyright (c) The PHP Group |
93+
+----------------------------------------------------------------------+
94+
| This source file is subject to version 3.01 of the PHP license, |
95+
| that is bundled with this package in the file LICENSE, and is |
96+
| available through the world-wide-web at the following url: |
97+
| https://www.php.net/license/3_01.txt |
98+
| If you did not receive a copy of the PHP license and are unable to |
99+
| obtain it through the world-wide-web, please send a note to |
100+
| [email protected] so we can mail you a copy immediately. |
101+
+----------------------------------------------------------------------+
102+
| Author: Johannes Schlueter <[email protected]> |
103+
+----------------------------------------------------------------------+
104+
*/
105+
106+
/*
107+
DO NOT EDIT THIS FILE!
108+
This file is generated using tokenizer_data_gen.php
109+
*/
110+
111+
#include <zend_language_parser.h>
112+
113+
char *get_token_type_name(int token_type)
114+
{
115+
@tab@switch (token_type) {
116+
117+
@content@
118+
@tab@}
119+
@tab@return NULL;
120+
}
121+
122+
]] @ONLY)

docs/cmake/cmake.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ also tracked in the Git repository for a smoother workflow:
527527
└─📂 libmbfl
528528
└─📄 config.h # The libmbfl configuration header
529529
└─📂 tokenizer
530-
├─📄 tokenizer_data_stub.php # Generated by `ext/tokenizer/tokenizer_data_gen.php`
530+
├─📄 tokenizer_data_stub.php # Generated by `ext/tokenizer/cmake/GenerateTokenizerData.cmake`
531531
└─📄 tokenizer_data.c # Generated token types data file
532532
└─📂 main
533533
├─📄 internal_functions*.c # Generated files with all internal functions

0 commit comments

Comments
 (0)