Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

symbol_table.h

Go to the documentation of this file.
00001 // AUTOMATICALLY GENERATED -- DO NOT EDIT!         -*- c++ -*-
00002 
00003 #ifndef symbol_table_h
00004 #define symbol_table_h
00005 
00006 #include <map>
00007 #include <string>
00008 #include <vector>
00009 #include <iosfwd>
00010 #include "type_rep.h"
00011 
00012 //
00013 // INTERFACE definition follows 
00014 //
00015 
00016 
00017 class Abstract_scope;
00027 
00028 class Symbol {
00029     std::string name;
00030     std::string::size_type base_len;
00031  public:
00032     const std::string& get_name() const { return name; }
00033     void set_name(const std::string& n, std::string::size_type bl) {
00034         name = n; base_len = bl;
00035     }
00036 
00037     enum Kind {
00038         // this list must match the array in Symbol::dump
00039         k_Variable,
00040         k_Namespace,
00041         k_Typedef,
00042         k_Function,
00043 
00044         k_Enum,
00045         k_ClassOrStruct,
00046         k_Union,
00047         k_ClassTemplate
00048     };
00049 
00050     enum Status {
00051         /* Symbol has been used indirectly, but not yet defined.
00052            For example, "extern int errno" in a function. 
00053            Must be first so that it converts to false. */
00054         st_Undefined,
00055         /* Symbol has been declared but not defined */
00056         st_Declared,
00057         /* Symbol has been defined */
00058         st_Defined
00059     };
00060 
00061     static bool is_tagged(Kind k) { return k >= k_Enum; }
00062     bool is_tagged() const { return is_tagged(get_kind()); }
00063 
00064     Status get_status() const { return status; }
00065     bool   is_defined() const { return status == st_Defined; }
00066     bool   is_declared() const { return status >= st_Declared; }
00067 
00068     virtual Kind get_kind() const = 0;
00069  private:
00070     Status status;
00071 
00072 public:  
00073   /********************************* Symbol ********************************/
00074   Symbol();
00075   
00076   virtual ~Symbol();
00077   
00079   virtual Abstract_scope* get_scope();
00080   
00082   void set_status(Status st);
00083   
00084   std::string get_basename() const;
00085   
00088   virtual void dump(std::ostream& out);
00089 };
00090 
00092 struct Symbol_pair {
00093     Symbol* untag;
00094     Symbol* tag;
00095     Symbol_pair(Symbol* u, Symbol* t) : untag(u), tag(t) { }
00096     Symbol_pair() : untag(0), tag(0) { }
00097     operator bool() const { return untag != 0; }
00098 };
00099 
00101 class Symbol_table {
00102     static Symbol_table instance;
00103     typedef std::map<std::string, Symbol_pair> content_type;
00104     content_type content;
00105  public:
00106     typedef content_type::const_iterator Sym_it;
00107 
00108     static Symbol_table& get_instance() { return instance; }
00109     static const char* dump_flags;
00110     Sym_it begin() const { return content.begin(); }
00111     Sym_it end() const { return content.end(); }
00112 
00113 public:  
00117   Symbol_table();
00118   
00119   virtual ~Symbol_table();
00120   
00122   void add_symbol(std::string name, std::string::size_type base_len, Symbol* sym);
00123   
00128   void set_peer(Symbol* orig, Symbol* faelschung);
00129   
00131   Symbol_pair get_symbol(std::string name) const;
00132   
00134   void dump(std::ostream& out);
00135   
00136   static bool has_dump_flag(char c);
00137   
00138   void clear();
00139 };
00140 
00142 class Type_symbol : public Symbol {
00143  public:
00144     void set_defined() { set_status(st_Defined); }
00145 
00146 public:  
00147   /**************************** Type_symbol ****************************/
00148   Type_symbol();
00149   
00150   ~Type_symbol();
00151   
00153   Type get_type() const;
00154 };
00155 
00156 //
00157 // IMPLEMENTATION of inline functions (and needed classes)
00158 //
00159 
00160 
00161 
00162 /********************************* Symbol ********************************/
00163 
00164 inline Symbol::Symbol()
00165     : name(), base_len(0), status(st_Undefined) 
00166 {
00167     // std::cout << "make " << (void*)this << "\n";
00168 }
00169 
00170 #endif // symbol_table_h

Generated on Mon Feb 10 17:32:57 2003 for VFiasco Semantics Compiler by doxygen1.2.15