]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
patch::: 1.3.59.uu2.jcn1
[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 #include "ly-smobs.icc"
23
24 IMPLEMENT_UNSMOB(Identifier, identifier);
25 IMPLEMENT_SMOBS(Identifier);
26
27 Identifier::Identifier (int code)
28 {
29   self_scm_ = SCM_EOL;
30   token_code_i_ = code;
31   accessed_b_ = 0;
32 }
33
34 Identifier::Identifier (Identifier const&s)
35   : Input (s)
36 {
37   self_scm_ = SCM_EOL;
38   token_code_i_ = s.token_code_i_;
39   accessed_b_ = s.accessed_b_;
40 }
41
42 Identifier::~Identifier()
43 {
44 }
45
46 void
47 Identifier::error (String expect) const
48 {
49   ::error (_f ("wrong identifier type, expected: `%s'", expect));
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   DEBUG_OUT << "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(Translator_group);
86 DEFAULT_PRINT(Music);
87 DEFAULT_PRINT(Request);
88 DEFAULT_PRINT(Score);
89 DEFAULT_PRINT(Midi_def);
90 DEFAULT_PRINT(Paper_def);
91
92 /* ugh. */
93 #define DUMMY_STR(Class) \
94 String \
95 Class ## _identifier::do_str () const { \
96   return String (#Class); \
97 }
98
99
100 DUMMY_STR(Translator_group);
101 DUMMY_STR(Music);
102 DUMMY_STR(Request);
103 DUMMY_STR(Score);
104 DUMMY_STR(Midi_def);
105 DUMMY_STR(Paper_def);
106 DUMMY_STR(Duration);
107
108 #define STRING_PRINT(Class) \
109 void \
110 Class ## _identifier::do_print () const\
111 {\
112   DEBUG_OUT << do_str () << '\n';\
113 }\
114
115
116 STRING_PRINT(Duration);
117 STRING_PRINT(Real);
118 STRING_PRINT(int);
119 STRING_PRINT(String);
120   
121 #define DEFAULT_STR(Class) \
122 String \
123 Class ## _identifier::do_str () const\
124 {\
125   return to_str (*data_p_);\
126 }
127
128 DEFAULT_STR(int);
129 DEFAULT_STR(Real);
130 DEFAULT_STR(String);
131   
132
133 /*
134   fucking C++ blows me.
135  */
136
137 #define DEFAULT_ACCESSOR(Class)\
138 Class*\
139 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
140   ((Class ## _identifier*)this)->accessed_b_ = true;\
141   return copy_b ? new Class (*data_p_) : data_p_;\
142 }
143
144 #define VIRTUAL_ACCESSOR(Class)\
145 Class*\
146 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
147   ((Class ## _identifier*)this)->accessed_b_ = true;\
148   return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
149 }
150
151 #define IMPLEMENT_ID_CLASS(Class)       \
152         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
153         Class ## _identifier::Class ## _identifier (Class*st, int code) \
154           :Identifier (code)\
155         {\
156           data_p_ = st;\
157         }\
158 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
159   : Identifier (s)\
160 {\
161    data_p_ = s.access_content_ ## Class (true);\
162
163
164
165 IMPLEMENT_ID_CLASS(Duration);
166 IMPLEMENT_ID_CLASS(Translator_group);
167 IMPLEMENT_ID_CLASS(int);
168 IMPLEMENT_ID_CLASS(Real);
169 IMPLEMENT_ID_CLASS(String);
170 IMPLEMENT_ID_CLASS(Music);
171 IMPLEMENT_ID_CLASS(Score);
172 IMPLEMENT_ID_CLASS(Request);
173 IMPLEMENT_ID_CLASS(Midi_def);
174 IMPLEMENT_ID_CLASS(Paper_def);
175 VIRTUAL_ACCESSOR(Music);
176 VIRTUAL_ACCESSOR(Request);
177 VIRTUAL_ACCESSOR(Translator_group);
178 DEFAULT_ACCESSOR(Duration);
179 DEFAULT_ACCESSOR(int);
180 DEFAULT_ACCESSOR(Real);
181 DEFAULT_ACCESSOR(String);
182 DEFAULT_ACCESSOR(Score);
183 DEFAULT_ACCESSOR(Midi_def);
184 DEFAULT_ACCESSOR(Paper_def);
185
186 int
187 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
188 {
189  return 1;  
190 }
191
192 SCM
193 Identifier::mark_smob (SCM s)
194 {
195   return SCM_EOL;
196 }
197
198
199
200 void
201 Identifier::do_smobify_self ()
202 {
203   
204 }