2 identifier.cc -- implement identifier and derived classes
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
10 #include "midi-def.hh"
11 #include "paper-def.hh"
13 #include "identifier.hh"
14 #include "my-lily-lexer.hh"
16 #include "symtable.hh"
18 #include "script-def.hh"
20 #include "translator.hh"
23 IMPLEMENT_IS_TYPE_B(Identifier);
25 Identifier::Identifier (int code)
34 Identifier::Identifier (Identifier const&s)
37 token_code_i_ = s.token_code_i_;
38 accessed_b_ = s.accessed_b_;
42 Identifier::~Identifier()
47 Identifier::error (String expect) const
49 String e (_("Wrong identifier type: "));
50 e += String (name()) + _("(expected ") + expect + ")";
55 Identifier::str () const
61 Identifier::do_str () const
67 Identifier::print () const
69 DOUT << "identifier ";
73 Identifier::do_print () const
78 /* UGH MEMORY LEAK! */
79 #define DEFAULT_PRINT(Class, accessor) \
81 Class ## _identifier::do_print () const { \
82 Class *cl = ((Class ## _identifier *)this)->accessor();\
89 DEFAULT_PRINT(General_script_def, script);
90 DEFAULT_PRINT(Lookup, lookup);
91 DEFAULT_PRINT(Translator, translator);
92 DEFAULT_PRINT(Symtables, symtables);
93 DEFAULT_PRINT(Music, music);
94 DEFAULT_PRINT(Request, request);
95 DEFAULT_PRINT(Score, score);
96 DEFAULT_PRINT(Midi_def, mididef);
97 DEFAULT_PRINT(Paper_def, paperdef);
100 #define DUMMY_STR(Class) \
102 Class ## _identifier::do_str () const { \
103 return String (#Class); \
108 DUMMY_STR(General_script_def);
110 DUMMY_STR(Translator);
111 DUMMY_STR(Symtables);
116 DUMMY_STR(Paper_def);
119 #define STRING_PRINT(Class) \
121 Class ## _identifier::do_print () const\
123 DOUT << do_str () << "\n";\
127 STRING_PRINT(Duration);
130 STRING_PRINT(String);
132 #define DEFAULT_STR(Class) \
134 Class ## _identifier::do_str () const\
136 return String (*data_p_);\
145 fucking C++ blows me.
148 #define DEFAULT_ACCESSOR(Class, accessor)\
150 Class ## _identifier::accessor () const {\
151 ((Class ## _identifier*)this)->accessed_b_ = true;\
152 return new Class (*data_p_);\
155 #define VIRTUAL_ACCESSOR(Class, accessor)\
157 Class ## _identifier::accessor () const{\
158 ((Class ## _identifier*)this)->accessed_b_ = true;\
159 return (Class*)data_p_->clone();\
162 #define IMPLEMENT_ID_CLASS(Class, accessor) \
163 IMPLEMENT_IS_TYPE_B1(Class ## _identifier,Identifier)\
164 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
165 Class ## _identifier::Class ## _identifier (Class*st, int code):Identifier (code) { data_p_ = st; }\
166 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
169 data_p_ = s.accessor ();\
173 IMPLEMENT_ID_CLASS(Duration, duration);
174 IMPLEMENT_ID_CLASS(Translator, translator);
175 IMPLEMENT_ID_CLASS(int, intid);
176 IMPLEMENT_ID_CLASS(Real, real);
177 IMPLEMENT_ID_CLASS(String, string);
178 IMPLEMENT_ID_CLASS(General_script_def, script);
179 IMPLEMENT_ID_CLASS(Lookup, lookup);
180 IMPLEMENT_ID_CLASS(Symtables, symtables);
181 IMPLEMENT_ID_CLASS(Music, music);
182 IMPLEMENT_ID_CLASS(Score, score);
183 IMPLEMENT_ID_CLASS(Request, request);
184 IMPLEMENT_ID_CLASS(Midi_def, mididef);
185 IMPLEMENT_ID_CLASS(Paper_def, paperdef);
187 VIRTUAL_ACCESSOR(Music, music);
188 VIRTUAL_ACCESSOR(Request, request);
189 VIRTUAL_ACCESSOR(Translator, translator);
190 VIRTUAL_ACCESSOR(General_script_def, script);
192 DEFAULT_ACCESSOR(Duration, duration);
193 DEFAULT_ACCESSOR(int, intid);
194 DEFAULT_ACCESSOR(Real, real);
195 DEFAULT_ACCESSOR(String, string);
196 DEFAULT_ACCESSOR(Lookup, lookup);
197 DEFAULT_ACCESSOR(Symtables, symtables);
198 DEFAULT_ACCESSOR(Score, score);
199 DEFAULT_ACCESSOR(Midi_def, mididef);
200 DEFAULT_ACCESSOR(Paper_def, paperdef);