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

Additional Inherited Members

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

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.