]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 1.1.29
[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--1999 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 "script-def.hh"
17 #include "request.hh"
18 #include "translator.hh"
19 #include "notename-table.hh"
20
21
22
23 Identifier::Identifier (int code)
24 {
25   token_code_i_ = code;
26   accessed_b_ = 0;
27   init_b_ = 0;
28 }
29
30
31
32 Identifier::Identifier (Identifier const&s)
33   : Input (s)
34 {
35   token_code_i_ = s.token_code_i_;
36   accessed_b_ = s.accessed_b_;
37   init_b_ = s.init_b_;
38 }
39
40 Identifier::~Identifier()
41 {
42 }
43
44 void
45 Identifier::error (String expect) const
46 {
47   String e (_("Wrong identifier type: "));
48   e += _f ("%s expected", expect);
49   ::error (e);
50 }
51
52 String
53 Identifier::str () const
54 {
55   return do_str ();
56 }
57
58 String
59 Identifier::do_str () const
60 {
61   return "";
62 }
63
64 void
65 Identifier::print () const
66 {
67   DOUT << "identifier ";
68   do_print ();
69 }
70 void
71 Identifier::do_print () const
72 {
73 }
74
75 /* ugh. */
76 #define DEFAULT_PRINT(Class) \
77 void \
78 Class ## _identifier::do_print () const { \
79   Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
80   cl->print (); \
81 }
82
83
84
85 DEFAULT_PRINT(General_script_def);
86 DEFAULT_PRINT(Translator);
87 DEFAULT_PRINT(Music);
88 DEFAULT_PRINT(Request);
89 DEFAULT_PRINT(Score);
90 DEFAULT_PRINT(Midi_def);
91 DEFAULT_PRINT(Paper_def);
92
93 /* ugh. */
94 #define DUMMY_STR(Class) \
95 String \
96 Class ## _identifier::do_str () const { \
97   return String (#Class); \
98 }
99
100
101 DUMMY_STR(Notename_table);
102 DUMMY_STR(General_script_def);
103 DUMMY_STR(Translator);
104 DUMMY_STR(Music);
105 DUMMY_STR(Request);
106 DUMMY_STR(Score);
107 DUMMY_STR(Midi_def);
108 DUMMY_STR(Paper_def);
109 DUMMY_STR(Duration);
110
111 #define STRING_PRINT(Class) \
112 void \
113 Class ## _identifier::do_print () const\
114 {\
115   DOUT << do_str () << '\n';\
116 }\
117
118
119 STRING_PRINT(Duration);
120 STRING_PRINT(Real);
121 STRING_PRINT(int);
122 STRING_PRINT(String);
123 STRING_PRINT(Notename_table);
124   
125 #define DEFAULT_STR(Class) \
126 String \
127 Class ## _identifier::do_str () const\
128 {\
129   return to_str (*data_p_);\
130 }
131
132 DEFAULT_STR(int);
133 DEFAULT_STR(Real);
134 DEFAULT_STR(String);
135   
136
137 /*
138   fucking C++ blows me.
139  */
140
141 #define DEFAULT_ACCESSOR(Class)\
142 Class*\
143 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
144   ((Class ## _identifier*)this)->accessed_b_ = true;\
145   return copy_b ? new Class (*data_p_) : data_p_;\
146 }
147
148 #define VIRTUAL_ACCESSOR(Class)\
149 Class*\
150 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
151   ((Class ## _identifier*)this)->accessed_b_ = true;\
152   return copy_b ? (Class*)data_p_->clone() : data_p_;\
153 }
154
155 #define IMPLEMENT_ID_CLASS(Class)       \
156         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
157         Class ## _identifier::Class ## _identifier (Class*st, int code) \
158           :Identifier (code)\
159         {\
160           data_p_ = st;\
161         }\
162 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
163   : Identifier (s)\
164 {\
165    data_p_ = s.access_content_ ## Class (true);\
166
167
168
169 IMPLEMENT_ID_CLASS(Duration);
170 IMPLEMENT_ID_CLASS(Translator);
171 IMPLEMENT_ID_CLASS(int);
172 IMPLEMENT_ID_CLASS(Real);
173 IMPLEMENT_ID_CLASS(String);
174 IMPLEMENT_ID_CLASS(General_script_def);
175 IMPLEMENT_ID_CLASS(Music);
176 IMPLEMENT_ID_CLASS(Score);
177 IMPLEMENT_ID_CLASS(Request);
178 IMPLEMENT_ID_CLASS(Midi_def);
179 IMPLEMENT_ID_CLASS(Paper_def);
180 IMPLEMENT_ID_CLASS(Notename_table);
181 VIRTUAL_ACCESSOR(Music);
182 VIRTUAL_ACCESSOR(Request);
183 VIRTUAL_ACCESSOR(Translator);
184 VIRTUAL_ACCESSOR(General_script_def);
185 DEFAULT_ACCESSOR(Notename_table);
186 DEFAULT_ACCESSOR(Duration);
187 DEFAULT_ACCESSOR(int);
188 DEFAULT_ACCESSOR(Real);
189 DEFAULT_ACCESSOR(String);
190 DEFAULT_ACCESSOR(Score);
191 DEFAULT_ACCESSOR(Midi_def);
192 DEFAULT_ACCESSOR(Paper_def);
193