]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier.cc
release: 0.0.42.pre3
[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 "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 void
32 Identifier::print()const
33 {
34     mtor << "identifier \'" << name << "\'=";
35     do_print();
36 }
37
38 /* ugh. */
39 #define DEFAULT_PRINT(Class, Content_type, accessor) \
40 void \
41 Class::do_print() const { \
42     ((Class*)this)->accessor(false)->print(); \
43 } \
44 class Class
45
46 DEFAULT_PRINT(Script_id, Script_def, script);
47 DEFAULT_PRINT(Lookup_id, Lookup, lookup);
48 DEFAULT_PRINT(Symtables_id, Symtables, symtables);
49 DEFAULT_PRINT(Staff_id, Input_staff, staff);
50 DEFAULT_PRINT(M_chord_id, Music_general_chord, mchord);
51 DEFAULT_PRINT(M_voice_id, Music_voice, mvoice);
52 DEFAULT_PRINT(Request_id, Request, request);
53 DEFAULT_PRINT(Score_id, Input_score, score);
54 void
55 Real_id::do_print() const
56 {
57     Identifier::print();
58     mtor << *((Real_id*)this)->real(false)<< "\n";
59 }
60
61 #define implement_id_class(Idclass, Class, accessor)    \
62 char const * Idclass::classname() const\
63 {\
64     return #Class;\
65 }\
66 Class*\
67 Idclass::accessor(bool copy) {\
68         if (copy)\
69             return new Class(* (Class*) data);\
70         else\
71             return (Class*) data;\
72     }\
73 Idclass::~Idclass() { delete accessor(false); }\
74 Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
75
76
77 implement_id_class(Real_id, Real, real)
78 implement_id_class(Script_id, Script_def, script)
79 implement_id_class(Lookup_id, Lookup, lookup)
80 implement_id_class(Symtables_id, Symtables, symtables)
81 implement_id_class(Staff_id, Input_staff, staff)
82 implement_id_class(M_chord_id, Music_general_chord, mchord)
83 implement_id_class(M_voice_id, Music_voice, mvoice)
84 implement_id_class(Score_id, Input_score, score)
85 implement_id_class(Request_id, Request, request)