
    wg"                         d dl mZmZmZ d dlmZ d dlmZ  ed      Z edddgi      Z	erd d	l
mZ e	rd d
lmZ  eddg       G d d             Zy)    )pycodeccodefcode)import_module)doctest_depends_onlfortranzclang.cindexfromlistcindex)import_kwargs)src_to_sympy)parse_c)modulesc                   B     e Zd ZdZd fd	Zd Zd Zd Zd Zd Z	 xZ
S )	SymPyExpressiona'	  Class to store and handle SymPy expressions

    This class will hold SymPy Expressions and handle the API for the
    conversion to and from different languages.

    It works with the C and the Fortran Parser to generate SymPy expressions
    which are stored here and which can be converted to multiple language's
    source code.

    Notes
    =====

    The module and its API are currently under development and experimental
    and can be changed during development.

    The Fortran parser does not support numeric assignments, so all the
    variables have been Initialized to zero.

    The module also depends on external dependencies:

    - LFortran which is required to use the Fortran parser
    - Clang which is required for the C parser

    Examples
    ========

    Example of parsing C code:

    >>> from sympy.parsing.sym_expr import SymPyExpression
    >>> src = '''
    ... int a,b;
    ... float c = 2, d =4;
    ... '''
    >>> a = SymPyExpression(src, 'c')
    >>> a.return_expr()
    [Declaration(Variable(a, type=intc)),
    Declaration(Variable(b, type=intc)),
    Declaration(Variable(c, type=float32, value=2.0)),
    Declaration(Variable(d, type=float32, value=4.0))]

    An example of variable definition:

    >>> from sympy.parsing.sym_expr import SymPyExpression
    >>> src2 = '''
    ... integer :: a, b, c, d
    ... real :: p, q, r, s
    ... '''
    >>> p = SymPyExpression()
    >>> p.convert_to_expr(src2, 'f')
    >>> p.convert_to_c()
    ['int a = 0', 'int b = 0', 'int c = 0', 'int d = 0', 'double p = 0.0', 'double q = 0.0', 'double r = 0.0', 'double s = 0.0']

    An example of Assignment:

    >>> from sympy.parsing.sym_expr import SymPyExpression
    >>> src3 = '''
    ... integer :: a, b, c, d, e
    ... d = a + b - c
    ... e = b * d + c * e / a
    ... '''
    >>> p = SymPyExpression(src3, 'f')
    >>> p.convert_to_python()
    ['a = 0', 'b = 0', 'c = 0', 'd = 0', 'e = 0', 'd = a + b - c', 'e = b*d + c*e/a']

    An example of function definition:

    >>> from sympy.parsing.sym_expr import SymPyExpression
    >>> src = '''
    ... integer function f(a,b)
    ... integer, intent(in) :: a, b
    ... integer :: r
    ... end function
    ... '''
    >>> a = SymPyExpression(src, 'f')
    >>> a.convert_to_python()
    ['def f(a, b):\n   f = 0\n    r = 0\n    return f']

    c                 V   t         |           |s
