xo-reader2 xo-expresion2: work on define-expressions [WIP]
This commit is contained in:
parent
f0e7a186a8
commit
da0d736946
14 changed files with 431 additions and 4 deletions
75
include/xo/expression2/DDefineExpr.hpp
Normal file
75
include/xo/expression2/DDefineExpr.hpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/** @file DDefineExpr.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Expression.hpp"
|
||||
#include "DVariable.hpp"
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class DUniqueString; // see DUniqueString.hpp
|
||||
|
||||
/** @class DDefineExpr
|
||||
* @brief an expression that introduces a variable.
|
||||
*
|
||||
* Variable may optionally be declared with a type,
|
||||
* and may come with an expression specifying an initial value
|
||||
**/
|
||||
class DDefineExpr {
|
||||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
public:
|
||||
/** create instance: define-expr using memory from @p mm
|
||||
* with lhs name @p lhs_name and rhs expression @p rhs_expr
|
||||
**/
|
||||
static DDefineExpr * make(obj<AAllocator> mm,
|
||||
const DUniqueString * lhs_name,
|
||||
obj<AExpression> rhs_expr);
|
||||
/** create empty skeleton. Rely on this for parsing
|
||||
**/
|
||||
static DDefineExpr * make_empty(obj<AAllocator> mm);
|
||||
|
||||
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 **/
|
||||
///@{
|
||||
|
||||
exprtype extype() const noexcept { return exprtype::define; }
|
||||
TypeRef typeref() const noexcept { return lhs_var_->typeref(); }
|
||||
TypeDescr valuetype() const noexcept { return lhs_var_->typeref().td(); }
|
||||
void assign_valuetype(TypeDescr td) noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
DDefineExpr(DVariable * lhs_var,
|
||||
obj<AExpression> rhs);
|
||||
|
||||
private:
|
||||
/** variable being defined by this expression.
|
||||
**/
|
||||
DVariable * lhs_var_ = nullptr;
|
||||
|
||||
/** expression for initial value of this expression
|
||||
**/
|
||||
obj<AExpression> rhs_;
|
||||
|
||||
// std::set<std::string> free_var_set_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DDefineExpr.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue