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