PluginProbe
SQLite Database Integration / 3.0.1
SQLite Database Integration v3.0.1
3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 All 32 releases
sqlite-database-integration / wp-includes / database / mysql / native / class-wp-mysql-native-parser-node.php

class-wp-mysql-native-parser-node.php in SQLite Database Integration 3.0.1, at wp-includes/database/mysql/native/class-wp-mysql-native-parser-node.php

182 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Parser node backed by a native (Rust) AST.
5 *
6 * Constructed by the native MySQL parser extension. Read methods delegate
7 * into the Rust-owned AST so children are never copied into PHP unless a
8 * caller actually walks the tree. On the first mutation (append_child or
9 * merge_fragment), the node materializes its children into the inherited
10 * `$children` array and behaves like a plain WP_Parser_Node from then on.
11 *
12 * @access private
13 */
14 class WP_MySQL_Native_Parser_Node extends WP_Parser_Node {
15 private $was_mutated = false;
16
17 public function __construct( $rule_id, $rule_name ) {
18 parent::__construct( $rule_id, $rule_name );
19 }
20
21 public function __destruct() {
22 if ( function_exists( 'wp_sqlite_mysql_native_ast_release_wrapper' ) ) {
23 wp_sqlite_mysql_native_ast_release_wrapper( $this );
24 }
25 }
26
27 /** @inheritDoc */
28 public function append_child( $node ) {
29 $this->materialize_native_children();
30 parent::append_child( $node );
31 }
32
33 /** @inheritDoc */
34 public function merge_fragment( $node ) {
35 $this->materialize_native_children();
36 if ( $node instanceof self ) {
37 $node->materialize_native_children();
38 }
39 parent::merge_fragment( $node );
40 }
41
42 /** @inheritDoc */
43 public function has_child(): bool {
44 if ( $this->was_mutated ) {
45 return parent::has_child();
46 }
47 return wp_sqlite_mysql_native_ast_has_child( $this );
48 }
49
50 /** @inheritDoc */
51 public function has_child_node( ?string $rule_name = null ): bool {
52 if ( $this->was_mutated ) {
53 return parent::has_child_node( $rule_name );
54 }
55 return wp_sqlite_mysql_native_ast_has_child_node( $this, $rule_name );
56 }
57
58 /** @inheritDoc */
59 public function has_child_token( ?int $token_id = null ): bool {
60 if ( $this->was_mutated ) {
61 return parent::has_child_token( $token_id );
62 }
63 return wp_sqlite_mysql_native_ast_has_child_token( $this, $token_id );
64 }
65
66 /** @inheritDoc */
67 public function get_first_child() {
68 if ( $this->was_mutated ) {
69 return parent::get_first_child();
70 }
71 return wp_sqlite_mysql_native_ast_get_first_child( $this );
72 }
73
74 /** @inheritDoc */
75 public function get_first_child_node( ?string $rule_name = null ): ?WP_Parser_Node {
76 if ( $this->was_mutated ) {
77 return parent::get_first_child_node( $rule_name );
78 }
79 return wp_sqlite_mysql_native_ast_get_first_child_node( $this, $rule_name );
80 }
81
82 /** @inheritDoc */
83 public function get_first_child_token( ?int $token_id = null ): ?WP_Parser_Token {
84 if ( $this->was_mutated ) {
85 return parent::get_first_child_token( $token_id );
86 }
87 return wp_sqlite_mysql_native_ast_get_first_child_token( $this, $token_id );
88 }
89
90 /** @inheritDoc */
91 public function get_first_descendant_node( ?string $rule_name = null ): ?WP_Parser_Node {
92 if ( $this->was_mutated ) {
93 return parent::get_first_descendant_node( $rule_name );
94 }
95 return wp_sqlite_mysql_native_ast_get_first_descendant_node( $this, $rule_name );
96 }
97
98 /** @inheritDoc */
99 public function get_first_descendant_token( ?int $token_id = null ): ?WP_Parser_Token {
100 if ( $this->was_mutated ) {
101 return parent::get_first_descendant_token( $token_id );
102 }
103 return wp_sqlite_mysql_native_ast_get_first_descendant_token( $this, $token_id );
104 }
105
106 /** @inheritDoc */
107 public function get_children(): array {
108 if ( $this->was_mutated ) {
109 return parent::get_children();
110 }
111 return wp_sqlite_mysql_native_ast_get_children( $this );
112 }
113
114 /** @inheritDoc */
115 public function get_child_nodes( ?string $rule_name = null ): array {
116 if ( $this->was_mutated ) {
117 return parent::get_child_nodes( $rule_name );
118 }
119 return wp_sqlite_mysql_native_ast_get_child_nodes( $this, $rule_name );
120 }
121
122 /** @inheritDoc */
123 public function get_child_tokens( ?int $token_id = null ): array {
124 if ( $this->was_mutated ) {
125 return parent::get_child_tokens( $token_id );
126 }
127 return wp_sqlite_mysql_native_ast_get_child_tokens( $this, $token_id );
128 }
129
130 /** @inheritDoc */
131 public function get_descendants(): array {
132 if ( $this->was_mutated ) {
133 return parent::get_descendants();
134 }
135 return wp_sqlite_mysql_native_ast_get_descendants( $this );
136 }
137
138 /** @inheritDoc */
139 public function get_descendant_nodes( ?string $rule_name = null ): array {
140 if ( $this->was_mutated ) {
141 return parent::get_descendant_nodes( $rule_name );
142 }
143 return wp_sqlite_mysql_native_ast_get_descendant_nodes( $this, $rule_name );
144 }
145
146 /** @inheritDoc */
147 public function get_descendant_tokens( ?int $token_id = null ): array {
148 if ( $this->was_mutated ) {
149 return parent::get_descendant_tokens( $token_id );
150 }
151 return wp_sqlite_mysql_native_ast_get_descendant_tokens( $this, $token_id );
152 }
153
154 /** @inheritDoc */
155 public function get_start(): int {
156 if ( $this->was_mutated ) {
157 return parent::get_start();
158 }
159 return wp_sqlite_mysql_native_ast_get_start( $this );
160 }
161
162 /** @inheritDoc */
163 public function get_length(): int {
164 if ( $this->was_mutated ) {
165 return parent::get_length();
166 }
167 return wp_sqlite_mysql_native_ast_get_length( $this );
168 }
169
170 private function materialize_native_children(): void {
171 if ( $this->was_mutated ) {
172 return;
173 }
174
175 $this->children = wp_sqlite_mysql_native_ast_get_children( $this );
176 $this->was_mutated = true;
177 if ( function_exists( 'wp_sqlite_mysql_native_ast_materialize_wrapper' ) ) {
178 wp_sqlite_mysql_native_ast_materialize_wrapper( $this );
179 }
180 }
181 }
182