]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/identifier.cc
release: 1.3.0
[lilypond.git] / lily / identifier.cc
index fbf806edf7af918cf1e76e0e00eb5e72535a8f7c..e8421fb70db9a435634d3c2fc5f5b6730dbe9cdc 100644 (file)
 /*
   identifier.cc -- implement identifier and derived classes
 
-  source file of the LilyPond music typesetter
+  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 "lexer.hh"
+#include "my-lily-lexer.hh"
 #include "debug.hh"
+#include "request.hh"
+#include "translator-group.hh"
+#include "notename-table.hh"
 
-void
-Identifier::error(String expect)
+
+
+Identifier::Identifier (int code)
 {
-    String e("Wrong identifier type: ");
-    e += String(classname()) + "(expected " + expect + ")";
-    ::error(e);
+  token_code_i_ = code;
+  accessed_b_ = 0;
+  init_b_ = 0;
 }
 
-void
-Identifier::print()const
+
+
+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()
 {
-    mtor << "identifier \'" << name << "\'=";
-    do_print();
 }
 
-/* ugh. */
-#define DEFAULT_PRINT(Class, Content_type, accessor) \
-void \
-Class::do_print() const { \
-    ((Class*)this)->accessor(false)->print(); \
-} \
-class Class
-
-DEFAULT_PRINT(Script_id, Script_def, script);
-DEFAULT_PRINT(Lookup_id, Lookup, lookup);
-DEFAULT_PRINT(Symtables_id, Symtables, symtables);
-DEFAULT_PRINT(Staff_id, Input_staff, staff);
-DEFAULT_PRINT(M_chord_id, Music_general_chord, mchord);
-DEFAULT_PRINT(M_voice_id, Music_voice, mvoice);
-DEFAULT_PRINT(Request_id, Request, request);
 void
-Real_id::do_print() const
+Identifier::error (String expect) const
 {
-    Identifier::print();
-    mtor << *((Real_id*)this)->real(false)<< "\n";
+  ::error (_f ("wrong identifier type, expected: `%s'", expect));
+}
+
+String
+Identifier::str () const
+{
+  return do_str ();
+}
+
+String
+Identifier::do_str () const
+{
+  return "";
 }
 
 void
-Notetab_id::do_print() const
+Identifier::print () const
 {
-    mtor << "unknown" << "\n";
+  DEBUG_OUT << "identifier ";
+  do_print ();
+}
+void
+Identifier::do_print () const
+{
+}
+
+/* ugh. */
+#define DEFAULT_PRINT(Class) \
+void \
+Class ## _identifier::do_print () const { \
+  Class *cl = ((Class ## _identifier *)this)->access_content_ ## Class(false);\
+  cl->print (); \
+}
+
+
+
+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); \
+}
+
+
+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 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.
+ */
+
+#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_;\
+}
+
+#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);
+