
    `i                       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e          Z ed           G d de                      Z ed           G d de                      ZdS )zAccess path classes.    )annotations)TYPE_CHECKING)Sequence)Object)Any)IntEnum   )register_objectc                  *    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     g/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/tvm_ffi/access_path.pyr   r   &   s6        22DJHLr   r   zffi.reflection.AccessStepc                  (    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*           
 IIIHHHHHr   r   zffi.reflection.AccessPathc                  &    e Zd ZU dZded<   ded<   ded<   er4ed+d	            Zd,dZd-dZ	d.dZ
d/dZd-dZd.dZd/dZd0dZd1dZd0dZd2 fdZed+d            Zd3dZd3dZd4d Zd5d"Zd5d#Zd6d%Zd6d&Zd7d(Zd7d)Zd1d*Zej        Z xZ S )8
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                     d S Nr   r   r   r   _rootzAccessPath._root[   s    #&3r   _1r   c                   d S r+   r   selfr-   s     r   _extendzAccessPath._extend]         r   strc                   d S r+   r   r/   s     r   _attrzAccessPath._attr^   r2   r   c                   d S r+   r   r/   s     r   _array_itemzAccessPath._array_item_   r2   r   r   c                   d S r+   r   r/   s     r   	_map_itemzAccessPath._map_item`   r2   r   c                   d S r+   r   r/   s     r   _attr_missingzAccessPath._attr_missinga   r2   r   c                   d S r+   r   r/   s     r   _array_item_missingzAccessPath._array_item_missingb   r2   r   c                   d S r+   r   r/   s     r   _map_item_missingzAccessPath._map_item_missingc   r2   r   boolc                   d S r+   r   r/   s     r   _is_prefix_ofzAccessPath._is_prefix_ofd   r2   r   Sequence[AccessStep]c                   d S r+   r   r0   s    r   	_to_stepszAccessPath._to_stepse   r2   r   c                   d S r+   r   r/   s     r   _path_equalzAccessPath._path_equalf   r2   r   Nonec                b    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__
ValueError)r0   	__class__s    r   rL   zAccessPath.__init__j   s1    H
 
 	
r   c                 4    t                                           S )zCreate a root access path.

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

        )r%   r,   r   r   r   rootzAccessPath.rootr   s     !!!r   otherc                Z    t          |t                    sdS |                     |          S )z*Return whether two access paths are equal.F
isinstancer%   rH   r0   rQ   s     r   __eq__zAccessPath.__eq__~   s-    %,, 	5&&&r   c                \    t          |t                    sdS |                     |           S )z.Return whether two access paths are not equal.TrS   rU   s     r   __ne__zAccessPath.__ne__   s0    %,, 	4##E****r   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

        )rB   rU   s     r   is_prefix_ofzAccessPath.is_prefix_of   s     !!%(((r   attr_keyc                ,    |                      |          S )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

        )r5   r0   r[   s     r   attrzAccessPath.attr   s     zz(###r   c                ,    |                      |          S )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

        )r;   r]   s     r   attr_missingzAccessPath.attr_missing   s     !!(+++r   indexc                ,    |                      |          S )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

        )r7   r0   ra   s     r   
array_itemzAccessPath.array_item   s     &&&r   c                ,    |                      |          S )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

        )r=   rc   s     r   array_item_missingzAccessPath.array_item_missing   s     ''...r   r"   c                ,    |                      |          S )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

        )r9   r0   r"   s     r   map_itemzAccessPath.map_item   s     ~~c"""r   c                ,    |                      |          S )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

        )r?   rh   s     r   map_item_missingzAccessPath.map_item_missing   s     %%c***r   c                *    |                                  S )zConvert the access path to a list of access steps.

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

        )rF   rE   s    r   to_stepszAccessPath.to_steps   s     ~~r   )r)   r%   )r-   r   r)   r%   )r-   r3   r)   r%   )r-   r    r)   r%   )r-   r   r)   r%   )r-   r%   r)   r@   )r)   rC   )r)   rI   )rQ   r   r)   r@   )rQ   r%   r)   r@   )r[   r3   r)   r%   )ra   r    r)   r%   )r"   r   r)   r%   )!r   r   r   r   r#   r   staticmethodr,   r1   r5   r7   r9   r;   r=   r?   rB   rF   rH   rL   rP   rV   rX   rZ   r^   r`   rd   rf   ri   rk   rm   r   __hash____classcell__)rN   s   @r   r%   r%   >   s         . JJJ >	&&& 
&????6666<<<<::::>>>>DDDDBBBB????;;;;====
 
 
 
 
 
 	" 	" 	" \	"' ' ' '+ + + +) ) ) ) $ $ $ $ , , , , ' ' ' ' / / / / # # # # + + + + 	  	  	  	  HHHHHr   r%   N)r   
__future__r   typingr   collections.abcr   tvm_ffir   r   enumr   coreregistryr
   r   r   r%   r   r   r   <module>rx      sk  $  
 # " " " " "             ((((((             % % % % % %        ,--       .- ,--F F F F F F F .-F F Fr   