xlang/bootstrap/error.hh

35 lines
1.2 KiB
C++
Raw Normal View History

2023-01-05 20:12:15 +00:00
#pragma once
#include <BaseErrorListener.h>
#include <string_view>
2023-01-07 07:54:53 +00:00
#include <typecheck.hh>
2023-01-05 20:12:15 +00:00
namespace xlang {
class ErrorListener : public antlr4::BaseErrorListener {
std::string_view file;
bool has_error;
2023-01-07 07:54:53 +00:00
void printError(size_t line, size_t charPositionInLine, std::string_view msg);
2023-01-05 20:12:15 +00:00
public:
ErrorListener(std::string_view inputfile);
2023-01-06 02:56:33 +00:00
2023-01-05 20:12:15 +00:00
bool hasError();
2023-01-07 07:54:53 +00:00
void compilerError(const std::string &file, size_t line);
void duplicateFunction(antlr4::Token *token, const std::string &name);
void shadowedVariable(antlr4::Token *token, const std::string &name);
2023-01-05 20:12:15 +00:00
void syntaxError(antlr4::Recognizer *recognizer,
antlr4::Token *offendingSymbol, size_t line,
size_t charPositionInLine, const std::string &msg,
std::exception_ptr e) override;
2023-01-07 07:54:53 +00:00
void typeMismatch(antlr4::Token *token, Type expected, Type actual);
void unknownFunction(antlr4::Token *token, const std::string &name);
void unknownVariable(antlr4::Token *token, const std::string &name);
void wrongArgumentNumber(antlr4::Token *token, const std::string &name,
size_t expected, size_t actual);
2023-01-05 20:12:15 +00:00
};
} // namespace xlang