
    :e>                        d Z ddlmZ ddlZddlZddlmZ ej                  rddl	Z	ej                   G d d             Zy)zProvides helpers for building AST

This is meant to make building Meson AST from foreign (largely declarative)
build descriptions easier.
    )annotationsN   )mparserc                      e Zd ZU d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ddZ	 	 d	 	 	 	 	 ddZ	 	 d	 	 	 	 	 ddZd dZd!dZd"dZd#dZd$dZy)%Builderstrfilenamec           	     L    t        j                  || j                  dddd|      S )a  Create a Token object, but with the line numbers stubbed out.

        :param tid: the token id (such as string, number, etc)
        :param filename: the filename that the token was generated from
        :param value: the value of the token
        :return: A Token object
        )r   r   )r   Tokenr	   )selftidvalues      :/usr/lib/python3/dist-packages/mesonbuild/cargo/builder.py_tokenzBuilder._token   s#     }}S$--RXuMM    c                L    t        j                  | j                  d|            S )N )r   
SymbolNoder   )r   vals     r   _symbolzBuilder._symbol#   s    !!$++b#"677r   c                l    t        j                  | j                  |      | j                  d      |      S )N=)r   AssignmentNode
identifierr   )r   r   varnames      r   assignzBuilder.assign&   s*    %%doog&>S@QSXYYr   c                L    t        j                  | j                  d|            S )zhBuild A StringNode

        :param value: the value of the string
        :return: A StringNode
        string)r   
StringNoder   r   r   s     r   r   zBuilder.string)   s      !!$++h">??r   c                ^    t        j                  | j                  dt        |                  S )zhBuild A NumberNode

        :param value: the value of the number
        :return: A NumberNode
        number)r   
NumberNoder   r   r!   s     r   r#   zBuilder.number1   s$     !!$++hE
"CDDr   c                L    t        j                  | j                  d|            S )zkBuild A BooleanNode

        :param value: the value of the boolean
        :return: A BooleanNode
        bool)r   BooleanNoder   r!   s     r   r&   zBuilder.bool9   s      ""4;;vu#=>>r   c                    t        j                  | j                  dd            }||_        t        j                  | j                  d      || j                  d            S )zBuild an Array Node

        :param value: A list of nodes to insert into the array
        :return: An ArrayNode built from the arguments
        arrayunused[])r   ArgumentNoder   	arguments	ArrayNoder   )r   r   argss      r   r)   zBuilder.arrayA   sM     ##DKK$BC  c!2D$,,s:KLLr   c                
   t        j                  | j                  dd            }|j                         D ]  \  }}|j	                  ||        t        j
                  | j                  d      || j                  d            S )zBuild an Dictionary Node

        :param value: A dict of nodes to insert into the dictionary
        :return: An DictNode built from the arguments
        dictr*   {})r   r-   r   itemsset_kwarg_no_checkDictNoder   )r   r   r0   keyr   s        r   r2   zBuilder.dictK   so     ##DKK$AB 	.HC##C-	.S 14c9JKKr   c                L    t        j                  | j                  d|            S )zfBuild A IdNode

        :param value: the value of the boolean
        :return: A BooleanNode
        id)r   IdNoder   r!   s     r   r   zBuilder.identifierV   s     ~~dkk$677r   Nc           
        t        j                  | j                  dd            }|||_        |8|j	                         D ci c]  \  }}| j                  |      | c}}|_        t        j                  || j                  d      | j                  |      | j                  d      || j                  d            S c c}}w )a2  Create a method call.

        :param name: the name of the method
        :param id_: the object to call the method of
        :param pos: a list of positional arguments, defaults to None
        :param kw: a dictionary of keyword arguments, defaults to None
        :return: a method call object
        r)   r*   .())	r   r-   r   r.   r5   r   kwargs
