-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSymbol.h
136 lines (116 loc) · 4.07 KB
/
Symbol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* $Id: Symbol.h,v 1.18 2002-04-19 07:53:54 pgr Exp $ */
#ifndef COM_JAXO_YAXX_SYMBOL_H_INCLUDED
#define COM_JAXO_YAXX_SYMBOL_H_INCLUDED
/*---------+
| Includes |
+---------*/
#include <assert.h>
#include "Constants.h"
#include "HashMap.h"
#ifdef YAXX_NAMESPACE
namespace YAXX_NAMESPACE {
#endif
class SymbolMap;
class Variable;
/*------------------------------------------------------------- class Symbol -+
| |
+----------------------------------------------------------------------------*/
class Symbol : public MapItem {
friend class ConstantSymbol;
friend class SimpleSymbol;
friend class CompoundSymbol;
friend class SymbolPartIterator;
public:
enum { NO_CACHE = -1 };
bool isCompound() const { return (m_litCount > 0); }
bool isSimple() const { return (m_litCount == 0); }
RexxString & getStemName();
Symbol * getStemSymbol();
void cacheVar(Variable * var, int idArg);
Variable * getCachedVar(int idArg);
void uncacheVar() { m_id = NO_CACHE; }
private:
int m_id; // last routine that has set the value
int m_litCount; // Compound: # of dot delimited substring
void * m_value; // point a cached Variable, or a list of parts
Symbol(RexxString const & keyArg); // public uses one of SimpleSymbol, etc..
};
/*----------------------------------------------------- class ConstantSymbol -+
| |
+----------------------------------------------------------------------------*/
class ConstantSymbol : public Symbol {
public:
ConstantSymbol(RexxString const & keyArg);
};
/*------------------------------------------------------- class SimpleSymbol -+
| |
+----------------------------------------------------------------------------*/
class SimpleSymbol : public Symbol {
public:
SimpleSymbol(RexxString const & keyArg);
};
/*----------------------------------------------------- class CompoundSymbol -+
| |
+----------------------------------------------------------------------------*/
class CompoundSymbol : public Symbol {
public:
CompoundSymbol(RexxString const & keyArg, SymbolMap & map);
~CompoundSymbol();
};
/*------------------------------------------------- class SymbolPartIterator -+
| |
+----------------------------------------------------------------------------*/
class SymbolPartIterator {
public:
SymbolPartIterator(Symbol * sym);
bool operator()(); // cursor to next entry...
RexxString const & getName();
Symbol * getSymbol();
private:
Symbol * m_sym;
int m_ix;
Symbol * m_symPart;
};
/*---------------------------------------------------------- class SymbolMap -+
| |
+----------------------------------------------------------------------------*/
class REXX_API SymbolMap : private HashMap {
public:
Symbol * put(RexxString const & lit, Token tk);
Symbol * get(RexxString const & lit) { return (Symbol *)HashMap::get(lit); }
using HashMap::print;
private:
HashMap constMap;
};
/* --- INLINES --- */
inline Symbol * Symbol::getStemSymbol() {
// ASSERT(m_litCount > 0)
return *(Symbol **)m_value;
}
inline RexxString & Symbol::getStemName() {
// ASSERT(m_litCount > 0)
return (*(Symbol **)m_value)->key();
}
inline Variable * Symbol::getCachedVar(int idArg) {
// ASSERT(m_litCount == 0);
assert (idArg!= NO_CACHE);
if (m_id == idArg) {
return (Variable *)m_value;
}else {
return 0;
}
}
inline void Symbol::cacheVar(Variable * var, int idArg) {
// ASSERT(m_litCount == 0)
if (var) {
m_id = idArg;
m_value = var;
}else {
m_id = NO_CACHE;
}
}
#ifdef YAXX_NAMESPACE
}
#endif
#endif
/*===========================================================================*/