]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
patch::: 1.0.12.jcn2: opniewvisite
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <assert.h>
10 #include "midi-def.hh"
11 #include "paper-def.hh"
12 #include "score.hh"
13 #include "identifier.hh"
14 #include "my-lily-lexer.hh"
15 #include "debug.hh"
16 #include "symtable.hh"
17 #include "script-def.hh"
18 #include "request.hh"
19 #include "translator.hh"
20 #include "notename-table.hh"
21
22 IMPLEMENT_IS_TYPE_B(Identifier);
23
24 Identifier::Identifier (int code)
25 {
26   token_code_i_ = code;
27   accessed_b_ = 0;
28   init_b_ = 0;
29 }
30
31
32
33 Identifier::Identifier (Identifier const&s)
34   : Input (s)
35 {
36   token_code_i_ = s.token_code_i_;
37   accessed_b_ = s.accessed_b_;
38   init_b_ = s.init_b_;
39 }
40
41 Identifier::~Identifier()
42 {
43 }
44
45 void
46 Identifier::error (String expect) const
47 {
48   String e (_("Wrong identifier type: "));
49   e += _f ("%s expected", expect);
50   ::error (e);
51 }
52
53 String
54 Identifier::str () const
55 {
56   return do_str ();
57 }
58
59 String
60 Identifier::do_str () const
61 {
62   return "";
63 }
64
65 void
66 Identifier::print () const
67 {
68   DOUT << "identifier ";
69   do_print ();
70 }
71 void
72 Identifier::do_print () const
73 {
74 }
75
76 /* ugh. */
77 #define DEFAULT_PRINT(Class) \
78 void \
79 Class ## _identifier::do_print () const { \
80   Class *cl = ((Class ## _identifier *)this)->access_ ## Class(false);\
81   cl->print (); \
82 }
83
84
85
86 DEFAULT_PRINT(General_script_def);
87 DEFAULT_PRINT(Translator);
88 DEFAULT_PRINT(Symtables);
89 DEFAULT_PRINT(Music);
90 DEFAULT_PRINT(Request);
91 DEFAULT_PRINT(Score);
92 DEFAULT_PRINT(Midi_def);
93 DEFAULT_PRINT(Paper_def);
94
95 /* ugh. */
96 #define DUMMY_STR(Class) \
97 String \
98 Class ## _identifier::do_str () const { \
99   return String (#Class); \
100 }
101
102
103 DUMMY_STR(Notename_table);
104 DUMMY_STR(General_script_def);
105 DUMMY_STR(Translator);
106 DUMMY_STR(Symtables);
107 DUMMY_STR(Music);
108 DUMMY_STR(Request);
109 DUMMY_STR(Score);
110 DUMMY_STR(Midi_def);
111 DUMMY_STR(Paper_def);
112 DUMMY_STR(Duration);
113
114 #define STRING_PRINT(Class) \
115 void \
116 Class ## _identifier::do_print () const\
117 {\
118   DOUT << do_str () << '\n';\
119 }\
120
121
122 STRING_PRINT(Duration);
123 STRING_PRINT(Real);
124 STRING_PRINT(int);
125 STRING_PRINT(String);
126 STRING_PRINT(Notename_table);
127   
128 #define DEFAULT_STR(Class) \
129 String \
130 Class ## _identifier::do_str () const\
131 {\
132   return to_str (*data_p_);\
133 }
134
135 DEFAULT_STR(int);
136 DEFAULT_STR(Real);
137 DEFAULT_STR(String);
138   
139
140 /*
141   fucking C++ blows me.
142  */
143
144 #define DEFAULT_ACCESSOR(Class)\
145 Class*\
146 Class ## _identifier::access_ ## Class (bool copy_b) const {\
147   ((Class ## _identifier*)this)->accessed_b_ = true;\
148   return copy_b ? new Class (*data_p_) : data_p_;\
149 }
150
151 #define VIRTUAL_ACCESSOR(Class)\
152 Class*\
153 Class ## _identifier::access_ ## Class (bool copy_b) const{\
154   ((Class ## _identifier*)this)->accessed_b_ = true;\
155   return copy_b ? (Class*)data_p_->clone() : data_p_;\
156 }
157
158 #define IMPLEMENT_ID_CLASS(Class)       \
159         IMPLEMENT_IS_TYPE_B1(Class ## _identifier,Identifier)\
160         Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
161         Class ## _identifier::Class ## _identifier (Class*st, int code) \
162           :Identifier (code)\
163         {\
164           data_p_ = st;\
165         }\
166 Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
167   : Identifier (s)\
168 {\
169    data_p_ = s.access_ ## Class (true);\
170
171
172
173 IMPLEMENT_ID_CLASS(Duration);
174 IMPLEMENT_ID_CLASS(Translator);
175 IMPLEMENT_ID_CLASS(int);
176 IMPLEMENT_ID_CLASS(Real);
177 IMPLEMENT_ID_CLASS(String);
178 IMPLEMENT_ID_CLASS(General_script_def);
179 IMPLEMENT_ID_CLASS(Symtables);
180 IMPLEMENT_ID_CLASS(Music);
181 IMPLEMENT_ID_CLASS(Score);
182 IMPLEMENT_ID_CLASS(Request);
183 IMPLEMENT_ID_CLASS(Midi_def);
184 IMPLEMENT_ID_CLASS(Paper_def);
185 IMPLEMENT_ID_CLASS(Notename_table);
186 VIRTUAL_ACCESSOR(Music);
187 VIRTUAL_ACCESSOR(Request);
188 VIRTUAL_ACCESSOR(Translator);
189 VIRTUAL_ACCESSOR(General_script_def);
190 DEFAULT_ACCESSOR(Notename_table);
191 DEFAULT_ACCESSOR(Duration);
192 DEFAULT_ACCESSOR(int);
193 DEFAULT_ACCESSOR(Real);
194 DEFAULT_ACCESSOR(String);
195 DEFAULT_ACCESSOR(Symtables);
196 DEFAULT_ACCESSOR(Score);
197 DEFAULT_ACCESSOR(Midi_def);
198 DEFAULT_ACCESSOR(Paper_def);
199