o
    Y۷i                     @  s   d Z ddlmZ ddlmZ er"ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ G d
d deZedG dd deZedG dd deZdS )zAccess path classes.    )annotations)TYPE_CHECKING)Sequence)Object)Any)IntEnum   )register_objectc                   @  s(   e Zd ZdZdZdZdZdZdZdZ	dS )	
AccessKindz(Kinds of access steps in an access path.r   r               N)
__name__
__module____qualname____doc__ATTR
ARRAY_ITEMMAP_ITEMATTR_MISSINGARRAY_ITEM_MISSINGMAP_ITEM_MISSING r   r   I/home/ubuntu/vllm_env/lib/python3.10/site-packages/tvm_ffi/access_path.pyr
   &   s    r
   zffi.reflection.AccessStepc                   @  s4   e Zd ZU dZded< ded< erddd	Zd
S d
S )
AccessStepzAccess step container.intkindr   keyreturnr   c                C     d S Nr   selfr   r   r   __ffi_shallow_copy__;       zAccessStep.__ffi_shallow_copy__Nr   r   )r   r   r   r   __annotations__r   r$   r   r   r   r   r   1   s   
 r   zffi.reflection.AccessPathc                      s4  e Zd ZU dZded< ded< ded< erSdEd
dZedFddZdGddZ	dHddZ
dIddZdJddZdHddZdIddZdJddZdKd!d"ZdLd$d%ZdKd&d'ZdM fd)d*ZedFd+d,ZdNd.d/ZdNd0d1ZdOd2d3ZdPd5d6ZdPd7d8ZdQd:d;ZdQd<d=ZdRd?d@ZdRdAdBZdLdCdDZej Z   Z!S )S
AccessPatha6  Access path container.

    It describes how to reach a nested attribute or item
    inside a complex FFI object by recording a sequence of steps
    (attribute, array index, or map key). It is primarily used by
    diagnostics to pinpoint structural mismatches.

    Examples
    --------
    .. code-block:: python

        from tvm_ffi.access_path import AccessPath

        root = AccessPath.root()
        # Build a path equivalent to obj.layer.weight[2]
        p = root.attr("layer").attr("weight").array_item(2)
        assert isinstance(p, AccessPath)

    zObject | NoneparentzAccessStep | Nonestepr   depthr   r   c                C  r    r!   r   r"   r   r   r   r$   ]   r%   zAccessPath.__ffi_shallow_copy__c                   C  r    r!   r   r   r   r   r   _root^   s   zAccessPath._root_1r   c                C  r    r!   r   r#   r-   r   r   r   _extend`   r%   zAccessPath._extendstrc                C  r    r!   r   r.   r   r   r   _attra   r%   zAccessPath._attrc                C  r    r!   r   r.   r   r   r   _array_itemb   r%   zAccessPath._array_itemr   c                C  r    r!   r   r.   r   r   r   	_map_itemc   r%   zAccessPath._map_itemc                C  r    r!   r   r.   r   r   r   _attr_missingd   r%   zAccessPath._attr_missingc                C  r    r!   r   r.   r   r   r   _array_item_missinge   r%   zAccessPath._array_item_missingc                C  r    r!   r   r.   r   r   r   _map_item_missingf   r%   zAccessPath._map_item_missingboolc                C  r    r!   r   r.   r   r   r   _is_prefix_ofg   r%   zAccessPath._is_prefix_ofSequence[AccessStep]c                C  r    r!   r   r"   r   r   r   	_to_stepsh   r%   zAccessPath._to_stepsc                C  r    r!   r   r.   r   r   r   _path_equali   r%   zAccessPath._path_equalNonec                   s   t    td)z>Disallow direct construction; use `AccessPath.root()` instead.zcAccessPath can't be initialized directly. Use AccessPath.root() to create a path to the root object)super__init__
ValueErrorr"   	__class__r   r   r>   m   s   
zAccessPath.__init__c                   C  s   t  S )zCreate a root access path.

        Returns
        -------
        AccessPath
            A path representing the root of an object graph.

        )r(   r,   r   r   r   r   rootu   s   
zAccessPath.roototherc                 C  s   t |tsdS | |S )z*Return whether two access paths are equal.F
isinstancer(   r;   r#   rC   r   r   r   __eq__   s   

zAccessPath.__eq__c                 C  s   t |tsdS | | S )z.Return whether two access paths are not equal.TrD   rF   r   r   r   __ne__   s   
zAccessPath.__ne__c                 C  
   |  |S )aP  Check if this access path is a prefix of another access path.

        Parameters
        ----------
        other
            The access path to check if it is a prefix of this access path

        Returns
        -------
        bool
            True if this access path is a prefix of the other access path, False otherwise

        )r8   rF   r   r   r   is_prefix_of      
zAccessPath.is_prefix_ofattr_keyc                 C  rI   )a  Create an access path to the attribute of the current object.

        Parameters
        ----------
        attr_key
            The key of the attribute to access

        Returns
        -------
        AccessPath
            The extended access path

        )r1   r#   rL   r   r   r   attr   rK   zAccessPath.attrc                 C  rI   )a  Create an access path that indicate an attribute is missing.

        Parameters
        ----------
        attr_key
            The key of the attribute to access

        Returns
        -------
        AccessPath
            The extended access path

        )r4   rM   r   r   r   attr_missing   rK   zAccessPath.attr_missingindexc                 C  rI   )zCreate an access path to the item of the current array.

        Parameters
        ----------
        index
            The index of the item to access

        Returns
        -------
        AccessPath
            The extended access path

        )r2   r#   rP   r   r   r   
array_item   rK   zAccessPath.array_itemc                 C  rI   )a  Create an access path that indicate an array item is missing.

        Parameters
        ----------
        index
            The index of the item to access

        Returns
        -------
        AccessPath
            The extended access path

        )r5   rQ   r   r   r   array_item_missing   rK   zAccessPath.array_item_missingr   c                 C  rI   )zCreate an access path to the item of the current map.

        Parameters
        ----------
        key
            The key of the item to access

        Returns
        -------
        AccessPath
            The extended access path

        )r3   r#   r   r   r   r   map_item   rK   zAccessPath.map_itemc                 C  rI   )zCreate an access path that indicate a map item is missing.

        Parameters
        ----------
        key
            The key of the item to access

        Returns
        -------
        AccessPath
            The extended access path

        )r6   rT   r   r   r   map_item_missing   rK   zAccessPath.map_item_missingc                 C  s   |   S )zConvert the access path to a list of access steps.

        Returns
        -------
        access_steps
            The list of access steps

        )r:   r"   r   r   r   to_steps   s   	zAccessPath.to_stepsr&   )r   r(   )r-   r   r   r(   )r-   r0   r   r(   )r-   r   r   r(   )r-   r   r   r(   )r-   r(   r   r7   )r   r9   )r   r<   )rC   r   r   r7   )rC   r(   r   r7   )rL   r0   r   r(   )rP   r   r   r(   )r   r   r   r(   )"r   r   r   r   r'   r   r$   staticmethodr,   r/   r1   r2   r3   r4   r5   r6   r8   r:   r;   r>   rB   rG   rH   rJ   rN   rO   rR   rS   rU   rV   rW   r   __hash____classcell__r   r   r@   r   r(   @   sB   
 




















r(   N)r   
__future__r   typingr   collections.abcr   tvm_ffir   r   enumr   coreregistryr	   r
   r   r(   r   r   r   r   <module>   s   