operators.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
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__,              // convenience
00038 
00039             __FIRST_OP__,
00040 
00041             __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)
00051  META_EQUAL_OP,        // (comparison)  IS_OP= META_EQUAL_OP,   // (comparison)META_NOT_EQUAL_OP,//(comparison)  ISNT_OP=META_NOT_EQUAL_OP,//(comparison)
00059             __COMPARISON_END__      = ISNT_OP,
00060 
00061             __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)
00072             __ARITHMETIC_END__      = MODULUS_OP,
00073 
00074             __LOGIC_START__,  LOGICAL_NOT_OP = __LOGIC_START__,  LOGICAL_OR_OP,          // (logical)  LOGICAL_AND_OP,         // (logical)
00081             __LOGIC_END__           = LOGICAL_AND_OP,
00082 
00083             __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)
00094             __BITWISE_END__         = URIGHT_SHIFT_OP,
00095 
00096             __MISC_START__,  PARENTHESES_OP = __MISC_START__,  SUBSCRIPT_OP,           // (misc)  TERNARY_OP,             // (misc)
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         // public access to operation function
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             // returns true if result is determined for this operation
00191             // based on the evaluated arg1
00192         bool shortCircuit( EvalState &state, Value const &arg1, Value &result ) const;
00193 
00194         // auxillary functionms
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         // operation specific information
00221         OpKind      operation;
00222         ExprTree    *child1;
00223         ExprTree    *child2;
00224         ExprTree    *child3;
00225 };
00226 
00227 END_NAMESPACE // classad
00228 
00229 #endif//__CLASSAD_OPERATORS_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends