pyccel.ast.literals module#

This module contains all literal types

class pyccel.ast.literals.Literal[source]View on GitHub#

Bases: TypedAstNode

Class representing a literal value.

Class representing a literal value. A literal is a value that is expressed as itself rather than as a variable or an expression, e.g. the number 3 or the string “Hello”.

This class is abstract and should be implemented for each dtype

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralComplex(real, imag, dtype=<pyccel.ast.datatypes.PythonNativeComplex object>)[source]View on GitHub#

Bases: Literal

Class representing a complex literal in Python.

Class representing a complex literal, such as 3+2j, in Python.

Parameters:
  • real (float) – The real part of the Python literal.

  • imag (float) – The imaginary part of the Python literal.

  • dtype (FixedSizeType) – The exact type of the literal.

property imagView on GitHub#

Return the imaginary part of the complex literal.

Return the imaginary part of the complex literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

property realView on GitHub#

Return the real part of the complex literal.

Return the real part of the complex literal.

class pyccel.ast.literals.LiteralEllipsis(self)[source]View on GitHub#

Bases: Literal

Class representing an Ellipsis object in the code.

Class representing the Python value Ellipsis in the code.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralFalse(dtype=<pyccel.ast.datatypes.PythonNativeBool object>)[source]View on GitHub#

Bases: Literal

Class representing the Python value False.

Class representing the Python value False.

Parameters:

dtype (FixedSizeType) – The exact type of the literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralFloat(value, dtype=<pyccel.ast.datatypes.PythonNativeFloat object>)[source]View on GitHub#

Bases: Literal

Class representing a float literal in Python.

Class representing a float literal, such as 3.5, in Python.

Parameters:
  • value (float) – The Python literal.

  • dtype (FixedSizeType) – The exact type of the literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralImaginaryUnit(real=0, imag=1, dtype=<pyccel.ast.datatypes.PythonNativeComplex object>)[source]View on GitHub#

Bases: LiteralComplex

Class representing the Python value j.

Class representing the imaginary unit j in Python.

Parameters:
  • real (float = 0) – The value of the real part. This argument is necessary to handle the inheritance but should not be provided explicitly.

  • imag (float = 0) – The value of the real part. This argument is necessary to handle the inheritance but should not be provided explicitly.

  • dtype (FixedSizeType) – The exact type of the literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralInteger(value, dtype=<pyccel.ast.datatypes.PythonNativeInt object>)[source]View on GitHub#

Bases: Literal

Class representing an integer literal in Python.

Class representing an integer literal, such as 3, in Python.

Parameters:
  • value (int) – The Python literal.

  • dtype (FixedSizeType) – The exact type of the literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralString(arg)[source]View on GitHub#

Bases: Literal

Class representing a string literal in Python.

Class representing a string literal, such as ‘hello’ in Python.

Parameters:

arg (str) – The Python literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.LiteralTrue(dtype=<pyccel.ast.datatypes.PythonNativeBool object>)[source]View on GitHub#

Bases: Literal

Class representing the Python value True.

Class representing the Python value True.

Parameters:

dtype (FixedSizeType) – The exact type of the literal.

property python_valueView on GitHub#

Get the Python literal represented by this instance.

Get the Python literal represented by this instance.

class pyccel.ast.literals.Nil(self)[source]View on GitHub#

Bases: Literal

Class representing a None object in the code.

Class representing the Python value None in the code.

class pyccel.ast.literals.NilArgument[source]View on GitHub#

Bases: PyccelAstNode

Represents None when passed as an argument to an inline function.

Represents the Python value None when passed as an argument to an inline function. This class is necessary as to avoid accidental substitution due to Singletons.

pyccel.ast.literals.convert_to_literal(value, dtype=None)[source]View on GitHub#

Convert a Python value to a pyccel Literal.

Convert a Python value to a pyccel Literal.

Parameters:
  • value (int/float/complex/bool/str) – The Python value.

  • dtype (DataType) – The datatype of the Python value. Default : Matches type of ‘value’.

Returns:

The Python value ‘value’ expressed as a literal with the specified dtype.

Return type:

Literal