lilypond-1.1.21
[lilypond.git] / lily / identifier.cc
blobb9e422a366504db689e0eca74c7f9a19ec69c563
1 /*
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@cs.uu.nl>
7 */
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 "script-def.hh"
18 #include "request.hh"
19 #include "translator.hh"
20 #include "notename-table.hh"
24 Identifier::Identifier (int code)
26 token_code_i_ = code;
27 accessed_b_ = 0;
28 init_b_ = 0;
33 Identifier::Identifier (Identifier const&s)
34 : Input (s)
36 token_code_i_ = s.token_code_i_;
37 accessed_b_ = s.accessed_b_;
38 init_b_ = s.init_b_;
41 Identifier::~Identifier()
45 void
46 Identifier::error (String expect) const
48 String e (_("Wrong identifier type: "));
49 e += _f ("%s expected", expect);
50 ::error (e);
53 String
54 Identifier::str () const
56 return do_str ();
59 String
60 Identifier::do_str () const
62 return "";
65 void
66 Identifier::print () const
68 DOUT << "identifier ";
69 do_print ();
71 void
72 Identifier::do_print () const
76 /* ugh. */
77 #define DEFAULT_PRINT(Class) \
78 void \
79 Class ## _identifier::do_print () const { \
80 Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
81 cl->print (); \
86 DEFAULT_PRINT(General_script_def);
87 DEFAULT_PRINT(Translator);
88 DEFAULT_PRINT(Symtables);
89 DEFAULT_PRINT(Music);
90 DEFAULT_PRINT(Request);
91 DEFAULT_PRINT(Score);
92 DEFAULT_PRINT(Midi_def);
93 DEFAULT_PRINT(Paper_def);
95 /* ugh. */
96 #define DUMMY_STR(Class) \
97 String \
98 Class ## _identifier::do_str () const { \
99 return String (#Class); \
103 DUMMY_STR(Notename_table);
104 DUMMY_STR(General_script_def);
105 DUMMY_STR(Translator);
106 DUMMY_STR(Symtables);
107 DUMMY_STR(Music);
108 DUMMY_STR(Request);
109 DUMMY_STR(Score);
110 DUMMY_STR(Midi_def);
111 DUMMY_STR(Paper_def);
112 DUMMY_STR(Duration);
114 #define STRING_PRINT(Class) \
115 void \
116 Class ## _identifier::do_print () const\
118 DOUT << do_str () << '\n';\
122 STRING_PRINT(Duration);
123 STRING_PRINT(Real);
124 STRING_PRINT(int);
125 STRING_PRINT(String);
126 STRING_PRINT(Notename_table);
128 #define DEFAULT_STR(Class) \
129 String \
130 Class ## _identifier::do_str () const\
132 return to_str (*data_p_);\
135 DEFAULT_STR(int);
136 DEFAULT_STR(Real);
137 DEFAULT_STR(String);
141 fucking C++ blows me.
144 #define DEFAULT_ACCESSOR(Class)\
145 Class*\
146 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
147 ((Class ## _identifier*)this)->accessed_b_ = true;\
148 return copy_b ? new Class (*data_p_) : data_p_;\
151 #define VIRTUAL_ACCESSOR(Class)\
152 Class*\
153 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
154 ((Class ## _identifier*)this)->accessed_b_ = true;\
155 return copy_b ? (Class*)data_p_->clone() : data_p_;\
158 #define IMPLEMENT_ID_CLASS(Class) \
159 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
160 Class ## _identifier::Class ## _identifier (Class*st, int code) \
161 :Identifier (code)\
163 data_p_ = st;\
165 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
166 : Identifier (s)\
168 data_p_ = s.access_content_ ## Class (true);\
172 IMPLEMENT_ID_CLASS(Duration);
173 IMPLEMENT_ID_CLASS(Translator);
174 IMPLEMENT_ID_CLASS(int);
175 IMPLEMENT_ID_CLASS(Real);
176 IMPLEMENT_ID_CLASS(String);
177 IMPLEMENT_ID_CLASS(General_script_def);
178 IMPLEMENT_ID_CLASS(Symtables);
179 IMPLEMENT_ID_CLASS(Music);
180 IMPLEMENT_ID_CLASS(Score);
181 IMPLEMENT_ID_CLASS(Request);
182 IMPLEMENT_ID_CLASS(Midi_def);
183 IMPLEMENT_ID_CLASS(Paper_def);
184 IMPLEMENT_ID_CLASS(Notename_table);
185 VIRTUAL_ACCESSOR(Music);
186 VIRTUAL_ACCESSOR(Request);
187 VIRTUAL_ACCESSOR(Translator);
188 VIRTUAL_ACCESSOR(General_script_def);
189 DEFAULT_ACCESSOR(Notename_table);
190 DEFAULT_ACCESSOR(Duration);
191 DEFAULT_ACCESSOR(int);
192 DEFAULT_ACCESSOR(Real);
193 DEFAULT_ACCESSOR(String);
194 DEFAULT_ACCESSOR(Symtables);
195 DEFAULT_ACCESSOR(Score);
196 DEFAULT_ACCESSOR(Midi_def);
197 DEFAULT_ACCESSOR(Paper_def);