Skip to content

Commit

Permalink
增加StmtManager
Browse files Browse the repository at this point in the history
  • Loading branch information
wangziwenhk committed Oct 4, 2024
1 parent b3c3b8d commit 9f1061e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 19 deletions.
43 changes: 43 additions & 0 deletions src/Tools/Managers/StmtManager.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module;
#include <vector>
export module Managers.StmtManager;

import Types.Statements;

export namespace Riddle {
class StmtManager {
std::vector<BaseStmt *> stmts;

public:
~StmtManager() {
for(const auto stmt: stmts) {
delete stmt;
}
}
BaseStmt *getConstant(const int value) {
const auto ptr = new IntegerStmt(value);
stmts.push_back(ptr);
return ptr;
}
BaseStmt *getConstant(const double value) {
const auto ptr = new DoubleStmt(value);
stmts.push_back(ptr);
return ptr;
}
BaseStmt *getConstant(const float value) {
const auto ptr = new FloatStmt(value);
stmts.push_back(ptr);
return ptr;
}
BaseStmt *getConstant(const bool value) {
const auto ptr = new BoolStmt(value);
stmts.push_back(ptr);
return ptr;
}
BaseStmt *getNull() {
const auto ptr = new NullStmt();
stmts.push_back(ptr);
return ptr;
}
};
}// namespace Riddle
4 changes: 2 additions & 2 deletions src/Types/Statements.ixx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module;
#include "Tools/GenTools.h"
#include <utility>
export module Statements;
namespace Riddle {
export module Types.Statements;
export namespace Riddle {
/// @brief 所有语句的基本语句
class BaseStmt {
public:
Expand Down
16 changes: 0 additions & 16 deletions src/Visitors/StatVisitor.cpp

This file was deleted.

19 changes: 19 additions & 0 deletions src/Visitors/StmtVisitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "StmtVisitor.h"

import Types.Statements;

namespace Riddle {
std::any StmtVisitor::visitStatement_ed(RiddleParser::Statement_edContext *ctx) {
return visit(ctx->children[0]);
}

std::any StmtVisitor::visitInteger(RiddleParser::IntegerContext *ctx) {
auto result = IntegerStmt(ctx->value);
return result;
}
std::any StmtVisitor::visitVarDefineStatement(RiddleParser::VarDefineStatementContext *ctx) {
const std::string name = ctx->name->getText();
return {};
}

}// namespace Riddle
2 changes: 1 addition & 1 deletion src/Visitors/StatVisitor.h → src/Visitors/StmtVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Riddle {

class StatVisitor final : RiddleParserBaseVisitor{
class StmtVisitor final : RiddleParserBaseVisitor{
std::any visitStatement_ed(RiddleParser::Statement_edContext *ctx) override;
std::any visitInteger(RiddleParser::IntegerContext *ctx) override;
std::any visitVarDefineStatement(RiddleParser::VarDefineStatementContext *ctx) override;
Expand Down

0 comments on commit 9f1061e

Please sign in to comment.