00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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;
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 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
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;
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
00100 unsigned refcount;
00101
00102
00103 unsigned size;
00104 unsigned depth;
00105 UniqueNodeStats* uniqueNodeStats;
00106
00107 };
00108
00109
00110 }
00111
00112 #endif
00113