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