pyccel.ast.c_concepts module#

Module representing concepts that are only applicable to C code (e.g. ObjectAddress).

class pyccel.ast.c_concepts.CMacro(arg)[source]View on GitHub#

Bases: PyccelAstNode

Represents a c macro

property macroView on GitHub#

The string containing macro name

class pyccel.ast.c_concepts.CNativeInt(self)[source]View on GitHub#

Bases: FixedSizeNumericType

Class representing C’s native integer type.

Class representing C’s native integer type.

class pyccel.ast.c_concepts.CStackArray(self)[source]View on GitHub#

Bases: HomogeneousContainerType

A data type representing an array allocated on the stack.

A data type representing an array allocated on the stack. E.g. float a[4];

classmethod get_new(element_type)[source]View on GitHub#

Get the parametrised stack array type.

Get the parametrised CStackArray subclass.

Parameters:

element_type (FixedSizeType) – The type of the elements inside the array.

class pyccel.ast.c_concepts.CStrStr(arg)[source]View on GitHub#

Bases: PyccelFunction

A class which extracts a const char* from a literal string.

A class which extracts a const char* from a literal string. This is useful for calling C functions which were not designed for STC.

Parameters:

arg (TypedAstNode | CMacro) – The object which should be passed as a const char*.

class pyccel.ast.c_concepts.CStringExpression(*args)[source]View on GitHub#

Bases: PyccelAstNode

Internal class used to hold a C string that has LiteralStrings and C macros.

Parameters:

*args (str / LiteralString / CMacro / CStringExpression) – any number of arguments to be added to the expression note: they will get added in the order provided

Example

>>> expr = CStringExpression(
...     CMacro("m"),
...     CStringExpression(
...         LiteralString("the macro is: "),
...         CMacro("mc")
...     ),
...     LiteralString("."),
... )
append(o)[source]View on GitHub#

append the argument o to the end of the list _expression

Parameter#

ostr / LiteralString / CMacro / CStringExpression

the expression to append

property expressionView on GitHub#

The list containing the literal strings and c macros

get_flat_expression_list()[source]View on GitHub#

returns a list of LiteralStrings and CMacros after merging every consecutive LiteralString

join(lst)[source]View on GitHub#

insert self between each element of the list lst

Parameter#

lstlist

the list to insert self between its elements

Example

>>> a = [
...     CMacro("m"),
...     CStringExpression(LiteralString("the macro is: ")),
...     LiteralString("."),
... ]
>>> b = CStringExpression("?").join(a)
...
... # is the same as:
...
>>> b = CStringExpression(
...     CMacro("m"),
...     CStringExpression("?"),
...     CStringExpression(LiteralString("the macro is: ")),
        CStringExpression("?"),
...     LiteralString("."),
... )
class pyccel.ast.c_concepts.ObjectAddress(obj)[source]View on GitHub#

Bases: TypedAstNode

Class representing the address of an object.

Class representing the address of an object. In most situations it will not be necessary to use this object explicitly. E.g. if you assign a pointer to a target then the pointer will be printed using AliasAssign. However for the _print_AliasAssign function to print neatly, this class will be used.

Parameters:

obj (TypedAstNode) – The object whose address should be printed.

Examples

>>> CCodePrinter._print(ObjectAddress(Variable(PythonNativeInt(),'a')))
'&a'
>>> CCodePrinter._print(ObjectAddress(Variable(PythonNativeInt(),'a', memory_handling='alias')))
'a'
property is_aliasView on GitHub#

Indicate that an ObjectAddress uses alias memory handling.

Indicate that an ObjectAddress uses alias memory handling.

property objView on GitHub#

The object whose address is of interest

class pyccel.ast.c_concepts.PointerCast(obj, cast_type)[source]View on GitHub#

Bases: TypedAstNode

A class which represents the casting of one pointer to another.

A class which represents the casting of one pointer to another in C code. This is useful for storing addresses in a void pointer. Using this class is not strictly necessary to produce correct C code, but avoids compiler warnings about the implicit conversion of pointers.

Parameters:
  • obj (Variable) – The pointer being cast.

  • cast_type (TypedAstNode) – A TypedAstNode describing the object resulting from the cast.

property cast_typeView on GitHub#

Get the TypedAstNode which describes the object resulting from the cast.

Get the TypedAstNode which describes the object resulting from the cast.

property is_argumentView on GitHub#

Indicates whether the variable is an argument.

Indicates whether the variable is an argument.

property objView on GitHub#

The object whose address is of interest.

The object whose address is of interest.