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