xlang/bootstrap/emit.hh

34 lines
994 B
C++
Raw Normal View History

#pragma once
#include <fstream>
2023-01-05 18:52:27 +00:00
#include <string>
#include <string_view>
2023-01-05 16:44:30 +00:00
#include <xlangBaseVisitor.h>
namespace xlang {
2023-01-05 16:44:30 +00:00
class EmitVisitor : public xlangBaseVisitor {
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();
public:
2023-01-05 16:44:30 +00:00
EmitVisitor(std::string_view outputfile);
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;
std::any visitVariable(xlangParser::VariableContext *ctx) override;
};
} // namespace xlang