1 /******************************************************************************
3 * Module Name: asltree - parse tree management
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
45 #include "aslcompiler.h"
46 #include "aslcompiler.y.h"
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("asltree")
53 /* Local prototypes */
55 static ACPI_PARSE_OBJECT
*
64 /*******************************************************************************
66 * FUNCTION: TrGetNextNode
70 * RETURN: New parse node. Aborts on allocation failure
72 * DESCRIPTION: Allocate a new parse node for the parse tree. Bypass the local
73 * dynamic memory manager for performance reasons (This has a
74 * major impact on the speed of the compiler.)
76 ******************************************************************************/
78 static ACPI_PARSE_OBJECT
*
83 if (Gbl_NodeCacheNext
>= Gbl_NodeCacheLast
)
85 Gbl_NodeCacheNext
= UtLocalCalloc (sizeof (ACPI_PARSE_OBJECT
) *
87 Gbl_NodeCacheLast
= Gbl_NodeCacheNext
+ ASL_NODE_CACHE_SIZE
;
90 return (Gbl_NodeCacheNext
++);
94 /*******************************************************************************
96 * FUNCTION: TrAllocateNode
98 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
100 * RETURN: New parse node. Aborts on allocation failure
102 * DESCRIPTION: Allocate and initialize a new parse node for the parse tree
104 ******************************************************************************/
110 ACPI_PARSE_OBJECT
*Op
;
113 Op
= TrGetNextNode ();
115 Op
->Asl
.ParseOpcode
= (UINT16
) ParseOpcode
;
116 Op
->Asl
.Filename
= Gbl_Files
[ASL_FILE_INPUT
].Filename
;
117 Op
->Asl
.LineNumber
= Gbl_CurrentLineNumber
;
118 Op
->Asl
.LogicalLineNumber
= Gbl_LogicalLineNumber
;
119 Op
->Asl
.LogicalByteOffset
= Gbl_CurrentLineOffset
;
120 Op
->Asl
.Column
= Gbl_CurrentColumn
;
122 UtSetParseOpName (Op
);
127 /*******************************************************************************
129 * FUNCTION: TrReleaseNode
131 * PARAMETERS: Op - Op to be released
135 * DESCRIPTION: "release" a node. In truth, nothing is done since the node
136 * is part of a larger buffer
138 ******************************************************************************/
142 ACPI_PARSE_OBJECT
*Op
)
149 /*******************************************************************************
151 * FUNCTION: TrUpdateNode
153 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
154 * Op - An existing parse node
156 * RETURN: The updated node
158 * DESCRIPTION: Change the parse opcode assigned to a node. Usually used to
159 * change an opcode to DEFAULT_ARG so that the node is ignored
160 * during the code generation. Also used to set generic integers
161 * to a specific size (8, 16, 32, or 64 bits)
163 ******************************************************************************/
168 ACPI_PARSE_OBJECT
*Op
)
176 DbgPrint (ASL_PARSE_OUTPUT
,
177 "\nUpdateNode: Old - %s, New - %s\n\n",
178 UtGetOpName (Op
->Asl
.ParseOpcode
),
179 UtGetOpName (ParseOpcode
));
181 /* Assign new opcode and name */
183 if (Op
->Asl
.ParseOpcode
== PARSEOP_ONES
)
187 case PARSEOP_BYTECONST
:
189 Op
->Asl
.Value
.Integer
= ACPI_UINT8_MAX
;
192 case PARSEOP_WORDCONST
:
194 Op
->Asl
.Value
.Integer
= ACPI_UINT16_MAX
;
197 case PARSEOP_DWORDCONST
:
199 Op
->Asl
.Value
.Integer
= ACPI_UINT32_MAX
;
202 /* Don't need to do the QWORD case */
206 /* Don't care about others */
211 Op
->Asl
.ParseOpcode
= (UINT16
) ParseOpcode
;
212 UtSetParseOpName (Op
);
215 * For the BYTE, WORD, and DWORD constants, make sure that the integer
216 * that was passed in will actually fit into the data type
220 case PARSEOP_BYTECONST
:
222 UtCheckIntegerRange (Op
, 0x00, ACPI_UINT8_MAX
);
223 Op
->Asl
.Value
.Integer
&= ACPI_UINT8_MAX
;
226 case PARSEOP_WORDCONST
:
228 UtCheckIntegerRange (Op
, 0x00, ACPI_UINT16_MAX
);
229 Op
->Asl
.Value
.Integer
&= ACPI_UINT16_MAX
;
232 case PARSEOP_DWORDCONST
:
234 UtCheckIntegerRange (Op
, 0x00, ACPI_UINT32_MAX
);
235 Op
->Asl
.Value
.Integer
&= ACPI_UINT32_MAX
;
240 /* Don't care about others, don't need to check QWORD */
249 /*******************************************************************************
251 * FUNCTION: TrGetNodeFlagName
253 * PARAMETERS: Flags - Flags word to be decoded
255 * RETURN: Name string. Always returns a valid string pointer.
257 * DESCRIPTION: Decode a flags word
259 ******************************************************************************/
270 return ("NODE_VISITED");
272 case NODE_AML_PACKAGE
:
274 return ("NODE_AML_PACKAGE");
278 return ("NODE_IS_TARGET");
280 case NODE_IS_RESOURCE_DESC
:
282 return ("NODE_IS_RESOURCE_DESC");
284 case NODE_IS_RESOURCE_FIELD
:
286 return ("NODE_IS_RESOURCE_FIELD");
288 case NODE_HAS_NO_EXIT
:
290 return ("NODE_HAS_NO_EXIT");
292 case NODE_IF_HAS_NO_EXIT
:
294 return ("NODE_IF_HAS_NO_EXIT");
296 case NODE_NAME_INTERNALIZED
:
298 return ("NODE_NAME_INTERNALIZED");
300 case NODE_METHOD_NO_RETVAL
:
302 return ("NODE_METHOD_NO_RETVAL");
304 case NODE_METHOD_SOME_NO_RETVAL
:
306 return ("NODE_METHOD_SOME_NO_RETVAL");
308 case NODE_RESULT_NOT_USED
:
310 return ("NODE_RESULT_NOT_USED");
312 case NODE_METHOD_TYPED
:
314 return ("NODE_METHOD_TYPED");
316 case NODE_COMPILE_TIME_CONST
:
318 return ("NODE_COMPILE_TIME_CONST");
320 case NODE_IS_TERM_ARG
:
322 return ("NODE_IS_TERM_ARG");
324 case NODE_WAS_ONES_OP
:
326 return ("NODE_WAS_ONES_OP");
328 case NODE_IS_NAME_DECLARATION
:
330 return ("NODE_IS_NAME_DECLARATION");
334 return ("Multiple Flags (or unknown flag) set");
339 /*******************************************************************************
341 * FUNCTION: TrSetNodeFlags
343 * PARAMETERS: Op - An existing parse node
344 * Flags - New flags word
346 * RETURN: The updated parser op
348 * DESCRIPTION: Set bits in the node flags word. Will not clear bits, only set
350 ******************************************************************************/
354 ACPI_PARSE_OBJECT
*Op
,
358 DbgPrint (ASL_PARSE_OUTPUT
,
359 "\nSetNodeFlags: Op %p, %8.8X %s\n\n", Op
, Flags
,
360 TrGetNodeFlagName (Flags
));
367 Op
->Asl
.CompileFlags
|= Flags
;
372 /*******************************************************************************
374 * FUNCTION: TrSetNodeAmlLength
376 * PARAMETERS: Op - An existing parse node
377 * Length - AML Length
379 * RETURN: The updated parser op
381 * DESCRIPTION: Set the AML Length in a node. Used by the parser to indicate
382 * the presence of a node that must be reduced to a fixed length
385 ******************************************************************************/
389 ACPI_PARSE_OBJECT
*Op
,
393 DbgPrint (ASL_PARSE_OUTPUT
,
394 "\nSetNodeAmlLength: Op %p, %8.8X\n", Op
, Length
);
401 Op
->Asl
.AmlLength
= Length
;
406 /*******************************************************************************
408 * FUNCTION: TrSetEndLineNumber
410 * PARAMETERS: Op - An existing parse node
414 * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
415 * parse node to the current line numbers.
417 ******************************************************************************/
421 ACPI_PARSE_OBJECT
*Op
)
424 /* If the end line # is already set, just return */
431 Op
->Asl
.EndLine
= Gbl_CurrentLineNumber
;
432 Op
->Asl
.EndLogicalLine
= Gbl_LogicalLineNumber
;
436 /*******************************************************************************
438 * FUNCTION: TrCreateLeafNode
440 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
442 * RETURN: Pointer to the new node. Aborts on allocation failure
444 * DESCRIPTION: Create a simple leaf node (no children or peers, and no value
445 * assigned to the node)
447 ******************************************************************************/
453 ACPI_PARSE_OBJECT
*Op
;
456 Op
= TrAllocateNode (ParseOpcode
);
458 DbgPrint (ASL_PARSE_OUTPUT
,
459 "\nCreateLeafNode Ln/Col %u/%u NewNode %p Op %s\n\n",
460 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, UtGetOpName(ParseOpcode
));
466 /*******************************************************************************
468 * FUNCTION: TrCreateConstantLeafNode
470 * PARAMETERS: ParseOpcode - The constant opcode
472 * RETURN: Pointer to the new node. Aborts on allocation failure
474 * DESCRIPTION: Create a leaf node (no children or peers) for one of the
475 * special constants - __LINE__, __FILE__, and __DATE__.
477 * Note: An implemenation of __FUNC__ cannot happen here because we don't
478 * have a full parse tree at this time and cannot find the parent control
479 * method. If it is ever needed, __FUNC__ must be implemented later, after
480 * the parse tree has been fully constructed.
482 ******************************************************************************/
485 TrCreateConstantLeafNode (
488 ACPI_PARSE_OBJECT
*Op
= NULL
;
490 char *StaticTimeString
;
498 case PARSEOP___LINE__
:
500 Op
= TrAllocateNode (PARSEOP_INTEGER
);
501 Op
->Asl
.Value
.Integer
= Op
->Asl
.LineNumber
;
504 case PARSEOP___PATH__
:
506 Op
= TrAllocateNode (PARSEOP_STRING_LITERAL
);
508 /* Op.Asl.Filename contains the full pathname to the file */
510 Op
->Asl
.Value
.String
= Op
->Asl
.Filename
;
513 case PARSEOP___FILE__
:
515 Op
= TrAllocateNode (PARSEOP_STRING_LITERAL
);
517 /* Get the simple filename from the full path */
519 FlSplitInputPathname (Op
->Asl
.Filename
, &Path
, &Filename
);
521 Op
->Asl
.Value
.String
= Filename
;
524 case PARSEOP___DATE__
:
526 Op
= TrAllocateNode (PARSEOP_STRING_LITERAL
);
528 /* Get a copy of the current time */
530 CurrentTime
= time (NULL
);
531 StaticTimeString
= ctime (&CurrentTime
);
532 TimeString
= UtLocalCalloc (strlen (StaticTimeString
) + 1);
533 strcpy (TimeString
, StaticTimeString
);
535 TimeString
[strlen(TimeString
) -1] = 0; /* Remove trailing newline */
536 Op
->Asl
.Value
.String
= TimeString
;
539 default: /* This would be an internal error */
544 DbgPrint (ASL_PARSE_OUTPUT
,
545 "\nCreateConstantLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
546 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, UtGetOpName (ParseOpcode
),
547 ACPI_FORMAT_UINT64 (Op
->Asl
.Value
.Integer
));
552 /*******************************************************************************
554 * FUNCTION: TrCreateValuedLeafNode
556 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
557 * Value - Value to be assigned to the node
559 * RETURN: Pointer to the new node. Aborts on allocation failure
561 * DESCRIPTION: Create a leaf node (no children or peers) with a value
564 ******************************************************************************/
567 TrCreateValuedLeafNode (
571 ACPI_PARSE_OBJECT
*Op
;
574 Op
= TrAllocateNode (ParseOpcode
);
576 DbgPrint (ASL_PARSE_OUTPUT
,
577 "\nCreateValuedLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
578 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, UtGetOpName(ParseOpcode
),
579 ACPI_FORMAT_UINT64 (Value
));
580 Op
->Asl
.Value
.Integer
= Value
;
584 case PARSEOP_STRING_LITERAL
:
586 DbgPrint (ASL_PARSE_OUTPUT
, "STRING->%s", Value
);
589 case PARSEOP_NAMESEG
:
591 DbgPrint (ASL_PARSE_OUTPUT
, "NAMESEG->%s", Value
);
594 case PARSEOP_NAMESTRING
:
596 DbgPrint (ASL_PARSE_OUTPUT
, "NAMESTRING->%s", Value
);
601 DbgPrint (ASL_PARSE_OUTPUT
, "EISAID->%s", Value
);
606 DbgPrint (ASL_PARSE_OUTPUT
, "METHOD");
609 case PARSEOP_INTEGER
:
611 DbgPrint (ASL_PARSE_OUTPUT
, "INTEGER");
619 DbgPrint (ASL_PARSE_OUTPUT
, "\n\n");
624 /*******************************************************************************
626 * FUNCTION: TrCreateNode
628 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
629 * NumChildren - Number of children to follow
630 * ... - A list of child nodes to link to the new
631 * node. NumChildren long.
633 * RETURN: Pointer to the new node. Aborts on allocation failure
635 * DESCRIPTION: Create a new parse node and link together a list of child
636 * nodes underneath the new node.
638 ******************************************************************************/
646 ACPI_PARSE_OBJECT
*Op
;
647 ACPI_PARSE_OBJECT
*Child
;
648 ACPI_PARSE_OBJECT
*PrevChild
;
654 va_start (ap
, NumChildren
);
656 /* Allocate one new node */
658 Op
= TrAllocateNode (ParseOpcode
);
660 DbgPrint (ASL_PARSE_OUTPUT
,
661 "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ",
662 Op
->Asl
.LineNumber
, Op
->Asl
.Column
, Op
, NumChildren
, UtGetOpName(ParseOpcode
));
664 /* Some extra debug output based on the parse opcode */
668 case PARSEOP_DEFINITIONBLOCK
:
671 DbgPrint (ASL_PARSE_OUTPUT
, "DEFINITION_BLOCK (Tree Completed)->");
674 case PARSEOP_OPERATIONREGION
:
676 DbgPrint (ASL_PARSE_OUTPUT
, "OPREGION->");
681 DbgPrint (ASL_PARSE_OUTPUT
, "OR->");
686 /* Nothing to do for other opcodes */
691 /* Link the new node to its children */
695 for (i
= 0; i
< NumChildren
; i
++)
697 /* Get the next child */
699 Child
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
700 DbgPrint (ASL_PARSE_OUTPUT
, "%p, ", Child
);
703 * If child is NULL, this means that an optional argument
704 * was omitted. We must create a placeholder with a special
705 * opcode (DEFAULT_ARG) so that the code generator will know
706 * that it must emit the correct default for this argument
710 Child
= TrAllocateNode (PARSEOP_DEFAULT_ARG
);
713 /* Link first child to parent */
718 Op
->Asl
.Child
= Child
;
721 /* Point all children to parent */
723 Child
->Asl
.Parent
= Op
;
725 /* Link children in a peer list */
729 PrevChild
->Asl
.Next
= Child
;
733 * This child might be a list, point all nodes in the list
736 while (Child
->Asl
.Next
)
738 Child
= Child
->Asl
.Next
;
739 Child
->Asl
.Parent
= Op
;
746 DbgPrint (ASL_PARSE_OUTPUT
, "\n\n");
751 /*******************************************************************************
753 * FUNCTION: TrLinkChildren
755 * PARAMETERS: Op - An existing parse node
756 * NumChildren - Number of children to follow
757 * ... - A list of child nodes to link to the new
758 * node. NumChildren long.
760 * RETURN: The updated (linked) node
762 * DESCRIPTION: Link a group of nodes to an existing parse node
764 ******************************************************************************/
768 ACPI_PARSE_OBJECT
*Op
,
772 ACPI_PARSE_OBJECT
*Child
;
773 ACPI_PARSE_OBJECT
*PrevChild
;
779 va_start (ap
, NumChildren
);
782 TrSetEndLineNumber (Op
);
784 DbgPrint (ASL_PARSE_OUTPUT
,
785 "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ",
786 Op
->Asl
.LineNumber
, Op
->Asl
.EndLine
,
787 Op
, NumChildren
, UtGetOpName(Op
->Asl
.ParseOpcode
));
789 switch (Op
->Asl
.ParseOpcode
)
791 case PARSEOP_DEFINITIONBLOCK
:
794 DbgPrint (ASL_PARSE_OUTPUT
, "DEFINITION_BLOCK (Tree Completed)->");
797 case PARSEOP_OPERATIONREGION
:
799 DbgPrint (ASL_PARSE_OUTPUT
, "OPREGION->");
804 DbgPrint (ASL_PARSE_OUTPUT
, "OR->");
809 /* Nothing to do for other opcodes */
814 /* Link the new node to it's children */
818 for (i
= 0; i
< NumChildren
; i
++)
820 Child
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
822 if ((Child
== PrevChild
) && (Child
!= NULL
))
824 AslError (ASL_WARNING
, ASL_MSG_COMPILER_INTERNAL
, Child
,
825 "Child node list invalid");
830 DbgPrint (ASL_PARSE_OUTPUT
, "%p, ", Child
);
833 * If child is NULL, this means that an optional argument
834 * was omitted. We must create a placeholder with a special
835 * opcode (DEFAULT_ARG) so that the code generator will know
836 * that it must emit the correct default for this argument
840 Child
= TrAllocateNode (PARSEOP_DEFAULT_ARG
);
843 /* Link first child to parent */
848 Op
->Asl
.Child
= Child
;
851 /* Point all children to parent */
853 Child
->Asl
.Parent
= Op
;
855 /* Link children in a peer list */
859 PrevChild
->Asl
.Next
= Child
;
863 * This child might be a list, point all nodes in the list
866 while (Child
->Asl
.Next
)
868 Child
= Child
->Asl
.Next
;
869 Child
->Asl
.Parent
= Op
;
875 DbgPrint (ASL_PARSE_OUTPUT
, "\n\n");
880 /*******************************************************************************
882 * FUNCTION: TrLinkPeerNode
884 * PARAMETERS: Op1 - First peer
887 * RETURN: Op1 or the non-null node.
889 * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null.
891 ******************************************************************************/
895 ACPI_PARSE_OBJECT
*Op1
,
896 ACPI_PARSE_OBJECT
*Op2
)
898 ACPI_PARSE_OBJECT
*Next
;
901 DbgPrint (ASL_PARSE_OUTPUT
,
902 "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n\n",
903 Op1
, Op1
? UtGetOpName(Op1
->Asl
.ParseOpcode
) : NULL
,
904 Op2
, Op2
? UtGetOpName(Op2
->Asl
.ParseOpcode
) : NULL
);
907 if ((!Op1
) && (!Op2
))
909 DbgPrint (ASL_PARSE_OUTPUT
, "\nTwo Null nodes!\n");
913 /* If one of the nodes is null, just return the non-null node */
927 DbgPrint (ASL_DEBUG_OUTPUT
,
928 "\n\n************* Internal error, linking node to itself %p\n\n\n",
930 AslError (ASL_WARNING
, ASL_MSG_COMPILER_INTERNAL
, Op1
,
931 "Linking node to itself");
935 Op1
->Asl
.Parent
= Op2
->Asl
.Parent
;
938 * Op 1 may already have a peer list (such as an IF/ELSE pair),
939 * so we must walk to the end of the list and attach the new
943 while (Next
->Asl
.Next
)
945 Next
= Next
->Asl
.Next
;
948 Next
->Asl
.Next
= Op2
;
953 /*******************************************************************************
955 * FUNCTION: TrLinkPeerNodes
957 * PARAMETERS: NumPeers - The number of nodes in the list to follow
958 * ... - A list of nodes to link together as peers
960 * RETURN: The first node in the list (head of the peer list)
962 * DESCRIPTION: Link together an arbitrary number of peer nodes.
964 ******************************************************************************/
971 ACPI_PARSE_OBJECT
*This
;
972 ACPI_PARSE_OBJECT
*Next
;
975 ACPI_PARSE_OBJECT
*Start
;
978 DbgPrint (ASL_PARSE_OUTPUT
,
979 "\nLinkPeerNodes: (%u) ", NumPeers
);
981 va_start (ap
, NumPeers
);
982 This
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
988 for (i
= 0; i
< (NumPeers
-1); i
++)
990 DbgPrint (ASL_PARSE_OUTPUT
, "%u=%p ", (i
+1), This
);
992 while (This
->Asl
.Next
)
994 This
= This
->Asl
.Next
;
997 /* Get another peer node */
999 Next
= va_arg (ap
, ACPI_PARSE_OBJECT
*);
1002 Next
= TrAllocateNode (PARSEOP_DEFAULT_ARG
);
1005 /* link new node to the current node */
1007 This
->Asl
.Next
= Next
;
1012 DbgPrint (ASL_PARSE_OUTPUT
,"\n\n");
1017 /*******************************************************************************
1019 * FUNCTION: TrLinkChildNode
1021 * PARAMETERS: Op1 - Parent node
1022 * Op2 - Op to become a child
1024 * RETURN: The parent node
1026 * DESCRIPTION: Link two nodes together as a parent and child
1028 ******************************************************************************/
1032 ACPI_PARSE_OBJECT
*Op1
,
1033 ACPI_PARSE_OBJECT
*Op2
)
1035 ACPI_PARSE_OBJECT
*Next
;
1038 DbgPrint (ASL_PARSE_OUTPUT
,
1039 "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n\n",
1040 Op1
, Op1
? UtGetOpName(Op1
->Asl
.ParseOpcode
): NULL
,
1041 Op2
, Op2
? UtGetOpName(Op2
->Asl
.ParseOpcode
): NULL
);
1048 Op1
->Asl
.Child
= Op2
;
1050 /* Set the child and all peers of the child to point to the parent */
1055 Next
->Asl
.Parent
= Op1
;
1056 Next
= Next
->Asl
.Next
;
1063 /*******************************************************************************
1065 * FUNCTION: TrWalkParseTree
1067 * PARAMETERS: Visitation - Type of walk
1068 * DescendingCallback - Called during tree descent
1069 * AscendingCallback - Called during tree ascent
1070 * Context - To be passed to the callbacks
1072 * RETURN: Status from callback(s)
1074 * DESCRIPTION: Walk the entire parse tree.
1076 ******************************************************************************/
1080 ACPI_PARSE_OBJECT
*Op
,
1082 ASL_WALK_CALLBACK DescendingCallback
,
1083 ASL_WALK_CALLBACK AscendingCallback
,
1087 BOOLEAN NodePreviouslyVisited
;
1088 ACPI_PARSE_OBJECT
*StartOp
= Op
;
1098 NodePreviouslyVisited
= FALSE
;
1102 case ASL_WALK_VISIT_DOWNWARD
:
1106 if (!NodePreviouslyVisited
)
1108 /* Let the callback process the node. */
1110 Status
= DescendingCallback (Op
, Level
, Context
);
1111 if (ACPI_SUCCESS (Status
))
1113 /* Visit children first, once */
1122 else if (Status
!= AE_CTRL_DEPTH
)
1124 /* Exit immediately on any error */
1130 /* Terminate walk at start op */
1137 /* No more children, visit peers */
1142 NodePreviouslyVisited
= FALSE
;
1146 /* No children or peers, re-visit parent */
1152 Op
= Op
->Asl
.Parent
;
1153 NodePreviouslyVisited
= TRUE
;
1158 case ASL_WALK_VISIT_UPWARD
:
1162 /* Visit leaf node (no children) or parent node on return trip */
1164 if ((!Op
->Asl
.Child
) ||
1165 (NodePreviouslyVisited
))
1167 /* Let the callback process the node. */
1169 Status
= AscendingCallback (Op
, Level
, Context
);
1170 if (ACPI_FAILURE (Status
))
1177 /* Visit children first, once */
1184 /* Terminate walk at start op */
1191 /* No more children, visit peers */
1196 NodePreviouslyVisited
= FALSE
;
1200 /* No children or peers, re-visit parent */
1206 Op
= Op
->Asl
.Parent
;
1207 NodePreviouslyVisited
= TRUE
;
1212 case ASL_WALK_VISIT_TWICE
:
1216 if (NodePreviouslyVisited
)
1218 Status
= AscendingCallback (Op
, Level
, Context
);
1219 if (ACPI_FAILURE (Status
))
1226 /* Let the callback process the node. */
1228 Status
= DescendingCallback (Op
, Level
, Context
);
1229 if (ACPI_SUCCESS (Status
))
1231 /* Visit children first, once */
1240 else if (Status
!= AE_CTRL_DEPTH
)
1242 /* Exit immediately on any error */
1248 /* Terminate walk at start op */
1255 /* No more children, visit peers */
1260 NodePreviouslyVisited
= FALSE
;
1264 /* No children or peers, re-visit parent */
1270 Op
= Op
->Asl
.Parent
;
1271 NodePreviouslyVisited
= TRUE
;
1277 /* No other types supported */
1281 /* If we get here, the walk completed with no errors */