2023-01-04 22:32:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fstream>
|
2023-01-05 18:52:27 +00:00
|
|
|
#include <string>
|
2023-01-04 22:32:55 +00:00
|
|
|
#include <string_view>
|
2023-01-05 16:44:30 +00:00
|
|
|
#include <xlangBaseVisitor.h>
|
2023-01-04 22:32:55 +00:00
|
|
|
|
|
|
|
namespace xlang {
|
|
|
|
|
2023-01-05 16:44:30 +00:00
|
|
|
class EmitVisitor : public xlangBaseVisitor {
|
2023-01-04 22:32:55 +00:00
|
|
|
std::ofstream output;
|
2023-01-07 08:56:27 +00:00
|
|
|
size_t blockcount;
|
|
|
|
size_t tmpcount;
|
2023-01-05 18:52:27 +00:00
|
|
|
std::string last;
|
2023-01-07 08:56:27 +00:00
|
|
|
std::vector<size_t> loopstack;
|
2023-01-05 18:52:27 +00:00
|
|
|
|
|
|
|
std::string tmp();
|
2023-01-04 22:32:55 +00:00
|
|
|
|
|
|
|
public:
|
2023-01-05 16:44:30 +00:00
|
|
|
EmitVisitor(std::string_view outputfile);
|
2023-01-04 22:32:55 +00:00
|
|
|
|
2023-01-05 16:44:30 +00:00
|
|
|
std::any visitFile(xlangParser::FileContext *ctx) override;
|
|
|
|
std::any visitFunction(xlangParser::FunctionContext *ctx) override;
|
|
|
|
std::any visitStatement(xlangParser::StatementContext *ctx) override;
|
2023-01-06 16:44:57 +00:00
|
|
|
std::any visitCondition(xlangParser::ConditionContext *ctx) override;
|
|
|
|
std::any visitBoolean(xlangParser::BooleanContext *ctx) override;
|
2023-01-05 16:44:30 +00:00
|
|
|
std::any visitExpr(xlangParser::ExprContext *ctx) override;
|
|
|
|
std::any visitTerm(xlangParser::TermContext *ctx) override;
|
|
|
|
std::any visitFactor(xlangParser::FactorContext *ctx) override;
|
2023-01-06 17:46:45 +00:00
|
|
|
std::any visitVariable(xlangParser::VariableContext *ctx) override;
|
2023-01-04 22:32:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace xlang
|