]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 1.0.10
[lilypond.git] / lily / identifier.cc
1 /*
2   identifier.cc -- implement identifier and derived classes
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <assert.h>
10 #include "midi-def.hh"
11 #include "paper-def.hh"
12 #include "score.hh"
13 #include "identifier.hh"
14 #include "my-lily-lexer.hh"
15 #include "debug.hh"
16 #include "symtable.hh"
17 #include "lookup.hh"
18 #include "script-def.hh"
19 #include "request.hh"
20 #include "translator.hh"
21 #include "notename-table.hh"
22
23 IMPLEMENT_IS_TYPE_B(Identifier);
24
25 Identifier::Identifier (int code)
26 {
27   token_code_i_ = code;
28   accessed_b_ = 0;
29   init_b_ = 0;
30 }
31
32
33
34 Identifier::Identifier (Identifier const&s)
35   : Input (s)
36 {
37   token_code_i_ = s.token_code_i_;
38   accessed_b_ = s.accessed_b_;
39   init_b_ = s.init_b_;
40 }
41
42 Identifier::~Identifier()
43 {
44 }
45
46 void
47 Identifier::error (String expect) const
48 {
49   String e (_("Wrong identifier type: "));
50   e += _f ("%s expected", expect);
51   ::error (e);
52 }
53
54 String
55 Identifier::str () const
56 {
57   return do_str ();
58 }
59
60 String
61 Identifier::do_str () const
62 {
63   return "";
64 }
65
66 void
67 Identifier::print () const
68 {
69   DOUT << "identifier ";
70   do_print ();
71 }
72 void
73 Identifier::do_print () const
74 {
75 }
76
77 /* ugh. */
78 #define DEFAULT_PRINT(Class) \
79 void \
80 Class ## _identifier::do_print () const { \
81   Class *cl = ((Class ## _identifier *)this)->access_ ## Class(false);\
82   cl->print (); \
83 }
84
85
86
87 DEFAULT_PRINT(General_script_def);
88 DEFAULT_PRINT(Lookup);
89 DEFAULT_PRINT(Translator);
90 DEFAULT_PRINT(Symtables);
91 DEFAULT_PRINT(Music);
92 DEFAULT_PRINT(Request);
93 DEFAULT_PRINT(Score);
94 DEFAULT_PRINT(Midi_def);
95 DEFAULT_PRINT(Paper_def);
96
97 /* ugh. */
98 #define DUMMY_STR(Class) \
99 String \
100 Class ## _identifier::do_str () const { \
101   return String (#Class); \
102 }
103
104
105 DUMMY_STR(Notename_table);
106 DUMMY_STR(General_script_def);
107 DUMMY_STR(Lookup);
108 DUMMY_STR(Translator);
109 DUMMY_STR(Symtables);
110 DUMMY_STR(Music);
111 DUMMY_STR(Request);
112 DUMMY_STR(Score);
113 DUMMY_STR(Midi_def);
114 DUMMY_STR(Paper_def);
115 DUMMY_STR(Duration);
116
117 #define STRING_PRINT(Class) \
118 void \
119 Class ## _identifier::do_print () const\
120 {\
121   DOUT << do_str () << '\n';\
122 }\
123
124
125 STRING_PRINT(Duration);
126 STRING_PRINT(Real);
127 STRING_PRINT(int);
128 STRING_PRINT(String);
129 STRING_PRINT(Notename_table);
130   
131 #define DEFAULT_STR(Class) \
132 String \
133 Class ## _identifier::do_str () const\
134 {\
135   return to_str (*data_p_);\
136 }
137
138 DEFAULT_STR(int);
139 DEFAULT_STR(Real);
140 DEFAULT_STR(String);
141   
142
143 /*
144   fucking C++ blows me.
145  */
146
147 #define DEFAULT_ACCESSOR(Class)\
148 Class*\
149 Class ## _identifier::access_ ## Class (bool copy_b) const {\
150   ((Class ## _identifier*)this)->accessed_b_ = true;\
151   return copy_b ? new Class (*data_p_) : data_p_;\
152 }
153
154 #define VIRTUAL_ACCESSOR(Class)\
155 Class*\
156 Class ## _identifier::access_ ## Class (bool copy_b) const{\
157   ((Class ## _identifier*)this)->accessed_b_ = true;\
158   return copy_b ? (Class*)data_p_->clone() : data_p_;\
159 }
160
161 #define IMPLEMENT_ID_CLASS(Class)       \
162         IMPLEMENT_IS_TYPE_B1(Class ## _identifier,Identifier)\
163         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
164         Class ## _identifier::Class ## _identifier (Class*st, int code) \
165           :Identifier (code)\
166         {\
167           data_p_ = st;\
168         }\
169 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
170   : Identifier (s)\
171 {\
172    data_p_ = s.access_ ## Class (true);\
173
174
175
176 IMPLEMENT_ID_CLASS(Duration);
177 IMPLEMENT_ID_CLASS(Translator);
178 IMPLEMENT_ID_CLASS(int);
179 IMPLEMENT_ID_CLASS(Real);
180 IMPLEMENT_ID_CLASS(String);
181 IMPLEMENT_ID_CLASS(General_script_def);
182 IMPLEMENT_ID_CLASS(Lookup);
183 IMPLEMENT_ID_CLASS(Symtables);
184 IMPLEMENT_ID_CLASS(Music);
185 IMPLEMENT_ID_CLASS(Score);
186 IMPLEMENT_ID_CLASS(Request);
187 IMPLEMENT_ID_CLASS(Midi_def);
188 IMPLEMENT_ID_CLASS(Paper_def);
189 IMPLEMENT_ID_CLASS(Notename_table);
190 VIRTUAL_ACCESSOR(Music);
191 VIRTUAL_ACCESSOR(Request);
192 VIRTUAL_ACCESSOR(Translator);
193 VIRTUAL_ACCESSOR(General_script_def);
194 DEFAULT_ACCESSOR(Notename_table);
195 DEFAULT_ACCESSOR(Duration);
196 DEFAULT_ACCESSOR(int);
197 DEFAULT_ACCESSOR(Real);
198 DEFAULT_ACCESSOR(String);
199 DEFAULT_ACCESSOR(Lookup);
200 DEFAULT_ACCESSOR(Symtables);
201 DEFAULT_ACCESSOR(Score);
202 DEFAULT_ACCESSOR(Midi_def);
203 DEFAULT_ACCESSOR(Paper_def);
204