2 /******************************************************************************
4 * Module Name: asltree - parse tree management
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
119 #include "aslcompiler.h"
120 #include "aslcompiler.y.h"
122 #define _COMPONENT ACPI_COMPILER
123 ACPI_MODULE_NAME ("asltree")
125 /* Local prototypes */
127 static ACPI_PARSE_OBJECT
*
136 /*******************************************************************************
138 * FUNCTION: TrGetNextNode
142 * RETURN: New parse node. Aborts on allocation failure
144 * DESCRIPTION: Allocate a new parse node for the parse tree. Bypass the local
145 * dynamic memory manager for performance reasons (This has a
146 * major impact on the speed of the compiler.)
148 ******************************************************************************/
150 static ACPI_PARSE_OBJECT
*
155 if (Gbl_NodeCacheNext
>= Gbl_NodeCacheLast
)
157 Gbl_NodeCacheNext
= UtLocalCalloc (sizeof (ACPI_PARSE_OBJECT
) *
158 ASL_NODE_CACHE_SIZE
);
159 Gbl_NodeCacheLast
= Gbl_NodeCacheNext
+ ASL_NODE_CACHE_SIZE
;
162 return (Gbl_NodeCacheNext
++);
166 /*******************************************************************************
168 * FUNCTION: TrAllocateNode
170 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
172 * RETURN: New parse node. Aborts on allocation failure
174 * DESCRIPTION: Allocate and initialize a new parse node for the parse tree
176 ******************************************************************************/
182 ACPI_PARSE_OBJECT
*Op
;
185 Op
= TrGetNextNode ();
187 Op
->Asl
.ParseOpcode
= (UINT16
) ParseOpcode
;
188 Op
->Asl
.Filename
= Gbl_Files
[ASL_FILE_INPUT
].Filename
;
189 Op
->Asl
.LineNumber
= Gbl_CurrentLineNumber
;
190 Op
->Asl
.LogicalLineNumber
= Gbl_LogicalLineNumber
;
191 Op
->Asl
.LogicalByteOffset
= Gbl_CurrentLineOffset
;
192 Op
->Asl
.Column
= Gbl_CurrentColumn
;
194 UtSetParseOpName (Op
);
199 /*******************************************************************************
201 * FUNCTION: TrReleaseNode
203 * PARAMETERS: Op - Op to be released
207 * DESCRIPTION: "release" a node. In truth, nothing is done since the node
208 * is part of a larger buffer
210 ******************************************************************************/
214 ACPI_PARSE_OBJECT
*Op
)
221 /*******************************************************************************
223 * FUNCTION: TrUpdateNode
225 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
226 * Op - An existing parse node
228 * RETURN: The updated node
230 * DESCRIPTION: Change the parse opcode assigned to a node. Usually used to
231 * change an opcode to DEFAULT_ARG so that the node is ignored
232 * during the code generation. Also used to set generic integers
233 * to a specific size (8, 16, 32, or 64 bits)
235 ******************************************************************************/
240 ACPI_PARSE_OBJECT
*Op
)
248 DbgPrint (ASL_PARSE_OUTPUT
,
249 "\nUpdateNode: Old - %s, New - %s\n\n",
250 UtGetOpName (Op
->Asl
.ParseOpcode
),
251 UtGetOpName (ParseOpcode
));
253 /* Assign new opcode and name */
255 if (Op
->Asl
.ParseOpcode
== PARSEOP_ONES
)
259 case PARSEOP_BYTECONST
:
260 Op
->Asl
.Value
.Integer
= 0xFF;
263 case PARSEOP_WORDCONST
:
264 Op
->Asl
.Value
.Integer
= 0xFFFF;
267 case PARSEOP_DWORDCONST
:
268 Op
->Asl
.Value
.Integer
= 0xFFFFFFFF;
272 /* Don't care about others, don't need to check QWORD */
277 Op
->Asl
.ParseOpcode
= (UINT16
) ParseOpcode
;
278 UtSetParseOpName (Op
);
281 * For the BYTE, WORD, and DWORD constants, make sure that the integer
282 * that was passed in will actually fit into the data type
286 case PARSEOP_BYTECONST
:
287 Op
= UtCheckIntegerRange (Op
, 0x00, ACPI_UINT8_MAX
);
290 case PARSEOP_WORDCONST
:
291 Op
= UtCheckIntegerRange (Op
, 0x00, ACPI_UINT16_MAX
);
294 case PARSEOP_DWORDCONST
:
295 Op
= UtCheckIntegerRange (Op
, 0x00, ACPI_UINT32_MAX
);
299 /* Don't care about others, don't need to check QWORD */
307 /*******************************************************************************
309 * FUNCTION: TrGetNodeFlagName
311 * PARAMETERS: Flags - Flags word to be decoded
313 * RETURN: Name string. Always returns a valid string pointer.
315 * DESCRIPTION: Decode a flags word
317 ******************************************************************************/
327 return ("NODE_VISITED");
329 case NODE_AML_PACKAGE
:
330 return ("NODE_AML_PACKAGE");
333 return ("NODE_IS_TARGET");
335 case NODE_IS_RESOURCE_DESC
:
336 return ("NODE_IS_RESOURCE_DESC");
338 case NODE_IS_RESOURCE_FIELD
:
339 return ("NODE_IS_RESOURCE_FIELD");
341 case NODE_HAS_NO_EXIT
:
342 return ("NODE_HAS_NO_EXIT");
344 case NODE_IF_HAS_NO_EXIT
:
345 return ("NODE_IF_HAS_NO_EXIT");
347 case NODE_NAME_INTERNALIZED
:
348 return ("NODE_NAME_INTERNALIZED");
350 case NODE_METHOD_NO_RETVAL
:
351 return ("NODE_METHOD_NO_RETVAL");
353 case NODE_METHOD_SOME_NO_RETVAL
:
354 return ("NODE_METHOD_SOME_NO_RETVAL");
356 case NODE_RESULT_NOT_USED
:
357 return ("NODE_RESULT_NOT_USED");
359 case NODE_METHOD_TYPED
:
360 return ("NODE_METHOD_TYPED");
362 case NODE_IS_BIT_OFFSET
:
363 return ("NODE_IS_BIT_OFFSET");
365 case NODE_COMPILE_TIME_CONST
:
366 return ("NODE_COMPILE_TIME_CONST");
368 case NODE_IS_TERM_ARG
:
369 return ("NODE_IS_TERM_ARG");
371 case NODE_WAS_ONES_OP
:
372 return ("NODE_WAS_ONES_OP");
374 case NODE_IS_NAME_DECLARATION
:
375 return ("NODE_IS_NAME_DECLARATION");
378 return ("Multiple Flags (or unknown flag) set");
383 /*******************************************************************************
385 * FUNCTION: TrSetNodeFlags
387 * PARAMETERS: Op - An existing parse node
388 * Flags - New flags word
390 * RETURN: The updated parser op
392 * DESCRIPTION: Set bits in the node flags word. Will not clear bits, only set
394 ******************************************************************************/
398 ACPI_PARSE_OBJECT
*Op
,
402 DbgPrint (ASL_PARSE_OUTPUT
,
403 "\nSetNodeFlags: Op %p, %8.8X %s\n\n", Op
, Flags
,
404 TrGetNodeFlagName (Flags
));
411 Op
->Asl
.CompileFlags
|= Flags
;
417 /*******************************************************************************
419 * FUNCTION: TrSetEndLineNumber
421 * PARAMETERS: Op - An existing parse node
425 * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
426 * parse node to the current line numbers.
428 ******************************************************************************/
432 ACPI_PARSE_OBJECT
*Op
)
435 /* If the end line # is already set, just return */
442 Op
->Asl
.EndLine
= Gbl_CurrentLineNumber
;
443 Op
->Asl
.EndLogicalLine
= Gbl_LogicalLineNumber
;
447 /*******************************************************************************
449 * FUNCTION: TrCreateLeafNode
451 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
453 * RETURN: Pointer to the new node. Aborts on allocation failure
455 * DESCRIPTION: Create a simple leaf node (no children or peers, and no value
456 * assigned to the node)
458 ******************************************************************************/
464 ACPI_PARSE_OBJECT
*Op
;
467 Op
= TrAllocateNode (ParseOpcode
);
469 DbgPrint (ASL_PARSE_OUTPUT
,
470 "\nCreateLeafNode Ln/Col %d/%d NewNode %p Op %s\n\n",
471 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, UtGetOpName(ParseOpcode
));
477 /*******************************************************************************
479 * FUNCTION: TrCreateValuedLeafNode
481 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
482 * Value - Value to be assigned to the node
484 * RETURN: Pointer to the new node. Aborts on allocation failure
486 * DESCRIPTION: Create a leaf node (no children or peers) with a value
489 ******************************************************************************/
492 TrCreateValuedLeafNode (
496 ACPI_PARSE_OBJECT
*Op
;
499 Op
= TrAllocateNode (ParseOpcode
);
501 DbgPrint (ASL_PARSE_OUTPUT
,
502 "\nCreateValuedLeafNode Ln/Col %d/%d NewNode %p Op %s Value %8.8X%8.8X ",
503 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, UtGetOpName(ParseOpcode
),
504 ACPI_FORMAT_UINT64 (Value
));
505 Op
->Asl
.Value
.Integer
= Value
;
509 case PARSEOP_STRING_LITERAL
:
510 DbgPrint (ASL_PARSE_OUTPUT
, "STRING->%s", Value
);
513 case PARSEOP_NAMESEG
:
514 DbgPrint (ASL_PARSE_OUTPUT
, "NAMESEG->%s", Value
);
517 case PARSEOP_NAMESTRING
:
518 DbgPrint (ASL_PARSE_OUTPUT
, "NAMESTRING->%s", Value
);
522 DbgPrint (ASL_PARSE_OUTPUT
, "EISAID->%s", Value
);
526 DbgPrint (ASL_PARSE_OUTPUT
, "METHOD");
529 case PARSEOP_INTEGER
:
530 DbgPrint (ASL_PARSE_OUTPUT
, "INTEGER");
537 DbgPrint (ASL_PARSE_OUTPUT
, "\n\n");
542 /*******************************************************************************
544 * FUNCTION: TrCreateNode
546 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
547 * NumChildren - Number of children to follow
548 * ... - A list of child nodes to link to the new
549 * node. NumChildren long.
551 * RETURN: Pointer to the new node. Aborts on allocation failure
553 * DESCRIPTION: Create a new parse node and link together a list of child
554 * nodes underneath the new node.
556 ******************************************************************************/
564 ACPI_PARSE_OBJECT
*Op
;
565 ACPI_PARSE_OBJECT
*Child
;
566 ACPI_PARSE_OBJECT
*PrevChild
;
572 va_start (ap
, NumChildren
);
574 /* Allocate one new node */
576 Op
= TrAllocateNode (ParseOpcode
);
578 DbgPrint (ASL_PARSE_OUTPUT
,
579 "\nCreateNode Ln/Col %d/%d NewParent %p Child %d Op %s ",
580 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, NumChildren
, UtGetOpName(ParseOpcode
));
582 /* Some extra debug output based on the parse opcode */
586 case PARSEOP_DEFINITIONBLOCK
:
588 DbgPrint (ASL_PARSE_OUTPUT
, "DEFINITION_BLOCK (Tree Completed)->");
591 case PARSEOP_OPERATIONREGION
:
592 DbgPrint (ASL_PARSE_OUTPUT
, "OPREGION->");
596 DbgPrint (ASL_PARSE_OUTPUT
, "OR->");
600 /* Nothing to do for other opcodes */
604 /* Link the new node to its children */
608 for (i
= 0; i
< NumChildren
; i
++)
610 /* Get the next child */
612 Child
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
613 DbgPrint (ASL_PARSE_OUTPUT
, "%p, ", Child
);
616 * If child is NULL, this means that an optional argument
617 * was omitted. We must create a placeholder with a special
618 * opcode (DEFAULT_ARG) so that the code generator will know
619 * that it must emit the correct default for this argument
623 Child
= TrAllocateNode (PARSEOP_DEFAULT_ARG
);
626 /* Link first child to parent */
631 Op
->Asl
.Child
= Child
;
634 /* Point all children to parent */
636 Child
->Asl
.Parent
= Op
;
638 /* Link children in a peer list */
642 PrevChild
->Asl
.Next
= Child
;
646 * This child might be a list, point all nodes in the list
649 while (Child
->Asl
.Next
)
651 Child
= Child
->Asl
.Next
;
652 Child
->Asl
.Parent
= Op
;
659 DbgPrint (ASL_PARSE_OUTPUT
, "\n\n");
664 /*******************************************************************************
666 * FUNCTION: TrLinkChildren
668 * PARAMETERS: Op - An existing parse node
669 * NumChildren - Number of children to follow
670 * ... - A list of child nodes to link to the new
671 * node. NumChildren long.
673 * RETURN: The updated (linked) node
675 * DESCRIPTION: Link a group of nodes to an existing parse node
677 ******************************************************************************/
681 ACPI_PARSE_OBJECT
*Op
,
685 ACPI_PARSE_OBJECT
*Child
;
686 ACPI_PARSE_OBJECT
*PrevChild
;
692 va_start (ap
, NumChildren
);
695 TrSetEndLineNumber (Op
);
697 DbgPrint (ASL_PARSE_OUTPUT
,
698 "\nLinkChildren Line [%d to %d] NewParent %p Child %d Op %s ",
699 Op
->Asl
.LineNumber
, Op
->Asl
.EndLine
,
700 Op
, NumChildren
, UtGetOpName(Op
->Asl
.ParseOpcode
));
702 switch (Op
->Asl
.ParseOpcode
)
704 case PARSEOP_DEFINITIONBLOCK
:
706 DbgPrint (ASL_PARSE_OUTPUT
, "DEFINITION_BLOCK (Tree Completed)->");
709 case PARSEOP_OPERATIONREGION
:
710 DbgPrint (ASL_PARSE_OUTPUT
, "OPREGION->");
714 DbgPrint (ASL_PARSE_OUTPUT
, "OR->");
718 /* Nothing to do for other opcodes */
722 /* Link the new node to it's children */
726 for (i
= 0; i
< NumChildren
; i
++)
728 Child
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
730 if ((Child
== PrevChild
) && (Child
!= NULL
))
732 AslError (ASL_WARNING
, ASL_MSG_COMPILER_INTERNAL
, Child
,
733 "Child node list invalid");
737 DbgPrint (ASL_PARSE_OUTPUT
, "%p, ", Child
);
740 * If child is NULL, this means that an optional argument
741 * was omitted. We must create a placeholder with a special
742 * opcode (DEFAULT_ARG) so that the code generator will know
743 * that it must emit the correct default for this argument
747 Child
= TrAllocateNode (PARSEOP_DEFAULT_ARG
);
750 /* Link first child to parent */
755 Op
->Asl
.Child
= Child
;
758 /* Point all children to parent */
760 Child
->Asl
.Parent
= Op
;
762 /* Link children in a peer list */
766 PrevChild
->Asl
.Next
= Child
;
770 * This child might be a list, point all nodes in the list
773 while (Child
->Asl
.Next
)
775 Child
= Child
->Asl
.Next
;
776 Child
->Asl
.Parent
= Op
;
782 DbgPrint (ASL_PARSE_OUTPUT
, "\n\n");
787 /*******************************************************************************
789 * FUNCTION: TrLinkPeerNode
791 * PARAMETERS: Op1 - First peer
794 * RETURN: Op1 or the non-null node.
796 * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null.
798 ******************************************************************************/
802 ACPI_PARSE_OBJECT
*Op1
,
803 ACPI_PARSE_OBJECT
*Op2
)
805 ACPI_PARSE_OBJECT
*Next
;
808 DbgPrint (ASL_PARSE_OUTPUT
,
809 "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n\n",
810 Op1
, Op1
? UtGetOpName(Op1
->Asl
.ParseOpcode
) : NULL
,
811 Op2
, Op2
? UtGetOpName(Op2
->Asl
.ParseOpcode
) : NULL
);
814 if ((!Op1
) && (!Op2
))
816 DbgPrint (ASL_PARSE_OUTPUT
, "\nTwo Null nodes!\n");
820 /* If one of the nodes is null, just return the non-null node */
834 DbgPrint (ASL_DEBUG_OUTPUT
,
835 "\n\n************* Internal error, linking node to itself %p\n\n\n",
837 AslError (ASL_WARNING
, ASL_MSG_COMPILER_INTERNAL
, Op1
,
838 "Linking node to itself");
842 Op1
->Asl
.Parent
= Op2
->Asl
.Parent
;
845 * Op 1 may already have a peer list (such as an IF/ELSE pair),
846 * so we must walk to the end of the list and attach the new
850 while (Next
->Asl
.Next
)
852 Next
= Next
->Asl
.Next
;
855 Next
->Asl
.Next
= Op2
;
860 /*******************************************************************************
862 * FUNCTION: TrLinkPeerNodes
864 * PARAMETERS: NumPeers - The number of nodes in the list to follow
865 * ... - A list of nodes to link together as peers
867 * RETURN: The first node in the list (head of the peer list)
869 * DESCRIPTION: Link together an arbitrary number of peer nodes.
871 ******************************************************************************/
878 ACPI_PARSE_OBJECT
*This
;
879 ACPI_PARSE_OBJECT
*Next
;
882 ACPI_PARSE_OBJECT
*Start
;
885 DbgPrint (ASL_PARSE_OUTPUT
,
886 "\nLinkPeerNodes: (%d) ", NumPeers
);
888 va_start (ap
, NumPeers
);
889 This
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
895 for (i
= 0; i
< (NumPeers
-1); i
++)
897 DbgPrint (ASL_PARSE_OUTPUT
, "%d=%p ", (i
+1), This
);
899 while (This
->Asl
.Next
)
901 This
= This
->Asl
.Next
;
904 /* Get another peer node */
906 Next
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
909 Next
= TrAllocateNode (PARSEOP_DEFAULT_ARG
);
912 /* link new node to the current node */
914 This
->Asl
.Next
= Next
;
918 DbgPrint (ASL_PARSE_OUTPUT
,"\n\n");
923 /*******************************************************************************
925 * FUNCTION: TrLinkChildNode
927 * PARAMETERS: Op1 - Parent node
928 * Op2 - Op to become a child
930 * RETURN: The parent node
932 * DESCRIPTION: Link two nodes together as a parent and child
934 ******************************************************************************/
938 ACPI_PARSE_OBJECT
*Op1
,
939 ACPI_PARSE_OBJECT
*Op2
)
941 ACPI_PARSE_OBJECT
*Next
;
944 DbgPrint (ASL_PARSE_OUTPUT
,
945 "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n\n",
946 Op1
, Op1
? UtGetOpName(Op1
->Asl
.ParseOpcode
): NULL
,
947 Op2
, Op2
? UtGetOpName(Op2
->Asl
.ParseOpcode
): NULL
);
954 Op1
->Asl
.Child
= Op2
;
956 /* Set the child and all peers of the child to point to the parent */
961 Next
->Asl
.Parent
= Op1
;
962 Next
= Next
->Asl
.Next
;
969 /*******************************************************************************
971 * FUNCTION: TrWalkParseTree
973 * PARAMETERS: Visitation - Type of walk
974 * DescendingCallback - Called during tree descent
975 * AscendingCallback - Called during tree ascent
976 * Context - To be passed to the callbacks
978 * RETURN: Status from callback(s)
980 * DESCRIPTION: Walk the entire parse tree.
982 ******************************************************************************/
986 ACPI_PARSE_OBJECT
*Op
,
988 ASL_WALK_CALLBACK DescendingCallback
,
989 ASL_WALK_CALLBACK AscendingCallback
,
993 BOOLEAN NodePreviouslyVisited
;
994 ACPI_PARSE_OBJECT
*StartOp
= Op
;
1004 NodePreviouslyVisited
= FALSE
;
1008 case ASL_WALK_VISIT_DOWNWARD
:
1012 if (!NodePreviouslyVisited
)
1014 /* Let the callback process the node. */
1016 Status
= DescendingCallback (Op
, Level
, Context
);
1017 if (ACPI_SUCCESS (Status
))
1019 /* Visit children first, once */
1028 else if (Status
!= AE_CTRL_DEPTH
)
1030 /* Exit immediately on any error */
1036 /* Terminate walk at start op */
1043 /* No more children, visit peers */
1048 NodePreviouslyVisited
= FALSE
;
1052 /* No children or peers, re-visit parent */
1058 Op
= Op
->Asl
.Parent
;
1059 NodePreviouslyVisited
= TRUE
;
1065 case ASL_WALK_VISIT_UPWARD
:
1069 /* Visit leaf node (no children) or parent node on return trip */
1071 if ((!Op
->Asl
.Child
) ||
1072 (NodePreviouslyVisited
))
1074 /* Let the callback process the node. */
1076 Status
= AscendingCallback (Op
, Level
, Context
);
1077 if (ACPI_FAILURE (Status
))
1084 /* Visit children first, once */
1091 /* Terminate walk at start op */
1098 /* No more children, visit peers */
1103 NodePreviouslyVisited
= FALSE
;
1107 /* No children or peers, re-visit parent */
1113 Op
= Op
->Asl
.Parent
;
1114 NodePreviouslyVisited
= TRUE
;
1120 case ASL_WALK_VISIT_TWICE
:
1124 if (NodePreviouslyVisited
)
1126 Status
= AscendingCallback (Op
, Level
, Context
);
1127 if (ACPI_FAILURE (Status
))
1134 /* Let the callback process the node. */
1136 Status
= DescendingCallback (Op
, Level
, Context
);
1137 if (ACPI_SUCCESS (Status
))
1139 /* Visit children first, once */
1148 else if (Status
!= AE_CTRL_DEPTH
)
1150 /* Exit immediately on any error */
1156 /* Terminate walk at start op */
1163 /* No more children, visit peers */
1168 NodePreviouslyVisited
= FALSE
;
1172 /* No children or peers, re-visit parent */
1178 Op
= Op
->Asl
.Parent
;
1179 NodePreviouslyVisited
= TRUE
;
1185 /* No other types supported */
1189 /* If we get here, the walk completed with no errors */