xo-reader2: intern for DDefineExpr lhs symbol
This commit is contained in:
parent
b29f72be5d
commit
0e62562f34
5 changed files with 31 additions and 17 deletions
|
|
@ -25,6 +25,9 @@ namespace xo {
|
|||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-defineexpr-constructors **/
|
||||
///@{
|
||||
|
||||
/** create instance: define-expr using memory from @p mm
|
||||
* with lhs name @p lhs_name and rhs expression @p rhs_expr
|
||||
**/
|
||||
|
|
@ -35,14 +38,20 @@ namespace xo {
|
|||
**/
|
||||
static DDefineExpr * make_empty(obj<AAllocator> mm);
|
||||
|
||||
DDefineExpr(DVariable * lhs_var,
|
||||
obj<AExpression> rhs);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-definexpr-access-methods **/
|
||||
///@{
|
||||
|
||||
DVariable * lhs() const { return lhs_var_; }
|
||||
obj<AExpression> rhs() const noexcept { return rhs_; }
|
||||
|
||||
const DUniqueString * name() const noexcept;
|
||||
|
||||
void assign_lhs_name(const DUniqueString * name);
|
||||
/** CONCESSION. will use DUniqueString* once we have StringTable **/
|
||||
void assign_lhs_name(std::string_view name);
|
||||
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-defineexpr-expression-facet **/
|
||||
///@{
|
||||
|
|
@ -55,10 +64,9 @@ namespace xo {
|
|||
///@}
|
||||
|
||||
private:
|
||||
DDefineExpr(DVariable * lhs_var,
|
||||
obj<AExpression> rhs);
|
||||
/** @defgrouop scm-defineexpr-instance-vars **/
|
||||
///@{
|
||||
|
||||
private:
|
||||
/** variable being defined by this expression.
|
||||
**/
|
||||
DVariable * lhs_var_ = nullptr;
|
||||
|
|
@ -68,6 +76,8 @@ namespace xo {
|
|||
obj<AExpression> rhs_;
|
||||
|
||||
// std::set<std::string> free_var_set_;
|
||||
|
||||
///@}
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -55,15 +55,6 @@ namespace xo {
|
|||
lhs_var_->assign_name(name);
|
||||
}
|
||||
|
||||
void
|
||||
DDefineExpr::assign_lhs_name(std::string_view name)
|
||||
{
|
||||
scope log(XO_DEBUG(true), "bogus impl - will require unique string");
|
||||
log && log(xtag("name", name));
|
||||
|
||||
//lhs_var_->assign_name(name);
|
||||
}
|
||||
|
||||
void
|
||||
DDefineExpr::assign_valuetype(TypeDescr td) noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ namespace xo {
|
|||
/** pop syntax state machine from top of @ref stack_ **/
|
||||
void pop_ssm();
|
||||
|
||||
/** get unique string copy of @p str. Idempotent for each @p str.
|
||||
**/
|
||||
const DUniqueString * intern_string(std::string_view str);
|
||||
|
||||
/** add variable to current local environment (innermost lexical scope) **/
|
||||
void upsert_var(DVariable * var);
|
||||
|
||||
|
|
|
|||
|
|
@ -412,12 +412,15 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DDefineSsm::on_parsed_symbol(std::string_view sym,
|
||||
DDefineSsm::on_parsed_symbol(std::string_view sym_name,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (this->defstate_ == defexprstatetype::def_1) {
|
||||
this->defstate_ = defexprstatetype::def_2;
|
||||
|
||||
const DUniqueString * sym
|
||||
= p_psm->intern_string(sym_name);
|
||||
|
||||
def_expr_.data()->assign_lhs_name(sym);
|
||||
|
||||
// if this is a genuine top-level define (i.e. nesting level = 0),
|
||||
|
|
@ -448,7 +451,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
p_psm->illegal_input_on_symbol("DDefineSsm::on_parsed_symbol",
|
||||
sym,
|
||||
sym_name,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,12 @@ namespace xo {
|
|||
this->stack_ = ParserStack::pop(stack_, parser_alloc_);
|
||||
}
|
||||
|
||||
const DUniqueString *
|
||||
ParserStateMachine::intern_string(std::string_view str)
|
||||
{
|
||||
return stringtable_.intern(str);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::upsert_var(DVariable * var)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue