Main Page | Class Hierarchy | Class List | File List | Class Members

operators.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
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__,              // convenience
00041 
00042                         __FIRST_OP__,
00043 
00044                         __COMPARISON_START__    = __FIRST_OP__, LESS_THAN_OP = __COMPARISON_START__,  LESS_OR_EQUAL_OP,       // (comparison)  NOT_EQUAL_OP,           // (comparison)  EQUAL_OP,               // (comparison)  GREATER_OR_EQUAL_OP,    // (comparison)  GREATER_THAN_OP,        // (comparison)
00054  META_EQUAL_OP,        // (comparison)  IS_OP= META_EQUAL_OP,   // (comparison)META_NOT_EQUAL_OP,//(comparison)  ISNT_OP=META_NOT_EQUAL_OP,//(comparison)
00062                         __COMPARISON_END__      = ISNT_OP,
00063 
00064                         __ARITHMETIC_START__,  UNARY_PLUS_OP = __ARITHMETIC_START__,  UNARY_MINUS_OP,         // (arithmetic)  ADDITION_OP,            // (arithmetic)  SUBTRACTION_OP,         // (arithmetic)  MULTIPLICATION_OP,      // (arithmetic)  DIVISION_OP,            // (arithmetic)  MODULUS_OP,             // (arithmetic)
00075                         __ARITHMETIC_END__      = MODULUS_OP,
00076 
00077                         __LOGIC_START__,  LOGICAL_NOT_OP = __LOGIC_START__,  LOGICAL_OR_OP,          // (logical)  LOGICAL_AND_OP,         // (logical)
00084                         __LOGIC_END__           = LOGICAL_AND_OP,
00085 
00086                         __BITWISE_START__,  BITWISE_NOT_OP = __BITWISE_START__,  BITWISE_OR_OP,          // (bitwise)  BITWISE_XOR_OP,         // (bitwise)  BITWISE_AND_OP,         // (bitwise)  LEFT_SHIFT_OP,          // (bitwise)  RIGHT_SHIFT_OP,         // (bitwise) URIGHT_SHIFT_OP,        // (bitwise)
00097                         __BITWISE_END__         = URIGHT_SHIFT_OP,
00098 
00099                         __MISC_START__,  PARENTHESES_OP = __MISC_START__,  SUBSCRIPT_OP,           // (misc)  TERNARY_OP,             // (misc)
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                 // public access to operation function
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                 // auxillary functionms
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                 // operation specific information
00220                 OpKind          operation;
00221                 ExprTree        *child1;
00222                 ExprTree        *child2;
00223                 ExprTree        *child3;
00224 };
00225 
00226 END_NAMESPACE // classad
00227 
00228 #endif//__OPERATORS_H__