xlang/bootstrap/typecheck.hh

50 lines
1.4 KiB
C++
Raw Normal View History

2023-01-06 02:56:33 +00:00
#pragma once
2023-01-07 07:54:53 +00:00
#include <scope.hh>
2023-01-06 02:56:33 +00:00
#include <string>
#include <unordered_map>
#include <vector>
#include <xlangBaseVisitor.h>
namespace xlang {
2023-01-07 07:54:53 +00:00
class ErrorListener;
enum class Type
{
Integer,
Boolean,
};
std::string typeToString(Type type);
2023-01-06 02:56:33 +00:00
class TypeCheckVisitor : public xlangBaseVisitor {
2023-01-07 07:54:53 +00:00
struct Signature {
Type returntype;
std::vector<Type> parametertypes;
};
2023-01-06 02:56:33 +00:00
2023-01-07 07:54:53 +00:00
ErrorListener &errorlistener;
std::unordered_map<std::string, Signature> signatures;
Type returntype;
Scope<Type> scope;
2023-01-06 02:56:33 +00:00
public:
TypeCheckVisitor(ErrorListener &errorlistener);
std::any visitFile(xlangParser::FileContext *ctx) override;
std::any visitFunction(xlangParser::FunctionContext *ctx) override;
2023-01-07 07:54:53 +00:00
std::any visitType(xlangParser::TypeContext *ctx) override;
2023-01-06 02:56:33 +00:00
std::any visitBlock(xlangParser::BlockContext *ctx) override;
std::any visitStatement(xlangParser::StatementContext *ctx) override;
2023-01-07 07:54:53 +00:00
std::any visitValue(xlangParser::ValueContext *ctx) override;
std::any visitCondition(xlangParser::ConditionContext *ctx) override;
std::any visitBoolean(xlangParser::BooleanContext *ctx) override;
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;
2023-01-06 02:56:33 +00:00
};
} // namespace xlang