Version 0.9.11 (????-??-??)
---------------------------
+- Implemented #1335305 symbol table reimplementation, just slightly modifed.
Version 0.9.10 (2005-09-04)
---------------------------
namespace re2c
{
-Symbol *Symbol::first = NULL;
-
-Symbol::Symbol(const SubStr &str) : next(first), name(str), re(NULL)
+void Symbol::ClearTable()
{
- first = this;
+ symbol_table.clear();
}
+Symbol::SymbolTable Symbol::symbol_table;
+
Symbol *Symbol::find(const SubStr &str)
{
- for (Symbol *sym = first; sym; sym = sym->next)
- if (sym->name == str)
- return sym;
+ const std::string ss(str.to_string());
+ SymbolTable::const_iterator it = symbol_table.find(ss);
- return new Symbol(str);
+ if (it == symbol_table.end())
+ {
+ return (*symbol_table.insert(SymbolTable::value_type(ss, new Symbol(str))).first).second;
+ }
+
+ return (*it).second;
}
void showIns(std::ostream &o, const Ins &i, const Ins &base)
#include "scanner.h"
#include "re.h"
#include <iosfwd>
+#include <map>
namespace re2c
{
class Symbol
{
-
public:
- static Symbol *first;
- Symbol *next;
- Str name;
- RegExp *re;
-public:
- Symbol(const SubStr&);
+ RegExp* re;
+
static Symbol *find(const SubStr&);
+ static void ClearTable();
+
+ ~Symbol()
+ {
+ /** \todo should we delete 're'? */
+ }
+
+protected:
+
+ Symbol(const SubStr& str)
+ : name(str)
+ , re(NULL)
+ {
+ }
+
+private:
+
+ typedef std::map<std::string, Symbol*> SymbolTable;
+
+ static SymbolTable symbol_table;
+
+ Str name;
};
void line_source(unsigned int, std::ostream&);
#define _substr_h
#include <iostream>
+#include <string>
#include "basics.h"
namespace re2c
SubStr(char*);
SubStr(const SubStr&);
void out(std::ostream&) const;
+ std::string to_string() const
+ {
+ return std::string(str, len);
+ }
};
class Str: public SubStr