00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef __CLASSAD_EXPR_TREE_H__
00022 #define __CLASSAD_EXPR_TREE_H__
00023 
00024 #include "classad/classad_stl.h"
00025 #include "classad/common.h"
00026 #include "classad/value.h"
00027 
00028 BEGIN_NAMESPACE( classad )
00029 
00030 
00031 
00032 class ExprTree;
00033 class ClassAd;
00034 class MatchClassAd;
00035 
00036 class EvalState {
00037     public:
00038         EvalState( );
00039         ~EvalState( );
00040 
00041         void SetRootScope( );
00042         void SetScopes( const ClassAd* );
00043 
00044         int depth_remaining; 
00045 
00046         const ClassAd *rootAd;
00047         const ClassAd *curAd;
00048 
00049         bool        flattenAndInline;   
00050 
00051         
00052         
00053         
00054         
00055         
00056         
00057         
00058         
00059 };
00060 
00066 class ExprTree 
00067 {
00068     public:
00070         enum NodeKind {
00072             LITERAL_NODE,
00074             ATTRREF_NODE,
00076             OP_NODE,
00078             FN_CALL_NODE,
00080             CLASSAD_NODE,
00082             EXPR_LIST_NODE
00083         };
00084 
00086         virtual ~ExprTree ();
00087 
00098         void SetParentScope( const ClassAd* p );
00099 
00103         const ClassAd *GetParentScope( ) const { return( parentScope ); }
00104 
00108         virtual ExprTree *Copy( ) const = 0;
00109 
00114         NodeKind GetKind (void) const { return nodeKind; }
00115 
00117         void Puke( ) const;
00118 
00124         bool Evaluate( EvalState &state, Value &val ) const; 
00125         
00131         bool Evaluate( Value& v ) const;
00132 
00136         virtual bool SameAs(const ExprTree *tree) const = 0;
00137 
00138     protected:
00139         ExprTree ();
00140 
00144         void CopyFrom(const ExprTree &literal);
00145 
00146         bool Evaluate( Value& v, ExprTree*& t ) const;
00147         bool Flatten( Value& val, ExprTree*& tree) const;
00148 
00149         bool Flatten( EvalState&, Value&, ExprTree*&, int* = NULL ) const;
00150         bool Evaluate( EvalState &, Value &, ExprTree *& ) const;
00151 
00152         const ClassAd   *parentScope;
00153         NodeKind        nodeKind;
00154 
00155         enum {
00156             EVAL_FAIL,
00157             EVAL_OK,
00158             EVAL_UNDEF,
00159             PROP_UNDEF,
00160             EVAL_ERROR,
00161             PROP_ERROR
00162         };
00163 
00164 
00165     private:
00166         friend class Operation;
00167         friend class AttributeReference;
00168         friend class FunctionCall;
00169         friend class FunctionTable;
00170         friend class ExprList;
00171         friend class ExprListIterator;
00172         friend class ClassAd; 
00173 
00175         ExprTree(const ExprTree &tree);
00176         ExprTree &operator=(const ExprTree &literal);
00177 
00178         virtual void _SetParentScope( const ClassAd* )=0;
00179         virtual bool _Evaluate( EvalState&, Value& ) const=0;
00180         virtual bool _Evaluate( EvalState&, Value&, ExprTree*& ) const=0;
00181         virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* )const=0;
00182 
00183         friend bool operator==(const ExprTree &tree1, const ExprTree &tree2);
00184 };
00185 
00186 std::ostream& operator<<(std::ostream &os, const ExprTree &expr);
00187 
00188 END_NAMESPACE 
00189 
00190 #include "classad/literals.h"
00191 #include "classad/attrrefs.h"
00192 #include "classad/operators.h"
00193 #include "classad/exprList.h"
00194 #include "classad/classad.h"
00195 #include "classad/fnCall.h"
00196 
00197 #endif//__CLASSAD_EXPR_TREE_H__