source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include <assert.h>
-
+#include "midi-def.hh"
+#include "paper-def.hh"
#include "score.hh"
#include "identifier.hh"
#include "my-lily-lexer.hh"
#include "debug.hh"
-#include "input-register.hh"
-#include "symtable.hh"
-#include "lookup.hh"
-#include "script-def.hh"
#include "request.hh"
-#include "input-register.hh"
+#include "translator-group.hh"
+#include "notename-table.hh"
+
+
-IMPLEMENT_STATIC_NAME(Identifier);
-IMPLEMENT_IS_TYPE_B(Identifier);
+Identifier::Identifier (int code)
+{
+ token_code_i_ = code;
+ accessed_b_ = 0;
+ init_b_ = 0;
+}
+
+
+
+Identifier::Identifier (Identifier const&s)
+ : Input (s)
+{
+ token_code_i_ = s.token_code_i_;
+ accessed_b_ = s.accessed_b_;
+ init_b_ = s.init_b_;
+}
Identifier::~Identifier()
{
- if (!accessed_b_ && !init_b_)
- warning("Variable not used");
}
+
void
-Identifier::error(String expect)
+Identifier::error (String expect) const
+{
+ ::error (_f ("wrong identifier type, expected: `%s'", expect));
+}
+
+String
+Identifier::str () const
{
- String e("Wrong identifier type: ");
- e += String(name()) + "(expected " + expect + ")";
- ::error(e);
+ return do_str ();
}
-Identifier::Identifier(String n, int code)
- : name_str_(n)
+String
+Identifier::do_str () const
{
- token_code_i_ = code;
- data = 0;
- accessed_b_ = 0;
- init_b_ = 0;
+ return "";
}
void
-Identifier::print()const
+Identifier::print () const
+{
+ DEBUG_OUT << "identifier ";
+ do_print ();
+}
+void
+Identifier::do_print () const
{
- mtor << "identifier \'" << name_str_ << "\'=";
- do_print();
}
/* ugh. */
-#define DEFAULT_PRINT(Class, Content_type, accessor) \
+#define DEFAULT_PRINT(Class) \
void \
-Class::do_print() const { \
- ((Class*)this)->accessor(false)->print(); \
-} \
-class Class
-
-DEFAULT_PRINT(Script_id, General_script_def, script);
-DEFAULT_PRINT(Lookup_id, Lookup, lookup);
-DEFAULT_PRINT(Symtables_id, Symtables, symtables);
-DEFAULT_PRINT(Music_id,Music , music);
-DEFAULT_PRINT(Request_id, Request, request);
-DEFAULT_PRINT(Score_id, Score, score);
-DEFAULT_PRINT(Input_regs_id, Input_register, iregs);
+Class ## _identifier::do_print () const { \
+ Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
+ cl->print (); \
+}
-void
-Real_id::do_print() const
-{
- Identifier::print();
- mtor << *((Real_id*)this)->real(false)<< "\n";
+
+
+DEFAULT_PRINT(Translator_group);
+DEFAULT_PRINT(Music);
+DEFAULT_PRINT(Request);
+DEFAULT_PRINT(Score);
+DEFAULT_PRINT(Midi_def);
+DEFAULT_PRINT(Paper_def);
+
+/* ugh. */
+#define DUMMY_STR(Class) \
+String \
+Class ## _identifier::do_str () const { \
+ return String (#Class); \
}
-#define default_accessor(Idclass, Class, accessor)\
-Class*\
-Idclass::accessor(bool copy) {\
- if (copy){ \
- accessed_b_ = true;\
- return new Class(* (Class*) data);\
- }else\
- return (Class*) data;\
- }\
-
-#define virtual_accessor(Idclass, Class, accessor)\
-Class*\
-Idclass::accessor(bool copy) {\
- if (copy){ \
- accessed_b_ = true;\
- return (Class*) ((Class*) data)->clone();\
- }else\
- return (Class*) data;\
- }\
+DUMMY_STR(Notename_table);
+DUMMY_STR(Translator_group);
+DUMMY_STR(Music);
+DUMMY_STR(Request);
+DUMMY_STR(Score);
+DUMMY_STR(Midi_def);
+DUMMY_STR(Paper_def);
+DUMMY_STR(Duration);
-#define implement_id_class(Idclass, Class, accessor) \
-IMPLEMENT_STATIC_NAME(Idclass)\
-IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\
-Idclass::~Idclass() { delete accessor(false); }\
-Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
+#define STRING_PRINT(Class) \
+void \
+Class ## _identifier::do_print () const\
+{\
+ DEBUG_OUT << do_str () << '\n';\
+}\
+
+
+STRING_PRINT(Duration);
+STRING_PRINT(Real);
+STRING_PRINT(int);
+STRING_PRINT(String);
+STRING_PRINT(Notename_table);
+
+#define DEFAULT_STR(Class) \
+String \
+Class ## _identifier::do_str () const\
+{\
+ return to_str (*data_p_);\
+}
+DEFAULT_STR(int);
+DEFAULT_STR(Real);
+DEFAULT_STR(String);
+
+/*
+ fucking C++ blows me.
+ */
-implement_id_class(Real_id, Real, real);
-implement_id_class(Script_id, General_script_def, script);
-implement_id_class(Lookup_id, Lookup, lookup);
-implement_id_class(Symtables_id, Symtables, symtables);
-implement_id_class(Music_id, Music, music);
-implement_id_class(Score_id, Score, score);
-implement_id_class(Request_id, Request, request);
-implement_id_class(Input_regs_id, Input_register, iregs);
+#define DEFAULT_ACCESSOR(Class)\
+Class*\
+Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
+ ((Class ## _identifier*)this)->accessed_b_ = true;\
+ return copy_b ? new Class (*data_p_) : data_p_;\
+}
-Identifier::Identifier(Identifier const&)
-{
- assert(false);
+#define VIRTUAL_ACCESSOR(Class)\
+Class*\
+Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
+ ((Class ## _identifier*)this)->accessed_b_ = true;\
+ return copy_b ? dynamic_cast<Class*> (data_p_->clone()) : data_p_;\
}
+#define IMPLEMENT_ID_CLASS(Class) \
+ Class ## _identifier::~Class ## _identifier() { delete data_p_; }\
+ Class ## _identifier::Class ## _identifier (Class*st, int code) \
+ :Identifier (code)\
+ {\
+ data_p_ = st;\
+ }\
+Class ## _identifier::Class ## _identifier (Class ## _identifier const &s) \
+ : Identifier (s)\
+{\
+ data_p_ = s.access_content_ ## Class (true);\
+}
+
+
+IMPLEMENT_ID_CLASS(Duration);
+IMPLEMENT_ID_CLASS(Translator_group);
+IMPLEMENT_ID_CLASS(int);
+IMPLEMENT_ID_CLASS(Real);
+IMPLEMENT_ID_CLASS(String);
+IMPLEMENT_ID_CLASS(Music);
+IMPLEMENT_ID_CLASS(Score);
+IMPLEMENT_ID_CLASS(Request);
+IMPLEMENT_ID_CLASS(Midi_def);
+IMPLEMENT_ID_CLASS(Paper_def);
+IMPLEMENT_ID_CLASS(Notename_table);
+VIRTUAL_ACCESSOR(Music);
+VIRTUAL_ACCESSOR(Request);
+VIRTUAL_ACCESSOR(Translator_group);
+DEFAULT_ACCESSOR(Notename_table);
+DEFAULT_ACCESSOR(Duration);
+DEFAULT_ACCESSOR(int);
+DEFAULT_ACCESSOR(Real);
+DEFAULT_ACCESSOR(String);
+DEFAULT_ACCESSOR(Score);
+DEFAULT_ACCESSOR(Midi_def);
+DEFAULT_ACCESSOR(Paper_def);
-default_accessor(Real_id, Real, real);
-default_accessor(Script_id, General_script_def, script);
-default_accessor(Lookup_id, Lookup, lookup);
-default_accessor(Symtables_id, Symtables, symtables);
-virtual_accessor(Music_id, Music, music);
-default_accessor(Score_id, Score, score);
-virtual_accessor(Request_id, Request, request);
-default_accessor(Input_regs_id, Input_register, iregs);