]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 0.0.46.jcn1
[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 #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 void
25 Identifier::error(String expect)
26 {
27     String e("Wrong identifier type: ");
28     e += String(classname()) + "(expected " + expect + ")";
29     ::error(e);
30 }
31
32 Identifier::Identifier(String n, int code)
33     :  name(n) 
34 {
35     token_code_i_ = code; 
36     data = 0;
37     accessed_b_ = 0;
38     init_b_ = 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 DEFAULT_PRINT(Input_regs_id, Input_register, iregs);
65
66 void
67 Real_id::do_print() const
68 {
69     Identifier::print();
70     mtor << *((Real_id*)this)->real(false)<< "\n";
71 }
72
73 #define implement_id_class(Idclass, Class, accessor)    \
74 char const * Idclass::classname() const\
75 {\
76     return #Class;\
77 }\
78 Class*\
79 Idclass::accessor(bool copy) {\
80         if (copy){ \
81             accessed_b_ = true;\
82             return new Class(* (Class*) data);\
83         }else\
84             return (Class*) data;\
85     }\
86 Idclass::~Idclass() { delete accessor(false); }\
87 Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
88
89
90 implement_id_class(Real_id, Real, real);
91 implement_id_class(Script_id, Script_def, script);
92 implement_id_class(Lookup_id, Lookup, lookup);
93 implement_id_class(Symtables_id, Symtables, symtables);
94 implement_id_class(Staff_id, Input_staff, staff);
95 implement_id_class(M_chord_id, Music_general_chord, mchord);
96 implement_id_class(M_voice_id, Music_voice, mvoice);
97 implement_id_class(Score_id, Input_score, score);
98 implement_id_class(Request_id, Request, request);
99 implement_id_class(Input_regs_id, Input_register, iregs);
100
101 Identifier::Identifier(Identifier const&)
102 {
103     assert(false);
104 }