o
    _f                     @   s   d Z ddlmZmZ ddlmZ edd dkrddlmZ nddlmZ ddl	m
Z
 dd	lT dd	lT ddlZG d
d deZG dd deZdS )zJ
This module contains the namespace class and the singleton module class.
    )dirnamebasename)version_infoN   )   r   )parse)matcher)*c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )		Namespacea[  
    Contains the naming information for an extension.

    Public fields:

    header is the header attribute ("header file" name).
    is_ext is true for extensions, false for xproto.
    major_version and minor_version are extension version info.
    ext_xname is the X extension name string.
    ext_name is the XCB extension name prefix.
    c                 C   s   || _ t|| _t|| _t| | _| jd| _	| j	d | _
i | _| jddrRd| _| jd| _| jd| _| jd| _| jd| _d	| jf| _d S d| _d
| _d| _d S )Nheader:zextension-xnameFTzmajor-versionzminor-versionzextension-namexcb r   )pathr   dirr   filer   Zgetrootrootgetr   nseventsZis_extZmajor_versionZminor_versionZ	ext_xnameext_nameprefix)selffilename r   c/home/ych/rk3568/buildroot/output/rockchip_rk3568/host/lib/python3.10/site-packages/xcbgen/state.py__init__   s"   


zNamespace.__init__c                 C   s   ||f| j |< d S Nr   r   idnameitemr   r   r   	add_event9      zNamespace.add_eventc                 C   sD   | j  D ]\}\}}|j|kr||}|d ur||f  S qd S r   )r   itemsis_ge_eventZget_name_for_opcode)r   Zopcoder'   r!   r"   ZeventZopcode_specific_namer   r   r   get_event_by_opcode<   s   

zNamespace.get_event_by_opcodeN)__name__
__module____qualname____doc__r   r$   r(   r   r   r   r   r
      s
    r
   c                   @   s   e Zd ZdZejd Zejd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&S )'Modulea8  
    This is the grand, encompassing class that represents an entire XCB specification.
    Only gets instantiated once, in the main() routine.

    Don't need to worry about this much except to declare it and to get the namespace.

    Public fields:
    namespace contains the namespace info for the spec.
    openclosec                 C   s4  t || _|| _g | _g | _d| _i | _i | _i | _g | _	i | _
| j| j
| jj< | dddt | dddt | dddt | d	dd
t | dddt | dddt | dddt | dddt | dddt | dddt | dddt | dddt | dddt | dddt d S )Nr   ZCARD8r   )Zuint8_tZCARD16)Zuint16_tZCARD32)Zuint32_tZCARD64)Zuint64_tZINT8)Zint8_tZINT16)Zint16_tZINT32)Zint32_tZINT64)Zint64_tZBYTEZBOOLchar)r0   float)r1   double)r2   void)r3   )r
   	namespaceoutputimportsdirect_importsimport_leveltypesr   errorsall
namespacesr   add_typeZtcard8Ztcard16Ztcard32Ztcard64Ztint8Ztint16Ztint32Ztint64ZtbyteZtboolZtcharZtfloatZtdoubleZtvoid)r   r   r5   r   r   r   r   R   s2   
zModule.__init__c                 C   s   t | | j d S r   )r   Zexecuter4   )r   r   r   r   registert   r%   zModule.registerc                 C   s,   |    | jD ]\}}d| _||  qd S Nr   )add_events_to_namespacesr;   Zpadsresolver   r"   r#   r   r   r   rA   x   s
   zModule.resolvec                 C   s.   |    | jD ]	\}}|| q|   d S r   )r.   r;   outr/   rB   r   r   r   generate   s   zModule.generatec                 C   s>   | j dkr| j||jf | j||jf || j|j< d S r?   )r8   r7   appendr   r6   r<   r   )r   r"   r4   r   r   r   
add_import   s   
zModule.add_importc                 C   s"   | j D ]\}}||kr dS qdS )NTF)r6   )r   r"   Zname_r   r   r   r   
has_import   s
   zModule.has_importc                 C   sP   || }|| j v rd S ||f| j |< |d d | jjkr&| j||f d S d S N)r9   r4   r   r;   rE   )r   r!   r   r"   r#   keyr   r   r   r=      s   
zModule.add_typec                 C   s   |}|| j v r| j | | S | jj| }|| j v r | j | | S | j  D ]}|dd |kr9| j | |   S q%td| )Nr   r   zType %s not found)r9   r4   r   keys
rpartitionZResolveException)r   r!   idxrJ   r   r   r   get_type_impl   s   

zModule.get_type_implc                 C      |  |dS N   rN   r   r!   r   r   r   get_type      zModule.get_typec                 C   rO   r?   rR   rS   r   r   r   get_type_name   rU   zModule.get_type_namec                 C   s
   | j | S r   )r<   )r   r   r   r   r   get_namespace   s   
zModule.get_namespacec                 C   s,   |d d | j jkr| j||f d S d S rH   )r4   r   r;   rE   r    r   r   r   add_request   s   zModule.add_requestc                 C   :   ||f| j |< |d d | jjkr| j||f d S d S rH   )r   r4   r   r;   rE   r    r   r   r   r$         zModule.add_eventc                 C   sZ   | j  D ]%\}\}}|d d dkrd}n|d }| j| }|d ur*|||| qd S )NrI   r   r   )r   r&   r<   r$   )r   r!   r"   r#   Znamespace_namer4   r   r   r   r@      s   
zModule.add_events_to_namespacesc                 C      | j | d S rP   r   rS   r   r   r   	get_event      zModule.get_eventc                 C   rY   rH   )r:   r4   r   r;   rE   r    r   r   r   	add_error   rZ   zModule.add_errorc                 C   r\   rP   )r:   rS   r   r   r   	get_error   r^   zModule.get_errorN)r)   r*   r+   r,   __main__r5   r.   r/   r   r>   rA   rD   rF   rG   r=   rN   rT   rV   rW   rX   r$   r@   r]   r_   r`   r   r   r   r   r-   E   s*    
	
"	r-   )r,   Zos.pathr   r   sysr   Zxml.etree.ElementTreer   Zxml.etree.cElementTreeZxcbgenr   Zxcbgen.errorZxcbgen.xtypesra   objectr
   r-   r   r   r   r   <module>   s    3