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

The SyntaxLexeme class. More...

#include <SyntaxLexeme.h>

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

Classes

struct  BitFields
 

Public Types

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

Public Member Functions

Kind 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 IdentifierasIdentifier ()
 
virtual IntegerConstantasIntegerConstant ()
 
virtual FloatingConstantasFloatingConstant ()
 
virtual CharacterConstantasCharacterConstant ()
 
virtual ImaginaryIntegerConstantasImaginaryIntegerConstant ()
 
virtual ImaginaryFloatingConstantasImaginaryFloatingConstant ()
 
virtual StringLiteralasStringLiteralExpression ()
 
- 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

 SyntaxLexeme (const char *chars, unsigned int size, Kind kind)
 
 SyntaxLexeme (const SyntaxLexeme &)=delete
 
SyntaxLexemeoperator= (const SyntaxLexeme &)=delete
 
void checkHexPrefix ()
 
void checkVariousPrefixesAndSuffixes ()
 

Protected Attributes

union {
   std::uint16_t   BF_all_
 
   BitFields   BF_
 
}; 
 

Detailed Description

The SyntaxLexeme class.

Member Function Documentation

◆ asCharacterConstant()

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

Cast this SyntaxLexeme.

Reimplemented in psy::C::CharacterConstant.

◆ asFloatingConstant()

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

Cast this SyntaxLexeme.

Reimplemented in psy::C::FloatingConstant.

◆ asIdentifier()

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

Cast this SyntaxLexeme.

Reimplemented in psy::C::Identifier.

◆ asImaginaryFloatingConstant()

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

Cast this SyntaxLexeme.

Reimplemented in psy::C::ImaginaryFloatingConstant.

◆ asImaginaryIntegerConstant()

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

Cast this SyntaxLexeme.

Reimplemented in psy::C::ImaginaryIntegerConstant.

◆ asIntegerConstant()

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

Cast this SyntaxLexeme.

Reimplemented in psy::C::IntegerConstant.

◆ asStringLiteralExpression()

virtual StringLiteral* psy::C::SyntaxLexeme::asStringLiteralExpression ( )
inlinevirtual

Cast this SyntaxLexeme.

Reimplemented in psy::C::StringLiteral.

◆ kind()

SyntaxLexeme::Kind SyntaxLexeme::kind ( ) const

The Kind of this SyntaxLexeme.

◆ value()

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

The value of this SyntaxLexeme. Template parameter ValueT must be substituted, as an argument, by the C type corresponding to the lexeme in question. Therefore, prior to calling SyntaxLexeme::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 SyntaxLexeme, named lexeme.

if (lexeme->asIntegerConstant()) {
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 SyntaxLexeme::valueText ( ) const

The value of this SyntaxLexeme 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 SyntaxLexeme was obtained.
See also
SyntaxToken::valueText

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