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

exprTree.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 __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 // forward declarations
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;       // NAC
00059 
00060                 // Cache_to_free are the things in the cache that must be
00061                 // freed when this gets deleted. The problem is that we put
00062                 // two kinds of things into the cache: some that must be
00063                 // freed, and some that must not be freed. We keep track of
00064                 // the ones that must be freed separately.  Memory managment
00065                 // is a pain! We should all use languages that do memory
00066                 // management for you.
00067                 //EvalCache   cache_to_delete; 
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 // classad
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__