FreeBSD/sys/contrib/dev/acpica/compiler/asltree.c
/*******************************************************************************
 *
 * FUNCTION:    TrWalkParseTree
 *
 * PARAMETERS:  Visitation              - Type of walk
 *              DescendingCallback      - Called during tree descent
 *              AscendingCallback       - Called during tree ascent
 *              Context                 - To be passed to the callbacks
 *
 * RETURN:      Status from callback(s)
 *
 * DESCRIPTION: Walk the entire parse tree.
 *
 ******************************************************************************/
TrWalkParseTree
PARAMETERS:  Visitation              - Type of walk
DescendingCallback      - Called during tree descent
AscendingCallback       - Called during tree ascent
Context                 - To be passed to the callbacks



Walk the entire parse tree.
TrWalkParseTree PARAMETERS : Visitation - Type of walk DescendingCallback - Called during tree descent AscendingCallback - Called during tree ascent Context - To be passed to the callbacks Walk the entire parse tree .
ACPI_STATUS
TrWalkParseTree (
    ACPI_PARSE_OBJECT       *Op,
    UINT32                  Visitation,
    ASL_WALK_CALLBACK       DescendingCallback,
    ASL_WALK_CALLBACK       AscendingCallback,
    void                    *Context)
{
    UINT32                  Level;
    BOOLEAN                 NodePreviouslyVisited;
    ACPI_PARSE_OBJECT       *StartOp = Op;
    ACPI_STATUS             Status;
    if (!Gbl_ParseTreeRoot)
    {
        return (AE_OK);
    }
    Level = 0;
    NodePreviouslyVisited = FALSE;
    switch (Visitation)
    {
    case ASL_WALK_VISIT_DOWNWARD:
        while (Op)
        {
            if (!NodePreviouslyVisited)
            {
                Status = DescendingCallback (Op, Level, Context);
                if (ACPI_SUCCESS (Status))
                {
                    if (Op->Asl.Child)
                    {
                        Level++;
                        Op = Op->Asl.Child;
                        continue;
                    }
                }
                else if (Status != AE_CTRL_DEPTH)
                {
                    return (Status);
                }
            }
            if (Op == StartOp)
            {
                break;
            }
            if (Op->Asl.Next)
            {
                Op = Op->Asl.Next;
                NodePreviouslyVisited = FALSE;
            }
            else
            {
                if (Level != 0 )
                {
                    Level--;
                }
                Op = Op->Asl.Parent;
                NodePreviouslyVisited = TRUE;
            }
        }
        break;
    case ASL_WALK_VISIT_UPWARD:
        while (Op)
        {
            if ((!Op->Asl.Child) ||
                (NodePreviouslyVisited))
            {
                Status = AscendingCallback (Op, Level, Context);
                if (ACPI_FAILURE (Status))
                {
                    return (Status);
                }
            }
            else
            {
                Level++;
                Op = Op->Asl.Child;
                continue;
            }
            if (Op == StartOp)
            {
                break;
            }
            if (Op->Asl.Next)
            {
                Op = Op->Asl.Next;
                NodePreviouslyVisited = FALSE;
            }
            else
            {
                if (Level != 0 )
                {
                    Level--;
                }
                Op = Op->Asl.Parent;
                NodePreviouslyVisited = TRUE;
            }
        }
        break;
     case ASL_WALK_VISIT_TWICE:
        while (Op)
        {
            if (NodePreviouslyVisited)
            {
                Status = AscendingCallback (Op, Level, Context);
                if (ACPI_FAILURE (Status))
                {
                    return (Status);
                }
            }
            else
            {
                Status = DescendingCallback (Op, Level, Context);
                if (ACPI_SUCCESS (Status))
                {
                    if (Op->Asl.Child)
                    {
                        Level++;
                        Op = Op->Asl.Child;
                        continue;
                    }
                }
                else if (Status != AE_CTRL_DEPTH)
                {
                    return (Status);
                }
            }
            if (Op == StartOp)
            {
                break;
            }
            if (Op->Asl.Next)
            {
                Op = Op->Asl.Next;
                NodePreviouslyVisited = FALSE;
            }
            else
            {
                if (Level != 0 )
                {
                    Level--;
                }
                Op = Op->Asl.Parent;
                NodePreviouslyVisited = TRUE;
            }
        }
        break;
    default:
        break;
    }
    return (AE_OK);
}
ACPI_STATUS TrWalkParseTree ( ACPI_PARSE_OBJECT * Op , UINT32 Visitation , ASL_WALK_CALLBACK DescendingCallback , ASL_WALK_CALLBACK AscendingCallback , void * Context ) { UINT32 Level ; BOOLEAN NodePreviouslyVisited ; ACPI_PARSE_OBJECT * StartOp = Op ; ACPI_STATUS Status ; if ( ! Gbl_ParseTreeRoot ) { return ( AE_OK ) ; } Level = 0 ; NodePreviouslyVisited = FALSE ; switch ( Visitation ) { case ASL_WALK_VISIT_DOWNWARD : while ( Op ) { if ( ! NodePreviouslyVisited ) { Status = DescendingCallback ( Op , Level , Context ) ; if ( ACPI_SUCCESS ( Status ) ) { if ( Op -> Asl . Child ) { Level ++ ; Op = Op -> Asl . Child ; continue ; } } else if ( Status != AE_CTRL_DEPTH ) { return ( Status ) ; } } if ( Op == StartOp ) { break ; } if ( Op -> Asl . Next ) { Op = Op -> Asl . Next ; NodePreviouslyVisited = FALSE ; } else { if ( Level != 0 ) { Level -- ; } Op = Op -> Asl . Parent ; NodePreviouslyVisited = TRUE ; } } break ; case ASL_WALK_VISIT_UPWARD : while ( Op ) { if ( ( ! Op -> Asl . Child ) || ( NodePreviouslyVisited ) ) { Status = AscendingCallback ( Op , Level , Context ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } } else { Level ++ ; Op = Op -> Asl . Child ; continue ; } if ( Op == StartOp ) { break ; } if ( Op -> Asl . Next ) { Op = Op -> Asl . Next ; NodePreviouslyVisited = FALSE ; } else { if ( Level != 0 ) { Level -- ; } Op = Op -> Asl . Parent ; NodePreviouslyVisited = TRUE ; } } break ; case ASL_WALK_VISIT_TWICE : while ( Op ) { if ( NodePreviouslyVisited ) { Status = AscendingCallback ( Op , Level , Context ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } } else { Status = DescendingCallback ( Op , Level , Context ) ; if ( ACPI_SUCCESS ( Status ) ) { if ( Op -> Asl . Child ) { Level ++ ; Op = Op -> Asl . Child ; continue ; } } else if ( Status != AE_CTRL_DEPTH ) { return ( Status ) ; } } if ( Op == StartOp ) { break ; } if ( Op -> Asl . Next ) { Op = Op -> Asl . Next ; NodePreviouslyVisited = FALSE ; } else { if ( Level != 0 ) { Level -- ; } Op = Op -> Asl . Parent ; NodePreviouslyVisited = TRUE ; } } break ; default : break ; } return ( AE_OK ) ; }
FUNCTION:    TrWalkParseTree
 PARAMETERS:  Visitation              - Type of walk
              DescendingCallback      - Called during tree descent
              AscendingCallback       - Called during tree ascent
              Context                 - To be passed to the callbacks
FUNCTION : TrWalkParseTree PARAMETERS : Visitation - Type of walk DescendingCallback - Called during tree descent AscendingCallback - Called during tree ascent Context - To be passed to the callbacks
/* Let the callback process the node. */ /* Visit children first, once */ /* Exit immediately on any error */ /* Terminate walk at start op */ /* No more children, visit peers */ /* No children or peers, re-visit parent */ /* Visit leaf node (no children) or parent node on return trip */ /* Let the callback process the node. */ /* Visit children first, once */ /* Terminate walk at start op */ /* No more children, visit peers */ /* No children or peers, re-visit parent */ /* Let the callback process the node. */ /* Visit children first, once */ /* Exit immediately on any error */ /* Terminate walk at start op */ /* No more children, visit peers */ /* No children or peers, re-visit parent */ /* No other types supported */ /* If we get here, the walk completed with no errors */