SymImpl.h

00001 /*          
00002  *             Copyright (C) 2005 Maarten Keijzer
00003  *
00004  *          This program is free software; you can redistribute it and/or modify
00005  *          it under the terms of version 2 of the GNU General Public License as 
00006  *          published by the Free Software Foundation. 
00007  *
00008  *          This program is distributed in the hope that it will be useful,
00009  *          but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *          GNU General Public License for more details.
00012  *
00013  *          You should have received a copy of the GNU General Public License
00014  *          along with this program; if not, write to the Free Software
00015  *          Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016  */
00017 #ifndef __SYM_IMPL_H__
00018 #define __SYM_IMPL_H__
00019 
00020 #include <vector>
00021 
00022 #include "token.h"
00023 
00024 class Sym;
00025 
00026 #if __GNUC__ > 4 
00027 #include <ext/pool_allocator.h>
00028 typedef std::vector<Sym, __gnu_cxx::__pool_alloc<Sym> > std::vector<Sym>;
00029 //typedef std::vector<Sym> SymVec;
00030 #else
00031 typedef std::vector<Sym> SymVec;
00032 #endif
00033 
00034 
00035 namespace detail {
00036 
00037 class SymArgsImpl;
00038 class SymArgs {
00039     
00040     mutable SymArgsImpl* pimpl; // contains circular reference to vector<Sym>
00041     mutable const std::vector<Sym>* args_ptr;
00042     
00043     public:
00044 
00045     SymArgs();
00046     SymArgs(const std::vector<Sym>& v);
00047     ~SymArgs();
00048 
00049     SymArgs(const SymArgs& args);
00050     const SymArgs& SymArgs::operator=(const SymArgs& other);
00051 
00052     size_t len() const;
00053     const std::vector<Sym>& vec() const { return *args_ptr; }
00054     void fixate() const;
00055 };
00056 
00057 class SymKey
00058 {
00059     public:
00060         SymKey(token_t _token) : args(), token(_token), hash_code(calc_hash()) {}
00061         SymKey(token_t _token, const detail::SymArgs& _args) : args(_args), token(_token), hash_code(calc_hash()) {}
00062         
00063         bool operator==(const SymKey& other) const;
00064         
00065         struct Hash
00066         {
00067             int operator()(const SymKey& k) const { return k.calc_hash(); }; 
00068         };
00069         
00070         unsigned arity() const { return args.len(); }
00071         const std::vector<Sym>& vec() const { return args.vec(); }
00072         
00073         // fixates (i.e. claims memory) for the embedded vector of Syms
00074         void fixate() const { args.fixate(); }
00075         
00076         int get_hash_code() const { return hash_code; }
00077         
00078         detail::SymArgs args;
00079         token_t token;     // identifies the function
00080 
00081     private:
00082         int calc_hash() const;
00083         int hash_code;
00084 };
00085 
00086 struct SymValue
00087 {
00088     friend class Sym;
00089      
00090     SymValue();
00091     ~SymValue(); 
00092     
00093     unsigned getRefCount() const { return refcount; }
00094     unsigned getSize() const     { return size; }
00095     unsigned getDepth() const    { return depth; }
00096     
00097      
00098     
00099     // for reference counting
00100     unsigned refcount;
00101     
00102     // some simple stats
00103     unsigned size;
00104     unsigned depth;
00105     UniqueNodeStats* uniqueNodeStats;
00106     
00107 };
00108 
00109 
00110 } // namespace detail
00111 
00112 #endif
00113 

Generated on Thu Oct 19 05:06:42 2006 for EO by  doxygen 1.3.9.1