From 50c3067802dcd1fba51208ffcf958c204108c978 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Mon, 17 Oct 2022 22:43:49 +0300 Subject: [PATCH] fix: make appropriate methods of token_t const --- include/compiler/treeifier/tokenizer.hh | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/include/compiler/treeifier/tokenizer.hh b/include/compiler/treeifier/tokenizer.hh index 78cd6b4..93e1cb6 100644 --- a/include/compiler/treeifier/tokenizer.hh +++ b/include/compiler/treeifier/tokenizer.hh @@ -95,40 +95,40 @@ namespace ppc::comp::tree { public: ppc::location_t location; - bool is_identifier() { return kind == IDENTIFIER; } - bool is_operator() { return kind == OPERATOR; } - bool is_int_lit() { return kind == INT; } - bool is_float_lit() { return kind == FLOAT; } - bool is_char_lit() { return kind == CHAR; } - bool is_string_lit() { return kind == STRING; } + bool is_identifier() const { return kind == IDENTIFIER; } + bool is_operator() const { return kind == OPERATOR; } + bool is_int_lit() const { return kind == INT; } + bool is_float_lit() const { return kind == FLOAT; } + bool is_char_lit() const { return kind == CHAR; } + bool is_string_lit() const { return kind == STRING; } - const auto &identifier() { + const auto &identifier() const { if (!is_identifier()) throw std::string { "Token is not an identifier." }; else return *data.identifier; } - auto _operator() { + auto _operator() const { if (!is_operator()) throw std::string { "Token is not an operator." }; else return data._operator; } - auto int_lit() { + auto int_lit() const { if (!is_int_lit()) throw std::string { "Token is not an int literal." }; else return data.int_literal; } - auto float_lit() { + auto float_lit() const { if (!is_float_lit()) throw std::string { "Token is not a float literal." }; else return data.float_literal; } - auto char_lit() { + auto char_lit() const { if (!is_char_lit()) throw std::string { "Token is not a char literal." }; else return data.char_literal; } - const auto &string_lit() { + const auto &string_lit() const { if (!is_string_lit()) throw std::string { "Token is not a string literal." }; else return *data.string_literal; } - bool is_operator(operator_t op) { return is_operator() && _operator() == op; } - bool is_identifier(std::string &&val) { return is_identifier() && identifier() == val; } + bool is_operator(operator_t op) const { return is_operator() && _operator() == op; } + bool is_identifier(const std::string &val) const { return is_identifier() && identifier() == val; } token_t() { kind = NONE; } token_t(const std::string &identifier, location_t loc = location_t::NONE): location(loc) {