1010 * `$children` array and behaves like a plain WP_Parser_Node from then on.
1111 */
1212class WP_MySQL_Native_Parser_Node extends WP_Parser_Node {
13- private $ native_ast = null ;
14- private $ native_node_index = null ;
15- private $ was_mutated = false ;
13+ private $ was_mutated = false ;
1614
17- public function __construct ( $ rule_id , $ rule_name, $ native_ast = null , $ native_node_index = null ) {
15+ public function __construct ( $ rule_id , $ rule_name ) {
1816 parent ::__construct ( $ rule_id , $ rule_name );
17+ }
1918
20- $ this ->native_ast = $ native_ast ;
21- $ this ->native_node_index = $ native_node_index ;
19+ public function __destruct () {
20+ if ( function_exists ( 'wp_sqlite_mysql_native_ast_release_wrapper ' ) ) {
21+ wp_sqlite_mysql_native_ast_release_wrapper ( $ this );
22+ }
2223 }
2324
2425 /** @inheritDoc */
@@ -41,127 +42,127 @@ public function has_child(): bool {
4142 if ( $ this ->was_mutated () ) {
4243 return parent ::has_child ();
4344 }
44- return wp_sqlite_mysql_native_ast_has_child ( $ this -> native_ast , $ this -> native_node_index );
45+ return wp_sqlite_mysql_native_ast_has_child ( $ this );
4546 }
4647
4748 /** @inheritDoc */
4849 public function has_child_node ( ?string $ rule_name = null ): bool {
4950 if ( $ this ->was_mutated () ) {
5051 return parent ::has_child_node ( $ rule_name );
5152 }
52- return wp_sqlite_mysql_native_ast_has_child_node ( $ this -> native_ast , $ this -> native_node_index , $ rule_name );
53+ return wp_sqlite_mysql_native_ast_has_child_node ( $ this , $ rule_name );
5354 }
5455
5556 /** @inheritDoc */
5657 public function has_child_token ( ?int $ token_id = null ): bool {
5758 if ( $ this ->was_mutated () ) {
5859 return parent ::has_child_token ( $ token_id );
5960 }
60- return wp_sqlite_mysql_native_ast_has_child_token ( $ this -> native_ast , $ this -> native_node_index , $ token_id );
61+ return wp_sqlite_mysql_native_ast_has_child_token ( $ this , $ token_id );
6162 }
6263
6364 /** @inheritDoc */
6465 public function get_first_child () {
6566 if ( $ this ->was_mutated () ) {
6667 return parent ::get_first_child ();
6768 }
68- return wp_sqlite_mysql_native_ast_get_first_child ( $ this -> native_ast , $ this -> native_node_index );
69+ return wp_sqlite_mysql_native_ast_get_first_child ( $ this );
6970 }
7071
7172 /** @inheritDoc */
7273 public function get_first_child_node ( ?string $ rule_name = null ): ?WP_Parser_Node {
7374 if ( $ this ->was_mutated () ) {
7475 return parent ::get_first_child_node ( $ rule_name );
7576 }
76- return wp_sqlite_mysql_native_ast_get_first_child_node ( $ this -> native_ast , $ this -> native_node_index , $ rule_name );
77+ return wp_sqlite_mysql_native_ast_get_first_child_node ( $ this , $ rule_name );
7778 }
7879
7980 /** @inheritDoc */
8081 public function get_first_child_token ( ?int $ token_id = null ): ?WP_Parser_Token {
8182 if ( $ this ->was_mutated () ) {
8283 return parent ::get_first_child_token ( $ token_id );
8384 }
84- return wp_sqlite_mysql_native_ast_get_first_child_token ( $ this -> native_ast , $ this -> native_node_index , $ token_id );
85+ return wp_sqlite_mysql_native_ast_get_first_child_token ( $ this , $ token_id );
8586 }
8687
8788 /** @inheritDoc */
8889 public function get_first_descendant_node ( ?string $ rule_name = null ): ?WP_Parser_Node {
8990 if ( $ this ->was_mutated () ) {
9091 return parent ::get_first_descendant_node ( $ rule_name );
9192 }
92- return wp_sqlite_mysql_native_ast_get_first_descendant_node ( $ this -> native_ast , $ this -> native_node_index , $ rule_name );
93+ return wp_sqlite_mysql_native_ast_get_first_descendant_node ( $ this , $ rule_name );
9394 }
9495
9596 /** @inheritDoc */
9697 public function get_first_descendant_token ( ?int $ token_id = null ): ?WP_Parser_Token {
9798 if ( $ this ->was_mutated () ) {
9899 return parent ::get_first_descendant_token ( $ token_id );
99100 }
100- return wp_sqlite_mysql_native_ast_get_first_descendant_token ( $ this -> native_ast , $ this -> native_node_index , $ token_id );
101+ return wp_sqlite_mysql_native_ast_get_first_descendant_token ( $ this , $ token_id );
101102 }
102103
103104 /** @inheritDoc */
104105 public function get_children (): array {
105106 if ( $ this ->was_mutated () ) {
106107 return parent ::get_children ();
107108 }
108- return wp_sqlite_mysql_native_ast_get_children ( $ this -> native_ast , $ this -> native_node_index );
109+ return wp_sqlite_mysql_native_ast_get_children ( $ this );
109110 }
110111
111112 /** @inheritDoc */
112113 public function get_child_nodes ( ?string $ rule_name = null ): array {
113114 if ( $ this ->was_mutated () ) {
114115 return parent ::get_child_nodes ( $ rule_name );
115116 }
116- return wp_sqlite_mysql_native_ast_get_child_nodes ( $ this -> native_ast , $ this -> native_node_index , $ rule_name );
117+ return wp_sqlite_mysql_native_ast_get_child_nodes ( $ this , $ rule_name );
117118 }
118119
119120 /** @inheritDoc */
120121 public function get_child_tokens ( ?int $ token_id = null ): array {
121122 if ( $ this ->was_mutated () ) {
122123 return parent ::get_child_tokens ( $ token_id );
123124 }
124- return wp_sqlite_mysql_native_ast_get_child_tokens ( $ this -> native_ast , $ this -> native_node_index , $ token_id );
125+ return wp_sqlite_mysql_native_ast_get_child_tokens ( $ this , $ token_id );
125126 }
126127
127128 /** @inheritDoc */
128129 public function get_descendants (): array {
129130 if ( $ this ->was_mutated () ) {
130131 return parent ::get_descendants ();
131132 }
132- return wp_sqlite_mysql_native_ast_get_descendants ( $ this -> native_ast , $ this -> native_node_index );
133+ return wp_sqlite_mysql_native_ast_get_descendants ( $ this );
133134 }
134135
135136 /** @inheritDoc */
136137 public function get_descendant_nodes ( ?string $ rule_name = null ): array {
137138 if ( $ this ->was_mutated () ) {
138139 return parent ::get_descendant_nodes ( $ rule_name );
139140 }
140- return wp_sqlite_mysql_native_ast_get_descendant_nodes ( $ this -> native_ast , $ this -> native_node_index , $ rule_name );
141+ return wp_sqlite_mysql_native_ast_get_descendant_nodes ( $ this , $ rule_name );
141142 }
142143
143144 /** @inheritDoc */
144145 public function get_descendant_tokens ( ?int $ token_id = null ): array {
145146 if ( $ this ->was_mutated () ) {
146147 return parent ::get_descendant_tokens ( $ token_id );
147148 }
148- return wp_sqlite_mysql_native_ast_get_descendant_tokens ( $ this -> native_ast , $ this -> native_node_index , $ token_id );
149+ return wp_sqlite_mysql_native_ast_get_descendant_tokens ( $ this , $ token_id );
149150 }
150151
151152 /** @inheritDoc */
152153 public function get_start (): int {
153154 if ( $ this ->was_mutated () ) {
154155 return parent ::get_start ();
155156 }
156- return wp_sqlite_mysql_native_ast_get_start ( $ this -> native_ast , $ this -> native_node_index );
157+ return wp_sqlite_mysql_native_ast_get_start ( $ this );
157158 }
158159
159160 /** @inheritDoc */
160161 public function get_length (): int {
161162 if ( $ this ->was_mutated () ) {
162163 return parent ::get_length ();
163164 }
164- return wp_sqlite_mysql_native_ast_get_length ( $ this -> native_ast , $ this -> native_node_index );
165+ return wp_sqlite_mysql_native_ast_get_length ( $ this );
165166 }
166167
167168 private function was_mutated (): bool {
@@ -173,9 +174,10 @@ private function materialize_native_children(): void {
173174 return ;
174175 }
175176
176- $ this ->children = wp_sqlite_mysql_native_ast_get_children ( $ this ->native_ast , $ this ->native_node_index );
177- $ this ->native_ast = null ;
178- $ this ->native_node_index = null ;
179- $ this ->was_mutated = true ;
177+ $ this ->children = wp_sqlite_mysql_native_ast_get_children ( $ this );
178+ $ this ->was_mutated = true ;
179+ if ( function_exists ( 'wp_sqlite_mysql_native_ast_materialize_wrapper ' ) ) {
180+ wp_sqlite_mysql_native_ast_materialize_wrapper ( $ this );
181+ }
180182 }
181183}
0 commit comments