-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringtab.cc
79 lines (64 loc) · 1.68 KB
/
stringtab.cc
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
//
// See copyright.h for copyright notice and limitation of liability
// and disclaimer of warranty provisions.
//
#include "copyright.h"
#include <assert.h>
#include "stringtab_functions.h"
#include "stringtab.h"
extern char *pad(int n);
//
// Explicit template instantiations.
// Comment out for versions of g++ prior to 2.7
//
template class StringTable<IdEntry>;
template class StringTable<StringEntry>;
template class StringTable<IntEntry>;
Entry::Entry(char *s, int l, int i) : len(l), index(i) {
str = new char [len+1];
strncpy(str, s, len);
str[len] = '\0';
}
int Entry::equal_string(char *string, int length) const
{
return (len == length) && (strncmp(str,string,len) == 0);
}
ostream& Entry::print(ostream& s) const
{
return s << "{" << str << ", " << len << ", " << index << "}\n";
}
ostream& operator<<(ostream& s, const Entry& sym)
{
return s << sym.get_string();
}
ostream& operator<<(ostream& s, Symbol sym)
{
return s << *sym;
}
char *Entry::get_string() const
{
return str;
}
int Entry::get_len() const
{
return len;
}
// A Symbol is a pointer to an Entry. Symbols are stored directly
// as nodes of the abstract syntax tree defined by the cool-tree.aps.
// The APS package requires that copy and print (called dump) functions
// be defined for components of the abstract syntax tree.
//
Symbol copy_Symbol(const Symbol s)
{
return s;
}
void dump_Symbol(ostream& s, int n, Symbol sym)
{
s << pad(n) << sym << endl;
}
StringEntry::StringEntry(char *s, int l, int i) : Entry(s,l,i) { }
IdEntry::IdEntry(char *s, int l, int i) : Entry(s,l,i) { }
IntEntry::IntEntry(char *s, int l, int i) : Entry(s,l,i) { }
IdTable idtable;
IntTable inttable;
StrTable stringtable;