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