]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 1.3.60
[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   
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
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 ? dynamic_cast<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_group);
166 IMPLEMENT_ID_CLASS(int);
167 IMPLEMENT_ID_CLASS(Real);
168 IMPLEMENT_ID_CLASS(Music);
169 IMPLEMENT_ID_CLASS(Score);
170 IMPLEMENT_ID_CLASS(Request);
171 IMPLEMENT_ID_CLASS(Midi_def);
172 IMPLEMENT_ID_CLASS(Paper_def);
173 VIRTUAL_ACCESSOR(Music);
174 VIRTUAL_ACCESSOR(Request);
175 VIRTUAL_ACCESSOR(Translator_group);
176 DEFAULT_ACCESSOR(Duration);
177 DEFAULT_ACCESSOR(int);
178 DEFAULT_ACCESSOR(Real);
179 DEFAULT_ACCESSOR(Score);
180 DEFAULT_ACCESSOR(Midi_def);
181 DEFAULT_ACCESSOR(Paper_def);
182
183 int
184 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
185 {
186  return 1;  
187 }
188
189 SCM
190 Identifier::mark_smob (SCM s)
191 {
192   return SCM_EOL;
193 }
194
195
196
197 void
198 Identifier::do_smobify_self ()
199 {
200   
201 }