a
    dx                      @   s   d dl mZ d dlmZ d dlmZ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mZ d	ZG d
d deZG dd deZd	S )    )StringIO)reduce)PredictionContextmerge)str_list)ATN)	ATNConfig)SemanticContext)UnsupportedOperationExceptionIllegalStateExceptionNc                   @   s   e Zd ZdZd.edddZdd Zd/ed	d
dZed	ddZ	dd Z
dd ZedddZedddZedddZdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zed)d*d+Zd,d- ZdS )0ATNConfigSet)	configLookupfullCtxreadonlyconfigs	uniqueAltconflictingAltshasSemanticContextdipsIntoOuterContextcachedHashCodeT)r   c                 C   s<   t  | _|| _d| _g | _d| _d | _d| _d| _d| _	d S )NFr   )
dictr   r   r   r   r   r   r   r   r   )selfr    r   `/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/antlr4/atn/ATNConfigSet.py__init__$   s    zATNConfigSet.__init__c                 C   s
   | j  S N)r   __iter__r   r   r   r   r   A   s    zATNConfigSet.__iter__Nconfigc                 C   s   | j rtd|jtjur d| _|jdkr0d| _| |}||u rXd| _	| j
| dS | j }t|j|j||}t|j|j|_|jrd|_||_dS )NThis set is readonlyTr   r   )r   	ExceptionsemanticContextr	   NONEr   ZreachesIntoOuterContextr   getOrAddr   r   appendr   r   contextmaxZprecedenceFilterSuppressed)r   r    Z
mergeCacheexistingZrootIsWildcardmergedr   r   r   addM   s$    

zATNConfigSet.addc                    sj      }| j|d }|d urBt fdd|D d }|d urB|S |d u r\ g}|| j|< n
|   S )Nc                 3   s   | ]}  |r|V  qd S r   )equalsForConfigSet.0cfgr   r   r   	<genexpr>j       z(ATNConfigSet.getOrAdd.<locals>.<genexpr>)hashCodeForConfigSetr   getnextr&   )r   r    hlrr   r   r   r%   f   s    
zATNConfigSet.getOrAddc                 C   s   t dd | jD S )Nc                 s   s   | ]}|j V  qd S r   )state)r.   cr   r   r   r0   u   r1   z)ATNConfigSet.getStates.<locals>.<genexpr>)setr   r   r   r   r   	getStatest   s    zATNConfigSet.getStatesc                 C   s   t dd | jD S )Nc                 s   s    | ]}|j tjkr|j V  qd S r   )r#   r	   r$   r-   r   r   r   r0   x   r1   z-ATNConfigSet.getPredicates.<locals>.<genexpr>)listr   r   r   r   r   getPredicatesw   s    zATNConfigSet.getPredicates)ic                 C   s
   | j | S r   )r   )r   r>   r   r   r   r3   z   s    zATNConfigSet.get)interpreterc                 C   s>   | j rtdt| jdkr d S | jD ]}||j|_q&d S )Nr!   r   )r   r   lenr   ZgetCachedContextr'   )r   r?   r    r   r   r   optimizeConfigs}   s    
zATNConfigSet.optimizeConfigs)collc                 C   s   |D ]}|  | qdS )NF)r+   )r   rB   r9   r   r   r   addAll   s    zATNConfigSet.addAllc                 C   sp   | |u rdS t |tsdS | jd uoj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j|jk}|S )NTF)
isinstancer   r   r   r   r   r   r   )r   otherZsamer   r   r   __eq__   s$    







zATNConfigSet.__eq__c                 C   s(   | j r | jdkr|  | _| jS |  S )Nr   )r   r   hashConfigsr   r   r   r   __hash__   s
    

zATNConfigSet.__hash__c                 C   s   t dd | jdS )Nc                 S   s   t | |fS r   )hash)r5   r/   r   r   r   <lambda>   r1   z*ATNConfigSet.hashConfigs.<locals>.<lambda>r   )r   r   r   r   r   r   rG      s    zATNConfigSet.hashConfigsc                 C   s
   t | jS r   r@   r   r   r   r   r   __len__   s    zATNConfigSet.__len__c                 C   s   t | jdkS )Nr   rK   r   r   r   r   isEmpty   s    zATNConfigSet.isEmptyc                 C   sN   | j d u rtd| }| j |d }|d urJ|D ]}||r4 dS q4dS )Nz1This method is not implemented for readonly sets.TF)r   r
   r2   r3   r,   )r   r    r5   r6   r9   r   r   r   __contains__   s    

zATNConfigSet.__contains__c                 C   s,   | j rtd| j  d| _| j  d S )Nr!   r   )r   r   r   clearr   r   r   r   r   r   rO      s
    
zATNConfigSet.clear)r   c                 C   s   || _ d | _d S r   )r   r   )r   r   r   r   r   setReadonly   s    zATNConfigSet.setReadonlyc                 C   s   t  }|t| j | jr8|d |t| j | jtjkr^|d |t| j | j	d ur|d |t| j	 | j
r|d | W  d    S 1 s0    Y  d S )Nz,hasSemanticContext=z,uniqueAlt=z,conflictingAlts=z,dipsIntoOuterContext)r   writer   r   r   strr   r   ZINVALID_ALT_NUMBERr   r   getvalue)r   bufr   r   r   __str__   s    




zATNConfigSet.__str__)T)N)__name__
__module____qualname__	__slots__boolr   r   r   r+   r%   r;   r=   intr3   ATNSimulatorrA   r<   rC   rF   rH   rG   rL   rM   rN   rO   rP   rU   r   r   r   r   r      s&   r   c                       s   e Zd Z fddZ  ZS )OrderedATNConfigSetc                    s   t    d S r   )superr   r   	__class__r   r   r      s    zOrderedATNConfigSet.__init__)rV   rW   rX   r   __classcell__r   r   r_   r   r]      s   r]   )ior   	functoolsr   Zantlr4.PredictionContextr   r   Zantlr4.Utilsr   Zantlr4.atn.ATNr   Zantlr4.atn.ATNConfigr   Zantlr4.atn.SemanticContextr	   Zantlr4.error.Errorsr
   r   r\   objectr   r]   r   r   r   r   <module>   s    <