xo-reader: split: exprstatestack to own .*pp files

This commit is contained in:
Roland Conybeare 2024-08-19 13:48:47 -04:00
commit bcb2af4a56
16 changed files with 152 additions and 117 deletions

View file

@ -1,6 +1,7 @@
/* @file exprstate.cpp */
#include "exprstate.hpp"
#include "exprstatestack.hpp"
#include "parserstatemachine.hpp"
//#include "formal_arg.hpp"
#include "xo/expression/Variable.hpp"
@ -390,67 +391,6 @@ namespace xo {
xtag("token", tk),
xtag("state", *this)));
}
// ----- exprstatestack -----
exprstate &
exprstatestack::top_exprstate() {
std::size_t z = stack_.size();
if (z == 0) {
throw std::runtime_error
("parser::top_exprstate: unexpected empty stack");
}
return *(stack_[z-1]);
}
void
exprstatestack::push_exprstate(std::unique_ptr<exprstate> exs) {
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag),
xtag("exs", *exs));
std::size_t z = stack_.size();
stack_.resize(z+1);
stack_[z] = std::move(exs);
}
std::unique_ptr<exprstate>
exprstatestack::pop_exprstate() {
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag),
xtag("top.exstype", top_exprstate().exs_type()));
std::size_t z = stack_.size();
if (z > 0) {
std::unique_ptr<exprstate> top = std::move(stack_[z-1]);
stack_.resize(z-1);
return top;
} else {
return nullptr;
}
}
void
exprstatestack::print(std::ostream & os) const {
os << "<exprstatestack"
<< xtag("size", stack_.size())
<< std::endl;
for (std::size_t i = 0, z = stack_.size(); i < z; ++i) {
os << " [" << z-i-1 << "] "
<< stack_[i]
<< std::endl;
}
os << ">" << std::endl;
}
} /*namespace scm*/
} /*namespace xo*/