MethodNoder   )r   nameid_poskwr0   kvs           r   methodzBuilder.method^   s     ##DKK$BC? DN>=?XXZHTQ4??1-q0HDK!!#t||C'8$//$:OQUQ]Q]^aQbdhjnjvjvwzj{|| Is   B?c                h   t        j                  | j                  dd            }|||_        |8|j	                         D ci c]  \  }}| j                  |      | c}}|_        t        j                  | j                  |      | j                  d      || j                  d            S c c}}w )a  Create a function call.

        :param name: the name of the function
        :param pos: a list of positional arguments, defaults to None
        :param kw: a dictionary of keyword arguments, defaults to None
        :return: a method call object
        r)   r*   r>   r?   )	r   r-   r   r.   r5   r   r@   FunctionNoder   )r   rB   rD   rE   r0   rF   rG   s          r   functionzBuilder.functionq   s     ##DKK$BC? DN>=?XXZHTQ4??1-q0HDK##DOOD$94<<;LdTXT`T`adTeff Is   B.c                P    t        j                  d|| j                  d      |      S )zCreate an equality operation

        :param lhs: The left hand side of the equal
        :param rhs: the right hand side of the equal
        :return: A compraison node
        z==)r   ComparisonNoder   r   lhsrhss      r   equalzBuilder.equal   s$     %%dCd1CSIIr   c                N    t        j                  || j                  d      |      S )zCreate and OrNode

        :param lhs: The Left of the Node
        :param rhs: The Right of the Node
        :return: The OrNode
        or)r   OrNoder   rN   s      r   or_zBuilder.or_   s      ~~c4<<#5s;;r   c                N    t        j                  || j                  d      |      S )zCreate an AndNode

        :param lhs: The left of the And
        :param rhs: The right of the And
        :return: The AndNode
        and)r   AndNoder   rN   s      r   and_zBuilder.and_   s      sDLL$7==r   c                n    t        j                  | j                  dd      | j                  d      |      S )zbCreate a not node

        :param value: The value to negate
        :return: The NotNode
        notr   )r   NotNoder   r   r!   s     r   not_zBuilder.not_   s+     t{{5"5t||E7JERRr   c                ^    t        j                  | j                  dd            }||_        |S )Nnoder   )r   CodeBlockNoder   lines)r   ra   blocks      r   rb   zBuilder.block   s)    %%dkk&"&=>r   )r   r   r   zmparser.TV_TokenTypesreturnz$mparser.Token[mparser.TV_TokenTypes])r   r   rc   zmparser.SymbolNode)r   mparser.BaseNoder   r   rc   zmparser.AssignmentNode)r   r   rc   zmparser.StringNode)r   intrc   zmparser.NumberNode)r   zbuiltins.boolrc   zmparser.BooleanNode)r   T.List[mparser.BaseNode]rc   zmparser.ArrayNode)r   z*T.Dict[mparser.BaseNode, mparser.BaseNode]rc   zmparser.DictNode)r   r   rc   mparser.IdNode)NN)
rB   r   rC   rg   rD   $T.Optional[T.List[mparser.BaseNode]]rE   ,T.Optional[T.Mapping[str, mparser.BaseNode]]rc   zmparser.MethodNode)rB   r   rD   rh   rE   ri   rc   zmparser.FunctionNode)rO   rd   rP   rd   rc   zmparser.ComparisonNode)rO   rd   rP   rd   rc   zmparser.OrNode)rO   rd   rP   rd   rc   zmparser.AndNode)r   rd   rc   zmparser.NotNode)ra   rf   rc   zmparser.CodeBlockNode)__name__
__module____qualname____annotations__r   r   r   r   r#   r&   r)   r2   r   rH   rK   rQ   rU   rY   r]   rb    r   r   r   r      s     MN8Z@E?M	L8 <@BF}8}?} '}( >BDHg:gAg +g$J<>Sr   r   )__doc__
__future__r   dataclassestypingTr   r   TYPE_CHECKINGbuiltins	dataclassr   rn   r   r   <module>rw      sD    #   ?? T T Tr   