diff --git a/include/xo/expression2/DIfElseExpr.hpp b/include/xo/expression2/DIfElseExpr.hpp index 4a1107ca..8222834a 100644 --- a/include/xo/expression2/DIfElseExpr.hpp +++ b/include/xo/expression2/DIfElseExpr.hpp @@ -59,6 +59,12 @@ namespace xo { obj when_true, obj when_false); + /** create empty if-else expression using memory from @p mm **/ + static obj make_empty(obj mm); + + /** create empty if-else expression using memory from @p mm **/ + static DIfElseExpr * _make_empty(obj mm); + ///@} /** @defgroup scm-ifelseexpr-access-methods **/ ///@{ @@ -67,6 +73,10 @@ namespace xo { obj when_true() const noexcept { return when_true_; } obj when_false() const noexcept { return when_false_; } + void assign_test(obj x) { this->test_ = x; } + void assign_when_true(obj x) { this->when_true_ = x; } + void assign_when_false(obj x) { this->when_false_ = x; } + ///@} /** @defgroup scm-ifelseexpr-expression-facet **/ ///@{ diff --git a/src/expression2/DIfElseExpr.cpp b/src/expression2/DIfElseExpr.cpp index 0e18114e..d858dfab 100644 --- a/src/expression2/DIfElseExpr.cpp +++ b/src/expression2/DIfElseExpr.cpp @@ -57,6 +57,21 @@ namespace xo { when_false); } + obj + DIfElseExpr::make_empty(obj mm) + { + return obj(_make_empty(mm)); + } + + DIfElseExpr * + DIfElseExpr::_make_empty(obj mm) + { + return _make(mm, + obj() /*test*/, + obj() /*when_true*/, + obj() /*when_false*/); + } + void DIfElseExpr::assign_valuetype(TypeDescr td) noexcept { @@ -76,14 +91,33 @@ namespace xo { = FacetRegistry::instance().try_variant(when_false_); - - return ppii.pps()->pretty_struct - (ppii, - "DIfElseExpr", - refrtag("typeref", typeref_), - refrtag("test", test), - refrtag("when_true", when_true), - refrtag("when_false", when_false)); + if (when_false) { + return ppii.pps()->pretty_struct + (ppii, + "DIfElseExpr", + refrtag("typeref", typeref_), + refrtag("test", test), + refrtag("when_true", when_true), + refrtag("when_false", when_false)); + } else if (when_true) { + return ppii.pps()->pretty_struct + (ppii, + "DIfElseExpr", + refrtag("typeref", typeref_), + refrtag("test", test), + refrtag("when_true", when_true)); + } else if (test) { + return ppii.pps()->pretty_struct + (ppii, + "DIfElseExpr", + refrtag("typeref", typeref_), + refrtag("test", test)); + } else { + return ppii.pps()->pretty_struct + (ppii, + "DIfElseExpr", + refrtag("typeref", typeref_)); + } } // ---------------------------------------------------------------- @@ -141,10 +175,13 @@ namespace xo { std::uint32_t IfExpr::pretty_print(const ppindentinfo & ppii) const { + return ppii.pps()->pretty_struct(ppii, "IfExpr"); +#ifdef NOT_YET return ppii.pps()->pretty_struct(ppii, "IfExpr", refrtag("test", test_), refrtag("when_true", when_true_), refrtag("when_false", when_false_)); +#endif } rp