
    \h                     n   S SK Jr  S SKr\" SSS/0S9r \(       a  S SKJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJrJrJ r J!r!  S S	K"J#r#J$r$J%r%J&r&J'r'  S S
K(J)r)J*r*J+r+J,r,  S SK-J.r.  S SK/J0r0  S SK(J1r1J2r2  S SK3r3S SK4r4 " S S5      r5 " S S\55      r6O
 " S S5      r6S r7g)    )import_moduleNzclang.cindexfromlistcindex)import_kwargs)VariableIntegerFloatFunctionPrototypeFunctionDefinitionFunctionCallnoneReturn
Assignmentintcint8int16int64uint8uint16uint32uint64float32float64float80
aug_assignbool_While	CodeBlock)PreDecrementPostDecrementPreIncrementPostIncrement)AddModMulPowRel)And
as_BooleanNotOr)Symbol)sympify)falsetruec                   $    \ rS rSrSrS rS rSrg)
BaseParser<   zBase Class for the C parserc                 J    [         R                  R                  5       U l        g)z6Initializes the Base parser creating a Clang AST indexN)cinIndexcreateindex)selfs    P/var/www/auris/envauris/lib/python3.13/site-packages/sympy/parsing/c/c_parser.py__init__BaseParser.__init__?   s    ))+DJ    c                 *   U R                   R                   Hy  n[        SSSSSS.UR                     < SUR                  R
                  < SUR                  R                  < S	UR                  R                  < S
UR                  < 3	US9  M{     g)z%Diagostics function for the Clang ASTFATALERRORWARNINGNOTEIGNORED)            r    z (line z, col z) fileN)	tudiagnosticsprintseveritylocationrI   linecolumnspelling)r8   outdiags      r9   rK   BaseParser.diagnosticsC   sz    ++&&(%( --) ****,,  ! ,r<   )r7   N)__name__
__module____qualname____firstlineno____doc__r:   rK   __static_attributes__ r<   r9   r1   r1   <   s    )	,	!r<   r1   c                      ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r Sr!U =r"$ ) CCodeConverterU   zThe Code Convereter for Clang AST

