pyccel.codegen.printing.cwrappercode module#
- class pyccel.codegen.printing.cwrappercode.CWrapperCodePrinter(filename, target_language, **settings)[source]#
Bases:
CCodePrinter
A printer for printing the C-Python interface.
A printer to convert Pyccel’s AST describing a translated module, to strings of C code which provide an interface between the module and Python code. As for all printers the navigation of this file is done via _print_X functions.
- Parameters:
filename (str) – The name of the file being pyccelised.
target_language (str) – The language which the code was translated to [fortran/c].
**settings (dict) – Any additional arguments which are necessary for CCodePrinter.
- dtype_registry = {(<pyccel.ast.datatypes.PrimitiveBooleanType object>, -1): 'bool', (<pyccel.ast.datatypes.PrimitiveComplexType object>, 4): 'float complex', (<pyccel.ast.datatypes.PrimitiveComplexType object>, 8): 'double complex', (<pyccel.ast.datatypes.PrimitiveFloatingPointType object>, 4): 'float', (<pyccel.ast.datatypes.PrimitiveFloatingPointType object>, 8): 'double', (<pyccel.ast.datatypes.PrimitiveIntegerType object>, 1): 'int8_t', (<pyccel.ast.datatypes.PrimitiveIntegerType object>, 2): 'int16_t', (<pyccel.ast.datatypes.PrimitiveIntegerType object>, 4): 'int32_t', (<pyccel.ast.datatypes.PrimitiveIntegerType object>, 8): 'int64_t', (<pyccel.ast.datatypes.PrimitiveIntegerType object>, None): 'int', <pyccel.ast.bind_c.BindCPointer object>: 'void', <pyccel.ast.cwrapper.PyccelPyObject object>: 'PyObject', <pyccel.ast.cwrapper.PyccelPyTypeObject object>: 'PyTypeObject', <pyccel.ast.datatypes.CharType object>: 'char', <pyccel.ast.datatypes.VoidType object>: 'void', <pyccel.ast.numpy_wrapper.PyccelPyArrayObject object>: 'PyArrayObject'}#
- function_signature(expr, print_arg_names=True)[source]#
Get the C representation of the function signature.
Extract from the function definition expr all the information (name, input, output) needed to create the function signature and return a string describing the function.
This is not a declaration as the signature does not end with a semi-colon.
- Parameters:
expr (FunctionDef) – The function definition for which a signature is needed.
print_arg_names (bool, default : True) – Indicates whether argument names should be printed.
- Returns:
Signature of the function.
- Return type:
str
- get_declare_type(expr)[source]#
Get the string which describes the type in a declaration.
This function extends CCodePrinter.get_declare_type to specify types which are only relevant in the C-Python interface.
- Parameters:
expr (Variable) – The variable whose type should be described.
- Returns:
The code describing the type.
- Return type:
str
- Raises:
PyccelCodegenError – If the type is not supported in the C code or the rank is too large.
See also
CCodePrinter.get_declare_type
The extended function.
- get_python_name(scope, obj)[source]#
Get the name of object as defined in the original python code.
Get the name of the object as it was originally defined in the Python code being translated. This name may have changed before the printing stage in the case of name clashes or language interfaces.
- Parameters:
scope (pyccel.parser.scope.Scope) – The scope where the object was defined.
obj (pyccel.ast.basic.PyccelAstNode) – The object whose name we wish to identify.
- Returns:
The original name of the object.
- Return type:
str
- is_c_pointer(a)[source]#
Indicate whether the object is a pointer in C code.
This function extends CCodePrinter.is_c_pointer to specify more objects which are always accessed via a C pointer.
- Parameters:
a (TypedAstNode) – The object whose storage we are enquiring about.
- Returns:
True if a C pointer, False otherwise.
- Return type:
bool
See also
CCodePrinter.is_c_pointer
The extended function.