]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 0.0.65
[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
11 #include "identifier.hh"
12 #include "my-lily-lexer.hh"
13 #include "debug.hh"
14 #include "input-register.hh"
15 #include "input-score.hh" 
16 #include "symtable.hh"
17 #include "input-staff.hh"
18 #include "input-music.hh"
19 #include "lookup.hh"
20 #include "script-def.hh"
21 #include "request.hh"
22 #include "input-register.hh"
23
24 Identifier::~Identifier()
25 {
26     if (!accessed_b_ && !init_b_)
27         warning("Variable not used");
28 }
29 void
30 Identifier::error(String expect)
31 {
32     String e("Wrong identifier type: ");
33     e += String(classname()) + "(expected " + expect + ")";
34     ::error(e);
35 }
36
37 Identifier::Identifier(String n, int code)
38     :  name_str_(n) 
39 {
40     token_code_i_ = code; 
41     data = 0;
42     accessed_b_ = 0;
43     init_b_ = 0;
44 }
45
46 void
47 Identifier::print()const
48 {
49     mtor << "identifier \'" << name_str_ << "\'=";
50     do_print();
51 }
52
53 /* ugh. */
54 #define DEFAULT_PRINT(Class, Content_type, accessor) \
55 void \
56 Class::do_print() const { \
57     ((Class*)this)->accessor(false)->print(); \
58 } \
59 class Class
60
61 DEFAULT_PRINT(Script_id, Script_def, script);
62 DEFAULT_PRINT(Lookup_id, Lookup, lookup);
63 DEFAULT_PRINT(Symtables_id, Symtables, symtables);
64 DEFAULT_PRINT(Staff_id, Input_staff, staff);
65 DEFAULT_PRINT(M_chord_id, Music_general_chord, mchord);
66 DEFAULT_PRINT(M_voice_id, Music_voice, mvoice);
67 DEFAULT_PRINT(Request_id, Request, request);
68 DEFAULT_PRINT(Score_id, Input_score, score);
69 DEFAULT_PRINT(Input_regs_id, Input_register, iregs);
70
71 void
72 Real_id::do_print() const
73 {
74     Identifier::print();
75     mtor << *((Real_id*)this)->real(false)<< "\n";
76 }
77
78 #define implement_id_class(Idclass, Class, accessor)    \
79 char const * Idclass::classname() const\
80 {\
81     return #Class;\
82 }\
83 Class*\
84 Idclass::accessor(bool copy) {\
85         if (copy){ \
86             accessed_b_ = true;\
87             return new Class(* (Class*) data);\
88         }else\
89             return (Class*) data;\
90     }\
91 Idclass::~Idclass() { delete accessor(false); }\
92 Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
93
94
95 implement_id_class(Real_id, Real, real);
96 implement_id_class(Script_id, Script_def, script);
97 implement_id_class(Lookup_id, Lookup, lookup);
98 implement_id_class(Symtables_id, Symtables, symtables);
99 implement_id_class(Staff_id, Input_staff, staff);
100 implement_id_class(M_chord_id, Music_general_chord, mchord);
101 implement_id_class(M_voice_id, Music_voice, mvoice);
102 implement_id_class(Score_id, Input_score, score);
103 implement_id_class(Request_id, Request, request);
104 implement_id_class(Input_regs_id, Input_register, iregs);
105
106 Identifier::Identifier(Identifier const&)
107 {
108     assert(false);
109 }