1 /******************************************************************************
3 * Module Name: pswalk - Parser routines to walk parsed op tree(s)
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define _COMPONENT ACPI_PARSER
30 MODULE_NAME ("pswalk")
33 /*******************************************************************************
35 * FUNCTION: Acpi_ps_get_next_walk_op
37 * PARAMETERS: Walk_state - Current state of the walk
38 * Op - Current Op to be walked
39 * Ascending_callback - Procedure called when Op is complete
43 * DESCRIPTION: Get the next Op in a walk of the parse tree.
45 ******************************************************************************/
48 acpi_ps_get_next_walk_op (
49 ACPI_WALK_STATE
*walk_state
,
50 ACPI_PARSE_OBJECT
*op
,
51 ACPI_PARSE_UPWARDS ascending_callback
)
53 ACPI_PARSE_OBJECT
*next
;
54 ACPI_PARSE_OBJECT
*parent
;
55 ACPI_PARSE_OBJECT
*grand_parent
;
59 /* Check for a argument only if we are descending in the tree */
61 if (walk_state
->next_op_info
!= NEXT_OP_UPWARD
) {
62 /* Look for an argument or child of the current op */
64 next
= acpi_ps_get_arg (op
, 0);
66 /* Still going downward in tree (Op is not completed yet) */
68 walk_state
->prev_op
= op
;
69 walk_state
->next_op
= next
;
70 walk_state
->next_op_info
= NEXT_OP_DOWNWARD
;
77 * No more children, this Op is complete. Save Next and Parent
78 * in case the Op object gets deleted by the callback routine
84 status
= ascending_callback (walk_state
, op
);
87 * If we are back to the starting point, the walk is complete.
89 if (op
== walk_state
->origin
) {
90 /* Reached the point of origin, the walk is complete */
92 walk_state
->prev_op
= op
;
93 walk_state
->next_op
= NULL
;
99 * Check for a sibling to the current op. A sibling means
100 * we are still going "downward" in the tree.
104 /* There is a sibling, it will be next */
106 walk_state
->prev_op
= op
;
107 walk_state
->next_op
= next
;
108 walk_state
->next_op_info
= NEXT_OP_DOWNWARD
;
110 /* Continue downward */
117 * Drop into the loop below because we are moving upwards in
124 * We are resuming a walk, and we were (are) going upward in the tree.
125 * So, we want to drop into the parent loop below.
133 * Look for a sibling of the current Op's parent
134 * Continue moving up the tree until we find a node that has not been
135 * visited, or we get back to where we started.
138 /* We are moving up the tree, therefore this parent Op is complete */
140 grand_parent
= parent
->parent
;
143 status
= ascending_callback (walk_state
, parent
);
146 * If we are back to the starting point, the walk is complete.
148 if (parent
== walk_state
->origin
) {
149 /* Reached the point of origin, the walk is complete */
151 walk_state
->prev_op
= parent
;
152 walk_state
->next_op
= NULL
;
158 * If there is a sibling to this parent (it is not the starting point
159 * Op), then we will visit it.
162 /* found sibling of parent */
164 walk_state
->prev_op
= parent
;
165 walk_state
->next_op
= next
;
166 walk_state
->next_op_info
= NEXT_OP_DOWNWARD
;
171 /* No siblings, no errors, just move up one more level in the tree */
174 parent
= grand_parent
;
175 walk_state
->prev_op
= op
;
179 /* Got all the way to the top of the tree, we must be done! */
180 /* However, the code should have terminated in the loop above */
182 walk_state
->next_op
= NULL
;
188 /*******************************************************************************
190 * FUNCTION: Acpi_ps_delete_completed_op
192 * PARAMETERS: State - Walk state
197 * DESCRIPTION: Callback function for Acpi_ps_get_next_walk_op(). Used during
198 * Acpi_ps_delete_parse tree to delete Op objects when all sub-objects
199 * have been visited (and deleted.)
201 ******************************************************************************/
204 acpi_ps_delete_completed_op (
205 ACPI_WALK_STATE
*state
,
206 ACPI_PARSE_OBJECT
*op
)
209 acpi_ps_free_op (op
);
214 /*******************************************************************************
216 * FUNCTION: Acpi_ps_delete_parse_tree
218 * PARAMETERS: Subtree_root - Root of tree (or subtree) to delete
222 * DESCRIPTION: Delete a portion of or an entire parse tree.
224 ******************************************************************************/
227 acpi_ps_delete_parse_tree (
228 ACPI_PARSE_OBJECT
*subtree_root
)
230 ACPI_WALK_STATE
*walk_state
;
231 ACPI_WALK_LIST walk_list
;
238 /* Create and initialize a new walk list */
240 walk_list
.walk_state
= NULL
;
241 walk_list
.acquired_mutex_list
.prev
= NULL
;
242 walk_list
.acquired_mutex_list
.next
= NULL
;
244 walk_state
= acpi_ds_create_walk_state (TABLE_ID_DSDT
, NULL
, NULL
, &walk_list
);
249 walk_state
->parser_state
= NULL
;
250 walk_state
->parse_flags
= 0;
251 walk_state
->descending_callback
= NULL
;
252 walk_state
->ascending_callback
= NULL
;
255 walk_state
->origin
= subtree_root
;
256 walk_state
->next_op
= subtree_root
;
259 /* Head downward in the tree */
261 walk_state
->next_op_info
= NEXT_OP_DOWNWARD
;
263 /* Visit all nodes in the subtree */
265 while (walk_state
->next_op
) {
266 acpi_ps_get_next_walk_op (walk_state
, walk_state
->next_op
,
267 acpi_ps_delete_completed_op
);
270 /* We are done with this walk */
272 acpi_aml_release_all_mutexes ((ACPI_OPERAND_OBJECT
*) &walk_list
.acquired_mutex_list
);
273 acpi_ds_delete_walk_state (walk_state
);