Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# rename the method in the class case
# TODO do we keep this?
f_name = name
cls_name = None
if cls_instance:
f_name = name.split('.')[-1]
cls_name = name.split('.')[0]
stmt = FunctionDef(f_name, args, results, body, \
local_vars, global_vars, \
cls_name=cls_name)
namespace[name] = stmt
# print "*********** FunctionDefStmt.expr: End"
return stmt
class ClassDefStmt(BasicStmt):
"""Class representing the definition of a class in the grammar."""
def __init__(self, **kwargs):
"""
Constructor for the definition of a class.
We only allow for single inheritence, to match with Fortran specs.
name: str
name of the class
base: list
base class
body: list
list of statements as given by the parser.
"""
self.name = kwargs.pop('name')
self.base = kwargs.pop('base')
# print ">>>> MultiAssignStmt : ", var_name
# print " : ", d_var
d_var['allocatable'] = not(d_var['shape'] is None)
insert_variable(var_name, **d_var)
return MultiAssign(lhs, rhs)
# if name == 'shape':
# if not(len(args) == 1):
# raise ValueError('shape takes only one argument.')
# return Shape(lhs, args[0])
# else:
# return MultiAssign(lhs, rhs, args)
class RangeStmt(BasicStmt):
"""Class representing a Range statement."""
def __init__(self, **kwargs):
"""
Constructor for the Range statement.
start: str
start index
end: str
end index
step: str
step for the iterable. if not given, 1 will be used.
"""
self.start = kwargs.pop('start')
self.end = kwargs.pop('end')
self.step = kwargs.pop('step', None)
def expr(self):
"""
Process the Stencil statement,
by returning the appropriate object from pyccel.types.ast
"""
self.update()
shape = self.shape
step = self.step
var_name = self.lhs
var = Symbol(var_name)
return Stencil(var, shape, step)
class EvalStmt(BasicStmt):
"""
Class representing an Eval statement in the grammar
"""
def __init__(self, **kwargs):
"""
Constructor for a eval statement.
lhs: str
variable name to create
expression: str
Expression to be evaluated
"""
self.lhs = kwargs.pop('lhs')
self.expression = kwargs.pop('expression')
super(EvalStmt, self).__init__(**kwargs)
if isinstance(name, (list, tuple)):
name = '{0}.{1}'.format(name[0], name[1])
if name in namespace:
ls.append(namespace[name])
else:
raise Exception('Unknown variable {}'.format(name))
elif isinstance(var, Tensor):
ls.append(var)
else:
raise NotImplementedError('Only Variable is trated')
self.update()
return Del(ls)
class SyncStmt(BasicStmt):
"""Class representing a sync statement."""
def __init__(self, **kwargs):
"""
Constructor for the Sync statement class.
variables: list of str
variables to delete
"""
self.variables = kwargs.pop('variables')
self.trailer = kwargs.pop('trailer', None)
super(SyncStmt, self).__init__(**kwargs)
@property
def expr(self):
elif operation == ">":
ret = Gt(ret, operand.expr)
elif operation == ">=":
ret = Ge(ret, operand.expr)
elif operation == "<":
ret = Lt(ret, operand.expr)
elif operation == "<=":
ret = Le(ret, operand.expr)
elif operation == "<>":
ret = Ne(ret, operand.expr)
else:
raise Exception('operation not yet available at position {}'
.format(self._tx_position))
return ret
class ExpressionList(BasicStmt):
"""Base class representing a list of elements statement in the grammar."""
def __init__(self, **kwargs):
"""
Constructor for a Expression list statement
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]
parent: ArithmeticExpression
parent ArithmeticExpression
op:
attribut in the ArithmeticExpression (see the grammar)
"""
# textX will pass in parent attribute used for parent-child
# relationships. We can use it if we want to.
self.parent = kwargs.get('parent', None)
# We have 'op' attribute in all grammar rules
self.op = kwargs['op']
super(ExpressionElement, self).__init__()
class FactorSigned(ExpressionElement, BasicStmt):
"""Class representing a signed factor."""
def __init__(self, **kwargs):
"""
Constructor for a signed factor.
sign: str
one among {'+', '-'}
"""
self.sign = kwargs.pop('sign', '+')
super(FactorSigned, self).__init__(**kwargs)
@property
def expr(self):
"""
Constructor of the Trailer
"""
super(TrailerDots, self).__init__(**kwargs)
@property
def expr(self):
"""
Process a Trailer by returning the approriate objects from
pyccel.types.ast
"""
self.update()
# args is not a list
return self.args
# return [arg.expr for arg in self.args]
class BasicSlice(BasicStmt):
"""Base class representing a Slice in the grammar."""
def __init__(self, **kwargs):
"""
Constructor for the base slice.
The general form of slices is 'a:b'
start: str, int, ArithmeticExpression
Starting index of the slice.
end: str, int, ArithmeticExpression
Ending index of the slice.
"""
self.start = kwargs.pop('start', None)
self.end = kwargs.pop('end', None)
super(BasicSlice, self).__init__(**kwargs)
"""
Process the If statement by returning a pyccel.types.ast object
"""
self.update()
args = [(self.test.expr, self.body_true.expr)]
if not self.body_elif==None:
for elif_block in self.body_elif:
args.append((elif_block.test.expr, elif_block.body.expr))
if not self.body_false==None:
args.append((True, self.body_false.expr))
return If(*args)
class AssignStmt(BasicStmt):
"""Class representing an assign statement."""
def __init__(self, **kwargs):
"""
Constructor for the Assign statement.
lhs: str
variable to assign to
rhs: ArithmeticExpression
expression to assign to the lhs
trailer: Trailer
a trailer is used for a function call or Array indexing.
"""
self.lhs = kwargs.pop('lhs')
self.rhs = kwargs.pop('rhs')
self.trailer = kwargs.pop('trailer', None)
s = set(ls)
return list(s)
@property
def expr(self):
"""
Process the Suite statement,
by returning a list of appropriate objects from pyccel.types.ast
"""
# print "local_vars = ", self.local_vars
# print "stmt_vars = ", self.stmt_vars
self.update()
ls = [stmt.expr for stmt in self.stmts]
return ls
class BasicTrailer(BasicStmt):
"""Base class representing a Trailer in the grammar."""
def __init__(self, **kwargs):
"""
Constructor for a Base Trailer.
args: list or ArgList
arguments of the trailer
"""
self.args = kwargs.pop('args', None)
super(BasicTrailer, self).__init__(**kwargs)
class Trailer(BasicTrailer):
"""Class representing a Trailer in the grammar."""
def __init__(self, **kwargs):
"""
label must be equal to 'pass'
"""
self.label = kwargs.pop('label')
super(PassStmt, self).__init__(**kwargs)
@property
def expr(self):
"""
Process the Delete statement by returning a pyccel.types.ast object
"""
self.update()
return self.label
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')