o
    Þý°j,  ã                   @   sÂ   d dl mZ d dlZd dlmZ G dd„ dƒZG dd„ dƒZdZd	Ze	d
kr_ej
 ej
 e¡¡Zej
 ed¡Zej
 ed¡ZeeƒZeedƒ�Ze e¡ W d  ƒ dS 1 sXw   Y  dS dS )é    )ÚTemplateN)ÚIOc                   @   s4   e Zd Zddd„Zdee ddfdd„Zd	d
„ ZdS )ÚASTCodeGeneratorú
_c_ast.cfgc                 C   s    || _ dd„ |  |¡D ƒ| _dS )zIInitialize the code generator from a configuration
        file.
        c                 S   s   g | ]	\}}t ||ƒ‘qS © )ÚNodeCfg)Ú.0ÚnameÚcontentsr   r   ú…/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pycparser/_ast_gen.pyÚ
<listcomp>   s    ÿÿz-ASTCodeGenerator.__init__.<locals>.<listcomp>N)Úcfg_filenameÚparse_cfgfileÚnode_cfg)Úselfr   r   r   r   Ú__init__   s   þzASTCodeGenerator.__init__ÚfileÚreturnNc                 C   sD   t tƒj| jd�}|t7 }| jD ]
}|| ¡ d 7 }q| |¡ dS )z2Generates the code into file, an open file buffer.)r   z

N)r   Ú_PROLOGUE_COMMENTÚ
substituter   Ú_PROLOGUE_CODEr   Úgenerate_sourceÚwrite)r   r   Úsrcr   r   r   r   Úgenerate    s
   
zASTCodeGenerator.generatec           
      c   sâ   � t |dƒ�a}|D ]U}| ¡ }|r| d¡rq	| d¡}| d¡}| d¡}|dk s2||ks2||kr=td|› d|› d	�ƒ‚|d
|… }||d |… }|rWdd„ | d¡D ƒng }	||	fV  q	W d
  ƒ d
S 1 sjw   Y  d
S )z`Parse the configuration file and yield pairs of
        (name, contents) for each node.
        Úrú#ú:ú[ú]é   zInvalid line in ú:
Ú
Nc                 S   s   g | ]}|  ¡ ‘qS r   )Ústrip)r   Úvr   r   r   r   ;   s    z2ASTCodeGenerator.parse_cfgfile.<locals>.<listcomp>ú,)Úopenr#   Ú
startswithÚfindÚRuntimeErrorÚsplit)
r   ÚfilenameÚfÚlineÚcolon_iÚ
lbracket_iÚ
rbracket_ir	   ÚvalÚvallistr   r   r   r   *   s"   €


ó"ÿzASTCodeGenerator.parse_cfgfile)r   )Ú__name__Ú
__module__Ú__qualname__r   r   Ústrr   r   r   r   r   r   r      s    


r   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )r   z­Node configuration.

    name: node name
    contents: a list of contents - attributes and child nodes
    See comment at the top of the configuration file for details.
    c                 C   s~   || _ g | _g | _g | _g | _|D ]+}| d¡}| j |¡ | d¡r*| j |¡ q| d¡r6| j |¡ q| j |¡ qd S )NÚ*z**)r	   Úall_entriesÚattrÚchildÚ	seq_childÚrstripÚappendÚendswith)r   r	   r
   ÚentryÚclean_entryr   r   r   r   G   s   


÷zNodeCfg.__init__c                 C   s<   |   ¡ }|d|  ¡  7 }|d|  ¡  7 }|d|  ¡  7 }|S )Nr"   )Ú	_gen_initÚ_gen_childrenÚ	_gen_iterÚ_gen_attr_names©r   r   r   r   r   r   Y   s
   zNodeCfg.generate_sourcec                 C   s    d| j › d�}| jr&d | j¡}d dd„ | jD ƒ¡}|d7 }d|› d�}nd	}d
}|d|› d�7 }|d|› d�7 }| jdg D ]}|d|› d|› d�7 }q@|S )Nzclass z(Node):
ú, c                 s   s   � | ]	}d |› d �V  qdS )ú'Nr   )r   Úer   r   r   Ú	<genexpr>e   s   € z$NodeCfg._gen_init.<locals>.<genexpr>z, 'coord', '__weakref__'z(self, z, coord=None)z'coord', '__weakref__'z(self, coord=None)z    __slots__ = (z)
z    def __init__r!   Úcoordz        self.z = r"   )r	   r8   Újoin)r   r   ÚargsÚslotsÚarglistr	   r   r   r   rA   `   s   zNodeCfg._gen_initc                 C   sˆ   d}| j r>|d7 }| jD ]}|d|› d�7 }|d|› d|› d�7 }q| jD ]}|d|› d	�7 }|d
|› d�7 }q%|d7 }|S |d7 }|S )Nz    def children(self):
z        nodelist = []
ú        if self.ú is not None:
z            nodelist.append(("z", self.z))
z'        for i, child in enumerate(self.ú	 or []):
z            nodelist.append((f"z[{i}]", child))
z        return tuple(nodelist)
z        return ()
©r8   r:   r;   ©r   r   r:   r;   r   r   r   rB   t   s   

þzNodeCfg._gen_childrenc                 C   s~   d}| j r9| jD ]}|d|› d�7 }|d|› d�7 }q| jD ]}|d|› d�7 }|d7 }q| js7| js7|d	7 }|S |d	7 }|S )
Nz    def __iter__(self):
rO   rP   z            yield self.r"   z        for child in (self.rQ   z            yield child
z        return
        yield
rR   rS   r   r   r   rC   ˆ   s   


