xo-expression2: + DVariable

This commit is contained in:
Roland Conybeare 2026-01-17 01:05:59 -05:00
commit a23307aabb
3 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,56 @@
/** @file DVariable.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include "DUniqueString.hpp"
#include "Binding.hpp"
#include "TypeRef.hpp"
#include "exprtype.hpp"
#include <xo/reflect/TypeDescr.hpp>
namespace xo {
namespace scm {
/** @class DVariable*
* @brief syntax for a variable reference
**/
class DVariable {
public:
using TypeDescr = xo::reflect::TypeDescr;
public:
DVariable(const DUniqueString & name, const TypeRef & typeref, Binding path)
: name_{name}, typeref_{typeref}, path_{path} {}
const DUniqueString & name() const { return name_; }
Binding path() const { return path_; }
/** @defgroup scm-variable-expression-facet**/
///@{
exprtype extype() const noexcept { return exprtype::variable; }
TypeRef typeref() const noexcept { return typeref_; }
TypeDescr valuetype() const noexcept { return typeref_.td(); };
void assign_valuetype(TypeDescr td) noexcept;
///@}
private:
/** symbol name **/
const DUniqueString & name_;
/** variable value always has type consistent
* with this description
**/
TypeRef typeref_;
/** at runtime: navigate environemnt via this path to get
* runtime memory location for this variable
**/
Binding path_;
};
} /*namespace scm*/
} /*namespace xo*/
/* end DVariable.hpp */

View file

@ -4,6 +4,7 @@ set(SELF_LIB xo_expression2)
set(SELF_SRCS
init_expression2.cpp
DConstant.cpp
DVariable.cpp
TypeRef.cpp
IExpression_Any.cpp
IExpression_DConstant.cpp

View file

@ -0,0 +1,19 @@
/** @file DVariable.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include "DVariable.hpp"
#include "exprtype.hpp"
namespace xo {
namespace scm {
void
DVariable::assign_valuetype(TypeDescr td) noexcept
{
typeref_.resolve(td);
}
} /*namespace scm*/
} /*namespace xo*/
/* end DVariable.cpp */