Skip to content

Commit

Permalink
增加常量处理
Browse files Browse the repository at this point in the history
  • Loading branch information
wangziwenhk committed Oct 4, 2024
1 parent 7fe370e commit b3c3b8d
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/Types/Statements.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ namespace Riddle {

IntegerStmtID,// int 类型
FloatStmtID, // float 类型
DoubleStmtID,
BoolStmtID,
NullStmtID,

NullStmtID,// 没有任何效果的语句
NoneStmtID,// 没有任何效果的语句
};

protected:
StmtTypeID StmtID;

public:
BaseStmt(): StmtID(StmtTypeID::NullStmtID) {}
BaseStmt(): StmtID(StmtTypeID::NoneStmtID) {}
explicit BaseStmt(const StmtTypeID stmtTypeID): StmtID(stmtTypeID) {}
virtual ~BaseStmt() = default;

Expand Down Expand Up @@ -62,13 +65,50 @@ namespace Riddle {

/// @brief 存储int类型数据
class IntegerStmt final : public ConstantStmt {
protected:
int value;

public:
explicit IntegerStmt(const int value): ConstantStmt(StmtTypeID::IntegerStmtID), value(value){};
explicit IntegerStmt(const int value): ConstantStmt(StmtTypeID::IntegerStmtID), value(value) {}
[[nodiscard]] inline int getValue() const { return value; }
};

/// @brief 存储 float 数据类型
class FloatStmt final : public ConstantStmt {
protected:
float value;

public:
explicit FloatStmt(const float value): ConstantStmt(StmtTypeID::FloatStmtID), value(value) {}
[[nodiscard]] inline float getValue() const { return value; }
};

/// @brief 存储 Null 数据类型
class NullStmt final : public ConstantStmt {
public:
NullStmt(): ConstantStmt(StmtTypeID::NullStmtID) {}
};

/// @brief 存储 double 数据类型
class DoubleStmt final : public ConstantStmt {
protected:
double value;

public:
explicit DoubleStmt(const double value): ConstantStmt(StmtTypeID::DoubleStmtID), value(value) {}
[[nodiscard]] inline double getValue() const { return value; }
};

/// @brief 存储 bool 数据类型
class BoolStmt final : public ConstantStmt {
protected:
bool value;

public:
explicit BoolStmt(const bool value): ConstantStmt(StmtTypeID::BoolStmtID), value(value) {}
[[nodiscard]] inline bool getValue() const { return value; }
};

// todo 实现多个变量定义

/// @brief 用于存储变量定义
Expand Down

0 comments on commit b3c3b8d

Please sign in to comment.