þzNodeCfg._gen_iterc                 C   s"   dd  dd„ | jD ƒ¡ d }|S )Nz    attr_names = (Ú c                 s   s   � | ]}|›d �V  qdS )rF   Nr   )r   Únmr   r   r   rI   ž   s   € z*NodeCfg._gen_attr_names.<locals>.<genexpr>ú))rK   r9   rE   r   r   r   rD   �   s   zNodeCfg._gen_attr_namesN)
r3   r4   r5   Ú__doc__r   r   rA   rB   rC   rD   r   r   r   r   r   ?   s    r   a¯  #-----------------------------------------------------------------
# ** ATTENTION **
# This code was automatically generated from _c_ast.cfg
#
# Do not modify it directly. Modify the configuration file and
# run the generator again.
# ** ** *** ** **
#
# pycparser: c_ast.py
#
# AST Node classes.
#
# Eli Bendersky [https://eli.thegreenplace.net/]
# License: BSD
#-----------------------------------------------------------------

ae  
import sys
from typing import Any, ClassVar, IO, Optional

def _repr(obj):
    """
    Get the representation of an object, with dedicated pprint-like format for lists.
    """
    if isinstance(obj, list):
        return '[' + (',\n '.join((_repr(e).replace('\n', '\n ') for e in obj))) + '\n]'
    else:
        return repr(obj)

class Node:
    __slots__ = ()
    """ Abstract base class for AST nodes.
    """
    attr_names: ClassVar[tuple[str, ...]] = ()
    coord: Optional[Any]
    def __repr__(self):
        """ Generates a python representation of the current node
        """
        result = self.__class__.__name__ + '('

        indent = ''
        separator = ''
        for name in self.__slots__[:-2]:
            result += separator
            result += indent
            result += name + '=' + (_repr(getattr(self, name)).replace('\n', '\n  ' + (' ' * (len(name) + len(self.__class__.__name__)))))

            separator = ','
            indent = '\n ' + (' ' * len(self.__class__.__name__))

        result += indent + ')'

        return result

    def children(self):
        """ A sequence of all children that are Nodes
        """
        pass

    def show(
        self,
        buf: IO[str] = sys.stdout,
        offset: int = 0,
        attrnames: bool = False,
        showemptyattrs: bool = True,
        nodenames: bool = False,
        showcoord: bool = False,
        _my_node_name: Optional[str] = None,
    ):
        """ Pretty print the Node and all its attributes and
            children (recursively) to a buffer.

            buf:
                Open IO buffer into which the Node is printed.

            offset:
                Initial offset (amount of leading spaces)

            attrnames:
                True if you want to see the attribute names in
                name=value pairs. False to only see the values.

            showemptyattrs:
                False if you want to suppress printing empty attributes.

            nodenames:
                True if you want to see the actual node names
                within their parents.

            showcoord:
                Do you want the coordinates of each Node to be
                displayed.
        """
        lead = ' ' * offset
        if nodenames and _my_node_name is not None:
            buf.write(lead + self.__class__.__name__+ ' <' + _my_node_name + '>: ')
        else:
            buf.write(lead + self.__class__.__name__+ ': ')

        if self.attr_names:
            def is_empty(v):
                v is None or (hasattr(v, '__len__') and len(v) == 0)
            nvlist = [(n, getattr(self,n)) for n in self.attr_names \
                        if showemptyattrs or not is_empty(getattr(self,n))]
            if attrnames:
                attrstr = ', '.join(f'{name}={value}' for name, value in nvlist)
            else:
                attrstr = ', '.join(f'{value}' for _, value in nvlist)
            buf.write(attrstr)

        if showcoord:
            buf.write(f' (at {self.coord})')
        buf.write('\n')

        for (child_name, child) in self.children():
            child.show(
                buf,
                offset=offset + 2,
                attrnames=attrnames,
                showemptyattrs=showemptyattrs,
                nodenames=nodenames,
                showcoord=showcoord,
                _my_node_name=child_name)


class NodeVisitor:
    """ A base NodeVisitor class for visiting c_ast nodes.
        Subclass it and define your own visit_XXX methods, where
        XXX is the class name you want to visit with these
        methods.

        For example:

        class ConstantVisitor(NodeVisitor):
            def __init__(self):
                self.values = []

            def visit_Constant(self, node):
                self.values.append(node.value)

        Creates a list of values of all the constant nodes
        encountered below the given node. To use it:

        cv = ConstantVisitor()
        cv.visit(node)

        Notes:

        *   generic_visit() will be called for AST nodes for which
            no visit_XXX method was defined.
        *   The children of nodes for which a visit_XXX was
            defined will not be visited - if you need this, call
            generic_visit() on the node.
            You can use:
                NodeVisitor.generic_visit(self, node)
        *   Modeled after Python's own AST visiting facilities
            (the ast module of Python 3.0)
    """

    _method_cache = None

    def visit(self, node: Node):
        """ Visit a node.
        """

        if self._method_cache is None:
            self._method_cache = {}

        visitor = self._method_cache.get(node.__class__.__name__, None)
        if visitor is None:
            method = 'visit_' + node.__class__.__name__
            visitor = getattr(self, method, self.generic_visit)
            self._method_cache[node.__class__.__name__] = visitor

        return visitor(node)

    def generic_visit(self, node: Node):
        """ Called if no explicit visitor function exists for a
            node. Implements preorder visiting of the node.
        """
        for _, c in node.children():
            self.visit(c)

Ú__main__r   zc_ast.pyÚw)Ústringr   ÚosÚtypingr   r   r   r   r   r3   ÚpathÚdirnameÚabspathÚ__file__Úbase_dirrK   Úcfg_pathÚout_pathÚast_genr&   Úoutr   r   r   r   r   Ú<module>   s"   *c +"ÿû