2 identifier.cc -- implement identifier and derived classes
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "music-output-def.hh"
15 #include "identifier.hh"
16 #include "my-lily-lexer.hh"
19 #include "translator-group.hh"
20 #include "ly-smobs.icc"
22 IMPLEMENT_UNSMOB(Identifier
, identifier
);
23 IMPLEMENT_SMOBS(Identifier
);
25 Identifier::Identifier (int code
)
32 Identifier::Identifier (Identifier
const&s
)
36 token_code_i_
= s
.token_code_i_
;
37 accessed_b_
= s
.accessed_b_
;
40 Identifier::~Identifier()
45 Identifier::error (String expect
) const
47 ::error (_f ("wrong identifier type, expected: `%s'", expect
));
51 Identifier::str () const
57 Identifier::do_str () const
63 Identifier::print () const
65 DEBUG_OUT
<< "identifier ";
69 Identifier::do_print () const
74 #define DEFAULT_PRINT(Class) \
76 Class ## _identifier::do_print () const { \
77 Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
83 DEFAULT_PRINT(Translator_group
);
85 DEFAULT_PRINT(Request
);
87 DEFAULT_PRINT(Music_output_def
);
90 #define DUMMY_STR(Class) \
92 Class ## _identifier::do_str () const { \
93 return String (#Class); \
97 DUMMY_STR(Translator_group
);
101 DUMMY_STR(Music_output_def
);
104 #define STRING_PRINT(Class) \
106 Class ## _identifier::do_print () const\
108 DEBUG_OUT << do_str () << '\n';\
112 STRING_PRINT(Duration);
114 #define DEFAULT_STR(Class) \
116 Class ## _identifier::do_str () const\
118 return to_str (*data_p_);\
124 fucking C++ blows me.
127 #define DEFAULT_ACCESSOR(Class)\
129 Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
130 ((Class ## _identifier*)this)->accessed_b_ = true;\
131 return copy_b ? new Class (*data_p_) : data_p_;\
134 #define VIRTUAL_ACCESSOR(Class)\
136 Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
137 ((Class ## _identifier*)this)->accessed_b_ = true;\
138 return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
141 #define IMPLEMENT_ID_CLASS(Class) \
142 Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
143 Class ## _identifier::Class ## _identifier (Class*st, int code) \
148 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
151 data_p_ = s.access_content_ ## Class (true);\
155 IMPLEMENT_ID_CLASS(Duration
);
156 IMPLEMENT_ID_CLASS(Translator_group
);
157 IMPLEMENT_ID_CLASS(Music
);
158 IMPLEMENT_ID_CLASS(Score
);
159 IMPLEMENT_ID_CLASS(Request
);
160 IMPLEMENT_ID_CLASS(Music_output_def
);
161 VIRTUAL_ACCESSOR(Music
);
162 VIRTUAL_ACCESSOR(Request
);
163 VIRTUAL_ACCESSOR(Translator_group
);
164 VIRTUAL_ACCESSOR(Music_output_def
);
165 DEFAULT_ACCESSOR(Duration
);
166 DEFAULT_ACCESSOR(Score
);
170 Identifier::print_smob (SCM s
, SCM p
, scm_print_state
*)
176 Identifier::mark_smob (SCM s
)
184 Identifier::do_smobify_self ()