00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CLASSAD_OPERATORS_H__
00022 #define __CLASSAD_OPERATORS_H__
00023
00024 #include "classad/exprTree.h"
00025
00026 BEGIN_NAMESPACE( classad )
00027
00028
00031 class Operation : public ExprTree
00032 {
00033 public:
00035 enum OpKind
00036 { __NO_OP__,
00038
00039 __FIRST_OP__,
00040
00041 __COMPARISON_START__ = __FIRST_OP__, LESS_THAN_OP = __COMPARISON_START__, LESS_OR_EQUAL_OP,
00051 META_EQUAL_OP,
00059 __COMPARISON_END__ = ISNT_OP,
00060
00061 __ARITHMETIC_START__, UNARY_PLUS_OP = __ARITHMETIC_START__, UNARY_MINUS_OP,
00072 __ARITHMETIC_END__ = MODULUS_OP,
00073
00074 __LOGIC_START__, LOGICAL_NOT_OP = __LOGIC_START__, LOGICAL_OR_OP,
00081 __LOGIC_END__ = LOGICAL_AND_OP,
00082
00083 __BITWISE_START__, BITWISE_NOT_OP = __BITWISE_START__, BITWISE_OR_OP,
00094 __BITWISE_END__ = URIGHT_SHIFT_OP,
00095
00096 __MISC_START__, PARENTHESES_OP = __MISC_START__, SUBSCRIPT_OP,
00103 __MISC_END__ = TERNARY_OP,
00104
00105 __LAST_OP__ = __MISC_END__
00106 };
00107
00109 Operation(const Operation &op);
00110
00112 virtual ~Operation ();
00113
00115 Operation &operator=(const Operation &op);
00116
00124 static Operation *MakeOperation(OpKind kind,ExprTree*e1=NULL,
00125 ExprTree*e2=NULL, ExprTree*e3=NULL);
00126
00133 void GetComponents( OpKind&, ExprTree*&, ExprTree*&, ExprTree *& )const;
00134
00135
00143 static void Operate (OpKind op, Value &op1, Value &op2, Value &result);
00144
00153 static void Operate (OpKind op, Value &op1, Value &op2, Value &op3,
00154 Value &result);
00155
00160 static bool IsStrictOperator( OpKind );
00161
00167 static int PrecedenceLevel( OpKind );
00168
00170 virtual ExprTree* Copy( ) const;
00171
00172 bool CopyFrom(const Operation &op);
00173
00174 virtual bool SameAs(const ExprTree *tree) const;
00175
00176 friend bool operator==(const Operation &op1, const Operation &op2);
00177
00178 protected:
00180 Operation ();
00181
00182 private:
00183 bool SameChild(const ExprTree *tree1, const ExprTree *tree2) const;
00184
00185 virtual void _SetParentScope( const ClassAd* );
00186 virtual bool _Evaluate( EvalState &, Value &) const;
00187 virtual bool _Evaluate( EvalState &, Value &, ExprTree*& ) const;
00188 virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00189
00190
00191
00192 bool shortCircuit( EvalState &state, Value const &arg1, Value &result ) const;
00193
00194
00195 bool combine( OpKind&, Value&, ExprTree*&,
00196 int, Value&, ExprTree*, int, Value&, ExprTree* ) const;
00197 bool flattenSpecials( EvalState &, Value &, ExprTree *& ) const;
00198
00199 static Operation* MakeOperation( OpKind, Value&, ExprTree* );
00200 static Operation* MakeOperation( OpKind, ExprTree*, Value& );
00201 static Value::ValueType coerceToNumber (Value&, Value &);
00202
00203 enum SigValues { SIG_NONE=0, SIG_CHLD1=1 , SIG_CHLD2=2 , SIG_CHLD3=4 };
00204
00205 static int _doOperation(OpKind,Value&,Value&,Value&,
00206 bool,bool,bool, Value&, EvalState* = NULL);
00207 static int doComparison (OpKind, Value&, Value&, Value&);
00208 static int doArithmetic (OpKind, Value&, Value&, Value&);
00209 static int doLogical (OpKind, Value&, Value&, Value&);
00210 static int doBitwise (OpKind, Value&, Value&, Value&);
00211 static int doRealArithmetic (OpKind, Value&, Value&, Value&);
00212 static int doTimeArithmetic (OpKind, Value&, Value&, Value&);
00213 static void compareStrings (OpKind, Value&, Value&, Value&,bool);
00214 static void compareReals (OpKind, Value&, Value&, Value&);
00215 static void compareBools (OpKind, Value&, Value&, Value&);
00216 static void compareIntegers (OpKind, Value&, Value&, Value&);
00217 static void compareAbsoluteTimes(OpKind, Value&, Value&, Value&);
00218 static void compareRelativeTimes(OpKind, Value&, Value&, Value&);
00219
00220
00221 OpKind operation;
00222 ExprTree *child1;
00223 ExprTree *child2;
00224 ExprTree *child3;
00225 };
00226
00227 END_NAMESPACE
00228
00229 #endif//__CLASSAD_OPERATORS_H__