o
    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   P/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/tvm_ffi/access_path.pyr
   &   s    r
   zffi.reflection.AccessStepc                   @  s"   e Zd ZU dZded< ded< dS )
AccessStepzAccess step container.intkindr   keyN)r   r   r   r   __annotations__r   r   r   r   r   1   s   
 r   zffi.reflection.AccessPathc                      s*  e Zd ZU dZded< ded< ded< erNedBd	d
ZdCddZdDddZ	dEddZ
dFddZdDddZdEddZdFddZdGddZdHd!d"ZdGd#d$ZdI fd&d'ZedBd(d)ZdJd+d,ZdJd-d.ZdKd/d0ZdLd2d3ZdLd4d5ZdMd7d8ZdMd9d:ZdNd<d=ZdNd>d?ZdHd@dAZejZ  Z S )O
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   depthreturnc                   C     d S Nr   r   r   r   r   _root[   s   zAccessPath._root_1r   c                C  r%   r&   r   selfr(   r   r   r   _extend]       zAccessPath._extendstrc                C  r%   r&   r   r)   r   r   r   _attr^   r,   zAccessPath._attrc                C  r%   r&   r   r)   r   r   r   _array_item_   r,   zAccessPath._array_itemr   c                C  r%   r&   r   r)   r   r   r   	_map_item`   r,   zAccessPath._map_itemc                C  r%   r&   r   r)   r   r   r   _attr_missinga   r,   zAccessPath._attr_missingc                C  r%   r&   r   r)   r   r   r   _array_item_missingb   r,   zAccessPath._array_item_missingc                C  r%   r&   r   r)   r   r   r   _map_item_missingc   r,   zAccessPath._map_item_missingboolc                C  r%   r&   r   r)   r   r   r   _is_prefix_ofd   r,   zAccessPath._is_prefix_ofSequence[AccessStep]c                C  r%   r&   r   r*   r   r   r   	_to_stepse   r,   zAccessPath._to_stepsc                C  r%   r&   r   r)   r   r   r   _path_equalf   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__
ValueErrorr7   	__class__r   r   r<   j   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   rootr   s   
zAccessPath.roototherc                 C  s   t |tsdS | |S )z*Return whether two access paths are equal.F
isinstancer    r9   r*   rA   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.TrB   rD   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

        )r5   rD   r   r   r   is_prefix_of      
zAccessPath.is_prefix_ofattr_keyc                 C  rG   )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

        )r.   r*   rJ   r   r   r   attr   rI   zAccessPath.attrc                 C  rG   )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

        )r1   rK   r   r   r   attr_missing   rI   zAccessPath.attr_missingindexc                 C  rG   )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

        )r/   r*   rN   r   r   r   
array_item   rI   zAccessPath.array_itemc                 C  rG   )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

        )r2   rO   r   r   r   array_item_missing   rI   zAccessPath.array_item_missingr   c                 C  rG   )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

        )r0   r*   r   r   r   r   map_item   rI   zAccessPath.map_itemc                 C  rG   )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

        )r3   rR   r   r   r   map_item_missing   rI   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

        )r8   r7   r   r   r   to_steps   s   	zAccessPath.to_steps)r$   r    )r(   r   r$   r    )r(   r-   r$   r    )r(   r   r$   r    )r(   r   r$   r    )r(   r    r$   r4   )r$   r6   )r$   r:   )rA   r   r$   r4   )rA   r    r$   r4   )rJ   r-   r$   r    )rN   r   r$   r    )r   r   r$   r    )!r   r   r   r   r   r   staticmethodr'   r+   r.   r/   r0   r1   r2   r3   r5   r8   r9   r<   r@   rE   rF   rH   rL   rM   rP   rQ   rS   rT   rU   r   __hash____classcell__r   r   r>   r   r    >   s@   
 



















r    N)r   
__future__r   typingr   collections.abcr   tvm_ffir   r   enumr   coreregistryr	   r
   r   r    r   r   r   r   <module>   s   