]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
patch::: 0.0.73pre.jcn1: epsilon performance
[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-engraver.hh"
21 #include "input-performer.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_gravs_id, Input_engraver, igravs);
71 DEFAULT_PRINT(Input_perfs_id, Input_performer, iperfs);
72 DEFAULT_PRINT(Midi_def_id,Midi_def, mididef);
73 DEFAULT_PRINT(Paper_def_id,Paper_def, paperdef);
74
75 void
76 Real_id::do_print() const
77 {
78     mtor << *((Real_id*)this)->real(false)<< "\n";
79 }
80
81 void
82 Int_id::do_print() const
83 {
84     mtor << *((Int_id*)this)->intid(false)<< "\n";
85 }
86
87
88 #define default_accessor(Idclass, Class, accessor)\
89 Class*\
90 Idclass::accessor(bool copy) {\
91         if (copy){ \
92             accessed_b_ = true;\
93             return new Class(* (Class*) data);\
94         }else\
95             return (Class*) data;\
96     }\
97
98 #define virtual_accessor(Idclass, Class, accessor)\
99 Class*\
100 Idclass::accessor(bool copy) {\
101         if (copy){ \
102             accessed_b_ = true;\
103             return (Class*) ((Class*) data)->clone();\
104         }else\
105             return (Class*) data;\
106     }\
107
108
109 #define implement_id_class(Idclass, Class, accessor)    \
110 IMPLEMENT_STATIC_NAME(Idclass)\
111 IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\
112 Idclass::~Idclass() { delete accessor(false); }\
113 Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
114
115
116
117 implement_id_class(Int_id, int, intid);
118 implement_id_class(Real_id, Real, real);
119 implement_id_class(Script_id, General_script_def, script);
120 implement_id_class(Lookup_id, Lookup, lookup);
121 implement_id_class(Symtables_id, Symtables, symtables);
122 implement_id_class(Music_id, Music, music);
123 implement_id_class(Score_id, Score, score);
124 implement_id_class(Request_id, Request, request);
125 implement_id_class(Input_gravs_id, Input_engraver, igravs);
126 implement_id_class(Input_perfs_id, Input_performer, iperfs);
127 implement_id_class(Midi_def_id, Midi_def, mididef);
128 implement_id_class(Paper_def_id, Paper_def, paperdef);
129
130 Identifier::Identifier(Identifier const&)
131 {
132     assert(false);
133 }
134
135 default_accessor(Int_id, int, intid);
136 default_accessor(Real_id, Real, real);
137 virtual_accessor(Script_id, General_script_def, script);
138 default_accessor(Lookup_id, Lookup, lookup);
139 default_accessor(Symtables_id, Symtables, symtables);
140 virtual_accessor(Music_id, Music, music);
141 default_accessor(Score_id, Score, score);
142 virtual_accessor(Request_id, Request, request);
143 default_accessor(Input_gravs_id, Input_engraver, igravs);
144 default_accessor(Input_perfs_id, Input_performer, iperfs);
145 default_accessor(Midi_def_id, Midi_def, mididef);
146 default_accessor(Paper_def_id, Paper_def, paperdef);