How to use the pyccel.parser.syntax.basic.BasicStmt function in pyccel

To help you get started, we’ve selected a few pyccel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyccel / pyccel / src_old / syntax_core.py View on Github external
fil = str(names[0])
            else:
                names = [str(n) for n in names]
                fil = DottedName(*names)
        elif isinstance(names, str):
            fil = str(names)

        funcs = self.import_as_names
        if isinstance(funcs, ImportAsNames):
            funcs = funcs.names
        if not isinstance(funcs, (tuple, list)):
            funcs = str(funcs) # cast unicode to str

        return Import(fil, funcs)

class ImportAsNames(BasicStmt):
    """class representing import as names in the grammar."""

    def __init__(self, **kwargs):
        """
        Constructor

        names: str
            list of names
        """
        self.names = kwargs.pop('names')

        super(ImportAsNames, self).__init__(**kwargs)

class CallStmt(BasicStmt):
    """Class representing the call to a function in the grammar."""
github pyccel / pyccel / pyccel / parser / syntax / openmp.py View on Github external
"""Class representing a ."""
    def __init__(self, **kwargs):
        """
        """
        self.status = kwargs.pop('status')

        super(OmpDefault, self).__init__(**kwargs)

    @property
    def expr(self):
        if DEBUG:
            print("> OmpDefault: expr")

        return 'default({})'.format(self.status)

class OmpProcBind(BasicStmt):
    """Class representing a ."""
    def __init__(self, **kwargs):
        """
        """
        self.status = kwargs.pop('status')

        super(OmpProcBind, self).__init__(**kwargs)

    @property
    def expr(self):
        if DEBUG:
            print("> OmpProcBind: expr")

        return 'proc_bind({})'.format(self.status)

class OmpPrivate(BasicStmt):
github pyccel / pyccel / src_old / syntax_core.py View on Github external
self.test = kwargs.pop('test')

        super(AssertStmt, self).__init__(**kwargs)

    @property
    def expr(self):
        """
        Process the If statement by returning a pyccel.ast.core object
        """
        self.update()
        test = self.test.expr

        return Assert(test)


class IfStmt(BasicStmt):
    """Class representing an If statement."""

    def __init__(self, **kwargs):
        """
        Constructor for the If statement class.

        body_true: list
            statements tree as given by the textX, for the true block (if)
        body_false: list
            statements tree as given by the textX, for the false block (else)
        body_elif: list
            statements tree as given by the textX, for the elif blocks
        test: Test
            represents the condition for the If statement.
        """
        self.body_true  = kwargs.pop('body_true')
github pyccel / pyccel / src_old / syntax_core.py View on Github external
self.key   = kwargs.pop('key', None)
        self.value = kwargs.pop('value')

        super(ArgValued, self).__init__(**kwargs)

    @property
    def expr(self):
        key   = self.key
        value = self.value.expr
        if key:
            return {'key': key, 'value': value}
        else:
            return value


class FlowStmt(BasicStmt):
    """Base class representing a Flow statement in the grammar."""

    def __init__(self, **kwargs):
        """
        Constructor for a Flow statement

        label: str
            name of the flow statement.
            One among {'break', 'continue', 'return', 'raise', 'yield'}
        """
        self.label = kwargs.pop('label')

class BreakStmt(FlowStmt):
    """Base class representing a Break statement in the grammar."""
    def __init__(self, **kwargs):
        super(BreakStmt, self).__init__(**kwargs)
