Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

symboltable.hpp

00001 /*
00002  * Copyright (c) 2003, Raymond Bosman
00003  * Copyright (c) 2003, Frederik Holljen
00004  * All Rights Reserved.
00005  *
00006  * See COPYING for licensing.
00007  */
00008 
00009 
00010 #ifndef SYMBOLTABLE_HPP
00011 #define SYMBOLTABLE_HPP
00012 
00013 #include <string>
00014 #include <vector>
00015 #include <map>
00016 #include <list>
00017 
00018 #include "datatype.hpp"
00019 
00021 struct CheckerIdEntry
00022 {
00024     CheckerIdEntry( unsigned int linenr, const CkDataType &type = CkDataType::Undefined,
00025                     bool constType = false )
00026         {
00027             LineNr = linenr;
00028             Type = type;
00029             Const = constType;
00030         }
00031     unsigned int LineNr;
00032     CkDataType Type;
00033     bool Const;
00034 };
00035 
00037 struct CGIdEntry
00038 {
00040     CGIdEntry( unsigned int jvmid ) { JVMId = jvmid; }
00041     unsigned int JVMId;
00042 };
00043 
00045 struct CGFunctionEntry
00046 {
00048     CGFunctionEntry() { Returns = false; }
00049     std::string FunctionID;
00050     bool Returns;
00051 };
00052 
00053 
00055 class FunctionIdEntry
00056 {
00057         public:
00058 
00060     FunctionIdEntry (unsigned int linenr) :  LineNr(linenr) {};
00062     virtual ~FunctionIdEntry() 
00063         {
00064                 // Remove all parameters.
00065                 while (paramSize() > 0) parameterList.pop_front();
00066         }
00068     void paramAdd(CkDataType type) {parameterList.push_back(type);};
00070     int paramSize() const { return parameterList.size(); };
00072     void paramReset() {parameterIter = parameterList.begin();};
00074     CkDataType paramGet ()
00075         {
00076                 CkDataType type = (*parameterIter);
00077                 parameterIter++;
00078 
00079                 return type;
00080         }
00081 
00082         public:
00083                 unsigned int LineNr;
00084         CkDataType ResultType;
00085 
00086 
00087         private:
00088         std::list<CkDataType> parameterList;
00089                 std::list<CkDataType>::iterator parameterIter;
00090 };
00091 
00092 
00094 class SymbolTableException
00095 {
00096 };
00097 
00099 
00115 template<class T>
00116 class SymbolTable
00117 {
00118 public:
00119     SymbolTable();
00120     virtual ~SymbolTable();
00121 
00122     void openScope();
00123     void closeScope();
00125     unsigned int currentLevel() const { return CurrentLevel; }
00126     T *retrieve( const std::string &id );
00127     void enter( const std::string &id, T *newEntry );
00128 
00129 private:
00130     std::vector<std::map<std::string, T*>*> Scopes;
00131     unsigned int CurrentLevel;
00132 };
00133 
00134 #endif // SYMBOLTABLE_HPP

Generated on Mon Dec 1 14:26:27 2003 for Ck by doxygen 1.3.3