FreeBSD/sys/contrib/dev/acpica/compiler/aslopt.c
/*******************************************************************************
 *
 * FUNCTION:    OptOptimizeNameDeclaration
 *
 * PARAMETERS:  Op                  - Current parser op
 *              WalkState           - Current state
 *              CurrentNode         - Where we are in the namespace
 *              AmlNameString       - Unoptimized namepath
 *              NewPath             - Where the optimized path is returned
 *
 * RETURN:      Status. AE_OK If path is optimized
 *
 * DESCRIPTION: Perform a simple optimization of removing an extraneous
 *              backslash prefix if we are already at the root scope.
 *
 ******************************************************************************/


Status. AE_OK If path is optimized

Perform a simple optimization of removing an extraneous
backslash prefix if we are already at the root scope.
Status . AE_OK If path is optimized Perform a simple optimization of removing an extraneous backslash prefix if we are already at the root scope .
static ACPI_STATUS
OptOptimizeNameDeclaration (
    ACPI_PARSE_OBJECT       *Op,
    ACPI_WALK_STATE         *WalkState,
    ACPI_NAMESPACE_NODE     *CurrentNode,
    ACPI_NAMESPACE_NODE     *TargetNode,
    char                    *AmlNameString,
    char                    **NewPath)
{
    ACPI_STATUS             Status;
    char                    *NewPathExternal;
    ACPI_NAMESPACE_NODE     *Node;
    ACPI_FUNCTION_TRACE (OptOptimizeNameDeclaration);
    if (((CurrentNode == AcpiGbl_RootNode) ||
        (Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)) &&
            (ACPI_IS_ROOT_PREFIX (AmlNameString[0])))
    {
        *NewPath = &AmlNameString[1];
        Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, *NewPath,
            NULL, &NewPathExternal);
        if (ACPI_FAILURE (Status))
        {
            AslCoreSubsystemError (Op, Status, "Externalizing NamePath",
                ASL_NO_ABORT);
            return (Status);
        }
        Status = AcpiNsLookup (NULL, *NewPath,
            ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
            ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
        if (ACPI_SUCCESS (Status))
        {
            if (Node == TargetNode)
            {
                AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
                    Op, NewPathExternal);
                ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
                    "AT ROOT:   %-24s", NewPathExternal));
            }
            else
            {
                Status = AE_NOT_FOUND;
                ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
                    " ***** WRONG NODE"));
                AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
                    "Not using optimized name - found wrong node");
            }
        }
        else
        {
            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
                " ***** NOT FOUND"));
            AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
                "Not using optimized name - did not find node");
        }
        ACPI_FREE (NewPathExternal);
        return (Status);
    }
    return (AE_NOT_FOUND);
}
static ACPI_STATUS OptOptimizeNameDeclaration ( ACPI_PARSE_OBJECT * Op , ACPI_WALK_STATE * WalkState , ACPI_NAMESPACE_NODE * CurrentNode , ACPI_NAMESPACE_NODE * TargetNode , char * AmlNameString , char * * NewPath ) { ACPI_STATUS Status ; char * NewPathExternal ; ACPI_NAMESPACE_NODE * Node ; ACPI_FUNCTION_TRACE ( OptOptimizeNameDeclaration ) ; if ( ( ( CurrentNode == AcpiGbl_RootNode ) || ( Op -> Common . Parent -> Asl . ParseOpcode == PARSEOP_DEFINITION_BLOCK ) ) && ( ACPI_IS_ROOT_PREFIX ( AmlNameString [ 0 ] ) ) ) { * NewPath = & AmlNameString [ 1 ] ; Status = AcpiNsExternalizeName ( ACPI_UINT32_MAX , * NewPath , NULL , & NewPathExternal ) ; if ( ACPI_FAILURE ( Status ) ) { AslCoreSubsystemError ( Op , Status , " " , ASL_NO_ABORT ) ; return ( Status ) ; } Status = AcpiNsLookup ( NULL , * NewPath , ACPI_TYPE_ANY , ACPI_IMODE_EXECUTE , ACPI_NS_DONT_OPEN_SCOPE , WalkState , & ( Node ) ) ; if ( ACPI_SUCCESS ( Status ) ) { if ( Node == TargetNode ) { AslError ( ASL_OPTIMIZATION , ASL_MSG_NAME_OPTIMIZATION , Op , NewPathExternal ) ; ACPI_DEBUG_PRINT_RAW ( ( ACPI_DB_OPTIMIZATIONS , " " , NewPathExternal ) ) ; } else { Status = AE_NOT_FOUND ; ACPI_DEBUG_PRINT_RAW ( ( ACPI_DB_OPTIMIZATIONS , " " ) ) ; AslError ( ASL_WARNING , ASL_MSG_COMPILER_INTERNAL , Op , " " ) ; } } else { ACPI_DEBUG_PRINT_RAW ( ( ACPI_DB_OPTIMIZATIONS , " " ) ) ; AslError ( ASL_WARNING , ASL_MSG_COMPILER_INTERNAL , Op , " " ) ; } ACPI_FREE ( NewPathExternal ) ; return ( Status ) ; } return ( AE_NOT_FOUND ) ; }
FUNCTION:    OptOptimizeNameDeclaration
 PARAMETERS:  Op                  - Current parser op
              WalkState           - Current state
              CurrentNode         - Where we are in the namespace
              AmlNameString       - Unoptimized namepath
              NewPath             - Where the optimized path is returned
FUNCTION : OptOptimizeNameDeclaration PARAMETERS : Op - Current parser op WalkState - Current state CurrentNode - Where we are in the namespace AmlNameString - Unoptimized namepath NewPath - Where the optimized path is returned
/*
         * The current scope is the root, and the namepath has a root prefix
         * that is therefore extraneous. Remove it.
         */ /* Debug output */ /*
         * Check to make sure that the optimization finds the node we are
         * looking for. This is simply a sanity check on the new
         * path that has been created.
         *
         * We know that we are at the root, so NULL is used for the scope.
         */ /* Found the namepath, but make sure the node is correct */ /* The lookup matched the node, accept this optimization */ /* Node is not correct, do not use this optimization */ /* The lookup failed, we obviously cannot use this optimization */ /* Could not optimize */