]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 1.3.74
[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 /*
11   JUNKTHIS!
12  */
13 #include <assert.h>
14 #include "music-output-def.hh"
15 #include "score.hh"
16 #include "identifier.hh"
17 #include "my-lily-lexer.hh"
18 #include "debug.hh"
19 #include "translator-group.hh"
20 #include "ly-smobs.icc"
21
22
23 IMPLEMENT_UNSMOB(Identifier, identifier);
24 IMPLEMENT_SMOBS(Identifier);
25 IMPLEMENT_DEFAULT_EQUAL_P(Identifier);
26
27 Identifier::Identifier (int code)
28 {
29   token_code_i_ = code;
30   accessed_b_ = 0;
31   smobify_self ();
32 }
33
34 Identifier::Identifier (Identifier const&s)
35   : Input (s)
36 {
37   smobify_self ();  
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(Score);
87 DEFAULT_PRINT(Music_output_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(Translator_group);
98 DUMMY_STR(Score);
99 DUMMY_STR(Music_output_def);
100 DUMMY_STR(Duration);
101
102 #define STRING_PRINT(Class) \
103 void \
104 Class ## _identifier::do_print () const\
105 {\
106   DEBUG_OUT << do_str () << '\n';\
107 }\
108
109
110 STRING_PRINT(Duration);
111   
112 #define DEFAULT_STR(Class) \
113 String \
114 Class ## _identifier::do_str () const\
115 {\
116   return to_str (*data_p_);\
117 }
118
119   
120
121 /*
122   fucking C++ blows me.
123  */
124
125 #define DEFAULT_ACCESSOR(Class)\
126 Class*\
127 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
128   ((Class ## _identifier*)this)->accessed_b_ = true;\
129   return copy_b ? new Class (*data_p_) : data_p_;\
130 }
131
132 #define VIRTUAL_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 ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
137 }
138
139 #define IMPLEMENT_ID_CLASS(Class)       \
140         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
141         Class ## _identifier::Class ## _identifier (Class*st, int code) \
142           :Identifier (code)\
143         {\
144           data_p_ = st;\
145         }\
146 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
147   : Identifier (s)\
148 {\
149    data_p_ = s.access_content_ ## Class (true);\
150
151
152
153 IMPLEMENT_ID_CLASS(Duration);
154 IMPLEMENT_ID_CLASS(Translator_group);
155 IMPLEMENT_ID_CLASS(Score);
156 IMPLEMENT_ID_CLASS(Music_output_def);
157 VIRTUAL_ACCESSOR(Translator_group);
158 VIRTUAL_ACCESSOR(Music_output_def);
159 DEFAULT_ACCESSOR(Duration);
160 DEFAULT_ACCESSOR(Score);
161
162
163 int
164 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
165 {
166  return 1;  
167 }
168
169 SCM
170 Identifier::mark_smob (SCM s)
171 {
172   return SCM_EOL;
173 }
174
175
176