Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SYMTAB_H
00019 #define SYMTAB_H
00020
00021 #include <list>
00022 #include <string>
00023
00024 class ModelComp;
00025
00026 class SymbolTable {
00027 public:
00028 enum symb_type {ST_NONE, ST_PARAM, ST_VAR, ST_CONS, ST_OBJ, ST_SET};
00029
00030 class Entry {
00031 private:
00032 const std::string name;
00033 const symb_type type;
00034 public:
00035 ModelComp *mc;
00036
00037 public:
00038 Entry(const std::string new_id, const symb_type new_type,
00039 ModelComp *new_mc) :
00040 name(new_id), type(new_type), mc(new_mc) {}
00041
00043 const std::string& id() const { return name; }
00044
00046 bool isType(symb_type t) const { return type == t; }
00047 };
00048
00049 private:
00050
00052 static const int n_hash = 100;
00053 static const bool logSymtab = false;
00054 std::list<Entry> table_[n_hash];
00055
00056 public:
00057 SymbolTable() {};
00058 void copy(const SymbolTable& src) {
00059 for(int i=0; i<n_hash; ++i) {
00060 for(std::list<Entry>::const_iterator j = src.table_[i].begin();
00061 j != src.table_[i].end(); ++j) {
00062 table_[i].push_back(*j);
00063 }
00064 }
00065 }
00066 bool defineSymbol(symb_type, char *id, ModelComp *mc);
00067 const Entry* findSymbol(const std::string& id) const;
00068 std::list<Entry> getListByType(const symb_type type) const;
00069
00070 private:
00071 unsigned long hash_function(const char *str) const;
00072 };
00073
00074 #endif