PUMA Library Reference Manual
Loading...
Searching...
No Matches
Puma::CConstant Class Reference

#include <Puma/CConstant.h>

+ Inheritance diagram for Puma::CConstant:

Description

Semantic information object for arithmetic constants.

Public Member Functions

 CConstant (LONG_LONG v, CTypeInfo *t)
 Constructor. More...
 
 CConstant (U_LONG_LONG v, CTypeInfo *t)
 Constructor. More...
 
 CConstant (long double v, CTypeInfo *t)
 Constructor. More...
 
virtual ~CConstant ()
 Destructor. More...
 
CConstantcast_to (CTypeInfo *t) const
 Cast the value to the given type. More...
 
CConstantcompute (int oper) const
 Compute the resulting value when applying the given unary operator to the value. More...
 
CConstantcompute (int oper, const CConstant *v) const
 Compute the resulting value when applying the given binary operator to this and the given value. More...
 
LONG_LONG convert_to_int () const
 Convert the value to a signed integer. More...
 
U_LONG_LONG convert_to_uint () const
 Convert the value to an unsiged integer. More...
 
long double convert_to_float () const
 Convert the value to floating point. More...
 
CConstantConstant () const
 Get this. More...
 
CConstantduplicate () const
 Duplicate this. More...
 
bool operator== (const CConstant &c) const
 Compare the value of this and the given constant. More...
 
bool operator!= (const CConstant &c) const
 Compare the value of this and the given constant. More...
 
bool isNull () const
 Check if the constant value is 0, regardless of the type. More...
 
bool isPositive () const
 Check if the value is positive (>= 0). More...
 
bool isNegative () const
 Check if the value is negative (< 0). More...
 
bool isSigned () const
 Check if the value is signed. More...
 
bool isUnsigned () const
 Check if the value is unsigned. More...
 
bool isFloat () const
 Check is the value is a floating point value. More...
 
virtual void print (std::ostream &out) const
 Print the value on the given output stream. More...
 
- Public Member Functions inherited from Puma::CExprValue
virtual ~CExprValue ()
 Destructor. More...
 
CTypeInfoType () const
 Get the type of the value. More...
 
virtual void print (std::ostream &out) const =0
 Print the value on the given output stream. More...
 
virtual CConstantConstant () const
 Get a pointer to CConstant if this is an arithmetic constant. More...
 
virtual CStrLiteralStrLiteral () const
 Get a pointer to CStrLiteral if this is a string literal. More...
 
virtual CWStrLiteralWStrLiteral () const
 Get a pointer to CWStrLiteral if this is a wide string literal. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Puma::CExprValue
 CExprValue (CTypeInfo *t)
 Constructor. More...
 

Constructor & Destructor Documentation

◆ CConstant() [1/3]

Puma::CConstant::CConstant ( LONG_LONG  v,
CTypeInfo t 
)
inline

Constructor.

Parameters
vThe value.
tThe type of the value.

◆ CConstant() [2/3]

Puma::CConstant::CConstant ( U_LONG_LONG  v,
CTypeInfo t 
)
inline

Constructor.

Parameters
vThe value.
tThe type of the value.

◆ CConstant() [3/3]

Puma::CConstant::CConstant ( long double  v,
CTypeInfo t 
)
inline

Constructor.

Parameters
vThe value.
tThe type of the value.

◆ ~CConstant()

virtual Puma::CConstant::~CConstant ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ cast_to()

CConstant * Puma::CConstant::cast_to ( CTypeInfo t) const

Cast the value to the given type.

Parameters
tThe type to which to cast.
Returns
A new object with the casted value. Has to be destroyed by the caller.

◆ compute() [1/2]

CConstant * Puma::CConstant::compute ( int  oper) const

Compute the resulting value when applying the given unary operator to the value.

Parameters
operThe operator to apply to the value (token type).
Returns
A new object with the computed value. Has to be destroyed by the caller.

◆ compute() [2/2]

CConstant * Puma::CConstant::compute ( int  oper,
const CConstant v 
) const

Compute the resulting value when applying the given binary operator to this and the given value.

Parameters
operThe operator to apply to the values (token type).
vThe other operand to the operator.
Returns
A new object with the computed value. Has to be destroyed by the caller.

◆ Constant()

CConstant * Puma::CConstant::Constant ( ) const
inlinevirtual

Get this.

Reimplemented from Puma::CExprValue.

◆ convert_to_float()

long double Puma::CConstant::convert_to_float ( ) const

Convert the value to floating point.

◆ convert_to_int()

LONG_LONG Puma::CConstant::convert_to_int ( ) const

Convert the value to a signed integer.

◆ convert_to_uint()

U_LONG_LONG Puma::CConstant::convert_to_uint ( ) const

Convert the value to an unsiged integer.

◆ duplicate()

CConstant * Puma::CConstant::duplicate ( ) const

Duplicate this.

Returns
A newly allocated duplicate of this. Has to be destroyed by the caller.

◆ isFloat()

bool Puma::CConstant::isFloat ( ) const
inline

Check is the value is a floating point value.

◆ isNegative()

bool Puma::CConstant::isNegative ( ) const

Check if the value is negative (< 0).

◆ isNull()

bool Puma::CConstant::isNull ( ) const

Check if the constant value is 0, regardless of the type.

◆ isPositive()

bool Puma::CConstant::isPositive ( ) const

Check if the value is positive (>= 0).

◆ isSigned()

bool Puma::CConstant::isSigned ( ) const
inline

Check if the value is signed.

◆ isUnsigned()

bool Puma::CConstant::isUnsigned ( ) const
inline

Check if the value is unsigned.

◆ operator!=()

bool Puma::CConstant::operator!= ( const CConstant c) const

Compare the value of this and the given constant.

Does not compare the types.

Parameters
cThe value to compare to.
Returns
True if the values are not equal.

◆ operator==()

bool Puma::CConstant::operator== ( const CConstant c) const

Compare the value of this and the given constant.

Does not compare the types.

Parameters
cThe value to compare to.
Returns
True if the values are equal.

◆ print()

virtual void Puma::CConstant::print ( std::ostream &  out) const
virtual

Print the value on the given output stream.

Parameters
outThe output stream.

Implements Puma::CExprValue.