pyccel.parser package

Submodules

pyccel.parser.errors module

class pyccel.parser.errors.ErrorInfo(filename, line=None, column=None, severity=None, message='', symbol=None, blocker=False)[source]

Representation of a single error message.

pyccel.parser.errors.Errors()[source]
pyccel.parser.errors.ErrorsMode()[source]
exception pyccel.parser.errors.PyccelCodegenError[source]

Bases: exceptions.Exception

exception pyccel.parser.errors.PyccelError(message, errors='')[source]

Bases: exceptions.Exception

exception pyccel.parser.errors.PyccelSemanticError[source]

Bases: exceptions.Exception

exception pyccel.parser.errors.PyccelSyntaxError[source]

Bases: exceptions.Exception

pyccel.parser.errors.make_symbol(s)[source]

pyccel.parser.messages module

pyccel.parser.parser module

class pyccel.parser.parser.Parser(inputs, debug=False, headers=None, static=None, show_traceback=True, output_folder='', context_import_path={})[source]

Bases: object

Class for a Parser.

annotate(**settings)[source]

.

append_parent(parent)[source]

.

append_son(son)[source]

.

ast
blocking
bounding_box
classes
code
create_variable(expr, store=False)[source]

.

current_class
d_parsers

Returns the d_parsers parser.

dot(filename)[source]

Exports sympy AST using graphviz then convert it to an image.

dump(filename=None)[source]

Dump the current ast using Pickle.

filename: str
output file name. if not given name.pyccel will be used and placed in the Pyccel directory ($HOME/.pyccel)
filename
fst
functions
get_class(name)[source]

.

get_class_construct(name)[source]

Returns the class datatype for name.

get_function(name)[source]

.

get_header(name)[source]

.

get_macro(name)[source]

.

get_python_function(name)[source]

.

get_symbolic_function(name)[source]

.

get_variable(name)[source]

.

get_variables(source=None)[source]
headers
imports
insert_class(cls)[source]

.

insert_function(func)[source]

.

insert_header(expr)[source]

.

insert_import(expr)[source]

.

insert_macro(macro)[source]

.

insert_python_function(func)[source]

.

insert_symbolic_function(func)[source]

.

insert_variable(expr, name=None)[source]

.

is_header_file

Returns True if we are treating a header file.

load(filename=None)[source]

Load the current ast using Pickle.

filename: str
output file name. if not given name.pyccel will be used and placed in the Pyccel directory ($HOME/.pyccel)
macros
metavars
namespace
parents

Returns the parents parser.

parse(d_parsers=None, verbose=False)[source]

converts redbaron fst to sympy ast.

print_namespace()[source]
python_functions
remove_variable(name)[source]

.

semantic_done
set_class_construct(name, value)[source]

Sets the class datatype for name.

set_current_fun(name)[source]

.

show_traceback
sons

Returns the sons parser.

static_functions
symbolic_functions
syntax_done
update_variable(var, **options)[source]

.

variables
view_namespace(entry)[source]
class pyccel.parser.parser.PyccelParser(inputs, debug=False, headers=None, static=None, show_traceback=True, output_folder='', context_import_path={})[source]

Bases: pyccel.parser.parser.Parser

pyccel.parser.parser.get_filename_from_import(module, output_folder='', context_import_path={})[source]

Returns a valid filename with absolute path, that corresponds to the definition of module. The priority order is:

  • header files (extension == pyh)
  • python files (extension == py)
pyccel.parser.parser.is_ignored_module(name)[source]

pyccel.parser.utilities module

pyccel.parser.utilities.acc_statement(x)
pyccel.parser.utilities.accelerator_statement(stmt, accel)[source]

Returns stmt if an accelerator statement. otherwise it returns None. this function can be used as the following >>> if accelerator_statement(stmt, ‘omp’):

# do stuff …

In general you can use the functions omp_statement and acc_statement

pyccel.parser.utilities.fst_move_directives(x)[source]
This function moves OpenMP/OpenAcc directives from loop statements to

their appropriate parent. This function will have inplace effect. In order to understand why it is needed, let’s take a look at the following exampe

>>> code = '''
... #$ omp do schedule(runtime)
... for i in range(0, n):
...     for j in range(0, m):
...         a[i,j] = i-j
... #$ omp end do nowait
... '''
>>> from redbaron import RedBaron
>>> red = RedBaron(code)
>>> red
0   '

1 #$ omp do schedule(runtime) 2 for i in range(0, n):

for j in range(0, m):
a[i,j] = i-j

#$ omp end do nowait

As you can see, the statement #$ omp end do nowait is inside the For statement, while we would like to have it outside. Now, let’s apply our function

>>> fst_move_directives(red)
0   #$ omp do schedule(runtime)
1   for i in range(0, n):
        for j in range(0, m):
            a[i,j] = i-j
2   #$ omp end do nowait
pyccel.parser.utilities.get_comments(y)
pyccel.parser.utilities.get_default_path(name)[source]

this function takes a an import name and returns the path full bash of the library if the library is in stdlib

pyccel.parser.utilities.get_defs(y)
pyccel.parser.utilities.get_ifblocks(y)
pyccel.parser.utilities.get_ifs(y)
pyccel.parser.utilities.get_loops(y)
pyccel.parser.utilities.get_withs(y)
pyccel.parser.utilities.header_statement(stmt, accel)[source]

Returns stmt if a header statement. otherwise it returns None. this function can be used as the following >>> if header_statement(stmt):

# do stuff …
pyccel.parser.utilities.is_valid_filename_py(filename)[source]

Returns True if filename is an existing python file.

pyccel.parser.utilities.is_valid_filename_pyh(filename)[source]

Returns True if filename is an existing pyccel header file.

pyccel.parser.utilities.omp_statement(x)
pyccel.parser.utilities.read_file(filename)[source]

Returns the source code from a filename.

pyccel.parser.utilities.reconstruct_pragma_multilines(header)[source]

Must be called once we visit an annotated comment, to get the remaining parts of a statement written on multiple lines.

pyccel.parser.utilities.view_tree(expr)[source]

Views a sympy expression tree.

Module contents