From f8d5d8834dc463928febf7675533c4e509a10adf Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 29 Jan 2026 13:28:30 -0500 Subject: [PATCH] xo-reader2: DExpectFormalArglistSsm handles+stores parsed formals --- .../xo/reader2/DExpectFormalArglistSsm.hpp | 2 +- .../src/reader2/DExpectFormalArglistSsm.cpp | 67 +++++++++++++++---- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/xo-reader2/include/xo/reader2/DExpectFormalArglistSsm.hpp b/xo-reader2/include/xo/reader2/DExpectFormalArglistSsm.hpp index f4c24303..ac7bc643 100644 --- a/xo-reader2/include/xo/reader2/DExpectFormalArglistSsm.hpp +++ b/xo-reader2/include/xo/reader2/DExpectFormalArglistSsm.hpp @@ -147,7 +147,7 @@ namespace xo { /** populate with (parmaeter-name, parameter-type) list * as they're encountered. * - * Not using flexible array here since we don't know size + * Not using flexible array here since we don't know size at construction time **/ DArray * argl_ = nullptr; }; diff --git a/xo-reader2/src/reader2/DExpectFormalArglistSsm.cpp b/xo-reader2/src/reader2/DExpectFormalArglistSsm.cpp index a5b77c4d..555ab275 100644 --- a/xo-reader2/src/reader2/DExpectFormalArglistSsm.cpp +++ b/xo-reader2/src/reader2/DExpectFormalArglistSsm.cpp @@ -7,6 +7,8 @@ #include "ssm/ISyntaxStateMachine_DExpectFormalArglistSsm.hpp" #include "DExpectFormalArgSsm.hpp" #include "ssm/ISyntaxStateMachine_DExpectFormalArgSsm.hpp" +#include +#include #include #include #include @@ -191,12 +193,65 @@ namespace xo { TypeDescr param_type, ParserStateMachine * p_psm) { + if (fastate_ == formalarglstatetype::argl_1a) { + this->fastate_ = formalarglstatetype::argl_1b; + + TypeRef typeref = TypeRef::dwim(TypeRef::prefix_type::from_chars("formal"), param_type); + + DVariable * var = DVariable::make(p_psm->expr_alloc(), + param_name, + typeref); + + // need AGCObject facet to use DArray here. + // May want to have gc feature that allows it to use + // FacetRegistry on memory that stores obj + // + // In this case doesn't matter since DExpectFormalArglistSsm not actually collected! + + obj var_o(var); + + if (argl_->size() == argl_->capacity()) { + // need to expand argl_ capacity. + // If DArena were to allow it (i.e. offer a realloc() feature, + // could do this in place since this SSM is at the top of the parser stack. + + obj mm(&(p_psm->parser_alloc())); + + DArray * argl_2x = DArray::empty(mm, 2 * argl_->capacity()); + + for (DArray::size_type i = 0, n = argl_->size(); i < n; ++i) { + // TODO: prefer non-bounds-checked access here + argl_2x->push_back(argl_->at(i)); + } + + // update in place + this->argl_ = argl_2x; + } + + this->argl_->push_back(var_o); + return; + } + p_psm->illegal_parsed_formal("DExpectFormalArglistSsm::on_parsed_formal", param_name, param_type, this->get_expect_str()); } +#ifdef NOT_YET + void + expect_formal_arglist_xs::on_formal(const rp & formal, + parserstatemachine * p_psm) + { + if (farglxs_type_ == formalarglstatetype::argl_1a) { + this->farglxs_type_ = formalarglstatetype::argl_1b; + this->argl_.push_back(formal); + } else { + exprstate::on_formal(formal, p_psm); + } + } +#endif + void DExpectFormalArglistSsm::on_parsed_expression(obj expr, ParserStateMachine * p_psm) @@ -239,18 +294,6 @@ namespace xo { } #ifdef NOT_YET - void - expect_formal_arglist_xs::on_formal(const rp & formal, - parserstatemachine * p_psm) - { - if (farglxs_type_ == formalarglstatetype::argl_1a) { - this->farglxs_type_ = formalarglstatetype::argl_1b; - this->argl_.push_back(formal); - } else { - exprstate::on_formal(formal, p_psm); - } - } - void expect_formal_arglist_xs::on_comma_token(const token_type & tk, parserstatemachine * p_psm)