From 5a9d4c1e92976d3122dbdc4cbd3734635d64da4d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 9 Sep 2020 13:29:28 -0700 Subject: [PATCH] Update ASTs to actually take in locations. Didn't realize I broke the build by leaving this out. --- 13/ast.hpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/13/ast.hpp b/13/ast.hpp index 1e2f8b5..162f1e0 100644 --- a/13/ast.hpp +++ b/13/ast.hpp @@ -8,11 +8,14 @@ #include "instruction.hpp" #include "env.hpp" #include "definition.hpp" +#include "location.hh" #include "global_scope.hpp" struct ast { type_env_ptr env; + yy::location loc; + ast(yy::location l) : env(nullptr), loc(std::move(l)) {} virtual ~ast() = default; virtual void print(int indent, std::ostream& to) const = 0; @@ -48,8 +51,8 @@ using branch_ptr = std::unique_ptr; struct ast_int : public ast { int value; - explicit ast_int(int v) - : value(v) {} + explicit ast_int(int v, yy::location l = yy::location()) + : ast(std::move(l)), value(v) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -61,8 +64,8 @@ struct ast_int : public ast { struct ast_lid : public ast { std::string id; - explicit ast_lid(std::string i) - : id(std::move(i)) {} + explicit ast_lid(std::string i, yy::location l = yy::location()) + : ast(std::move(l)), id(std::move(i)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -74,8 +77,8 @@ struct ast_lid : public ast { struct ast_uid : public ast { std::string id; - explicit ast_uid(std::string i) - : id(std::move(i)) {} + explicit ast_uid(std::string i, yy::location l = yy::location()) + : ast(std::move(l)), id(std::move(i)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -89,8 +92,8 @@ struct ast_binop : public ast { ast_ptr left; ast_ptr right; - ast_binop(binop o, ast_ptr l, ast_ptr r) - : op(o), left(std::move(l)), right(std::move(r)) {} + ast_binop(binop o, ast_ptr l, ast_ptr r, yy::location lc = yy::location()) + : ast(std::move(lc)), op(o), left(std::move(l)), right(std::move(r)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -103,8 +106,8 @@ struct ast_app : public ast { ast_ptr left; ast_ptr right; - ast_app(ast_ptr l, ast_ptr r) - : left(std::move(l)), right(std::move(r)) {} + ast_app(ast_ptr l, ast_ptr r, yy::location lc = yy::location()) + : ast(std::move(lc)), left(std::move(l)), right(std::move(r)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -118,8 +121,8 @@ struct ast_case : public ast { type_ptr input_type; std::vector branches; - ast_case(ast_ptr o, std::vector b) - : of(std::move(o)), branches(std::move(b)) {} + ast_case(ast_ptr o, std::vector b, yy::location l = yy::location()) + : ast(std::move(l)), of(std::move(o)), branches(std::move(b)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -136,8 +139,8 @@ struct ast_let : public ast { std::vector translated_definitions; - ast_let(definition_group g, ast_ptr i) - : definitions(std::move(g)), in(std::move(i)) {} + ast_let(definition_group g, ast_ptr i, yy::location l = yy::location()) + : ast(std::move(l)), definitions(std::move(g)), in(std::move(i)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into); @@ -155,8 +158,8 @@ struct ast_lambda : public ast { std::set free_variables; ast_ptr translated; - ast_lambda(std::vector ps, ast_ptr b) - : params(std::move(ps)), body(std::move(b)) {} + ast_lambda(std::vector ps, ast_ptr b, yy::location l = yy::location()) + : ast(std::move(l)), params(std::move(ps)), body(std::move(b)) {} void print(int indent, std::ostream& to) const; void find_free(std::set& into);