]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
bedc2f9dfd9bfa7bea3ce2e3adf85e58da856df3
[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
15 #include "music-output-def.hh"
16 #include "score.hh"
17 #include "identifier.hh"
18 #include "my-lily-lexer.hh"
19 #include "debug.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 DEFAULT_PRINT(Score);
85 DEFAULT_PRINT(Music_output_def);
86
87 /* ugh. */
88 #define DUMMY_STR(Class) \
89 String \
90 Class ## _identifier::do_str () const { \
91   return String (#Class); \
92 }
93
94 DUMMY_STR(Score);
95 DUMMY_STR(Music_output_def);
96 DUMMY_STR(Duration);
97
98 #define STRING_PRINT(Class) \
99 void \
100 Class ## _identifier::do_print () const\
101 {\
102   DEBUG_OUT << do_str () << '\n';\
103 }\
104
105
106 STRING_PRINT(Duration);
107   
108 #define DEFAULT_STR(Class) \
109 String \
110 Class ## _identifier::do_str () const\
111 {\
112   return to_str (*data_p_);\
113 }
114
115   
116
117 /*
118   fucking C++ blows me.
119  */
120
121 #define DEFAULT_ACCESSOR(Class)\
122 Class*\
123 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
124   ((Class ## _identifier*)this)->accessed_b_ = true;\
125   return copy_b ? new Class (*data_p_) : data_p_;\
126 }
127
128 #define VIRTUAL_ACCESSOR(Class)\
129 Class*\
130 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
131   ((Class ## _identifier*)this)->accessed_b_ = true;\
132   return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
133 }
134
135 #define IMPLEMENT_ID_CLASS(Class)       \
136         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
137         Class ## _identifier::Class ## _identifier (Class*st, int code) \
138           :Identifier (code)\
139         {\
140           data_p_ = st;\
141         }\
142 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
143   : Identifier (s)\
144 {\
145    data_p_ = s.access_content_ ## Class (true);\
146
147
148
149 IMPLEMENT_ID_CLASS(Duration);
150 IMPLEMENT_ID_CLASS(Score);
151 IMPLEMENT_ID_CLASS(Music_output_def);
152 VIRTUAL_ACCESSOR(Music_output_def);
153 DEFAULT_ACCESSOR(Duration);
154 DEFAULT_ACCESSOR(Score);
155
156
157 int
158 Identifier::print_smob (SCM s, SCM p, scm_print_state*)
159 {
160  return 1;  
161 }
162
163 SCM
164 Identifier::mark_smob (SCM s)
165 {
166   return SCM_EOL;
167 }
168
169
170