|sg | _        y|r|ru|j                         dk(  r"t        rt        |      | _        yt        d      |j                         dk(  r"t        rt        |      | _        yt        d      t        d      t        d      t        d      )	z%Constructor for SymPyExpression classf4LFortran is not installed, cannot parse Fortran codec+Clang is not installed, cannot parse C codez0Parser for specified language is not implementedzSource code not presentz$Please specify a mode for conversionN)super__init___exprlowerr   r   ImportErrorcinr   NotImplementedError
ValueError)selfsource_codemode	__class__s      [/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/parsing/sym_expr.pyr   zSymPyExpression.__init__^   s    {DJ::<3&%1+%>
)*`aaZZ\S(%,[%9
)*WXX-J  !!:;;CDD    c                     |j                         dk(  r"t        rt        |      | _        yt	        d      |j                         dk(  r"t
        rt        |      | _        yt	        d      t        d      )ae  Converts the given source code to SymPy Expressions

        Attributes
        ==========

        src_code : String
            the source code or filename of the source code that is to be
            converted

        mode: String
            the mode to determine which parser is to be used according to
            the language of the source code
            f or F for Fortran
            c or C for C/C++

        Examples
        ========

        >>> from sympy.parsing.sym_expr import SymPyExpression
        >>> src3 = '''
        ... integer function f(a,b) result(r)
        ... integer, intent(in) :: a, b
        ... integer :: x
        ... r = a + b -x
        ... end function
        ... '''
        >>> p = SymPyExpression()
        >>> p.convert_to_expr(src3, 'f')
        >>> p.return_expr()
        [FunctionDefinition(integer, name=f, parameters=(Variable(a), Variable(b)), body=CodeBlock(
        Declaration(Variable(r, type=integer, value=0)),
        Declaration(Variable(x, type=integer, value=0)),
        Assignment(Variable(r), a + b - x),
        Return(Variable(r))
        ))]




        r   r   r   r   z6Parser for specified language has not been implementedN)r   r   r   r   r   r   r   r   )r   src_coder    s      r"   convert_to_exprzSymPyExpression.convert_to_exprx   sg    R ::<3)(3
!"XYYZZ\S $X.
!"OPP%H r#   c                     g | _         | j                  D ]&  }| j                   j                  t        |             ( | j                   S )a0  Returns a list with Python code for the SymPy expressions

        Examples
        ========

        >>> from sympy.parsing.sym_expr import SymPyExpression
        >>> src2 = '''
        ... integer :: a, b, c, d
        ... real :: p, q, r, s
        ... c = a/b
        ... d = c/a
        ... s = p/q
        ... r = q/p
        ... '''
        >>> p = SymPyExpression(src2, 'f')
        >>> p.convert_to_python()
        ['a = 0', 'b = 0', 'c = 0', 'd = 0', 'p = 0.0', 'q = 0.0', 'r = 0.0', 's = 0.0', 'c = a/b', 'd = c/a', 's = p/q', 'r = q/p']

        )_pycoder   appendr   r   iters     r"   convert_to_pythonz!SymPyExpression.convert_to_python   s>    ( JJ 	.DLLt-	.||r#   c                     g | _         | j                  D ]&  }| j                   j                  t        |             ( | j                   S )a  Returns a list with the c source code for the SymPy expressions


        Examples
        ========

        >>> from sympy.parsing.sym_expr import SymPyExpression
        >>> src2 = '''
        ... integer :: a, b, c, d
        ... real :: p, q, r, s
        ... c = a/b
        ... d = c/a
        ... s = p/q
        ... r = q/p
        ... '''
        >>> p = SymPyExpression()
        >>> p.convert_to_expr(src2, 'f')
        >>> p.convert_to_c()
        ['int a = 0', 'int b = 0', 'int c = 0', 'int d = 0', 'double p = 0.0', 'double q = 0.0', 'double r = 0.0', 'double s = 0.0', 'c = a/b;', 'd = c/a;', 's = p/q;', 'r = q/p;']

        )_ccoder   r)   r   r*   s     r"   convert_to_czSymPyExpression.convert_to_c   s>    , JJ 	,DKKuT{+	,{{r#   c                     g | _         | j                  D ]&  }| j                   j                  t        |             ( | j                   S )a  Returns a list with the fortran source code for the SymPy expressions

        Examples
        ========

        >>> from sympy.parsing.sym_expr import SymPyExpression
        >>> src2 = '''
        ... integer :: a, b, c, d
        ... real :: p, q, r, s
        ... c = a/b
        ... d = c/a
        ... s = p/q
        ... r = q/p
        ... '''
        >>> p = SymPyExpression(src2, 'f')
        >>> p.convert_to_fortran()
        ['      integer*4 a', '      integer*4 b', '      integer*4 c', '      integer*4 d', '      real*8 p', '      real*8 q', '      real*8 r', '      real*8 s', '      c = a/b', '      d = c/a', '      s = p/q', '      r = q/p']

        )_fcoder   r)   r   r*   s     r"   convert_to_fortranz"SymPyExpression.convert_to_fortran   s>    ( JJ 	,DKKuT{+	,{{r#   c                     | j                   S )a  Returns the expression list

        Examples
        ========

        >>> from sympy.parsing.sym_expr import SymPyExpression
        >>> src3 = '''
        ... integer function f(a,b)
        ... integer, intent(in) :: a, b
        ... integer :: r
        ... r = a+b
        ... f = r
        ... end function
        ... '''
        >>> p = SymPyExpression()
        >>> p.convert_to_expr(src3, 'f')
        >>> p.return_expr()
        [FunctionDefinition(integer, name=f, parameters=(Variable(a), Variable(b)), body=CodeBlock(
        Declaration(Variable(f, type=integer, value=0)),
        Declaration(Variable(r, type=integer, value=0)),
        Assignment(Variable(f), Variable(r)),
        Return(Variable(f))
        ))]

        )r   )r   s    r"   return_exprzSymPyExpression.return_expr   s    4 zzr#   )NN)__name__
__module____qualname____doc__r   r&   r,   r/   r2   r4   __classcell__)r!   s   @r"   r   r      s*    M^E46p262r#   r   N)sympy.printingr   r   r   sympy.externalr   sympy.utilities.decoratorr   r   r   $sympy.parsing.fortran.fortran_parserr   sympy.parsing.c.c_parserr   r    r#   r"   <module>r@      s^    / / ( 8$NZ(4LMA0Z89I I :Ir#   