00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __OPERATORS_H__
00025 #define __OPERATORS_H__
00026
00027 #include "exprTree.h"
00028
00029 BEGIN_NAMESPACE( classad )
00030
00031
00034 class Operation : public ExprTree
00035 {
00036 public:
00038 enum OpKind
00039 { __NO_OP__,
00041
00042 __FIRST_OP__,
00043
00044 __COMPARISON_START__ = __FIRST_OP__, LESS_THAN_OP = __COMPARISON_START__, LESS_OR_EQUAL_OP,
00054 META_EQUAL_OP,
00062 __COMPARISON_END__ = ISNT_OP,
00063
00064 __ARITHMETIC_START__, UNARY_PLUS_OP = __ARITHMETIC_START__, UNARY_MINUS_OP,
00075 __ARITHMETIC_END__ = MODULUS_OP,
00076
00077 __LOGIC_START__, LOGICAL_NOT_OP = __LOGIC_START__, LOGICAL_OR_OP,
00084 __LOGIC_END__ = LOGICAL_AND_OP,
00085
00086 __BITWISE_START__, BITWISE_NOT_OP = __BITWISE_START__, BITWISE_OR_OP,
00097 __BITWISE_END__ = URIGHT_SHIFT_OP,
00098
00099 __MISC_START__, PARENTHESES_OP = __MISC_START__, SUBSCRIPT_OP,
00106 __MISC_END__ = TERNARY_OP,
00107
00108 __LAST_OP__ = __MISC_END__
00109 };
00110
00112 Operation(const Operation &op);
00113
00115 ~Operation ();
00116
00118 Operation &operator=(const Operation &op);
00119
00127 static Operation *MakeOperation(OpKind kind,ExprTree*e1=NULL,
00128 ExprTree*e2=NULL, ExprTree*e3=NULL);
00129
00136 void GetComponents( OpKind&, ExprTree*&, ExprTree*&, ExprTree *& )const;
00137
00138
00146 static void Operate (OpKind op, Value &op1, Value &op2, Value &result);
00147
00156 static void Operate (OpKind op, Value &op1, Value &op2, Value &op3,
00157 Value &result);
00158
00163 static bool IsStrictOperator( OpKind );
00164
00170 static int PrecedenceLevel( OpKind );
00171
00173 virtual ExprTree* Copy( ) const;
00174
00175 bool CopyFrom(const Operation &op);
00176
00177 virtual bool SameAs(const ExprTree *tree) const;
00178
00179 friend bool operator==(const Operation &op1, const Operation &op2);
00180
00181 protected:
00183 Operation ();
00184
00185 private:
00186 bool SameChild(const ExprTree *tree1, const ExprTree *tree2) const;
00187
00188 virtual void _SetParentScope( const ClassAd* );
00189 virtual bool _Evaluate( EvalState &, Value &) const;
00190 virtual bool _Evaluate( EvalState &, Value &, ExprTree*& ) const;
00191 virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00192
00193
00194 bool combine( OpKind&, Value&, ExprTree*&,
00195 int, Value&, ExprTree*, int, Value&, ExprTree* ) const;
00196 bool flattenSpecials( EvalState &, Value &, ExprTree *& ) const;
00197
00198 static Operation* MakeOperation( OpKind, Value&, ExprTree* );
00199 static Operation* MakeOperation( OpKind, ExprTree*, Value& );
00200 static Value::ValueType coerceToNumber (Value&, Value &);
00201
00202 enum SigValues { SIG_NONE=0, SIG_CHLD1=1 , SIG_CHLD2=2 , SIG_CHLD3=4 };
00203
00204 static int _doOperation(OpKind,Value&,Value&,Value&,
00205 bool,bool,bool, Value&, EvalState* = NULL);
00206 static int doComparison (OpKind, Value&, Value&, Value&);
00207 static int doArithmetic (OpKind, Value&, Value&, Value&);
00208 static int doLogical (OpKind, Value&, Value&, Value&);
00209 static int doBitwise (OpKind, Value&, Value&, Value&);
00210 static int doRealArithmetic (OpKind, Value&, Value&, Value&);
00211 static int doTimeArithmetic (OpKind, Value&, Value&, Value&);
00212 static void compareStrings (OpKind, Value&, Value&, Value&,bool);
00213 static void compareReals (OpKind, Value&, Value&, Value&);
00214 static void compareBools (OpKind, Value&, Value&, Value&);
00215 static void compareIntegers (OpKind, Value&, Value&, Value&);
00216 static void compareAbsoluteTimes(OpKind, Value&, Value&, Value&);
00217 static void compareRelativeTimes(OpKind, Value&, Value&, Value&);
00218
00219
00220 OpKind operation;
00221 ExprTree *child1;
00222 ExprTree *child2;
00223 ExprTree *child3;
00224 };
00225
00226 END_NAMESPACE
00227
00228 #endif//__OPERATORS_H__