source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include <assert.h>
#include "my-lily-lexer.hh"
#include "debug.hh"
#include "symtable.hh"
-#include "lookup.hh"
#include "script-def.hh"
#include "request.hh"
#include "translator.hh"
-
+#include "notename-table.hh"
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
{
String e (_("Wrong identifier type: "));
- e += String (name()) + _("(expected ") + expect + ")";
+ e += _f ("%s expected", expect);
::error (e);
}
-Identifier::Identifier (int code)
+String
+Identifier::str () const
{
- token_code_i_ = code;
- accessed_b_ = 0;
- init_b_ = 0;
+ return do_str ();
+}
+
+String
+Identifier::do_str () const
+{
+ return "";
}
void
-Identifier::print() const
+Identifier::print () const
{
DOUT << "identifier ";
- do_print();
+ do_print ();
+}
+void
+Identifier::do_print () const
+{
}
/* ugh. */
-#define DEFAULT_PRINT(Class, Content_type, accessor) \
+#define DEFAULT_PRINT(Class) \
void \
-Class::do_print() const { \
- ((Class*)this)->accessor()->print(); \
-} \
-class Class
-
+Class ## _identifier::do_print () const { \
+ Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
+ cl->print (); \
+}
-DEFAULT_PRINT(Script_id, General_script_def, script);
-DEFAULT_PRINT(Lookup_id, Lookup, lookup);
-DEFAULT_PRINT(Translator_id, Translator, translator);
-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(Midi_def_id,Midi_def, mididef);
-DEFAULT_PRINT(Paper_def_id,Paper_def, paperdef);
-void
-Duration_id::do_print() const
-{}
+DEFAULT_PRINT(General_script_def);
+DEFAULT_PRINT(Translator);
+DEFAULT_PRINT(Symtables);
+DEFAULT_PRINT(Music);
+DEFAULT_PRINT(Request);
+DEFAULT_PRINT(Score);
+DEFAULT_PRINT(Midi_def);
+DEFAULT_PRINT(Paper_def);
-void
-Real_id::do_print() const
-{
- DOUT << *data_p_<< "\n";
+/* ugh. */
+#define DUMMY_STR(Class) \
+String \
+Class ## _identifier::do_str () const { \
+ return String (#Class); \
}
-void
-Int_id::do_print() const
-{
- DOUT << *data_p_<< "\n";
+
+DUMMY_STR(Notename_table);
+DUMMY_STR(General_script_def);
+DUMMY_STR(Translator);
+DUMMY_STR(Symtables);
+DUMMY_STR(Music);
+DUMMY_STR(Request);
+DUMMY_STR(Score);
+DUMMY_STR(Midi_def);
+DUMMY_STR(Paper_def);
+DUMMY_STR(Duration);
+
+#define STRING_PRINT(Class) \
+void \
+Class ## _identifier::do_print () const\
+{\
+ DOUT << 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);
+
-#define DEFAULT_ACCESSOR(Idclass, Class, accessor)\
+/*
+ fucking C++ blows me.
+ */
+
+#define DEFAULT_ACCESSOR(Class)\
Class*\
-Idclass::accessor () {\
- accessed_b_ = true;\
- return new Class (*data_p_);\
+Class ## _identifier::access_content_ ## Class (bool copy_b) const {\
+ ((Class ## _identifier*)this)->accessed_b_ = true;\
+ return copy_b ? new Class (*data_p_) : data_p_;\
}
-#define VIRTUAL_ACCESSOR(Idclass, Class, accessor)\
+#define VIRTUAL_ACCESSOR(Class)\
Class*\
-Idclass::accessor () {\
- accessed_b_ = true;\
- return (Class*)data_p_->clone();\
+Class ## _identifier::access_content_ ## Class (bool copy_b) const{\
+ ((Class ## _identifier*)this)->accessed_b_ = true;\
+ return copy_b ? (Class*)data_p_->clone() : data_p_;\
}
-#define IMPLEMENT_ID_CLASS(Idclass, Class, accessor) \
- IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\
- Idclass::~Idclass() { delete data_p_; }\
- Idclass::Idclass (Class*st, int code):Identifier (code) { data_p_ = st; }\
-
-IMPLEMENT_ID_CLASS(Duration_id, Duration, duration);
-IMPLEMENT_ID_CLASS(Translator_id, Translator, translator);
-IMPLEMENT_ID_CLASS(Int_id, int, intid);
-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(Midi_def_id, Midi_def, mididef);
-IMPLEMENT_ID_CLASS(Paper_def_id, Paper_def, paperdef);
-
-Identifier::Identifier (Identifier const&)
-{
- assert (false);
-}
+#define IMPLEMENT_ID_CLASS(Class) \
+ IMPLEMENT_IS_TYPE_B1(Class ## _identifier,Identifier)\
+ 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);
+IMPLEMENT_ID_CLASS(int);
+IMPLEMENT_ID_CLASS(Real);
+IMPLEMENT_ID_CLASS(String);
+IMPLEMENT_ID_CLASS(General_script_def);
+IMPLEMENT_ID_CLASS(Symtables);
+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);
+VIRTUAL_ACCESSOR(General_script_def);
+DEFAULT_ACCESSOR(Notename_table);
+DEFAULT_ACCESSOR(Duration);
+DEFAULT_ACCESSOR(int);
+DEFAULT_ACCESSOR(Real);
+DEFAULT_ACCESSOR(String);
+DEFAULT_ACCESSOR(Symtables);
+DEFAULT_ACCESSOR(Score);
+DEFAULT_ACCESSOR(Midi_def);
+DEFAULT_ACCESSOR(Paper_def);
-DEFAULT_ACCESSOR(Duration_id, Duration, duration);
-VIRTUAL_ACCESSOR(Translator_id,Translator, translator);
-DEFAULT_ACCESSOR(Int_id, int, intid);
-DEFAULT_ACCESSOR(Real_id, Real, real);
-VIRTUAL_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(Midi_def_id, Midi_def, mididef);
-DEFAULT_ACCESSOR(Paper_def_id, Paper_def, paperdef);