xo-reader: split: exprstatestack to own .*pp files
This commit is contained in:
parent
bdf75d5620
commit
bcb2af4a56
16 changed files with 152 additions and 117 deletions
|
|
@ -171,59 +171,6 @@ namespace xo {
|
|||
x.print(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
// ----- exprstatestack -----
|
||||
|
||||
/** @class exprstatestack
|
||||
* @brief A stack of exprstate objects
|
||||
**/
|
||||
class exprstatestack {
|
||||
public:
|
||||
exprstatestack() {}
|
||||
|
||||
bool empty() const { return stack_.empty(); }
|
||||
std::size_t size() const { return stack_.size(); }
|
||||
|
||||
exprstate & top_exprstate();
|
||||
void push_exprstate(std::unique_ptr<exprstate> exs);
|
||||
std::unique_ptr<exprstate> pop_exprstate();
|
||||
|
||||
/** relative to top-of-stack.
|
||||
* 0 -> top (last in), z-1 -> bottom (first in)
|
||||
**/
|
||||
std::unique_ptr<exprstate> & operator[](std::size_t i) {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
assert(i < z);
|
||||
|
||||
return stack_[z - i - 1];
|
||||
}
|
||||
|
||||
const std::unique_ptr<exprstate> & operator[](std::size_t i) const {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
assert(i < z);
|
||||
|
||||
return stack_[z - i - 1];
|
||||
}
|
||||
|
||||
void print (std::ostream & os) const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<exprstate>> stack_;
|
||||
};
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, const exprstatestack & x) {
|
||||
x.print(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, const exprstatestack * x) {
|
||||
x->print(os);
|
||||
return os;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
66
include/xo/reader/exprstatestack.hpp
Normal file
66
include/xo/reader/exprstatestack.hpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* file exprstatestack.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2024
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "exprstate.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class exprstatestack
|
||||
* @brief A stack of exprstate objects
|
||||
**/
|
||||
class exprstatestack {
|
||||
public:
|
||||
exprstatestack() {}
|
||||
|
||||
bool empty() const { return stack_.empty(); }
|
||||
std::size_t size() const { return stack_.size(); }
|
||||
|
||||
exprstate & top_exprstate();
|
||||
void push_exprstate(std::unique_ptr<exprstate> exs);
|
||||
std::unique_ptr<exprstate> pop_exprstate();
|
||||
|
||||
/** relative to top-of-stack.
|
||||
* 0 -> top (last in), z-1 -> bottom (first in)
|
||||
**/
|
||||
std::unique_ptr<exprstate> & operator[](std::size_t i) {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
assert(i < z);
|
||||
|
||||
return stack_[z - i - 1];
|
||||
}
|
||||
|
||||
const std::unique_ptr<exprstate> & operator[](std::size_t i) const {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
assert(i < z);
|
||||
|
||||
return stack_[z - i - 1];
|
||||
}
|
||||
|
||||
void print (std::ostream & os) const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<exprstate>> stack_;
|
||||
};
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, const exprstatestack & x) {
|
||||
x.print(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, const exprstatestack * x) {
|
||||
x->print(os);
|
||||
return os;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end exprstatestack.hpp */
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "exprstate.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ set(SELF_SRCS
|
|||
parser.cpp
|
||||
reader.cpp
|
||||
exprstate.cpp
|
||||
exprstatestack.cpp
|
||||
define_xs.cpp
|
||||
progress_xs.cpp
|
||||
paren_xs.cpp
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/* @file define_xs.cpp */
|
||||
|
||||
#include "define_xs.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "expect_symbol_xs.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "lambda_xs.hpp"
|
||||
#include "paren_xs.hpp"
|
||||
#include "progress_xs.hpp"
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
*/
|
||||
|
||||
#include "expect_formal_arglist_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "expect_formal_xs.hpp"
|
||||
#include "expect_symbol_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
#include "xo/indentlog/print/vector.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "expect_symbol_xs.hpp"
|
||||
#include "expect_type_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "expect_symbol_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "expect_type_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
/* @file exprseq_xs.cpp */
|
||||
|
||||
#include "exprseq_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "define_xs.hpp"
|
||||
#include "expect_symbol_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
|
|||
|
|
@ -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*/
|
||||
|
||||
|
|
|
|||
71
src/reader/exprstatestack.cpp
Normal file
71
src/reader/exprstatestack.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* file exprstatestack.cpp
|
||||
*
|
||||
* author: Roland Conybeare
|
||||
*/
|
||||
|
||||
#include "exprstatestack.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
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*/
|
||||
|
||||
/* end exprstatestack.cpp */
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "lambda_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "expect_formal_arglist_xs.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "xo/expression/Lambda.hpp"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "paren_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "progress_xs.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/* @file progress_xs.cpp */
|
||||
|
||||
#include "progress_xs.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue