]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 0.1.63
[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@stack.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
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 += String (name()) + _("(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 /* UGH MEMORY LEAK! */
79 #define DEFAULT_PRINT(Class, accessor) \
80 void \
81 Class ## _identifier::do_print () const { \
82   Class *cl = ((Class ## _identifier *)this)->accessor();\
83   cl->print (); \
84   delete cl; \
85 }
86
87
88
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);
98
99 /* ugh. */
100 #define DUMMY_STR(Class) \
101 String \
102 Class ## _identifier::do_str () const { \
103   return String (#Class); \
104 }
105
106
107
108 DUMMY_STR(General_script_def);
109 DUMMY_STR(Lookup);
110 DUMMY_STR(Translator);
111 DUMMY_STR(Symtables);
112 DUMMY_STR(Music);
113 DUMMY_STR(Request);
114 DUMMY_STR(Score);
115 DUMMY_STR(Midi_def);
116 DUMMY_STR(Paper_def);
117 DUMMY_STR(Duration);
118
119 #define STRING_PRINT(Class) \
120 void \
121 Class ## _identifier::do_print () const\
122 {\
123   DOUT << do_str () << "\n";\
124 }\
125
126
127 STRING_PRINT(Duration);
128 STRING_PRINT(Real);
129 STRING_PRINT(int);
130 STRING_PRINT(String);
131
132 #define DEFAULT_STR(Class) \
133 String \
134 Class ## _identifier::do_str () const\
135 {\
136   return String (*data_p_);\
137 }
138
139 DEFAULT_STR(int);
140 DEFAULT_STR(Real);
141 DEFAULT_STR(String);
142   
143
144 /*
145   fucking C++ blows me.
146  */
147
148 #define DEFAULT_ACCESSOR(Class, accessor)\
149 Class*\
150 Class ## _identifier::accessor () const {\
151   ((Class ## _identifier*)this)->accessed_b_ = true;\
152   return new Class (*data_p_);\
153 }
154
155 #define VIRTUAL_ACCESSOR(Class, accessor)\
156 Class*\
157 Class ## _identifier::accessor () const{\
158   ((Class ## _identifier*)this)->accessed_b_ = true;\
159   return (Class*)data_p_->clone();\
160 }
161
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) \
167 : Identifier (s)\
168 {\
169    data_p_ = s.accessor ();\
170
171
172
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);
186
187 VIRTUAL_ACCESSOR(Music, music);
188 VIRTUAL_ACCESSOR(Request, request);
189 VIRTUAL_ACCESSOR(Translator, translator);
190 VIRTUAL_ACCESSOR(General_script_def, script);
191
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);
201