]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 0.0.43
[lilypond.git] / lily / identifier.cc
1 /*
2   identifier.cc -- implement identifier and derived classes
3
4   source file of the 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
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
23 void
24 Identifier::error(String expect)
25 {
26     String e("Wrong identifier type: ");
27     e += String(classname()) + "(expected " + expect + ")";
28     ::error(e);
29 }
30
31 Identifier::Identifier(String n, int code)
32     : name(n) 
33 {
34     token_code_i_ = code; 
35     data = 0;
36     accessed_b_ = 0;
37     init_b_ = 0;
38     defined_ch_C_ = 0;
39 }
40
41 void
42 Identifier::print()const
43 {
44     mtor << "identifier \'" << name << "\'=";
45     do_print();
46 }
47
48 /* ugh. */
49 #define DEFAULT_PRINT(Class, Content_type, accessor) \
50 void \
51 Class::do_print() const { \
52     ((Class*)this)->accessor(false)->print(); \
53 } \
54 class Class
55
56 DEFAULT_PRINT(Script_id, Script_def, script);
57 DEFAULT_PRINT(Lookup_id, Lookup, lookup);
58 DEFAULT_PRINT(Symtables_id, Symtables, symtables);
59 DEFAULT_PRINT(Staff_id, Input_staff, staff);
60 DEFAULT_PRINT(M_chord_id, Music_general_chord, mchord);
61 DEFAULT_PRINT(M_voice_id, Music_voice, mvoice);
62 DEFAULT_PRINT(Request_id, Request, request);
63 DEFAULT_PRINT(Score_id, Input_score, score);
64 void
65 Real_id::do_print() const
66 {
67     Identifier::print();
68     mtor << *((Real_id*)this)->real(false)<< "\n";
69 }
70
71 #define implement_id_class(Idclass, Class, accessor)    \
72 char const * Idclass::classname() const\
73 {\
74     return #Class;\
75 }\
76 Class*\
77 Idclass::accessor(bool copy) {\
78         if (copy){ \
79             accessed_b_ = true;\
80             return new Class(* (Class*) data);\
81         }else\
82             return (Class*) data;\
83     }\
84 Idclass::~Idclass() { delete accessor(false); }\
85 Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
86
87
88 implement_id_class(Real_id, Real, real)
89 implement_id_class(Script_id, Script_def, script)
90 implement_id_class(Lookup_id, Lookup, lookup)
91 implement_id_class(Symtables_id, Symtables, symtables)
92 implement_id_class(Staff_id, Input_staff, staff)
93 implement_id_class(M_chord_id, Music_general_chord, mchord)
94 implement_id_class(M_voice_id, Music_voice, mvoice)
95 implement_id_class(Score_id, Input_score, score)
96 implement_id_class(Request_id, Request, request)