]> git.donarmstrong.com Git - lilypond.git/blob - lily/symtable.cc
release: 0.1.47
[lilypond.git] / lily / symtable.cc
1 /*
2   symtable.cc -- implement Symbol_table
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "misc.hh"
10 #include "dimen.hh"
11 #include "debug.hh"
12 #include "real.hh"
13 #include "atom.hh"
14 #include "assoc.hh"
15 #include "assoc-iter.hh"
16 #include "symtable.hh"
17
18 Symtables::Symtables()
19 {
20 }
21
22
23 Symtables::Symtables (Symtables const &s)
24   : Dictionary<Symtable*> (s)
25 {
26   for (Assoc_iter<String, Symtable*>  i (s); i.ok(); i++)
27     {
28       add (i.key(), new Symtable (*i.val ()));
29     }
30 }
31
32 Symtables::~Symtables()
33 {
34   for (Assoc_iter<String, Symtable*>  i (*this); i.ok(); i++)
35     {
36       delete i.val();
37     }
38 }
39
40 Atom
41 Symtable::lookup (String s) const
42 {
43   if (elt_b (s))
44     return (*this)[s];
45   else
46     {
47       warning ("Symtable `" + id_str+ _("\': unknown symbol `") +s+"'\n");
48       Atom sy;
49       return sy;
50     }
51 }
52
53 Symtable*
54 Symtables::operator()(String s)
55 {
56   if (!elt_b (s))
57     {
58       error ("Symtable `" + s + _("\' unknown"));
59       /* 
60          We can't return, because we'll dump core anyway.
61        */
62       return 0;
63     }
64   else
65     return Dictionary<Symtable*>::operator[](s);
66 }
67 void
68 Symtables::print() const
69 {
70   for (Assoc_iter<String, Symtable*>  i (*this); i.ok(); i++)
71     {
72       DOUT << "table \'" << i.key() << "\' {\n";
73       i.val()->print ();
74       DOUT << "}\n";
75     }
76 }
77 void
78 Symtable::print() const
79 {
80   for (Assoc_iter<String, Atom>  i (*this); i.ok(); i++)
81     {
82       DOUT << "\'" << i.key() << "\'->" << i.val ().str () << "\n";
83     }
84 }
85
86 void
87 Symtables::add (String s, Symtable*p)
88 {
89   p-> id_str = s;
90   Dictionary<Symtable*>::add (s,p);
91 }