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 "aslcompiler.h"
45 #include "aslcompiler.y.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);
534 Op->Asl.Value.String = Filename;
537 case PARSEOP___DATE__:
539 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
541 /* Get a copy of the current time */
543 CurrentTime = time (NULL);
544 StaticTimeString = ctime (&CurrentTime);
545 TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);
546 strcpy (TimeString, StaticTimeString);
548 TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */
549 Op->Asl.Value.String = TimeString;
552 default: /* This would be an internal error */
557 DbgPrint (ASL_PARSE_OUTPUT,
558 "\nCreateConstantLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
559 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),
560 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
565 /*******************************************************************************
567 * FUNCTION: TrCreateValuedLeafNode
569 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
570 * Value - Value to be assigned to the node
572 * RETURN: Pointer to the new node. Aborts on allocation failure
574 * DESCRIPTION: Create a leaf node (no children or peers) with a value
577 ******************************************************************************/
580 TrCreateValuedLeafNode (
584 ACPI_PARSE_OBJECT *Op;
587 Op = TrAllocateNode (ParseOpcode);
589 DbgPrint (ASL_PARSE_OUTPUT,
590 "\nCreateValuedLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
591 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),
592 ACPI_FORMAT_UINT64 (Value));
593 Op->Asl.Value.Integer = Value;
597 case PARSEOP_STRING_LITERAL:
599 DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Value);
602 case PARSEOP_NAMESEG:
604 DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Value);
607 case PARSEOP_NAMESTRING:
609 DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Value);
614 DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Value);
619 DbgPrint (ASL_PARSE_OUTPUT, "METHOD");
622 case PARSEOP_INTEGER:
624 DbgPrint (ASL_PARSE_OUTPUT, "INTEGER");
632 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
637 /*******************************************************************************
639 * FUNCTION: TrCreateNode
641 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
642 * NumChildren - Number of children to follow
643 * ... - A list of child nodes to link to the new
644 * node. NumChildren long.
646 * RETURN: Pointer to the new node. Aborts on allocation failure
648 * DESCRIPTION: Create a new parse node and link together a list of child
649 * nodes underneath the new node.
651 ******************************************************************************/
659 ACPI_PARSE_OBJECT *Op;
660 ACPI_PARSE_OBJECT *Child;
661 ACPI_PARSE_OBJECT *PrevChild;
667 va_start (ap, NumChildren);
669 /* Allocate one new node */
671 Op = TrAllocateNode (ParseOpcode);
673 DbgPrint (ASL_PARSE_OUTPUT,
674 "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ",
675 Op->Asl.LineNumber, Op->Asl.Column, Op, NumChildren, UtGetOpName(ParseOpcode));
677 /* Some extra debug output based on the parse opcode */
681 case PARSEOP_DEFINITIONBLOCK:
684 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
687 case PARSEOP_OPERATIONREGION:
689 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
694 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
699 /* Nothing to do for other opcodes */
704 /* Link the new node to its children */
708 for (i = 0; i < NumChildren; i++)
710 /* Get the next child */
712 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
713 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
716 * If child is NULL, this means that an optional argument
717 * was omitted. We must create a placeholder with a special
718 * opcode (DEFAULT_ARG) so that the code generator will know
719 * that it must emit the correct default for this argument
723 Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
726 /* Link first child to parent */
731 Op->Asl.Child = Child;
734 /* Point all children to parent */
736 Child->Asl.Parent = Op;
738 /* Link children in a peer list */
742 PrevChild->Asl.Next = Child;
746 * This child might be a list, point all nodes in the list
749 while (Child->Asl.Next)
751 Child = Child->Asl.Next;
752 Child->Asl.Parent = Op;
759 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
764 /*******************************************************************************
766 * FUNCTION: TrLinkChildren
768 * PARAMETERS: Op - An existing parse node
769 * NumChildren - Number of children to follow
770 * ... - A list of child nodes to link to the new
771 * node. NumChildren long.
773 * RETURN: The updated (linked) node
775 * DESCRIPTION: Link a group of nodes to an existing parse node
777 ******************************************************************************/
781 ACPI_PARSE_OBJECT *Op,
785 ACPI_PARSE_OBJECT *Child;
786 ACPI_PARSE_OBJECT *PrevChild;
792 va_start (ap, NumChildren);
795 TrSetEndLineNumber (Op);
797 DbgPrint (ASL_PARSE_OUTPUT,
798 "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ",
799 Op->Asl.LineNumber, Op->Asl.EndLine,
800 Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
802 switch (Op->Asl.ParseOpcode)
804 case PARSEOP_DEFINITIONBLOCK:
807 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
810 case PARSEOP_OPERATIONREGION:
812 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
817 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
822 /* Nothing to do for other opcodes */
827 /* Link the new node to it's children */
831 for (i = 0; i < NumChildren; i++)
833 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
835 if ((Child == PrevChild) && (Child != NULL))
837 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
838 "Child node list invalid");
843 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
846 * If child is NULL, this means that an optional argument
847 * was omitted. We must create a placeholder with a special
848 * opcode (DEFAULT_ARG) so that the code generator will know
849 * that it must emit the correct default for this argument
853 Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
856 /* Link first child to parent */
861 Op->Asl.Child = Child;
864 /* Point all children to parent */
866 Child->Asl.Parent = Op;
868 /* Link children in a peer list */
872 PrevChild->Asl.Next = Child;
876 * This child might be a list, point all nodes in the list
879 while (Child->Asl.Next)
881 Child = Child->Asl.Next;
882 Child->Asl.Parent = Op;
888 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
893 /*******************************************************************************
895 * FUNCTION: TrLinkPeerNode
897 * PARAMETERS: Op1 - First peer
900 * RETURN: Op1 or the non-null node.
902 * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null.
904 ******************************************************************************/
908 ACPI_PARSE_OBJECT *Op1,
909 ACPI_PARSE_OBJECT *Op2)
911 ACPI_PARSE_OBJECT *Next;
914 DbgPrint (ASL_PARSE_OUTPUT,
915 "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n\n",
916 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
917 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
920 if ((!Op1) && (!Op2))
922 DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null nodes!\n");
926 /* If one of the nodes is null, just return the non-null node */
940 DbgPrint (ASL_DEBUG_OUTPUT,
941 "\n\n************* Internal error, linking node to itself %p\n\n\n",
943 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
944 "Linking node to itself");
948 Op1->Asl.Parent = Op2->Asl.Parent;
951 * Op 1 may already have a peer list (such as an IF/ELSE pair),
952 * so we must walk to the end of the list and attach the new
956 while (Next->Asl.Next)
958 Next = Next->Asl.Next;
961 Next->Asl.Next = Op2;
966 /*******************************************************************************
968 * FUNCTION: TrLinkPeerNodes
970 * PARAMETERS: NumPeers - The number of nodes in the list to follow
971 * ... - A list of nodes to link together as peers
973 * RETURN: The first node in the list (head of the peer list)
975 * DESCRIPTION: Link together an arbitrary number of peer nodes.
977 ******************************************************************************/
984 ACPI_PARSE_OBJECT *This;
985 ACPI_PARSE_OBJECT *Next;
988 ACPI_PARSE_OBJECT *Start;
991 DbgPrint (ASL_PARSE_OUTPUT,
992 "\nLinkPeerNodes: (%u) ", NumPeers);
994 va_start (ap, NumPeers);
995 This = va_arg (ap, ACPI_PARSE_OBJECT *);
1001 for (i = 0; i < (NumPeers -1); i++)
1003 DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
1005 while (This->Asl.Next)
1007 This = This->Asl.Next;
1010 /* Get another peer node */
1012 Next = va_arg (ap, ACPI_PARSE_OBJECT *);
1015 Next = TrAllocateNode (PARSEOP_DEFAULT_ARG);
1018 /* link new node to the current node */
1020 This->Asl.Next = Next;
1025 DbgPrint (ASL_PARSE_OUTPUT,"\n\n");
1030 /*******************************************************************************
1032 * FUNCTION: TrLinkChildNode
1034 * PARAMETERS: Op1 - Parent node
1035 * Op2 - Op to become a child
1037 * RETURN: The parent node
1039 * DESCRIPTION: Link two nodes together as a parent and child
1041 ******************************************************************************/
1045 ACPI_PARSE_OBJECT *Op1,
1046 ACPI_PARSE_OBJECT *Op2)
1048 ACPI_PARSE_OBJECT *Next;
1051 DbgPrint (ASL_PARSE_OUTPUT,
1052 "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n\n",
1053 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
1054 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
1061 Op1->Asl.Child = Op2;
1063 /* Set the child and all peers of the child to point to the parent */
1068 Next->Asl.Parent = Op1;
1069 Next = Next->Asl.Next;
1076 /*******************************************************************************
1078 * FUNCTION: TrWalkParseTree
1080 * PARAMETERS: Visitation - Type of walk
1081 * DescendingCallback - Called during tree descent
1082 * AscendingCallback - Called during tree ascent
1083 * Context - To be passed to the callbacks
1085 * RETURN: Status from callback(s)
1087 * DESCRIPTION: Walk the entire parse tree.
1089 ******************************************************************************/
1093 ACPI_PARSE_OBJECT *Op,
1095 ASL_WALK_CALLBACK DescendingCallback,
1096 ASL_WALK_CALLBACK AscendingCallback,
1100 BOOLEAN NodePreviouslyVisited;
1101 ACPI_PARSE_OBJECT *StartOp = Op;
1111 NodePreviouslyVisited = FALSE;
1115 case ASL_WALK_VISIT_DOWNWARD:
1119 if (!NodePreviouslyVisited)
1121 /* Let the callback process the node. */
1123 Status = DescendingCallback (Op, Level, Context);
1124 if (ACPI_SUCCESS (Status))
1126 /* Visit children first, once */
1135 else if (Status != AE_CTRL_DEPTH)
1137 /* Exit immediately on any error */
1143 /* Terminate walk at start op */
1150 /* No more children, visit peers */
1155 NodePreviouslyVisited = FALSE;
1159 /* No children or peers, re-visit parent */
1165 Op = Op->Asl.Parent;
1166 NodePreviouslyVisited = TRUE;
1171 case ASL_WALK_VISIT_UPWARD:
1175 /* Visit leaf node (no children) or parent node on return trip */
1177 if ((!Op->Asl.Child) ||
1178 (NodePreviouslyVisited))
1180 /* Let the callback process the node. */
1182 Status = AscendingCallback (Op, Level, Context);
1183 if (ACPI_FAILURE (Status))
1190 /* Visit children first, once */
1197 /* Terminate walk at start op */
1204 /* No more children, visit peers */
1209 NodePreviouslyVisited = FALSE;
1213 /* No children or peers, re-visit parent */
1219 Op = Op->Asl.Parent;
1220 NodePreviouslyVisited = TRUE;
1225 case ASL_WALK_VISIT_TWICE:
1229 if (NodePreviouslyVisited)
1231 Status = AscendingCallback (Op, Level, Context);
1232 if (ACPI_FAILURE (Status))
1239 /* Let the callback process the node. */
1241 Status = DescendingCallback (Op, Level, Context);
1242 if (ACPI_SUCCESS (Status))
1244 /* Visit children first, once */
1253 else if (Status != AE_CTRL_DEPTH)
1255 /* Exit immediately on any error */
1261 /* Terminate walk at start op */
1268 /* No more children, visit peers */
1273 NodePreviouslyVisited = FALSE;
1277 /* No children or peers, re-visit parent */
1283 Op = Op->Asl.Parent;
1284 NodePreviouslyVisited = TRUE;
1290 /* No other types supported */
1294 /* If we get here, the walk completed with no errors */