Om
translate_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_TranslateOperation_
16 
18 
19 #else
20 
22 
23  #ifndef Om_Macro_Precompilation_
24 
25  #include "boost/utility/in_place_factory.hpp"
26 
27  #endif
28 
29 // MARK: - Om::Language::Operation::TranslateOperation
30 
31  #define Template_ \
32  template <typename ThisImplementation>
33 
34  #define Type_ \
35  Om::Language::Operation::TranslateOperation<ThisImplementation>
36 
37 // MARK: public (static)
38 
39 Template_
40 template <typename TheTranslateOperation>
41 inline void Type_::GiveElements(
42  TheTranslateOperation & theTranslateOperation,
43  Consumer & theConsumer
44 ) {
45  assert(
46  typeid(TheTranslateOperation) == typeid(ThisImplementation)
47  );
48  theConsumer.TakeElement(
49  ThisImplementation::GetOperator()
50  );
51  if (theTranslateOperation.thisLexicon) {
52  theConsumer.TakeQuotedElements(*theTranslateOperation.thisLexicon);
53  }
54 }
55 
56 // MARK: public (non-static)
57 
58 Template_
59 inline Type_::~TranslateOperation() {}
60 
61 Template_
62 template <typename TheOperand>
63 inline bool Type_::TakeOperand(
64  Evaluation & theEvaluation,
65  TheOperand & theOperand
66 ) {
67  assert(
68  !theOperand.IsEmpty()
69  );
70  return this->TakeQuotedProducer(
71  theEvaluation,
72  *theOperand.GetProgram()
73  );
74 }
75 
76 Template_
77 template <typename TheProducer>
78 inline bool Type_::TakeQuotedProducer(
79  Evaluation & theEvaluation,
80  TheProducer & theProducer
81 ) {
82  if (this->thisLexicon) {
83  {
84  // Perform the translation. Note that this uses this->thisLexicon and must be done before the lexicon is given to the Evaluation.
85  Expression theExpression;
86  assert(
87  dynamic_cast<ThisImplementation *>(this)
88  );
89  static_cast<ThisImplementation &>(*this).Translate(
90  theEvaluation.GetTranslator(),
91  theProducer,
92  theExpression
93  );
94  theEvaluation.TakeQuotedProducer(theExpression);
95  }
96  theEvaluation.TakeQuotedProducer(*this->thisLexicon);
97  return true;
98  }
99  this->thisLexicon = boost::in_place();
100  assert(this->thisLexicon);
101  this->thisLexicon->TakeElements(theProducer);
102  return false;
103 }
104 
105 // MARK: protected (non-static)
106 
107 Template_
108 inline Type_::TranslateOperation():
109 thisLexicon() {}
110 
111  #undef Type_
112  #undef Template_
113 
114 #endif
Om header file.