00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OW_WQLCOMPILE_HPP_INCLUDE_GUARD_H_
00028 #define OW_WQLCOMPILE_HPP_INCLUDE_GUARD_H_
00029 #include "OW_config.h"
00030 #include "OW_Array.hpp"
00031 #include "OW_WQLOperation.hpp"
00032 #include "OW_WQLOperand.hpp"
00033 #include "OW_WQLSelectStatement.hpp"
00034 #include "OW_NoSuchPropertyException.hpp"
00035
00036 namespace OW_NAMESPACE
00037 {
00038
00039 class OW_WQLCOMMON_API WQLCompile
00040 {
00041 public:
00042 struct term_el
00043 {
00044 term_el()
00045 {}
00046 term_el(bool mark_, WQLOperation op_, const WQLOperand& opn1_, const WQLOperand& opn2_)
00047 : mark(mark_)
00048 , op(op_)
00049 , opn1(opn1_)
00050 , opn2(opn2_)
00051 {}
00052
00053 bool mark;
00054 WQLOperation op;
00055 WQLOperand opn1;
00056 WQLOperand opn2;
00057
00058 void negate();
00059 };
00060
00061 enum el_type
00062 {
00063 EVAL_HEAP,
00064 TERMINAL_HEAP,
00065 OPERAND
00066 };
00067 struct stack_el
00068 {
00069 stack_el()
00070 {}
00071 stack_el(int opn_, el_type type_)
00072 : opn(opn_)
00073 , type(type_)
00074 {}
00075 int opn;
00076 el_type type;
00077 };
00078
00079
00080 struct eval_el
00081 {
00082 eval_el()
00083 {}
00084 eval_el(bool mark_, WQLOperation op_, int opn1_, el_type is_terminal1_, int opn2_, el_type is_terminal2_)
00085 : mark(mark_)
00086 , op(op_)
00087 , opn1(opn1_)
00088 , is_terminal1(is_terminal1_)
00089 , opn2(opn2_)
00090 , is_terminal2(is_terminal2_)
00091 {}
00092
00093 bool mark;
00094 WQLOperation op;
00095 int opn1;
00096 el_type is_terminal1;
00097 int opn2;
00098 el_type is_terminal2;
00099
00100 stack_el getFirst();
00101
00102 stack_el getSecond();
00103
00104 void setFirst(const stack_el s);
00105
00106 void setSecond(const stack_el s);
00107
00108 void assign_unary_to_first(const eval_el & assignee);
00109
00110 void assign_unary_to_second(const eval_el & assignee);
00111
00112
00113
00114 void order();
00115 };
00116
00117 typedef Array<term_el> TableauRow;
00118
00119 typedef Array<TableauRow> Tableau;
00120
00121 WQLCompile();
00122
00123 WQLCompile(const WQLSelectStatement& wqs);
00124 ~WQLCompile();
00125 void compile (const WQLSelectStatement * wqs);
00126 const Tableau& getTableau() const {return _tableau;}
00135 bool evaluate(const WQLPropertySource& source) const;
00136 void print(std::ostream& ostr);
00137 void printTableau(std::ostream& ostr);
00138 private:
00139 void _buildEvalHeap(const WQLSelectStatement * wqs);
00140 void _pushNOTDown();
00141 void _factoring();
00142 void _gatherDisj(Array<stack_el>& stk);
00143 void _gatherConj(Array<stack_el>& stk, stack_el sel);
00144 void _gather(Array<stack_el>& stk, stack_el sel, bool or_flag);
00145 void _sortTableau();
00146 static inline void _ResolveProperty(
00147 WQLOperand& op,
00148 const WQLPropertySource& source)
00149 {
00150
00151
00152
00153 if (op.getType() == WQLOperand::PROPERTY_NAME)
00154 {
00155 const String& propertyName = op.getPropertyName();
00156 if (!source.getValue(propertyName, op))
00157 OW_THROW(NoSuchPropertyException, "No such property");
00158 }
00159 }
00160
00161 #ifdef OW_WIN32
00162 #pragma warning (push)
00163 #pragma warning (disable: 4251)
00164 #endif
00165
00166
00167 Tableau _tableau;
00168
00169
00170
00171
00172
00173 Array<term_el> terminal_heap;
00174 Array<eval_el> eval_heap;
00175
00176 #ifdef OW_WIN32
00177 #pragma warning (pop)
00178 #endif
00179
00180 };
00181 OW_WQLCOMMON_API bool operator==(const WQLCompile::term_el& x, const WQLCompile::term_el& y);
00182 OW_WQLCOMMON_API bool operator!=(const WQLCompile::term_el& x, const WQLCompile::term_el& y);
00183
00184 }
00185
00186 #endif