vrq
csymbol.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 1997-2007, Mark Hummel
3  * This file is part of Vrq.
4  *
5  * Vrq is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * Vrq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301 USA
19  *****************************************************************************
20  */
21 /******************************************************************************
22  *
23  *
24  * csymbol.hpp
25  * - class definition for symbol CSymbol
26  *
27  *
28  ******************************************************************************
29  */
30 
31 #ifndef CSYMBOL_HPP
32 #define CSYMBOL_HPP
33 
34 #include "glue.h"
35 #include "cobject.h"
36 #include <set>
37 
38 
44 class CSymbol : public CObject
45 {
46 private:
47  struct SymbolCompare {
48  bool operator()( CSymbol* const& lhs, CSymbol* const& rhs );
49  };
50  static set<CSymbol*,SymbolCompare> hashTable;
51  static CSymbol* freeSymbol;
52  static CObstack* obstack;
53  static INT32 nextLabelId;
54 
56  const char* name;
57  INT32 hash;
58 public:
65  static CSymbol* Lookup( const char* name );
72  static CSymbol* GenSymbol( const char* prefix );
76  static void DumpTable( void );
80  static void SetObstack( CObstack* aObstack );
85  CSymbol( const char* aName );
89  ~CSymbol( void );
94  const char* GetName( void ) const;
99  int Escaped( void ) const;
104  int External() const;
108  static void DumpStats();
112 private:
113  static INT32 Hash( const char* string );
117 };
118 
129 const char* Identifier( const char* s );
130 
131 #endif // CSYMBOL_HPP
static CSymbol * GenSymbol(const char *prefix)
Generated a new symbol with a unique name using the given prefix.
int Escaped(void) const
Determine if string is an escaped symbol.
long INT32
Short cut for signed 32 bit integer.
Definition: glue.h:38
CSymbol(const char *aName)
Create a symbol.
static CSymbol * Lookup(const char *name)
Find symbol for given string.
Holder for character strings.
Definition: csymbol.h:44
Bulk object allocation object.
Definition: cobstack.h:46
int External() const
Determine if symbol is external reference return non-zero if symbol is external.
static void DumpTable(void)
Dump symbol table.
const char * GetName(void) const
Get symbol&#39;s text.
static void DumpStats()
Dump hash table stats.
const char * Identifier(const char *s)
Convert a string representing an identifier to an escaped format for printing (if needed)...
~CSymbol(void)
Destroy symbol.
Base class for vrq objects.
Definition: cobject.h:41
static void SetObstack(CObstack *aObstack)
Set heap to use for storage.