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