pyccel.ast.bind_c module#
Module describing all elements of the AST needed to represent elements which appear in a Fortran-C binding file.
- class pyccel.ast.bind_c.BindCArrayType(self, rank, has_strides)[source]#
Bases:
InhomogeneousTupleType
Datatype for a tuple containing all the information necessary to describe an array.
Datatype for a tuple containing a pointer to array data and integers describing their shape and strides.
- Parameters:
rank (int) – The rank of the array being described.
has_strides (bool) – Indicates whether strides are used to describe the array.
- class pyccel.ast.bind_c.BindCArrayVariable(*args, wrapper_function, original_variable, **kwargs)[source]#
Bases:
Variable
A class which wraps an array from Fortran to make it available in C.
A class which wraps an array from Fortran to make it available in C.
- Parameters:
*args (tuple) – See Variable.
wrapper_function (FunctionDef) – The function which can be used to access the array.
original_variable (Variable) – The original variable in the Fortran code.
**kwargs (dict) – See Variable.
See also
Variable
The super class.
- property original_variable#
The original variable in the Fortran code.
The original variable in the Fortran code. This is important in order to access the correct type and other details about the Variable.
- property wrapper_function#
The function which can be used to access the array.
The function which can be used to access the array. The function must return the pointer to the raw data and information about the shape.
- class pyccel.ast.bind_c.BindCClassDef(original_class, new_func, **kwargs)[source]#
Bases:
ClassDef
Represents a class which is compatible with C.
Represents a class which is compatible with C. This means that it stores C-compatible versions of class methods and getters and setters for class variables.
- Parameters:
original_class (ClassDef) – The class being wrapped.
new_func (BindCFunctionDef) – The function which provides a new instance of the class.
**kwargs (dict) – See ClassDef.
- property new_func#
Get the wrapper for __new__.
Get the wrapper for __new__ which allocates the memory for the class instance.
- class pyccel.ast.bind_c.BindCClassProperty(python_name, getter, setter, class_type, docstring=None)[source]#
Bases:
PyccelAstNode
A class which wraps a class attribute.
A class which wraps a class attribute to make it accessible from C. In the future this class will also be used to handle properties of classes (i.e. functions marked with the @property decorator).
- Parameters:
python_name (str) – The name of the attribute/property in the original Python code.
getter (FunctionDef) – The function which collects the value of the class attribute.
setter (FunctionDef) – The function which modifies the value of the class attribute.
class_type (Variable) – The type of the class to which the attribute belongs.
docstring (LiteralString, optional) – The docstring of the property.
- property class_type#
The type of the class to which the attribute belongs.
The type of the class to which the attribute belongs.
- property docstring#
The docstring of the property being wrapped.
The docstring of the property being wrapped.
- property getter#
The BindCFunctionDef describing the getter function.
The BindCFunctionDef describing the function which allows the user to collect the value of the property.
- property python_name#
The name of the attribute/property in the original Python code.
The name of the attribute/property in the original Python code.
- property setter#
The BindCFunctionDef describing the setter function.
The BindCFunctionDef describing the function which allows the user to modify the value of the property.
- class pyccel.ast.bind_c.BindCFunctionDef(*args, original_function, **kwargs)[source]#
Bases:
FunctionDef
Represents the definition of a C-compatible function.
Contains the C-compatible version of the function which is used for the wrapper. As compared to a normal FunctionDef, this version contains arguments for the shape of arrays. It should be generated by calling codegen.wrapper.FortranToCWrapper.wrap.
- Parameters:
*args (list) – See FunctionDef.
original_function (FunctionDef) – The function from which the C-compatible version was created.
**kwargs (dict) – See FunctionDef.
See also
pyccel.ast.core.FunctionDef
The class from which BindCFunctionDef inherits which contains all details about the args and kwargs.
- property original_function#
The function which is wrapped by this BindCFunctionDef.
The original function which would be printed in pure Fortran which is not compatible with C.
- class pyccel.ast.bind_c.BindCModule(*args, original_module, variable_wrappers=(), removed_functions=None, **kwargs)[source]#
Bases:
Module
Represents a Module which only contains functions compatible with C.
Represents a Module which provides the C-Fortran interface to another module. Both functions and module variables are wrapped in order to be compatible with C.
- Parameters:
*args (tuple) – See pyccel.ast.core.Module.
original_module (Module) – The Module being wrapped.
variable_wrappers (list of BindCFunctionDef) – A list containing all the functions which expose module variables to C.
removed_functions (list of FunctionDef) – A list of any functions which weren’t translated to BindCFunctionDef objects (e.g. private functions).
**kwargs (dict) – See pyccel.ast.core.Module.
See also
pyccel.ast.core.Module
The class from which BindCModule inherits which contains all details about the args and kwargs.
- property declarations#
Get the declarations of all module variables.
In the case of a BindCModule no variables should be declared. Basic variables are used directly from the original module and more complex variables require wrapper functions.
- property original_module#
The module which was wrapped.
The original module for which this object provides the C-Fortran interface.
- property removed_functions#
Get the functions which weren’t translated to BindCFunctionDef objects.
Get a list of the functions which weren’t translated to BindCFunctionDef objects. This includes private functions and objects for which wrapper support is lacking.
- property variable_wrappers#
Get the wrappers which expose module variables to C.
Get a list containing all the BindCFunctionDefs which expose module variables to C.
- class pyccel.ast.bind_c.BindCModuleVariable(*args, **kwargs)[source]#
Bases:
Variable
A class which wraps a compatible variable from Fortran to make it available in C.
A class which wraps a compatible module variable from Fortran to make it available in C. A compatible variable is a variable which can be exposed to C simply using iso_c_binding (i.e. no wrapper function is required).
- Parameters:
*args (tuple) – See Variable.
**kwargs (dict) – See Variable.
See also
Variable
The super class.
- property indexed_name#
The name under which the variable is indexed in the scope.
The name under which the variable is indexed in the scope. This is important in order to be able to collect the original Python name used by the user in case of collisions.
- property name#
The name of the external variable that should be printed in C.
The name of the external variable that should be printed in C. In order to be compatible with Fortran the name must be printed in lower case letters.
- class pyccel.ast.bind_c.BindCPointer(self)[source]#
Bases:
FixedSizeType
Datatype representing a C pointer in Fortran.
Datatype representing a C pointer in Fortran. This data type is defined in the iso_c_binding module.
- class pyccel.ast.bind_c.BindCSizeOf(element)[source]#
Bases:
PyccelFunction
Represents a call to a function which can calculate the size of an object in bits.
Represents a call to a function which can calculate the size of an object in bits.
- Parameters:
element (TypedAstNode) – The object whose type should be determined.
- class pyccel.ast.bind_c.BindCVariable(new_var, original_var)[source]#
Bases:
Variable
A wrapper linking the new C-compatible variable to the original variable.
A wrapper linking the new C-compatible variable to the variable that is accessible via this information. This object is a variable which mimics the new variable so it can be used in some of the same contexts but the underlying variables should be extracted before manipulating them.
- Parameters:
- property new_var#
The new C-compatible variable.
The new C-compatible variable.
- property original_var#
The original variable in the target language.
The original variable from the target language that was wrapped.
- class pyccel.ast.bind_c.CLocFunc(argument, result)[source]#
Bases:
PyccelAstNode
Creates a C-compatible pointer to the argument.
Class representing the iso_c_binding function cloc which returns a valid C pointer to the location where an object can be found.
- Parameters:
- property arg#
Pointer target.
Object which will be pointed at by the result pointer.
- property result#
The variable where the C-compatible pointer should be stored.
The variable where the C-compatible pointer of dtype BindCPointer should be stored.
- class pyccel.ast.bind_c.C_F_Pointer(c_expr, f_expr, shape=None)[source]#
Bases:
PyccelAstNode
Creates a Fortran array pointer from a C pointer and size information.
Represents the iso_c_binding function C_F_Pointer which takes a pointer to an object in C (with dtype BindCPointer) and a list of sizes and returns a Fortran array pointer.
- Parameters:
- property c_pointer#
The Variable containing the C pointer.
The Variable of dtype BindCPointer which contains the C pointer.
- property f_array#
The Variable containing the resulting array.
The Variable where the array pointer will be stored.
- property shape#
A list of the sizes of the array in each dimension.
A list describing the Variables which are passed as arguments, in order to determine the size of the array in each dimension.
- class pyccel.ast.bind_c.C_NULL_CHAR[source]#
Bases:
TypedAstNode
A class representing the C_NULL_CHAR character from the iso_c_binding module.
A class representing the C_NULL_CHAR character from the iso_c_binding module. This object should be appended to strings before returning them from Fortran to C.
- class pyccel.ast.bind_c.DeallocatePointer(variable)[source]#
Bases:
Deallocate
Represents memory deallocation for memory only stored in a pointer.
Represents memory deallocation for memory only stored in a pointer. Usually deallocate is not called on pointers so as not to delete the target values however this capability is necessary in the wrapper.
- Parameters:
variable (pyccel.ast.core.Variable) – The typed variable (usually an array) that needs memory deallocation.