]> git.donarmstrong.com Git - lilypond.git/blob - lily/symtable.cc
release: 0.0.49
[lilypond.git] / lily / symtable.cc
1 /*
2   symtable.cc -- implement Symbol_table
3
4   source file of the 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 "symbol.hh"
14 #include "assoc.hh"
15 #include "assoc-iter.hh"
16 #include "symtable.hh"
17
18 Symtables::Symtables()
19 {
20 }
21
22 Symtables::Symtables(Symtables const &s)
23 {
24     for (Assoc_iter<String, Symtable*>  i(s); i.ok(); i++) {
25         add(i.key(), new Symtable(*i.val()));
26     }
27 }
28
29 Symtables::~Symtables()
30 {
31     for (Assoc_iter<String, Symtable*>  i(*this); i.ok(); i++) {
32         delete i.val();
33     }
34 }
35
36 Symbol 
37 Symtable::lookup(String s) const
38 {
39     if (elt_b(s))
40         return (*this)[s];
41     else {
42         error( "Symtable `" + id_str+ "\': unknown symbol `" +s+"'\n");
43     }
44     Symbol sy;                  // unreachable
45     return sy;
46 }
47
48 Symtable* 
49 Symtables::operator()(String s) 
50 {
51     return Assoc<String, Symtable*>::operator[](s);
52
53 void
54 Symtables::print() const
55 {
56     for (Assoc_iter<String, Symtable*>  i(*this); i.ok(); i++) {
57         mtor << "table \'" << i.key() << "\' {\n";
58         i.val()->print();
59         mtor << "}\n";
60     }
61 }
62 void
63 Symtable::print() const
64 {
65     for (Assoc_iter<String, Symbol>  i(*this); i.ok(); i++) {
66         mtor << "\'" << i.key() << "\'->" << i.val().str() << "\n";
67     }
68 }
69         
70 void
71 Symtables::add(String s, Symtable*p)
72 {
73     p-> id_str = s;
74     Assoc<String, Symtable*>::add(s,p);
75 }