The Psyche Project
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
psy::C::Lexeme Class Reference

The Lexeme class. More...

#include <Lexeme.h>

Inheritance diagram for psy::C::Lexeme:
psy::TextElement psy::C::CharacterConstant psy::C::FloatingConstant psy::C::Identifier psy::C::ImaginaryFloatingConstant psy::C::ImaginaryIntegerConstant psy::C::IntegerConstant psy::C::StringLiteral

Classes

struct  BitFields
 

Public Types

enum  LexemeKind : std::uint16_t {
  Identifier, IntegerConstant, FloatingConstant, CharacterConstant,
  ImaginaryIntegerConstant, ImaginaryFloatingConstant, StringLiteral
}
 The LexemeKind enumeraiton.
 
- Public Types inherited from psy::TextElement
typedef const char * iterator
 
typedef iterator const_iterator
 

Public Member Functions

LexemeKind kind () const
 
std::string valueText () const
 
template<class ValueT >
ValueT value () const
 
template<>
int value () const
 
template<>
long value () const
 
template<>
long long value () const
 
template<>
unsigned long value () const
 
template<>
unsigned long long value () const
 
template<>
float value () const
 
template<>
double value () const
 
template<>
long double value () const
 
template<>
unsigned char value () const
 
template<>
wchar_t value () const
 
template<>
char16_t value () const
 
template<>
char32_t value () const
 
virtual Identifier * asIdentifier ()
 
virtual const Identifier * asIdentifier () const
 
virtual IntegerConstant * asIntegerConstant ()
 
virtual const IntegerConstant * asIntegerConstant () const
 
virtual FloatingConstant * asFloatingConstant ()
 
virtual const FloatingConstant * asFloatingConstant () const
 
virtual CharacterConstant * asCharacterConstant ()
 
virtual const CharacterConstant * asCharacterConstant () const
 
virtual ImaginaryIntegerConstant * asImaginaryIntegerConstant ()
 
virtual const ImaginaryIntegerConstant * asImaginaryIntegerConstant () const
 
virtual ImaginaryFloatingConstant * asImaginaryFloatingConstant ()
 
virtual const ImaginaryFloatingConstant * asImaginaryFloatingConstant () const
 
virtual StringLiteral * asStringLiteral ()
 
virtual const StringLiteral * asStringLiteral () const
 
- Public Member Functions inherited from psy::TextElement
 TextElement (const char *c_str, unsigned int size)
 
 TextElement (const TextElement &other)=delete
 
void operator= (const TextElement &other)=delete
 
iterator begin () const
 
iterator end () const
 
char at (unsigned int idx) const
 
const char * c_str () const
 
unsigned int size () const
 
unsigned int length () const
 

Protected Member Functions

 Lexeme (const Lexeme &)=delete
 
Lexeme & operator= (const Lexeme &)=delete
 
 Lexeme (const char *chars, unsigned int size, LexemeKind kind)
 

Protected Attributes

union {
   std::uint16_t   BF_all_
 
   BitFields   BF_
 
}; 
 

Detailed Description

The Lexeme class.

Member Function Documentation

◆ asCharacterConstant() [1/2]

virtual CharacterConstant* psy::C::Lexeme::asCharacterConstant ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::CharacterConstant.

◆ asCharacterConstant() [2/2]

virtual const CharacterConstant* psy::C::Lexeme::asCharacterConstant ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::CharacterConstant.

◆ asFloatingConstant() [1/2]

virtual FloatingConstant* psy::C::Lexeme::asFloatingConstant ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::FloatingConstant.

◆ asFloatingConstant() [2/2]

virtual const FloatingConstant* psy::C::Lexeme::asFloatingConstant ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::FloatingConstant.

◆ asIdentifier() [1/2]

virtual Identifier* psy::C::Lexeme::asIdentifier ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::Identifier.

◆ asIdentifier() [2/2]

virtual const Identifier* psy::C::Lexeme::asIdentifier ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::Identifier.

◆ asImaginaryFloatingConstant() [1/2]

virtual ImaginaryFloatingConstant* psy::C::Lexeme::asImaginaryFloatingConstant ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::ImaginaryFloatingConstant.

◆ asImaginaryFloatingConstant() [2/2]

virtual const ImaginaryFloatingConstant* psy::C::Lexeme::asImaginaryFloatingConstant ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::ImaginaryFloatingConstant.

◆ asImaginaryIntegerConstant() [1/2]

virtual ImaginaryIntegerConstant* psy::C::Lexeme::asImaginaryIntegerConstant ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::ImaginaryIntegerConstant.

◆ asImaginaryIntegerConstant() [2/2]

virtual const ImaginaryIntegerConstant* psy::C::Lexeme::asImaginaryIntegerConstant ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::ImaginaryIntegerConstant.

◆ asIntegerConstant() [1/2]

virtual IntegerConstant* psy::C::Lexeme::asIntegerConstant ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::IntegerConstant.

◆ asIntegerConstant() [2/2]

virtual const IntegerConstant* psy::C::Lexeme::asIntegerConstant ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::IntegerConstant.

◆ asStringLiteral() [1/2]

virtual StringLiteral* psy::C::Lexeme::asStringLiteral ( )
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::StringLiteral.

◆ asStringLiteral() [2/2]

virtual const StringLiteral* psy::C::Lexeme::asStringLiteral ( ) const
inlinevirtual

Cast this Lexeme.

Reimplemented in psy::C::StringLiteral.

◆ kind()

Lexeme::LexemeKind Lexeme::kind ( ) const

The LexemeKind of this Lexeme.

◆ value()

template<class ValueT >
ValueT psy::C::Lexeme::value ( ) const

The value of this Lexeme. Template parameter ValueT must be substituted, as an argument, by the C type corresponding to the lexeme in question. Therefore, prior to calling Lexeme::value, one must check the speficic kind of a lexeme, and any variant it might have. Consider the snippet below, which stores in i the C value of 42UL of a given Lexeme, named lexeme.

if (lexeme->kind() == LexemeKind::IntegerConstant) {
auto intLexeme = lexeme->asIntegerConstant();
if (intLexeme->signedness() == IntegerConstant::Signedness::Unsigned
&& intLexeme->variant() == IntegerConstant::Variant::Long) {
auto i = intLexeme->value<unsigned long>();
// ...
}
}
Remarks
6.2.5
6.4

◆ valueText()

std::string Lexeme::valueText ( ) const

The value of this Lexeme represented as text, by an std::string.

Note
The return of this method is the same as that of SyntaxToken::valueText, for the SyntaxToken from which this Lexeme was obtained.
See also
SyntaxToken::valueText

The documentation for this class was generated from the following files: