Porytiles
Loading...
Searching...
No Matches
porytiles::DefineStatement Class Reference

Represents a parsed #define preprocessor statement. More...

#include <define_statement.hpp>

Public Member Functions

 DefineStatement (std::string name, std::int64_t value, SourcePosition position)
 Constructs a DefineStatement with an integer value.
 
 DefineStatement (std::string name, std::string value, SourcePosition position)
 Constructs a DefineStatement with a string value.
 
 DefineStatement (std::string name, SourcePosition position)
 Constructs a DefineStatement with no value (flag-like define).
 
const std::string & name () const
 Returns the macro name.
 
const DefineValuevalue () const
 Returns the value variant.
 
const SourcePositionposition () const
 Returns the source position of the #define.
 
bool has_int_value () const
 Checks if this define has an integer value.
 
bool has_string_value () const
 Checks if this define has a string value.
 
bool is_flag () const
 Checks if this define has no value (flag-like).
 
std::int64_t int_value () const
 Returns the integer value.
 
const std::string & string_value () const
 Returns the string value.
 

Detailed Description

Represents a parsed #define preprocessor statement.

DefineStatement captures the name and value of a C preprocessor #define directive. For simple numeric defines like #define FOO 123 or #define BAR (1 << 4), the value is evaluated and stored as an integer. For string defines like #define MSG "hello", the string value is stored. For flag-like defines with no value like #define DEBUG, the value is std::monostate.

The original source position is preserved for error reporting.

Example defines this class can represent:

#define FOO 123 // name="FOO", value=123
#define BAR 0xFF // name="BAR", value=255
#define BAZ (1 << 4) // name="BAZ", value=16
#define MSG "hello" // name="MSG", value="hello"
#define DEBUG // name="DEBUG", value=monostate

Definition at line 43 of file define_statement.hpp.

Constructor & Destructor Documentation

◆ DefineStatement() [1/3]

porytiles::DefineStatement::DefineStatement ( std::string  name,
std::int64_t  value,
SourcePosition  position 
)
inline

Constructs a DefineStatement with an integer value.

Parameters
nameThe macro name
valueThe integer value
positionThe source position of the #define

Definition at line 52 of file define_statement.hpp.

◆ DefineStatement() [2/3]

porytiles::DefineStatement::DefineStatement ( std::string  name,
std::string  value,
SourcePosition  position 
)
inline

Constructs a DefineStatement with a string value.

Parameters
nameThe macro name
valueThe string value
positionThe source position of the #define

Definition at line 64 of file define_statement.hpp.

◆ DefineStatement() [3/3]

porytiles::DefineStatement::DefineStatement ( std::string  name,
SourcePosition  position 
)
inline

Constructs a DefineStatement with no value (flag-like define).

Parameters
nameThe macro name
positionThe source position of the #define

Definition at line 75 of file define_statement.hpp.

Member Function Documentation

◆ has_int_value()

bool porytiles::DefineStatement::has_int_value ( ) const
inline

Checks if this define has an integer value.

Returns
True if value holds an integer

Definition at line 115 of file define_statement.hpp.

◆ has_string_value()

bool porytiles::DefineStatement::has_string_value ( ) const
inline

Checks if this define has a string value.

Returns
True if value holds a string

Definition at line 125 of file define_statement.hpp.

◆ int_value()

std::int64_t porytiles::DefineStatement::int_value ( ) const
inline

Returns the integer value.

Precondition
has_int_value() == true
Returns
The integer value

Definition at line 146 of file define_statement.hpp.

◆ is_flag()

bool porytiles::DefineStatement::is_flag ( ) const
inline

Checks if this define has no value (flag-like).

Returns
True if value holds monostate

Definition at line 135 of file define_statement.hpp.

◆ name()

const std::string & porytiles::DefineStatement::name ( ) const
inline

Returns the macro name.

Returns
A const reference to the name

Definition at line 85 of file define_statement.hpp.

◆ position()

const SourcePosition & porytiles::DefineStatement::position ( ) const
inline

Returns the source position of the #define.

Returns
A const reference to the source position

Definition at line 105 of file define_statement.hpp.

◆ string_value()

const std::string & porytiles::DefineStatement::string_value ( ) const
inline

Returns the string value.

Precondition
has_string_value() == true
Returns
A const reference to the string value

Definition at line 158 of file define_statement.hpp.

◆ value()

const DefineValue & porytiles::DefineStatement::value ( ) const
inline

Returns the value variant.

Returns
A const reference to the DefineValue variant

Definition at line 95 of file define_statement.hpp.


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