Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / parser / psscope.c
blob822709224560273f7bb6427f7eca1afe19c3a36b
1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include "acpi.h"
46 #include "accommon.h"
47 #include "acparser.h"
49 #define _COMPONENT ACPI_PARSER
50 ACPI_MODULE_NAME ("psscope")
53 /*******************************************************************************
55 * FUNCTION: AcpiPsGetParentScope
57 * PARAMETERS: ParserState - Current parser state object
59 * RETURN: Pointer to an Op object
61 * DESCRIPTION: Get parent of current op being parsed
63 ******************************************************************************/
65 ACPI_PARSE_OBJECT *
66 AcpiPsGetParentScope (
67 ACPI_PARSE_STATE *ParserState)
70 return (ParserState->Scope->ParseScope.Op);
74 /*******************************************************************************
76 * FUNCTION: AcpiPsHasCompletedScope
78 * PARAMETERS: ParserState - Current parser state object
80 * RETURN: Boolean, TRUE = scope completed.
82 * DESCRIPTION: Is parsing of current argument complete? Determined by
83 * 1) AML pointer is at or beyond the end of the scope
84 * 2) The scope argument count has reached zero.
86 ******************************************************************************/
88 BOOLEAN
89 AcpiPsHasCompletedScope (
90 ACPI_PARSE_STATE *ParserState)
93 return ((BOOLEAN)
94 ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
95 !ParserState->Scope->ParseScope.ArgCount)));
99 /*******************************************************************************
101 * FUNCTION: AcpiPsInitScope
103 * PARAMETERS: ParserState - Current parser state object
104 * Root - the Root Node of this new scope
106 * RETURN: Status
108 * DESCRIPTION: Allocate and init a new scope object
110 ******************************************************************************/
112 ACPI_STATUS
113 AcpiPsInitScope (
114 ACPI_PARSE_STATE *ParserState,
115 ACPI_PARSE_OBJECT *RootOp)
117 ACPI_GENERIC_STATE *Scope;
120 ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
123 Scope = AcpiUtCreateGenericState ();
124 if (!Scope)
126 return_ACPI_STATUS (AE_NO_MEMORY);
129 Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
130 Scope->ParseScope.Op = RootOp;
131 Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;
132 Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
133 Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
135 ParserState->Scope = Scope;
136 ParserState->StartOp = RootOp;
138 return_ACPI_STATUS (AE_OK);
142 /*******************************************************************************
144 * FUNCTION: AcpiPsPushScope
146 * PARAMETERS: ParserState - Current parser state object
147 * Op - Current op to be pushed
148 * RemainingArgs - List of args remaining
149 * ArgCount - Fixed or variable number of args
151 * RETURN: Status
153 * DESCRIPTION: Push current op to begin parsing its argument
155 ******************************************************************************/
157 ACPI_STATUS
158 AcpiPsPushScope (
159 ACPI_PARSE_STATE *ParserState,
160 ACPI_PARSE_OBJECT *Op,
161 UINT32 RemainingArgs,
162 UINT32 ArgCount)
164 ACPI_GENERIC_STATE *Scope;
167 ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
170 Scope = AcpiUtCreateGenericState ();
171 if (!Scope)
173 return_ACPI_STATUS (AE_NO_MEMORY);
176 Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
177 Scope->ParseScope.Op = Op;
178 Scope->ParseScope.ArgList = RemainingArgs;
179 Scope->ParseScope.ArgCount = ArgCount;
180 Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
182 /* Push onto scope stack */
184 AcpiUtPushGenericState (&ParserState->Scope, Scope);
186 if (ArgCount == ACPI_VAR_ARGS)
188 /* Multiple arguments */
190 Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
192 else
194 /* Single argument */
196 Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
199 return_ACPI_STATUS (AE_OK);
203 /*******************************************************************************
205 * FUNCTION: AcpiPsPopScope
207 * PARAMETERS: ParserState - Current parser state object
208 * Op - Where the popped op is returned
209 * ArgList - Where the popped "next argument" is
210 * returned
211 * ArgCount - Count of objects in ArgList
213 * RETURN: Status
215 * DESCRIPTION: Return to parsing a previous op
217 ******************************************************************************/
219 void
220 AcpiPsPopScope (
221 ACPI_PARSE_STATE *ParserState,
222 ACPI_PARSE_OBJECT **Op,
223 UINT32 *ArgList,
224 UINT32 *ArgCount)
226 ACPI_GENERIC_STATE *Scope = ParserState->Scope;
229 ACPI_FUNCTION_TRACE (PsPopScope);
232 /* Only pop the scope if there is in fact a next scope */
234 if (Scope->Common.Next)
236 Scope = AcpiUtPopGenericState (&ParserState->Scope);
238 /* Return to parsing previous op */
240 *Op = Scope->ParseScope.Op;
241 *ArgList = Scope->ParseScope.ArgList;
242 *ArgCount = Scope->ParseScope.ArgCount;
243 ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
245 /* All done with this scope state structure */
247 AcpiUtDeleteGenericState (Scope);
249 else
251 /* Empty parse stack, prepare to fetch next opcode */
253 *Op = NULL;
254 *ArgList = 0;
255 *ArgCount = 0;
258 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
259 "Popped Op %p Args %X\n", *Op, *ArgCount));
260 return_VOID;
264 /*******************************************************************************
266 * FUNCTION: AcpiPsCleanupScope
268 * PARAMETERS: ParserState - Current parser state object
270 * RETURN: None
272 * DESCRIPTION: Destroy available list, remaining stack levels, and return
273 * root scope
275 ******************************************************************************/
277 void
278 AcpiPsCleanupScope (
279 ACPI_PARSE_STATE *ParserState)
281 ACPI_GENERIC_STATE *Scope;
284 ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
287 if (!ParserState)
289 return_VOID;
292 /* Delete anything on the scope stack */
294 while (ParserState->Scope)
296 Scope = AcpiUtPopGenericState (&ParserState->Scope);
297 AcpiUtDeleteGenericState (Scope);
300 return_VOID;