]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 0.1.61
[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@stack.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 "lookup.hh"
18 #include "script-def.hh"
19 #include "request.hh"
20 #include "translator.hh"
21
22
23 IMPLEMENT_IS_TYPE_B(Identifier);
24
25 Identifier::~Identifier()
26 {
27 }
28
29 void
30 Identifier::error (String expect)
31 {
32   String e (_("Wrong identifier type: "));
33   e += String (name()) + _("(expected ") + expect + ")";
34   ::error (e);
35 }
36
37 Identifier::Identifier (int code)
38 {
39   token_code_i_ = code;
40   accessed_b_ = 0;
41   init_b_ = 0;
42 }
43
44 void
45 Identifier::print() const
46 {
47   DOUT << "identifier ";
48   do_print();
49 }
50
51 /* ugh. */
52 #define DEFAULT_PRINT(Class, Content_type, accessor) \
53 void \
54 Class::do_print() const { \
55   ((Class*)this)->accessor()->print(); \
56 } \
57 class Class
58
59
60 DEFAULT_PRINT(Script_id, General_script_def, script);
61 DEFAULT_PRINT(Lookup_id, Lookup, lookup);
62 DEFAULT_PRINT(Translator_id, Translator, translator);
63 DEFAULT_PRINT(Symtables_id, Symtables, symtables);
64 DEFAULT_PRINT(Music_id,Music , music);
65 DEFAULT_PRINT(Request_id, Request, request);
66 DEFAULT_PRINT(Score_id, Score, score);
67 DEFAULT_PRINT(Midi_def_id,Midi_def, mididef);
68 DEFAULT_PRINT(Paper_def_id,Paper_def, paperdef);
69
70
71 void
72 Duration_id::do_print() const
73 {}
74
75 void
76 Real_id::do_print() const
77 {
78   DOUT << *data_p_<< "\n";
79 }
80
81 void
82 Int_id::do_print() const
83 {
84   DOUT << *data_p_<< "\n";
85 }
86
87
88 #define DEFAULT_ACCESSOR(Idclass, Class, accessor)\
89 Class*\
90 Idclass::accessor () {\
91   accessed_b_ = true;\
92   return new Class (*data_p_);\
93 }
94
95 #define VIRTUAL_ACCESSOR(Idclass, Class, accessor)\
96 Class*\
97 Idclass::accessor () {\
98   accessed_b_ = true;\
99   return (Class*)data_p_->clone();\
100 }
101
102 #define IMPLEMENT_ID_CLASS(Idclass, Class, accessor)    \
103         IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\
104         Idclass::~Idclass() { delete data_p_; }\
105         Idclass::Idclass (Class*st, int code):Identifier (code) { data_p_ = st; }\
106
107 IMPLEMENT_ID_CLASS(Duration_id, Duration, duration);
108 IMPLEMENT_ID_CLASS(Translator_id, Translator, translator);
109 IMPLEMENT_ID_CLASS(Int_id, int, intid);
110 IMPLEMENT_ID_CLASS(Real_id, Real, real);
111 IMPLEMENT_ID_CLASS(Script_id, General_script_def, script);
112 IMPLEMENT_ID_CLASS(Lookup_id, Lookup, lookup);
113 IMPLEMENT_ID_CLASS(Symtables_id, Symtables, symtables);
114 IMPLEMENT_ID_CLASS(Music_id, Music, music);
115 IMPLEMENT_ID_CLASS(Score_id, Score, score);
116 IMPLEMENT_ID_CLASS(Request_id, Request, request);
117 IMPLEMENT_ID_CLASS(Midi_def_id, Midi_def, mididef);
118 IMPLEMENT_ID_CLASS(Paper_def_id, Paper_def, paperdef);
119
120 Identifier::Identifier (Identifier const&s)
121   : Input (s)
122 {
123   assert (false);
124 }
125
126 DEFAULT_ACCESSOR(Duration_id, Duration, duration);
127 VIRTUAL_ACCESSOR(Translator_id,Translator, translator);
128 DEFAULT_ACCESSOR(Int_id, int, intid);
129 DEFAULT_ACCESSOR(Real_id, Real, real);
130 VIRTUAL_ACCESSOR(Script_id, General_script_def, script);
131 DEFAULT_ACCESSOR(Lookup_id, Lookup, lookup);
132 DEFAULT_ACCESSOR(Symtables_id, Symtables, symtables);
133 VIRTUAL_ACCESSOR(Music_id, Music, music);
134 DEFAULT_ACCESSOR(Score_id, Score, score);
135 VIRTUAL_ACCESSOR(Request_id, Request, request);
136 DEFAULT_ACCESSOR(Midi_def_id, Midi_def, mididef);
137 DEFAULT_ACCESSOR(Paper_def_id, Paper_def, paperdef);