Om
evaluation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Evaluation_
16 
18 
19 #else
20 
21  #include "om/language/evaluator.hpp"
22 
23 // MARK: - Om::Language::Evaluation
24 
25  #define Type_ \
26  Om::Language::Evaluation
27 
28 // MARK: public (non-static)
29 
30 inline Type_::~Evaluation() {
31  assert(
32  this->thisExpression.IsEmpty() &&
33  "The Evaluation was not fully consumed."
34  );
35 }
36 
37 inline Type_::Evaluation(Evaluator & theEvaluator):
38 thisExpression(),
39 thisEvaluator(theEvaluator) {}
40 
41 inline Om::Language::Translator const & Type_::GetTranslator() const {
42  return this->thisEvaluator.GetTranslator();
43 }
44 
45 inline bool Type_::GiveTerm(Evaluator & theEvaluator) {
46  if (
47  this->thisExpression.IsEmpty()
48  ) {
49  return false;
50  }
51  Expression::FormRange<Form> theFormRange(this->thisExpression);
52  assert(theFormRange);
53  if (
54  theFormRange->GetOperator().IsEmpty()
55  ) {
56  Operand theOperand;
57  {
58  Form::OperandRange<Operand> theOperandRange(*theFormRange);
59  assert(theOperandRange);
60  theOperand.Swap(*theOperandRange);
61  }
62  this->thisExpression.FrontPopTerm();
63  theEvaluator.TakeOperand(
64  *this,
65  theOperand
66  );
67  } else {
68  Operator theOperator;
69  this->thisExpression.FrontGiveTerm(theOperator);
70  theEvaluator.TakeOperator(
71  *this,
72  theOperator
73  );
74  }
75  return true;
76 }
77 
78 template <typename TheOperand>
79 inline void Type_::TakeOperand(TheOperand & theOperand) {
80  assert(
81  !theOperand.IsEmpty()
82  );
83  this->thisExpression.FrontTakeOperand(theOperand);
84 }
85 
86 template <typename TheOperation>
87 inline void Type_::TakeOperation(
88  std::auto_ptr<TheOperation> theOperation
89 ) {
90  this->thisEvaluator.TakeOperation(theOperation);
91 }
92 
93 template <typename TheOperator>
94 inline void Type_::TakeOperator(TheOperator & theOperator) {
95  assert(
96  !theOperator.IsEmpty()
97  );
98  this->thisExpression.FrontTakeOperator(theOperator);
99 }
100 
101 template <typename TheProducer>
102 inline void Type_::TakeQuotedProducer(TheProducer & theProducer) {
103  this->thisExpression.FrontTakeQuotedProducer(theProducer);
104 }
105 
106 template <typename TheProducer>
107 inline void Type_::TakeProducer(TheProducer & theProducer) {
108  Expression theExpression;
109  theExpression.TakeElements(theProducer);
110  theExpression.TakeElements(this->thisExpression);
111  this->thisExpression.Swap(theExpression);
112 }
113 
114  #undef Type_
115 
116 #endif
An Operator lookup for use by an Evaluator.
Definition: translator.hpp:62
Om header file.
Om header file.