1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
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
30 #define _COMPONENT ACPI_PARSER
31 MODULE_NAME ("psscope")
34 /*******************************************************************************
36 * FUNCTION: Acpi_ps_get_parent_scope
38 * PARAMETERS: Parser_state - Current parser state object
40 * RETURN: Pointer to an Op object
42 * DESCRIPTION: Get parent of current op being parsed
44 ******************************************************************************/
47 acpi_ps_get_parent_scope (
48 ACPI_PARSE_STATE *parser_state)
50 return (parser_state->scope->parse_scope.op);
54 /*******************************************************************************
56 * FUNCTION: Acpi_ps_has_completed_scope
58 * PARAMETERS: Parser_state - Current parser state object
60 * RETURN: Boolean, TRUE = scope completed.
62 * DESCRIPTION: Is parsing of current argument complete? Determined by
63 * 1) AML pointer is at or beyond the end of the scope
64 * 2) The scope argument count has reached zero.
66 ******************************************************************************/
69 acpi_ps_has_completed_scope (
70 ACPI_PARSE_STATE *parser_state)
72 return ((u8) ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
73 !parser_state->scope->parse_scope.arg_count)));
77 /*******************************************************************************
79 * FUNCTION: Acpi_ps_init_scope
81 * PARAMETERS: Parser_state - Current parser state object
82 * Root - the Root Node of this new scope
86 * DESCRIPTION: Allocate and init a new scope object
88 ******************************************************************************/
92 ACPI_PARSE_STATE *parser_state,
93 ACPI_PARSE_OBJECT *root_op)
95 ACPI_GENERIC_STATE *scope;
98 scope = acpi_cm_create_generic_state ();
100 return (AE_NO_MEMORY);
103 scope->parse_scope.op = root_op;
104 scope->parse_scope.arg_count = ACPI_VAR_ARGS;
105 scope->parse_scope.arg_end = parser_state->aml_end;
106 scope->parse_scope.pkg_end = parser_state->aml_end;
108 parser_state->scope = scope;
109 parser_state->start_op = root_op;
115 /*******************************************************************************
117 * FUNCTION: Acpi_ps_push_scope
119 * PARAMETERS: Parser_state - Current parser state object
120 * Op - Current op to be pushed
121 * Remaining_args - List of args remaining
122 * Arg_count - Fixed or variable number of args
126 * DESCRIPTION: Push current op to begin parsing its argument
128 ******************************************************************************/
132 ACPI_PARSE_STATE *parser_state,
133 ACPI_PARSE_OBJECT *op,
137 ACPI_GENERIC_STATE *scope;
140 scope = acpi_cm_create_generic_state ();
142 return (AE_NO_MEMORY);
146 scope->parse_scope.op = op;
147 scope->parse_scope.arg_list = remaining_args;
148 scope->parse_scope.arg_count = arg_count;
149 scope->parse_scope.pkg_end = parser_state->pkg_end;
151 /* Push onto scope stack */
153 acpi_cm_push_generic_state (&parser_state->scope, scope);
156 if (arg_count == ACPI_VAR_ARGS) {
157 /* multiple arguments */
159 scope->parse_scope.arg_end = parser_state->pkg_end;
163 /* single argument */
165 scope->parse_scope.arg_end = ACPI_MAX_AML;
172 /*******************************************************************************
174 * FUNCTION: Acpi_ps_pop_scope
176 * PARAMETERS: Parser_state - Current parser state object
177 * Op - Where the popped op is returned
178 * Arg_list - Where the popped "next argument" is
180 * Arg_count - Count of objects in Arg_list
184 * DESCRIPTION: Return to parsing a previous op
186 ******************************************************************************/
190 ACPI_PARSE_STATE *parser_state,
191 ACPI_PARSE_OBJECT **op,
195 ACPI_GENERIC_STATE *scope = parser_state->scope;
199 * Only pop the scope if there is in fact a next scope
201 if (scope->common.next) {
202 scope = acpi_cm_pop_generic_state (&parser_state->scope);
205 /* return to parsing previous op */
207 *op = scope->parse_scope.op;
208 *arg_list = scope->parse_scope.arg_list;
209 *arg_count = scope->parse_scope.arg_count;
210 parser_state->pkg_end = scope->parse_scope.pkg_end;
212 /* All done with this scope state structure */
214 acpi_cm_delete_generic_state (scope);
218 /* empty parse stack, prepare to fetch next opcode */
230 /*******************************************************************************
232 * FUNCTION: Acpi_ps_cleanup_scope
234 * PARAMETERS: Parser_state - Current parser state object
238 * DESCRIPTION: Destroy available list, remaining stack levels, and return
241 ******************************************************************************/
244 acpi_ps_cleanup_scope (
245 ACPI_PARSE_STATE *parser_state)
247 ACPI_GENERIC_STATE *scope;
255 /* Delete anything on the scope stack */
257 while (parser_state->scope) {
258 scope = acpi_cm_pop_generic_state (&parser_state->scope);
259 acpi_cm_delete_generic_state (scope);