Add 'xo-expression/' from commit '5ac3c03a0c'
git-subtree-dir: xo-expression git-subtree-mainline:d0f5ccc1cegit-subtree-split:5ac3c03a0c
This commit is contained in:
commit
aecabbb144
46 changed files with 3241 additions and 0 deletions
45
xo-expression/src/expression/IfExpr.cpp
Normal file
45
xo-expression/src/expression/IfExpr.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* @file IfExpr.cpp */
|
||||
|
||||
#include "IfExpr.hpp"
|
||||
#include "xo/indentlog/print/vector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace ast {
|
||||
rp<IfExpr>
|
||||
IfExpr::make(const rp<Expression> & test,
|
||||
const rp<Expression> & when_true,
|
||||
const rp<Expression> & when_false)
|
||||
{
|
||||
/** TODO: verify test returns _boolean_ type **/
|
||||
|
||||
if (when_true->valuetype() != when_false->valuetype()) {
|
||||
throw std::runtime_error
|
||||
(tostr("IfExpr::make:"
|
||||
" types {T1,T2} found for branches of if-expr"
|
||||
" where equal types expected",
|
||||
xtag("T1", when_true->valuetype()->canonical_name()),
|
||||
xtag("T2", when_false->valuetype()->canonical_name())));
|
||||
}
|
||||
|
||||
/* arbitrary choice here */
|
||||
auto ifexpr_type = when_true->valuetype();
|
||||
|
||||
return new IfExpr(ifexpr_type,
|
||||
test,
|
||||
when_true,
|
||||
when_false);
|
||||
} /*make*/
|
||||
|
||||
void
|
||||
IfExpr::display(std::ostream & os) const {
|
||||
os << "<IfExpr"
|
||||
<< xtag("test", test_)
|
||||
<< xtag("when_true", when_true_)
|
||||
<< xtag("when_false", when_false_)
|
||||
<< ">";
|
||||
} /*display*/
|
||||
} /*namespace ast*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end IfExpr.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue