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