pyccel.codegen.printing.codeprinter module#
Module containing the base class CodePrinter from which all code printers inherit. The sub-classes should define a language and _print_X functions. The CodePrinter class also contains some general functionality which may be used by all code printers, such as the management of imports and the current scope.
- class pyccel.codegen.printing.codeprinter.CodePrinter(verbose)[source]View on GitHub#
Bases:
objectThe base class for code-printing subclasses.
The base class from which code printers inherit. The sub-classes should define a language and _print_X functions.
- Parameters:
verbose (int) – The level of verbosity.
- add_import(import_obj)[source]View on GitHub#
Add a new import to the current context.
Add a new import to the current context. This allows the import to be recognised at the compiling/linking stage. If the source of the import is not new then any new targets are added to the Import object.
- Parameters:
import_obj (Import) – The AST node describing the import.
- doprint(expr)[source]View on GitHub#
Print the expression as code.
Print the expression as code.
- Parameters:
expr (Expression) – The expression to be printed.
- Returns:
The generated code.
- Return type:
str
- exit_scope()[source]View on GitHub#
Exit the current scope and return to the enclosing scope
- get_additional_imports()[source]View on GitHub#
Get any additional imports collected during the printing stage.
Get any additional imports collected during the printing stage. This is necessary to correctly compile the files.
- Returns:
A dictionary mapping the include strings to the import module.
- Return type:
dict[str, Import]
- language = None#
- property scopeView on GitHub#
Return the scope associated with the object being printed
- set_scope(scope)[source]View on GitHub#
Change the current scope