github pyccel / pyccel / src_old / syntax_core.py View on Github external
Process the With statement by returning a pyccel.ast.core object
        """
        self.update()

        domain = self.domain.expr

        if not (isinstance(domain, (Variable, ConstructorCall))):
            if not(domain in namespace):
                raise ValueError('undefined {0} domain'.format(domain))

        body = self.body.expr
        settings = None

        return With(domain, body, settings)

class WhileStmt(BasicStmt):
    """Class representing a While statement."""

    def __init__(self, **kwargs):
        """
        Constructor for the While statement.

        test: Test
            a test expression
        body: list
            a list of statements for the body of the While statement.
        """
        self.test = kwargs.pop('test')
        self.body = kwargs.pop('body')

        super(WhileStmt, self).__init__(**kwargs)
github pyccel / pyccel / pyccel / parser / syntax / headers.py View on Github external
if d_var['rank']>1:
            d_var['order'] = order
        return d_var

class TypeHeader(BasicStmt):
    pass

class StringStmt(BasicStmt):
    def __init__(self, **kwargs):
       self.arg = kwargs.pop('arg')
    @property
    def expr(self):
        return String(repr(str(self.arg)))

class UnionTypeStmt(BasicStmt):
    def __init__(self, **kwargs):
        """
        Constructor for a TypeHeader.

        dtype: list fo str
        """
        self.dtype = kwargs.pop('dtype')

        super(UnionTypeStmt, self).__init__(**kwargs)

    @property
    def expr(self):
        l = []
        for i in self.dtype:
            l += [i.expr]
        if len(l)>1:
github pyccel / pyccel / src_old / syntax_core.py View on Github external
args: list, tuple
            list of elements
        """
        self.args = kwargs.pop('args')

        super(ExpressionList, self).__init__(**kwargs)

    @property
    def expr(self):
        args = [a.expr for a in self.args]
        # TODO use List object from AST
        #return List(*args)
        return Tuple(*args)

class ExpressionDict(BasicStmt):
    """Base class representing a dictionary of elements statement in the grammar."""

    def __init__(self, **kwargs):
        """
        Constructor for a Expression dictionary statement

        args: list, tuple
            list of elements
        """
        self.args = kwargs.pop('args')

        super(ExpressionDict, self).__init__(**kwargs)

    @property
    def expr(self):
        raise NotImplementedError('No fortran backend yet for dictionaries.')
github pyccel / pyccel / pyccel / parser / syntax / openmp.py View on Github external
"""
        """
        self.args = kwargs.pop('args')

        super(OmpLastPrivate, self).__init__(**kwargs)

    @property
    def expr(self):
        if DEBUG:
            print("> OmpLastPrivate: expr")

        # TODO check if variable exist in namespace
        args = ', '.join(str(arg) for arg in self.args)
        return 'lastprivate({})'.format(args)

class OmpCopyin(BasicStmt):
    """Class representing a ."""
    def __init__(self, **kwargs):
        """
        """
        self.args = kwargs.pop('args')

        super(OmpCopyin, self).__init__(**kwargs)

    @property
    def expr(self):
        if DEBUG:
            print("> OmpCopyin: expr")

        # TODO check if variable exist in namespace
        args = ', '.join(str(arg) for arg in self.args)
        return 'copyin({})'.format(args)
github pyccel / pyccel / src_old / syntax_core.py View on Github external
"""
        self.exception = kwargs.pop('exception')

        super(RaiseStmt, self).__init__(**kwargs)

    # TODO finish return Raise
    @property
    def expr(self):
        exception = self.exception.expr
        return Raise()

class YieldStmt(FlowStmt):
    """Base class representing a Yield statement in the grammar."""
    pass

class FunctionDefStmt(BasicStmt):
    """Class representing the definition of a function in the grammar."""

    def __init__(self, **kwargs):
        """
        Constructor for the definition of a function.

        name: str
            name of the function
        args: list
            list of the function arguments
        body: list
            list of statements as given by the parser.
        parent: stmt
            parent statement.
        """
        self.name    = kwargs.pop('name')
github pyccel / pyccel / pyccel / parser / syntax / headers.py View on Github external
name: str

          args: list of function names

          """

          self.name = kwargs.pop('name')
          self.args = kwargs.pop('args')
          super(InterfaceStmt, self).__init__(**kwargs)

      @property
      def expr(self):
          return InterfaceHeader(self.name, self.args)

# ...
class MacroArg(BasicStmt):
    """."""

    def __init__(self, **kwargs):
        """
        """

        self.arg = kwargs.pop('arg')
        self.value = kwargs.pop('value',None)

        super(MacroArg, self).__init__(**kwargs)

    @property
    def expr(self):
        arg_ = self.arg
        if isinstance(arg_, MacroList):
            return Tuple(*arg_.expr)