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 __EXPR_TREE_H__
00025 #define __EXPR_TREE_H__
00026
00027 #include "classad_stl.h"
00028 #include "common.h"
00029 #include "value.h"
00030
00031 #if defined (__GNUC__) && (__GNUC__<3)
00032 #include <ostream.h>
00033 #else
00034 #include <ostream>
00035 #endif
00036
00037 BEGIN_NAMESPACE( classad )
00038
00039
00040 class ExprTree;
00041 class ClassAd;
00042 class MatchClassAd;
00043
00044 typedef classad_hash_map< const ExprTree*, Value, ExprHash > EvalCache;
00045
00046 class EvalState {
00047 public:
00048 EvalState( );
00049 ~EvalState( );
00050
00051 void SetRootScope( );
00052 void SetScopes( const ClassAd* );
00053
00054 EvalCache cache;
00055 ClassAd *rootAd;
00056 ClassAd *curAd;
00057
00058 bool flattenAndInline;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 };
00069
00075 class ExprTree
00076 {
00077 public:
00079 enum NodeKind {
00081 LITERAL_NODE,
00083 ATTRREF_NODE,
00085 OP_NODE,
00087 FN_CALL_NODE,
00089 CLASSAD_NODE,
00091 EXPR_LIST_NODE
00092 };
00093
00095 virtual ~ExprTree ();
00096
00107 void SetParentScope( const ClassAd* p );
00108
00112 const ClassAd *GetParentScope( ) const { return( parentScope ); }
00113
00117 virtual ExprTree *Copy( ) const = 0;
00118
00123 NodeKind GetKind (void) const { return nodeKind; }
00124
00126 void Puke( ) const;
00127
00133 bool Evaluate( EvalState &state, Value &val ) const;
00134
00140 bool Evaluate( Value& v ) const;
00141
00145 virtual bool SameAs(const ExprTree *tree) const = 0;
00146
00147 protected:
00148 ExprTree ();
00149
00153 void CopyFrom(const ExprTree &literal);
00154
00155 bool Evaluate( Value& v, ExprTree*& t ) const;
00156 bool Flatten( Value& val, ExprTree*& tree) const;
00157
00158 bool Flatten( EvalState&, Value&, ExprTree*&, int* = NULL ) const;
00159 bool Evaluate( EvalState &, Value &, ExprTree *& ) const;
00160
00161 const ClassAd *parentScope;
00162 NodeKind nodeKind;
00163
00164 enum {
00165 EVAL_FAIL,
00166 EVAL_OK,
00167 EVAL_UNDEF,
00168 PROP_UNDEF,
00169 EVAL_ERROR,
00170 PROP_ERROR
00171 };
00172
00173
00174 private:
00175 friend class Operation;
00176 friend class AttributeReference;
00177 friend class FunctionCall;
00178 friend class FunctionTable;
00179 friend class ExprList;
00180 friend class ExprListIterator;
00181 friend class ClassAd;
00182
00184 ExprTree(const ExprTree &tree);
00185 ExprTree &operator=(const ExprTree &literal);
00186
00187 virtual void _SetParentScope( const ClassAd* )=0;
00188 virtual bool _Evaluate( EvalState&, Value& ) const=0;
00189 virtual bool _Evaluate( EvalState&, Value&, ExprTree*& ) const=0;
00190 virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* )const=0;
00191
00192 friend bool operator==(const ExprTree &tree1, const ExprTree &tree2);
00193 };
00194
00195 std::ostream& operator<<(std::ostream &os, const ExprTree &expr);
00196
00197 END_NAMESPACE
00198
00199 #include "literals.h"
00200 #include "attrrefs.h"
00201 #include "operators.h"
00202 #include "exprList.h"
00203 #include "classad.h"
00204 #include "fnCall.h"
00205
00206 #endif//__EXPR_TREE_H__