spudplate
Template scaffolding compiler for spudlang .spud files
Loading...
Searching...
No Matches
validator.h
1#ifndef SPUDPLATE_VALIDATOR_H
2#define SPUDPLATE_VALIDATOR_H
3
4#include <stdexcept>
5#include <string>
6#include <unordered_map>
7
8#include "spudplate/ast.h"
9
10namespace spudplate {
11
16using TypeMap = std::unordered_map<std::string, VarType>;
17
24class SemanticError : public std::runtime_error {
25 public:
27 SemanticError(const std::string& message, int line, int column)
28 : std::runtime_error(message), line_(line), column_(column) {}
29
31 [[nodiscard]] int line() const { return line_; }
33 [[nodiscard]] int column() const { return column_; }
34
35 private:
36 int line_;
37 int column_;
38};
39
46void validate(const Program& program);
47
52ExprPtr clone_expr(const Expr& expr);
53
61ExprPtr normalize(const Expr& expr, const TypeMap& tm);
62
69bool exprs_equal(const Expr& a, const Expr& b);
70
71} // namespace spudplate
72
73#endif // SPUDPLATE_VALIDATOR_H
Exception thrown when the semantic validator finds a rule violation.
Definition validator.h:24
int column() const
1-based column number of the offending statement or expression.
Definition validator.h:33
SemanticError(const std::string &message, int line, int column)
Construct an error tagged with the offending source position.
Definition validator.h:27
int line() const
1-based line number of the offending statement or expression.
Definition validator.h:31