Home | History | Annotate | Line # | Download | only in parser
pswalk.c revision 1.1.1.9
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: pswalk - Parser routines to walk parsed op tree(s)
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.8  christos  * Copyright (C) 2000 - 2018, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11  1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2    jruoho  * are met:
     14  1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2    jruoho  *    without modification.
     17  1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2    jruoho  *    binary redistribution.
     22  1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2    jruoho  *
     26  1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2    jruoho  * Software Foundation.
     29  1.1.1.2    jruoho  *
     30  1.1.1.2    jruoho  * NO WARRANTY
     31  1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #include "acpi.h"
     45      1.1    jruoho #include "accommon.h"
     46      1.1    jruoho #include "acparser.h"
     47      1.1    jruoho 
     48      1.1    jruoho #define _COMPONENT          ACPI_PARSER
     49      1.1    jruoho         ACPI_MODULE_NAME    ("pswalk")
     50      1.1    jruoho 
     51      1.1    jruoho 
     52      1.1    jruoho /*******************************************************************************
     53      1.1    jruoho  *
     54      1.1    jruoho  * FUNCTION:    AcpiPsDeleteParseTree
     55      1.1    jruoho  *
     56      1.1    jruoho  * PARAMETERS:  SubtreeRoot         - Root of tree (or subtree) to delete
     57      1.1    jruoho  *
     58      1.1    jruoho  * RETURN:      None
     59      1.1    jruoho  *
     60      1.1    jruoho  * DESCRIPTION: Delete a portion of or an entire parse tree.
     61      1.1    jruoho  *
     62      1.1    jruoho  ******************************************************************************/
     63      1.1    jruoho 
     64  1.1.1.9  christos #include "amlcode.h"
     65  1.1.1.9  christos 
     66      1.1    jruoho void
     67      1.1    jruoho AcpiPsDeleteParseTree (
     68      1.1    jruoho     ACPI_PARSE_OBJECT       *SubtreeRoot)
     69      1.1    jruoho {
     70      1.1    jruoho     ACPI_PARSE_OBJECT       *Op = SubtreeRoot;
     71      1.1    jruoho     ACPI_PARSE_OBJECT       *Next = NULL;
     72      1.1    jruoho     ACPI_PARSE_OBJECT       *Parent = NULL;
     73  1.1.1.9  christos     UINT32                  Level = 0;
     74      1.1    jruoho 
     75      1.1    jruoho 
     76      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (PsDeleteParseTree, SubtreeRoot);
     77      1.1    jruoho 
     78  1.1.1.9  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE_TREES,
     79  1.1.1.9  christos         " root %p\n", SubtreeRoot));
     80      1.1    jruoho 
     81      1.1    jruoho     /* Visit all nodes in the subtree */
     82      1.1    jruoho 
     83      1.1    jruoho     while (Op)
     84      1.1    jruoho     {
     85      1.1    jruoho         if (Op != Parent)
     86      1.1    jruoho         {
     87  1.1.1.9  christos             /* This is the descending case */
     88  1.1.1.9  christos 
     89  1.1.1.9  christos             if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_PARSE_TREES, _COMPONENT))
     90  1.1.1.9  christos             {
     91  1.1.1.9  christos                 /* This debug option will print the entire parse tree */
     92  1.1.1.9  christos 
     93  1.1.1.9  christos                 AcpiOsPrintf ("        %*.s%s %p", (Level * 4), " ",
     94  1.1.1.9  christos                     AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Op);
     95  1.1.1.9  christos 
     96  1.1.1.9  christos                 if (Op->Named.AmlOpcode == AML_INT_NAMEPATH_OP)
     97  1.1.1.9  christos                 {
     98  1.1.1.9  christos                     AcpiOsPrintf ("    %4.4s", Op->Common.Value.String);
     99  1.1.1.9  christos                 }
    100  1.1.1.9  christos                 if (Op->Named.AmlOpcode == AML_STRING_OP)
    101  1.1.1.9  christos                 {
    102  1.1.1.9  christos                     AcpiOsPrintf ("    %s", Op->Common.Value.String);
    103  1.1.1.9  christos                 }
    104  1.1.1.9  christos                 AcpiOsPrintf ("\n");
    105  1.1.1.9  christos             }
    106  1.1.1.9  christos 
    107      1.1    jruoho             /* Look for an argument or child of the current op */
    108      1.1    jruoho 
    109      1.1    jruoho             Next = AcpiPsGetArg (Op, 0);
    110      1.1    jruoho             if (Next)
    111      1.1    jruoho             {
    112      1.1    jruoho                 /* Still going downward in tree (Op is not completed yet) */
    113      1.1    jruoho 
    114      1.1    jruoho                 Op = Next;
    115  1.1.1.9  christos                 Level++;
    116      1.1    jruoho                 continue;
    117      1.1    jruoho             }
    118      1.1    jruoho         }
    119      1.1    jruoho 
    120      1.1    jruoho         /* No more children, this Op is complete. */
    121      1.1    jruoho 
    122      1.1    jruoho         Next = Op->Common.Next;
    123      1.1    jruoho         Parent = Op->Common.Parent;
    124      1.1    jruoho 
    125      1.1    jruoho         AcpiPsFreeOp (Op);
    126      1.1    jruoho 
    127      1.1    jruoho         /* If we are back to the starting point, the walk is complete. */
    128      1.1    jruoho 
    129      1.1    jruoho         if (Op == SubtreeRoot)
    130      1.1    jruoho         {
    131      1.1    jruoho             return_VOID;
    132      1.1    jruoho         }
    133  1.1.1.6  christos 
    134      1.1    jruoho         if (Next)
    135      1.1    jruoho         {
    136      1.1    jruoho             Op = Next;
    137      1.1    jruoho         }
    138      1.1    jruoho         else
    139      1.1    jruoho         {
    140  1.1.1.9  christos             Level--;
    141      1.1    jruoho             Op = Parent;
    142      1.1    jruoho         }
    143      1.1    jruoho     }
    144      1.1    jruoho 
    145      1.1    jruoho     return_VOID;
    146      1.1    jruoho }
    147