The converter object takes the C source code or file as input and
converts them to SymPy Expressions.
c                 T  > [         TU ]  5         / U l        [        R                  R
                  [        0[        R                  R                  [        0[        R                  R                  [        [        R                  R                  [        [        R                  R                  [        [        R                  R                  [         [        R                  R"                  [$        [        R                  R&                  [(        [        R                  R*                  [,        [        R                  R.                  [0        0[        R                  R2                  [4        [        R                  R6                  [8        [        R                  R:                  [<        0S.U l        g)zInitializes the code converter)voidboolintfloatN) superr:   	_py_nodesr4   TypeKindVOIDr   BOOLr   SCHARr   SHORTr   INTr   LONGr   UCHARr   USHORTr   UINTr   ULONGr   FLOATr   DOUBLEr   
LONGDOUBLEr   _data_types)r8   	__class__s    r9   r:   CCodeConverter.__init__\   s    GDN LL%%t LL%%u LL&&LL&&LL$$dLL%%uLL&&LL''LL%%vLL&&	 LL&&LL''LL++W# Dr<   c                    [         R                  R                  U5      nU R                  R	                  UU[
        R                  R                  S9U l        U R                  R                  R                  5        H  nUR                  [
        R                  R                  :X  d*  UR                  [
        R                  R                  :X  d  MU  U R                  R!                  U R#                  U5      5        M     U R                  $ )a  Function to parse a file with C source code

It takes the filename as an attribute and creates a Clang AST
Translation Unit parsing the file.
Then the transformation function is called on the translation unit,
whose results are collected into a list which is returned by the
function.

Parameters
==========

filename : string
    Path to the C file to be parsed

flags: list
    Arguments to be passed to Clang while parsing the C code

Returns
=======

py_nodes: list
    A list of SymPy AST nodes

argsoptions)ospathabspathr7   parser4   TranslationUnit PARSE_DETAILED_PROCESSING_RECORDrJ   cursorget_childrenkind
CursorKindVAR_DECLFUNCTION_DECLre   append	transform)r8   filenameflagsfilepathchilds        r9   r~   CCodeConverter.parsex   s    2 wwx0Hjj&&++LL ' DG
 446::!8!88EJJ#..JfJf<fNN))$..*?@ 7 >>!r<   c                    [         R                  " SSS9nUR                  U5        UR                  5         UR	                  S5        U R
                  R                  UR                  U[        R                  R                  S9U l        UR                  5         U R                  R                  R                  5        H  nUR                  [        R                   R"                  :X  d*  UR                  [        R                   R$                  :X  d  MU  U R&                  R)                  U R+                  U5      5        M     U R&                  $ )a*  Function to parse a string with C source code

It takes the source code as an attribute, stores it in a temporary
file and creates a Clang AST Translation Unit parsing the file.
Then the transformation function is called on the translation unit,
whose results are collected into a list which is returned by the
function.

Parameters
==========

source : string
    A string containing the C source code to be parsed

flags: list
    Arguments to be passed to Clang while parsing the C code

Returns
=======

py_nodes: list
    A list of SymPy AST nodes

zw+z.cpp)modesuffixr   rx   )tempfileNamedTemporaryFilewriteflushseekr7   r~   namer4   r   r   rJ   closer   r   r   r   r   r   re   r   r   )r8   sourcer   rI   r   s        r9   	parse_strCCodeConverter.parse_str   s    2 ..dVLDJJvJJLIIaLjj&&		++LL ' DG
 JJL446::!8!88EJJ#..JfJf<fNN))$..*?@ 7 >>!r<   c           
         [        U SUR                  R                  R                  5       -  S5      nUcO  [	        SUR                  < SSR                  S UR                  5        5       5      < S3[        R                  S9  U" U5      $ )	zTransformation Function for Clang AST nodes

It determines the kind of node and calls the respective
transformation function for that node.

Raises
======

NotImplementedError : if the transformation for the provided node
is not implemented

ztransform_%sNzIgnoring node of type z (rG   c              3   8   #    U  H  oR                   v   M     g 7fNrQ   .0ts     r9   	<genexpr>+CCodeConverter.transform.<locals>.<genexpr>   s      !C0A1JJ0A   )rH   )	getattrr   r   lowerrL   join
get_tokenssysstderr)r8   nodehandlers      r9   r   CCodeConverter.transform   sy     dNTYY^^5I5I5K$KTRG		 !C040A!C C
  4= r<   c           	      Z
   UR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOYUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nO[        S5      e UR	                  5       n[        U5      nUR                  [        R                  R                  :X  d(  UR                  [        R                  R                  :X  a_  [        U5      nUR                  [        R                  R                  :X  a  M5  UR                  [        R                  R                  :X  a  M_  U R                  U5      n[        R                  R                  [        R                  R                  [        R                  R                  [        R                  R                  [        R                  R                  [        R                  R                   [        R                  R"                  /nUR                  U;   Ga  [%        U[&        5      (       a  [)        U5      nGO[%        U[*        5      (       a  UR                   R                  U R                  S   ;   a  US:X  a  [-        S5      O
[-        S5      nGO@UR                   R                  U R                  S   ;   a  US:X  a  [/        S5      O
[/        S	5      nOUR                   R                  U R                  S   ;   a  [1        U5      nO[%        U[,        [2        [.        [4        45      (       a  UR                   R                  U R                  S   ;   a  [-        U5      nOqUR                   R                  U R                  S   ;   a  [/        U5      nO>UR                   R                  U R                  S   ;   a  [1        [+        U5      5      nOUn[7        UR8                  5      R;                  UWS
9$ UR                  [        R                  R<                  :X  a"  [7        UR8                  5      R;                  US9$ [        SR?                  SRA                  S URC                  5        5       5      5      5      e! [D         a%    [7        UR8                  5      R;                  US9s $ f = f)aY  Transformation Function for Variable Declaration

Used to create nodes for variable declarations and assignments with
values or function call for the respective nodes in the clang AST

Returns
=======

A variable node as Declaration, with the initial value if given

Raises
======

NotImplementedError : if called for data types not currently
implemented

Notes
=====

The function currently supports following data types:

Boolean:
    bool, _Bool

Integer:
    8-bit: signed char and unsigned char
    16-bit: short, short int, signed short,
        signed short int, unsigned short, unsigned short int
    32-bit: int, signed int, unsigned int
    64-bit: long, long int, signed long,
        signed long int, unsigned long, unsigned long int

Floating point:
    Single Precision: float
    Double Precision: double
    Extended Precision: long double

rb   rc   ra   &Only bool, int and float are supportedFr   rF   g        g      ?typevalue)r   z=Given variable declaration "{}" is not possible to parse yet!rG   c              3   8   #    U  H  oR                   v   M     g 7fr   r   r   s     r9   r   4CCodeConverter.transform_var_decl.<locals>.<genexpr>I  s      )0A1JJ0Ar   r   )#r   r   rt   NotImplementedErrorr   nextr4   r   NAMESPACE_REFTYPE_REFr   INTEGER_LITERALFLOATING_LITERALUNEXPOSED_EXPRBINARY_OPERATOR
PAREN_EXPRUNARY_OPERATORCXX_BOOL_LITERAL_EXPR
isinstancestrr,   ra   r   r	   r-   rb   rc   r   rQ   as_Declaration	CALL_EXPRformatr   r   StopIteration)r8   r   r   childrenr   valsupported_rhsr   s           r9   transform_var_decl!CCodeConverter.transform_var_decl   s   N yy~~!1!1%!88''.tyy~~>4#3#3G#<<''0@4#3#3F#;;''/		?) +. / /D,,.X jjCNN$@$@@EJJRUR`R`RiRiDi NE jjCNN$@$@@EJJRUR`R`RiRiDi nnU+ NN22NN33NN11NN22NN--NN11NN88! ::.!#s++ &s#C..99>>T-=-=e-DD25,GAJGAJE!YY^^t/?/?/HH25,E#JE#JE!YY^^t/?/?/GG$+CLE#C'3u)EFF99>>T-=-=e-DD$+CLE!YY^^t/?/?/HH$)#JE!YY^^t/?/?/GG$+DI$6E ##MM$n# % %  ZZ3>>#;#;;#(.$' )  . /8   )040A) !   !  . ! s-   7BS; (S; J1S; 3A	S; =>S; ;,T*)T*c                 j   UR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOYUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nO[        S5      e/ n/ nUR	                  5        H  nU R                  U5      nUR                  [        R                  R                  :X  a  UR                  U5        MO  UR                  [        R                  R                  :X  a  U H  nUR                  U5        M     M  UR                  U5        M     U/ :X  a  [        UUR                  US9nU$ [        UUR                  UUS9nU$ )aF  Transformation Function For Function Declaration

Used to create nodes for function declarations and definitions for
the respective nodes in the clang AST

Returns
=======

function : Codegen AST node
    - FunctionPrototype node if function body is not present
    - FunctionDefinition node if the function body is present


rb   rc   ra   r`   z,Only void, bool, int and float are supported)return_typer   
parameters)r   r   r   body)result_typer   rt   r   r   r   r4   r   	PARM_DECLr   COMPOUND_STMTr
   rQ   r   )	r8   r   ret_typer   paramr   declr   functions	            r9   transform_function_decl&CCodeConverter.transform_function_declU  s     $$(8(8(??++E243C3C3H3HI!!&&$*:*:7*CC++G4T5E5E5J5JK!!&&$*:*:6*BB++F3D4D4D4I4IJ!!&&$*:*:6*BB++F3D4D4D4I4IJ) +. / /DE **,~~e,::!9!99LL&ZZ3>>#?#??#C(  $ KK% - rz,"*==!& O ."*==!&	 Or<   c                 >   UR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nOYUR                   R                  U R                  S   ;   a'  U R                  S   UR                   R                     nO[        S5      e UR	                  5       n[        U5      nUR                  [        R                  R                  [        R                  R                  [        R                  R                  4;   ah  [        U5      nUR                  [        R                  R                  [        R                  R                  [        R                  R                  4;   a  Mh  U R                  U5      nUR                   R                  U R                  S   ;   a  [        U5      nOzUR                   R                  U R                  S   ;   a  [        U5      nOGUR                   R                  U R                  S   ;   a  [        [        U5      5      nO[        S5      e[!        UR"                  5      R%                  UUS9n U R                  [        W5      5        [)        S5      e! [&         a%    [!        UR"                  5      R%                  US9n NTf = f! [&         a     U$ f = f)aO  Transformation function for Parameter Declaration

Used to create parameter nodes for the required functions for the
respective nodes in the clang AST

Returns
=======

param : Codegen AST Node
    Variable node with the value and type of the variable

Raises
======

ValueError if multiple children encountered in the parameter node

rb   rc   ra   r   r   r   z+Can't handle multiple children on parameter)r   r   rt   r   r   r   r4   r   r   r   TEMPLATE_REFr   r   r	   r-   ra   r   rQ   r   r   
ValueError)r8   r   r   r   r   litr   r   s           r9   transform_parm_decl"CCodeConverter.transform_parm_decl  s   $ yy~~!1!1%!88''.tyy~~>4#3#3G#<<''0@4#3#3F#;;''/		?) +. / /!,,.X jjS^^%A%A%(^^%<%<%(^^%@%@%B B !NE jjS^^%A%A%(^^%<%<%(^^%@%@%B B nnU+99>>T%5%5e%<<!#,CYY^^t'7'7'@@*CYY^^t'7'7'??!$s),C- /2 3 3 !MM . !  tH~. !NOO !  MM . !   ! Ls,   7CK C!K 7%L ,L
L
LLc                      [        UR                  5       5      R                  n[        U5      $ ! [         a    UR                  n N#f = f)aH  Transformation function for integer literal

Used to get the value and type of the given integer literal.

Returns
=======

val : list
    List with two arguments type and Value
    type contains the type of the integer
    value contains the value stored in the variable

Notes
=====

Only Base Integer type supported for now

)r   r   rQ   r   literalrb   r8   r   r   s      r9   transform_integer_literal(CCodeConverter.transform_integer_literal  sD    &%T__./88 u: ! %%s   #0 A	A	c                      [        UR                  5       5      R                  n[        U5      $ ! [        [        4 a    UR
                  n N)f = f)aB  Transformation function for floating literal

Used to get the value and type of the given floating literal.

Returns
=======

val : list
    List with two arguments type and Value
    type contains the type of float
    value contains the value stored in the variable

Notes
=====

Only Base Float type supported for now

)r   r   rQ   r   r   r   rc   r   s      r9   transform_floating_literal)CCodeConverter.transform_floating_literal  sI    &%T__./88 < ":. %%s   #0 AAc                     g r   r[   r8   r   s     r9   transform_string_literal'CCodeConverter.transform_string_literal  s     r<   c                      [        UR                  5       5      R                  n[        [        US   5      5      $ ! [        [        4 a    UR
                  n N5f = f)a5  Transformation function for character literal

Used to get the value of the given character literal.

Returns
=======

val : int
    val contains the ascii value of the character literal

Notes
=====

Only for cases where character is assigned to a integer value,
since character literal is not in SymPy AST

rF   )r   r   rQ   r   r   r   ordr   r   s      r9   transform_character_literal*CCodeConverter.transform_character_literal  sR    $%T__./88 s58}%% ":. %%s   #< AAc                      [        UR                  5       5      R                  nUS:X  a  S$ S$ ! [        [        4 a    UR
                  n N(f = f)zTransformation function for boolean literal

Used to get the value of the given boolean literal.

Returns
=======

value : bool
    value contains the boolean value of the variable

r/   TF)r   r   rQ   r   r   r   r   s      r9   transform_cxx_bool_literal_expr.CCodeConverter.transform_cxx_bool_literal_expr,  sP    %T__./88 !F?455 ":. %%s   #/ AAc                     g)z2Transformation function for unexposed declarationsNr[   r   s     r9   transform_unexposed_decl'CCodeConverter.transform_unexposed_decl>  s    r<   c                      UR                  5       nU R                  [        U5      5      n [        U5        [	        S5      e! [         a     gf = f! [         a     U$ f = f)aV  Transformation function for unexposed expression

Unexposed expressions are used to wrap float, double literals and
expressions

Returns
=======

expr : Codegen AST Node
    the result from the wrapped expression

None : NoneType
    No children are found for the node

Raises
======

ValueError if the expression contains multiple children

Nz&Unexposed expression has > 1 children.r   r   r   r   r   )r8   r   r   exprs       r9   transform_unexposed_expr'CCodeConverter.transform_unexposed_exprB  sk    .,,.~~d8n5X !IJJ !  ! Ks"   *A A 
AA
A! A!c                     UR                   $ )z-Returns the name of the declaration referencer   r   s     r9   transform_decl_ref_expr&CCodeConverter.transform_decl_ref_exprg  s    == r<   c                    / nUR                  5       n[        U5      nUR                  [        R                  R
                  :X  a5  [        U5      nUR                  [        R                  R
                  :X  a  M5  UR                  [        R                  R                  :X  a5  [        U5      nUR                  [        R                  R                  :X  a  M5  U R                  U5      n U H  nU R                  U5      nUR                  [        R                  R                  :X  a  UR                  [        U5      5        MX  UR                  [        R                  R                  :X  a  UR                  [        U5      5        M  UR                  U5        M     [        XR5      $ ! [         a    [        U5      s $ f = f)zTransformation function for a call expression

Used to create function call nodes for the function calls present
in the C code

Returns
=======

FunctionCall : Codegen AST Node
    FunctionCall node with parameters if any parameters are present

)r   r   r   r4   r   r   r   r   r   r   r   r   r	   r   r   )r8   r   r   r   r   first_childargs          r9   transform_call_expr"CCodeConverter.transform_call_exprk  s:    E((*HNE** < <<X ** < <<** 7 77X ** 7 77 ../K1%E../CzzS^^%C%CCWS\2s~~'F'FFU3Z0S) & $K77  1#K001s   *B=F( (G ?G c                 Z    [        [        UR                  5       5      R                  5      $ )z.Returns the Return Node for a return statement)r   r   r   rQ   r   s     r9   transform_return_stmt$CCodeConverter.transform_return_stmt  s!    $t0023<<==r<   c                 |    / nUR                  5       nU H#  nUR                  U R                  U5      5        M%     U$ )zTransformation function for compound statements

Returns
=======

expr : list
    list of Nodes for the expressions present in the statement

None : NoneType
    if the compound statement is empty

)r   r   r   )r8   r   r   r   r   s        r9   transform_compound_stmt&CCodeConverter.transform_compound_stmt  s;     D((*H!DNN512 "Kr<   c                      UR                  5       nU R                  [        U5      5      n U R                  [        W5      5        [	        S5      e! [         a     N2f = f! [         a     W$ f = f)a  Transformation function for declaration statements

These statements are used to wrap different kinds of declararions
like variable or function declaration
The function calls the transformer function for the child of the
given node

Returns
=======

statement : Codegen AST Node
    contains the node returned by the children node for the type of
    declaration

Raises
======

ValueError if multiple children present

z,Don't know how to handle multiple statementsr   )r8   r   r   	statements       r9   transform_decl_stmt"CCodeConverter.transform_decl_stmt  su    *,,. NN4>:	tH~. !OPP !  ! s"   *A %A" 
AA"
A0/A0c                 R    U R                  [        UR                  5       5      5      $ )zcTransformation function for Parenthesized expressions

Returns the result from its children nodes

)r   r   r   r   s     r9   transform_paren_expr#CCodeConverter.transform_paren_expr  s!     >>$t'8'8':";<<r<   c                 $    U R                  U5      $ )aG  Transformation function for handling shorthand operators

Returns
=======

augmented_assignment_expression: Codegen AST node
        shorthand assignment expression represented as Codegen AST

Raises
======

NotImplementedError
    If the shorthand operator for bitwise operators
    (~=, ^=, &=, |=, <<=, >>=) is encountered

)transform_binary_operatorr   s     r9   &transform_compound_assignment_operator5CCodeConverter.transform_compound_assignment_operator  s    " 11$77r<   c                 J   / SQn[        UR                  5       5      nUS   R                  U;   Ga^  U R                  [	        UR                  5       5      5      n[        U[        5      (       a  US   R                  S:X  a  [        U5      $ US   R                  S:X  a  [        [        U5      S5      $ US   R                  S:X  a  [        [        U5      5      $ US   R                  S:X  a  [        [        U5      5      $ US   R                  S:X  a  [        [        U5      5      $ gUS   R                  S:X  a  U$ US   R                  S:X  a  [        US5      $ US   R                  S:X  a  [        [        [        U5      5      5      $ gUS	   R                  S
;   aw  U R                  [	        UR                  5       5      5      nUS	   R                  S:X  a  [        [        U5      5      $ US	   R                  S:X  a  [!        [        U5      5      $ g[#        S5      e)a2  Transformation function for handling unary operators

Returns
=======

unary_expression: Codegen AST node
        simplified unary expression represented as Codegen AST

Raises
======

NotImplementedError
    If dereferencing operator(*), address operator(&) or
    bitwise NOT operator(~) is encountered

)+-++--!r   r  r  r  r  r  rF   )r  r  z`Dereferencing operator, Address operator and bitwise NOT operator have not been implemented yet!N)listr   rQ   r   r   r   r   r   r,   r%   r!   r   r*   r-   ra   r"   r    r   )r8   r   operators_listtokensr   s        r9   transform_unary_operator'CCodeConverter.transform_unary_operator  s   $ 9N$//+,F ay!!^3tD,=,=,?'@AeS))ay))S0%e},ay))S0"6%="55ay))T1+F5M::ay))T1+F5M::ay))S0"6%=11 1 ay))S0$ay))S0"5"~-ay))S0"74;#788 1
 ##|3tD,=,=,?'@A!9%%-(77!9%%-(77 . * +5 6 6r<   c                 2   [        UR                  5       5      n/ SQn/ n/ nU GHm  nUR                  [        R                  R
                  :X  Ga7  UR                  S:X  a  UR                  S5        MP  UR                  S:X  a  U(       a  US   S:w  a}  [        U5      S:  a  [        S5      eUR                  5       nUR                  5       nUR                  5       n	UR                  U R                  XU	5      5        U(       a  US   S:w  a  M}  UR                  5         M  UR                  U;   a  U(       a  U R                  UR                  5      U R                  US   5      ::  a  [        U5      S:  a  [        S5      eUR                  5       nUR                  5       nUR                  5       n	UR                  U R                  XU	5      5        U(       a3  U R                  UR                  5      U R                  US   5      ::  a  M  UR                  UR                  5        GM
  UR                  S;   a  [        S5      eUR                  S	;   a  [        S
5      e[        SR                  UR                  5      5      eUR                  [        R                  R                  :X  a   UR                  UR                  S/5        GM  UR                  [        R                  R                  :X  a   UR                  UR                  S/5        GM  UR                  [        R                  R                   :X  a0  UR                  S;   a   UR                  UR                  S/5        GML  [        SR                  UR                  5      5      e   U(       at  [        U5      S:  a  [        S5      eUR                  5       nUR                  5       nUR                  5       n	UR                  U R                  XU	5      5        U(       a  Mt  US   S   $ )aJ  Transformation function for handling binary operators

Returns
=======

binary_expression: Codegen AST node
        simplified binary expression represented as Codegen AST

Raises
======

NotImplementedError
    If a bitwise operator or
    unary operator(which is a child of any binary
    operator in Clang AST) is encountered

)r  r  */%=>>=<<===!=&&||+=-=*=/=%=(r   r  rE   zCUnary operators as a part of binary operators is not supported yet!)&|^z<<z>>z.Bitwise operator has not been implemented yet!)z&=z|=z^=z<<=z>>=z8Shorthand bitwise operator has not been implemented yet!z&Given token {} is not implemented yet!
identifierr   )r/   r.   booleanr   )r  r   r   r4   	TokenKindPUNCTUATIONrQ   r   lenr   popperform_operationpriority_ofr   
IDENTIFIERLITERALKEYWORD)
r8   r   r  r  combined_variables_stackoperators_stacktokenrhslhsoperators
             r9   r  (CCodeConverter.transform_binary_operator   s   ( $//+,FN (*$ !O   ::!:!:: ~~,'..s33.  / / 3s :"#;<q@&9%5'6 !6 #;">">"@C":">">"@C'6':':'<H4;; $ 6 6 #(!45  / / 3s : (++- >9. $ 0 0 @#//+B/ 1!1  ##;<q@&9%5'6 !6 #;">">"@C":">">"@C'6':':'<H4;; $ 6 6 #(!45  / $ 0 0 @#//+B/ 1!1  (..u~~> +FF1/0 0
  , 1/0 0 2D#VENN35 5
 ZZ3==#;#;;,3368 ZZ3==#8#88,3335 jjCMM$9$99*;;,3335 .@/1 1i  r "/014-)* * /224.224*..0(//**3X>@ "/ ,B/22r<   c                 J    US;   a  gUS;   a  gUS;   a  gUS;   a  gUS	;   a  g
g)z%To get the priority of given operator)r$  r-  r.  r/  r0  r1  rF   )r+  r,  rE   r'  r(  r%  r&  r)  r*  rD   )r  r  rC   )r!  r"  r#     r   r[   )r8   ops     r9   r=  CCodeConverter.priority_of  s>    88\!77Z_$r<   c           	      l   U R                  U5      nU R                  U5      nUS:X  a  [        XE5      S/$ US:X  a  [        XE* 5      S/$ US:X  a  [        XE5      S/$ US:X  a!  [        U[        U[	        S5      5      5      S/$ US:X  a  [        XE5      S/$ US;   a  [        XEU5      S/$ US	:X  a   [        [        U5      [        U5      5      S/$ US
:X  a   [        [        U5      [        U5      5      S/$ US:X  a  [        [        U5      U5      S/$ US;   a  [        [        U5      US   U5      S/$ g)zPerforms operation supported by the SymPy core

Returns
=======

combined_variable: list
    contains variable content and type of variable

r  r   r  r!  r"  r  r#  rI  r+  r,  r$  )r-  r.  r/  r0  r1  r   N)get_expr_for_operandr#   r%   r&   r   r$   r'   r(   r)   r+   r   r   r   )r8   rE  rD  rK  	lhs_value	rhs_values         r9   r<   CCodeConverter.perform_operation  sP    11#6I11#6ISyI16::SyIz2F;;SyI16::SyIs9gbk'BCVLLSyI16::77I"5v>>TzJy1:i3HI6RRTz:i0*Y2GH&QQSy"8I#6	BFKK33"8I#61yI6RR 4r<   c                 
   US   S:X  a  [        US   5      $ US   S:X  a7  SUS   ;   a  [        [        US   5      5      $ [        [	        US   5      5      $ US   S:X  a  US   $ US   S:X  a  US   S:X  a  [
        $ [        $ g	)
zGives out SymPy Codegen AST node

AST node returned is corresponding to
combined variable passed.Combined variable contains
variable content and type of variable

rF   r6  r   r   .r   r7  r/   N)r,   r	   rc   r   rb   r/   r.   )r8   combined_variables     r9   rN  #CCodeConverter.get_expr_for_operand  s     !#|3/233 #y0+A.. '8';!<=="3'8';#<== #v-(++ #y0#4Q#76#A4LuL 1r<   c                     [         $ )z'Handles Null Statement and returns None)r   r   s     r9   transform_null_stmt"CCodeConverter.transform_null_stmt  s    Kr<   c                     UR                  5       nU R                  [        U5      5      nU R                  [        U5      5      n[        U[        5      (       a	  [        U6 nO[        U5      n[        X55      $ )zTransformation function for handling while statement

Returns
=======

while statement : Codegen AST Node
    contains the while statement node having condition and
    statement block

)r   r   r   r   r  r   r   )r8   r   r   	condition
statementsstatement_blocks         r9   transform_while_stmt#CCodeConverter.transform_while_stmt  sb     ((*HtH~6IX7J*d++"+Z"8"+J"744r<   )rt   re   rJ   )#rU   rV   rW   rX   rY   r:   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r=  r<  rN  rW  r]  rZ   __classcell__)ru   s   @r9   r]   r]   U   s    		8"	"H&	"P	!6t	l6	pD	L	4	 4
		&2	6$	#	J	!#	1J	>	(!	F	=	8&8	6tI	3V		SB	M(		5 	5r<   r]   c                       \ rS rSrS rSrg)r]   i  c                     [        S5      e)NzModule not Installed)ImportError)r8   ry   kwargss      r9   r:   rv     s    455r<   r[   N)rU   rV   rW   rX   r:   rZ   r[   r<   r9   r]   r]     s    	6r<   c                     [        5       n[        R                  R                  U 5      (       a  UR	                  U / S9nU$ UR                  U / S9nU$ )zFunction for converting a C source code

The function reads the source code present in the given file and parses it
to give out SymPy Expressions

Returns
=======

src : list
    List of Python expression strings

)r   )r]   r{   r|   existsr~   r   )r   	convertersrcs      r9   parse_crh    sT      I	ww~~foofbo1 J !!&"!5Jr<   )8sympy.externalr   r{   r4   sympy.codegen.astr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   sympy.codegen.cnodesr   r    r!   r"   
sympy.corer#   r$   r%   r&   r'   sympy.logic.boolalgr(   r)   r*   r+   sympy.core.symbolr,   sympy.core.sympifyr-   r.   r/   r   r   r1   r]   rh  r[   r<   r9   <module>rp     s    ( 	NZ(4LM$L - - - - - - -
% %22<<(*1! !2r5 r5n6 6
r<   