1 /******************************************************************************
3 * Module Name: asltree - parse tree management
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/acapps.h>
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("asltree")
52 /* Local prototypes */
54 static ACPI_PARSE_OBJECT *
63 /*******************************************************************************
65 * FUNCTION: TrGetNextNode
69 * RETURN: New parse node. Aborts on allocation failure
71 * DESCRIPTION: Allocate a new parse node for the parse tree. Bypass the local
72 * dynamic memory manager for performance reasons (This has a
73 * major impact on the speed of the compiler.)
75 ******************************************************************************/
77 static ACPI_PARSE_OBJECT *
81 ASL_CACHE_INFO *Cache;
84 if (Gbl_ParseOpCacheNext >= Gbl_ParseOpCacheLast)
86 /* Allocate a new buffer */
88 Cache = UtLocalCalloc (sizeof (Cache->Next) +
89 (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE));
91 /* Link new cache buffer to head of list */
93 Cache->Next = Gbl_ParseOpCacheList;
94 Gbl_ParseOpCacheList = Cache;
96 /* Setup cache management pointers */
98 Gbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer);
99 Gbl_ParseOpCacheLast = Gbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE;
103 return (Gbl_ParseOpCacheNext++);
107 /*******************************************************************************
109 * FUNCTION: TrAllocateNode
111 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
113 * RETURN: New parse node. Aborts on allocation failure
115 * DESCRIPTION: Allocate and initialize a new parse node for the parse tree
117 ******************************************************************************/
123 ACPI_PARSE_OBJECT *Op;
126 Op = TrGetNextNode ();
128 Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
129 Op->Asl.Filename = Gbl_Files[ASL_FILE_INPUT].Filename;
130 Op->Asl.LineNumber = Gbl_CurrentLineNumber;
131 Op->Asl.LogicalLineNumber = Gbl_LogicalLineNumber;
132 Op->Asl.LogicalByteOffset = Gbl_CurrentLineOffset;
133 Op->Asl.Column = Gbl_CurrentColumn;
135 UtSetParseOpName (Op);
140 /*******************************************************************************
142 * FUNCTION: TrReleaseNode
144 * PARAMETERS: Op - Op to be released
148 * DESCRIPTION: "release" a node. In truth, nothing is done since the node
149 * is part of a larger buffer
151 ******************************************************************************/
155 ACPI_PARSE_OBJECT *Op)
162 /*******************************************************************************
164 * FUNCTION: TrUpdateNode
166 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
167 * Op - An existing parse node
169 * RETURN: The updated node
171 * DESCRIPTION: Change the parse opcode assigned to a node. Usually used to
172 * change an opcode to DEFAULT_ARG so that the node is ignored
173 * during the code generation. Also used to set generic integers
174 * to a specific size (8, 16, 32, or 64 bits)
176 ******************************************************************************/
181 ACPI_PARSE_OBJECT *Op)
189 DbgPrint (ASL_PARSE_OUTPUT,
190 "\nUpdateNode: Old - %s, New - %s\n\n",
191 UtGetOpName (Op->Asl.ParseOpcode),
192 UtGetOpName (ParseOpcode));
194 /* Assign new opcode and name */
196 if (Op->Asl.ParseOpcode == PARSEOP_ONES)
200 case PARSEOP_BYTECONST:
202 Op->Asl.Value.Integer = ACPI_UINT8_MAX;
205 case PARSEOP_WORDCONST:
207 Op->Asl.Value.Integer = ACPI_UINT16_MAX;
210 case PARSEOP_DWORDCONST:
212 Op->Asl.Value.Integer = ACPI_UINT32_MAX;
215 /* Don't need to do the QWORD case */
219 /* Don't care about others */
224 Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
225 UtSetParseOpName (Op);
228 * For the BYTE, WORD, and DWORD constants, make sure that the integer
229 * that was passed in will actually fit into the data type
233 case PARSEOP_BYTECONST:
235 UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
236 Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
239 case PARSEOP_WORDCONST:
241 UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
242 Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
245 case PARSEOP_DWORDCONST:
247 UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
248 Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
253 /* Don't care about others, don't need to check QWORD */
262 /*******************************************************************************
264 * FUNCTION: TrGetNodeFlagName
266 * PARAMETERS: Flags - Flags word to be decoded
268 * RETURN: Name string. Always returns a valid string pointer.
270 * DESCRIPTION: Decode a flags word
272 ******************************************************************************/
283 return ("NODE_VISITED");
285 case NODE_AML_PACKAGE:
287 return ("NODE_AML_PACKAGE");
291 return ("NODE_IS_TARGET");
293 case NODE_IS_RESOURCE_DESC:
295 return ("NODE_IS_RESOURCE_DESC");
297 case NODE_IS_RESOURCE_FIELD:
299 return ("NODE_IS_RESOURCE_FIELD");
301 case NODE_HAS_NO_EXIT:
303 return ("NODE_HAS_NO_EXIT");
305 case NODE_IF_HAS_NO_EXIT:
307 return ("NODE_IF_HAS_NO_EXIT");
309 case NODE_NAME_INTERNALIZED:
311 return ("NODE_NAME_INTERNALIZED");
313 case NODE_METHOD_NO_RETVAL:
315 return ("NODE_METHOD_NO_RETVAL");
317 case NODE_METHOD_SOME_NO_RETVAL:
319 return ("NODE_METHOD_SOME_NO_RETVAL");
321 case NODE_RESULT_NOT_USED:
323 return ("NODE_RESULT_NOT_USED");
325 case NODE_METHOD_TYPED:
327 return ("NODE_METHOD_TYPED");
329 case NODE_COMPILE_TIME_CONST:
331 return ("NODE_COMPILE_TIME_CONST");
333 case NODE_IS_TERM_ARG:
335 return ("NODE_IS_TERM_ARG");
337 case NODE_WAS_ONES_OP:
339 return ("NODE_WAS_ONES_OP");
341 case NODE_IS_NAME_DECLARATION:
343 return ("NODE_IS_NAME_DECLARATION");
347 return ("Multiple Flags (or unknown flag) set");
352 /*******************************************************************************
354 * FUNCTION: TrSetNodeFlags
356 * PARAMETERS: Op - An existing parse node
357 * Flags - New flags word
359 * RETURN: The updated parser op
361 * DESCRIPTION: Set bits in the node flags word. Will not clear bits, only set
363 ******************************************************************************/
367 ACPI_PARSE_OBJECT *Op,
371 DbgPrint (ASL_PARSE_OUTPUT,
372 "\nSetNodeFlags: Op %p, %8.8X %s\n\n", Op, Flags,
373 TrGetNodeFlagName (Flags));
380 Op->Asl.CompileFlags |= Flags;
385 /*******************************************************************************
387 * FUNCTION: TrSetNodeAmlLength
389 * PARAMETERS: Op - An existing parse node
390 * Length - AML Length
392 * RETURN: The updated parser op
394 * DESCRIPTION: Set the AML Length in a node. Used by the parser to indicate
395 * the presence of a node that must be reduced to a fixed length
398 ******************************************************************************/
402 ACPI_PARSE_OBJECT *Op,
406 DbgPrint (ASL_PARSE_OUTPUT,
407 "\nSetNodeAmlLength: Op %p, %8.8X\n", Op, Length);
414 Op->Asl.AmlLength = Length;
419 /*******************************************************************************
421 * FUNCTION: TrSetEndLineNumber
423 * PARAMETERS: Op - An existing parse node
427 * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
428 * parse node to the current line numbers.
430 ******************************************************************************/
434 ACPI_PARSE_OBJECT *Op)
437 /* If the end line # is already set, just return */
444 Op->Asl.EndLine = Gbl_CurrentLineNumber;
445 Op->Asl.EndLogicalLine = Gbl_LogicalLineNumber;
449 /*******************************************************************************
451 * FUNCTION: TrCreateLeafNode
453 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
455 * RETURN: Pointer to the new node. Aborts on allocation failure
457 * DESCRIPTION: Create a simple leaf node (no children or peers, and no value
458 * assigned to the node)
460 ******************************************************************************/
466 ACPI_PARSE_OBJECT *Op;
469 Op = TrAllocateNode (ParseOpcode);
471 DbgPrint (ASL_PARSE_OUTPUT,
472 "\nCreateLeafNode Ln/Col %u/%u NewNode %p Op %s\n\n",
473 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode));
479 /*******************************************************************************
481 * FUNCTION: TrCreateConstantLeafNode
483 * PARAMETERS: ParseOpcode - The constant opcode
485 * RETURN: Pointer to the new node. Aborts on allocation failure
487 * DESCRIPTION: Create a leaf node (no children or peers) for one of the
488 * special constants - __LINE__, __FILE__, and __DATE__.
490 * Note: An implemenation of __FUNC__ cannot happen here because we don't
491 * have a full parse tree at this time and cannot find the parent control
492 * method. If it is ever needed, __FUNC__ must be implemented later, after
493 * the parse tree has been fully constructed.
495 ******************************************************************************/
498 TrCreateConstantLeafNode (
501 ACPI_PARSE_OBJECT *Op = NULL;
503 char *StaticTimeString;
511 case PARSEOP___LINE__:
513 Op = TrAllocateNode (PARSEOP_INTEGER);
514 Op->Asl.Value.Integer = Op->Asl.LineNumber;
517 case PARSEOP___PATH__:
519 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
521 /* Op.Asl.Filename contains the full pathname to the file */
523 Op->Asl.Value.String = Op->Asl.Filename;
526 case PARSEOP___FILE__:
528 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
530 /* Get the simple filename from the full path */
532 FlSplitInputPathname (Op->Asl.Filename, &Path, &Filename);
533 Op->Asl.Value.String = Filename;
536 case PARSEOP___DATE__:
538 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
540 /* Get a copy of the current time */
542 CurrentTime = time (NULL);
543 StaticTimeString = ctime (&CurrentTime);
544 TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);
545 strcpy (TimeString, StaticTimeString);
547 TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */
548 Op->Asl.Value.String = TimeString;
551 default: /* This would be an internal error */
556 DbgPrint (ASL_PARSE_OUTPUT,
557 "\nCreateConstantLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
558 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),
559 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
564 /*******************************************************************************
566 * FUNCTION: TrCreateValuedLeafNode
568 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
569 * Value - Value to be assigned to the node
571 * RETURN: Pointer to the new node. Aborts on allocation failure
573 * DESCRIPTION: Create a leaf node (no children or peers) with a value
576 ******************************************************************************/
579 TrCreateValuedLeafNode (
583 ACPI_PARSE_OBJECT *Op;
586 Op = TrAllocateNode (ParseOpcode);
588 DbgPrint (ASL_PARSE_OUTPUT,
589 "\nCreateValuedLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
590 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),
591 ACPI_FORMAT_UINT64 (Value));
592 Op->Asl.Value.Integer = Value;
596 case PARSEOP_STRING_LITERAL:
598 DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Value);
601 case PARSEOP_NAMESEG:
603 DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Value);
606 case PARSEOP_NAMESTRING:
608 DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Value);
613 DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Value);
618 DbgPrint (ASL_PARSE_OUTPUT, "METHOD");
621 case PARSEOP_INTEGER:
623 DbgPrint (ASL_PARSE_OUTPUT, "INTEGER");
631 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
636 /*******************************************************************************
638 * FUNCTION: TrCreateNode
640 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
641 * NumChildren - Number of children to follow
642 * ... - A list of child nodes to link to the new
643 * node. NumChildren long.
645 * RETURN: Pointer to the new node. Aborts on allocation failure
647 * DESCRIPTION: Create a new parse node and link together a list of child
648 * nodes underneath the new node.
650 ******************************************************************************/
658 ACPI_PARSE_OBJECT *Op;
659 ACPI_PARSE_OBJECT *Child;
660 ACPI_PARSE_OBJECT *PrevChild;
666 va_start (ap, NumChildren);
668 /* Allocate one new node */
670 Op = TrAllocateNode (ParseOpcode);
672 DbgPrint (ASL_PARSE_OUTPUT,
673 "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ",
674 Op->Asl.LineNumber, Op->Asl.Column, Op, NumChildren, UtGetOpName(ParseOpcode));
676 /* Some extra debug output based on the parse opcode */
680 case PARSEOP_DEFINITIONBLOCK:
683 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
686 case PARSEOP_OPERATIONREGION:
688 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
693 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
698 /* Nothing to do for other opcodes */
703 /* Link the new node to its children */
707 for (i = 0; i < NumChildren; i++)
709 /* Get the next child */
711 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
712 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
715 * If child is NULL, this means that an optional argument
716 * was omitted. We must create a placeholder with a special
717 * opcode (DEFAULT_ARG) so that the code generator will know
718 * that it must emit the correct default for this argument
722 Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
725 /* Link first child to parent */
730 Op->Asl.Child = Child;
733 /* Point all children to parent */
735 Child->Asl.Parent = Op;
737 /* Link children in a peer list */
741 PrevChild->Asl.Next = Child;
745 * This child might be a list, point all nodes in the list
748 while (Child->Asl.Next)
750 Child = Child->Asl.Next;
751 Child->Asl.Parent = Op;
758 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
763 /*******************************************************************************
765 * FUNCTION: TrLinkChildren
767 * PARAMETERS: Op - An existing parse node
768 * NumChildren - Number of children to follow
769 * ... - A list of child nodes to link to the new
770 * node. NumChildren long.
772 * RETURN: The updated (linked) node
774 * DESCRIPTION: Link a group of nodes to an existing parse node
776 ******************************************************************************/
780 ACPI_PARSE_OBJECT *Op,
784 ACPI_PARSE_OBJECT *Child;
785 ACPI_PARSE_OBJECT *PrevChild;
791 va_start (ap, NumChildren);
794 TrSetEndLineNumber (Op);
796 DbgPrint (ASL_PARSE_OUTPUT,
797 "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ",
798 Op->Asl.LineNumber, Op->Asl.EndLine,
799 Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
801 switch (Op->Asl.ParseOpcode)
803 case PARSEOP_DEFINITIONBLOCK:
806 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
809 case PARSEOP_OPERATIONREGION:
811 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
816 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
821 /* Nothing to do for other opcodes */
826 /* Link the new node to it's children */
830 for (i = 0; i < NumChildren; i++)
832 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
834 if ((Child == PrevChild) && (Child != NULL))
836 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
837 "Child node list invalid");
842 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
845 * If child is NULL, this means that an optional argument
846 * was omitted. We must create a placeholder with a special
847 * opcode (DEFAULT_ARG) so that the code generator will know
848 * that it must emit the correct default for this argument
852 Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
855 /* Link first child to parent */
860 Op->Asl.Child = Child;
863 /* Point all children to parent */
865 Child->Asl.Parent = Op;
867 /* Link children in a peer list */
871 PrevChild->Asl.Next = Child;
875 * This child might be a list, point all nodes in the list
878 while (Child->Asl.Next)
880 Child = Child->Asl.Next;
881 Child->Asl.Parent = Op;
887 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
892 /*******************************************************************************
894 * FUNCTION: TrLinkPeerNode
896 * PARAMETERS: Op1 - First peer
899 * RETURN: Op1 or the non-null node.
901 * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null.
903 ******************************************************************************/
907 ACPI_PARSE_OBJECT *Op1,
908 ACPI_PARSE_OBJECT *Op2)
910 ACPI_PARSE_OBJECT *Next;
913 DbgPrint (ASL_PARSE_OUTPUT,
914 "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n\n",
915 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
916 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
919 if ((!Op1) && (!Op2))
921 DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null nodes!\n");
925 /* If one of the nodes is null, just return the non-null node */
939 DbgPrint (ASL_DEBUG_OUTPUT,
940 "\n\n************* Internal error, linking node to itself %p\n\n\n",
942 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
943 "Linking node to itself");
947 Op1->Asl.Parent = Op2->Asl.Parent;
950 * Op 1 may already have a peer list (such as an IF/ELSE pair),
951 * so we must walk to the end of the list and attach the new
955 while (Next->Asl.Next)
957 Next = Next->Asl.Next;
960 Next->Asl.Next = Op2;
965 /*******************************************************************************
967 * FUNCTION: TrLinkPeerNodes
969 * PARAMETERS: NumPeers - The number of nodes in the list to follow
970 * ... - A list of nodes to link together as peers
972 * RETURN: The first node in the list (head of the peer list)
974 * DESCRIPTION: Link together an arbitrary number of peer nodes.
976 ******************************************************************************/
983 ACPI_PARSE_OBJECT *This;
984 ACPI_PARSE_OBJECT *Next;
987 ACPI_PARSE_OBJECT *Start;
990 DbgPrint (ASL_PARSE_OUTPUT,
991 "\nLinkPeerNodes: (%u) ", NumPeers);
993 va_start (ap, NumPeers);
994 This = va_arg (ap, ACPI_PARSE_OBJECT *);
1000 for (i = 0; i < (NumPeers -1); i++)
1002 DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
1004 while (This->Asl.Next)
1006 This = This->Asl.Next;
1009 /* Get another peer node */
1011 Next = va_arg (ap, ACPI_PARSE_OBJECT *);
1014 Next = TrAllocateNode (PARSEOP_DEFAULT_ARG);
1017 /* link new node to the current node */
1019 This->Asl.Next = Next;
1024 DbgPrint (ASL_PARSE_OUTPUT,"\n\n");
1029 /*******************************************************************************
1031 * FUNCTION: TrLinkChildNode
1033 * PARAMETERS: Op1 - Parent node
1034 * Op2 - Op to become a child
1036 * RETURN: The parent node
1038 * DESCRIPTION: Link two nodes together as a parent and child
1040 ******************************************************************************/
1044 ACPI_PARSE_OBJECT *Op1,
1045 ACPI_PARSE_OBJECT *Op2)
1047 ACPI_PARSE_OBJECT *Next;
1050 DbgPrint (ASL_PARSE_OUTPUT,
1051 "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n\n",
1052 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
1053 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
1060 Op1->Asl.Child = Op2;
1062 /* Set the child and all peers of the child to point to the parent */
1067 Next->Asl.Parent = Op1;
1068 Next = Next->Asl.Next;
1075 /*******************************************************************************
1077 * FUNCTION: TrWalkParseTree
1079 * PARAMETERS: Visitation - Type of walk
1080 * DescendingCallback - Called during tree descent
1081 * AscendingCallback - Called during tree ascent
1082 * Context - To be passed to the callbacks
1084 * RETURN: Status from callback(s)
1086 * DESCRIPTION: Walk the entire parse tree.
1088 ******************************************************************************/
1092 ACPI_PARSE_OBJECT *Op,
1094 ASL_WALK_CALLBACK DescendingCallback,
1095 ASL_WALK_CALLBACK AscendingCallback,
1099 BOOLEAN NodePreviouslyVisited;
1100 ACPI_PARSE_OBJECT *StartOp = Op;
1110 NodePreviouslyVisited = FALSE;
1114 case ASL_WALK_VISIT_DOWNWARD:
1118 if (!NodePreviouslyVisited)
1120 /* Let the callback process the node. */
1122 Status = DescendingCallback (Op, Level, Context);
1123 if (ACPI_SUCCESS (Status))
1125 /* Visit children first, once */
1134 else if (Status != AE_CTRL_DEPTH)
1136 /* Exit immediately on any error */
1142 /* Terminate walk at start op */
1149 /* No more children, visit peers */
1154 NodePreviouslyVisited = FALSE;
1158 /* No children or peers, re-visit parent */
1164 Op = Op->Asl.Parent;
1165 NodePreviouslyVisited = TRUE;
1170 case ASL_WALK_VISIT_UPWARD:
1174 /* Visit leaf node (no children) or parent node on return trip */
1176 if ((!Op->Asl.Child) ||
1177 (NodePreviouslyVisited))
1179 /* Let the callback process the node. */
1181 Status = AscendingCallback (Op, Level, Context);
1182 if (ACPI_FAILURE (Status))
1189 /* Visit children first, once */
1196 /* Terminate walk at start op */
1203 /* No more children, visit peers */
1208 NodePreviouslyVisited = FALSE;
1212 /* No children or peers, re-visit parent */
1218 Op = Op->Asl.Parent;
1219 NodePreviouslyVisited = TRUE;
1224 case ASL_WALK_VISIT_TWICE:
1228 if (NodePreviouslyVisited)
1230 Status = AscendingCallback (Op, Level, Context);
1231 if (ACPI_FAILURE (Status))
1238 /* Let the callback process the node. */
1240 Status = DescendingCallback (Op, Level, Context);
1241 if (ACPI_SUCCESS (Status))
1243 /* Visit children first, once */
1252 else if (Status != AE_CTRL_DEPTH)
1254 /* Exit immediately on any error */
1260 /* Terminate walk at start op */
1267 /* No more children, visit peers */
1272 NodePreviouslyVisited = FALSE;
1276 /* No children or peers, re-visit parent */
1282 Op = Op->Asl.Parent;
1283 NodePreviouslyVisited = TRUE;
1289 /* No other types supported */
1293 /* If we get here, the walk completed with no errors */