32 lines
870 B
C++
32 lines
870 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include "antlr4-runtime.h"
|
|
#include "SymbolTable.h"
|
|
#include "generated/ifccBaseVisitor.h"
|
|
|
|
|
|
class CodeGenVisitor : public ifccBaseVisitor {
|
|
SymbolTable *symbolTable; // shared, not owned
|
|
std::vector<std::string> scopeStack; // navigation state, owned by this visitor
|
|
|
|
std::string currentScope() const { return scopeStack.back(); }
|
|
|
|
public:
|
|
explicit CodeGenVisitor(SymbolTable *st) : symbolTable(st) {
|
|
}
|
|
|
|
std::any visitProg(ifccParser::ProgContext *ctx) override;
|
|
|
|
std::any visitStmt(ifccParser::StmtContext *ctx) override;
|
|
|
|
std::any visitReturn_stmt(ifccParser::Return_stmtContext *ctx) override;
|
|
|
|
std::any visitDecl_stmt(ifccParser::Decl_stmtContext *ctx) override;
|
|
|
|
std::any visitSet_stmt(ifccParser::Set_stmtContext *ctx) override;
|
|
|
|
std::any visitVal(ifccParser::ValContext *ctx) override;
|
|
};
|