From 0b1d83869f72de13ace2ecf2afbc3686e8267466 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 13 Aug 2015 19:48:58 +0100 Subject: [PATCH] add StackedValue for more convenient alias handling --- cubescript.hh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cubescript.hh b/cubescript.hh index 43f0a53..b583f52 100644 --- a/cubescript.hh +++ b/cubescript.hh @@ -412,6 +412,38 @@ void init_lib_math(CsState &cs); void init_lib_string(CsState &cs); void init_lib_list(CsState &cs); +inline bool check_alias(Ident *id) { + return id && (id->type == ID_ALIAS); +} + +struct StackedValue: TaggedValue { + IdentStack stack; + Ident *id; + bool pushed; + + StackedValue(Ident *id = nullptr): + TaggedValue(), stack(), id(id), pushed(false) {} + + ~StackedValue() { + pop(); + } + + bool push() { + if (pushed || !id) return false; + id->push_arg(*this, stack); + pushed = true; + return true; + } + + bool pop() { + printf("pop\n"); + if (!pushed || !id) return false; + id->pop_arg(); + pushed = false; + return true; + } +}; + namespace util { template inline ostd::Size escape_string(R &&writer, ostd::ConstCharRange str) {