exprTree.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_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 // forward declarations
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; // max recursion depth - current depth
00045 
00046         const ClassAd *rootAd;
00047         const ClassAd *curAd;
00048 
00049         bool        flattenAndInline;   // NAC
00050 
00051         // Cache_to_free are the things in the cache that must be
00052         // freed when this gets deleted. The problem is that we put
00053         // two kinds of things into the cache: some that must be
00054         // freed, and some that must not be freed. We keep track of
00055         // the ones that must be freed separately.  Memory managment
00056         // is a pain! We should all use languages that do memory
00057         // management for you.
00058         //EvalCache   cache_to_delete; 
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 // classad
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__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends