]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.3.60
authorfred <fred>
Tue, 26 Mar 2002 23:23:02 +0000 (23:23 +0000)
committerfred <fred>
Tue, 26 Mar 2002 23:23:02 +0000 (23:23 +0000)
lily/identifier.cc
lily/include/identifier.hh
lily/include/my-lily-lexer.hh
lily/include/scope.hh
lily/music-output-def.cc
lily/paper-outputter.cc
lily/scope.cc

index 964b33ceebd8c7b9138f61a82eebdf1dda531835..4c6284eb013d58f31fbdc75fc9bcf3a6e9b353b4 100644 (file)
 #include "debug.hh"
 #include "request.hh"
 #include "translator-group.hh"
+#include "ly-smobs.icc"
 
+IMPLEMENT_UNSMOB(Identifier, identifier);
+IMPLEMENT_SMOBS(Identifier);
 
 Identifier::Identifier (int code)
 {
+  self_scm_ = SCM_EOL;
   token_code_i_ = code;
   accessed_b_ = 0;
 }
@@ -30,6 +34,7 @@ Identifier::Identifier (int code)
 Identifier::Identifier (Identifier const&s)
   : Input (s)
 {
+  self_scm_ = SCM_EOL;
   token_code_i_ = s.token_code_i_;
   accessed_b_ = s.accessed_b_;
 }
@@ -111,7 +116,6 @@ Class ## _identifier::do_print () const\
 STRING_PRINT(Duration);
 STRING_PRINT(Real);
 STRING_PRINT(int);
-STRING_PRINT(String);
   
 #define DEFAULT_STR(Class) \
 String \
@@ -122,7 +126,7 @@ Class ## _identifier::do_str () const\
 
 DEFAULT_STR(int);
 DEFAULT_STR(Real);
-DEFAULT_STR(String);
+
   
 
 /*
@@ -161,7 +165,6 @@ 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);
@@ -173,8 +176,26 @@ VIRTUAL_ACCESSOR(Translator_group);
 DEFAULT_ACCESSOR(Duration);
 DEFAULT_ACCESSOR(int);
 DEFAULT_ACCESSOR(Real);
-DEFAULT_ACCESSOR(String);
 DEFAULT_ACCESSOR(Score);
 DEFAULT_ACCESSOR(Midi_def);
 DEFAULT_ACCESSOR(Paper_def);
 
+int
+Identifier::print_smob (SCM s, SCM p, scm_print_state*)
+{
+ return 1;  
+}
+
+SCM
+Identifier::mark_smob (SCM s)
+{
+  return SCM_EOL;
+}
+
+
+
+void
+Identifier::do_smobify_self ()
+{
+  
+}
index 002b935202b0ff1306f340c5c890368c610acaef..94bceeebb8136903819f03af6f4e21d110bad1ba 100644 (file)
@@ -8,9 +8,11 @@
 #define IDENTIFIER_HH
 
 #include "lily-proto.hh"
+#include "lily-guile.hh"
 #include "string.hh"
 #include "input.hh"
 #include "virtual-methods.hh"
+#include "smobs.hh"
 
 
 #define DECLARE_TYPE_NAME(Class)
@@ -22,7 +24,6 @@ class Midi_def_identifier;
 class Paper_def_identifier;
 class Real_identifier;
 class int_identifier;
-class String_identifier;
 class Request_identifier;
 class Score_identifier;
 class Duration_identifier;
@@ -39,13 +40,15 @@ virtual Class *  access_content_ ## Class (bool) const { error (#Class  + String
    TODO: use SMOBS for the union type, and junk all derived classes.
    */
 struct Identifier : public Input {
+
+  DECLARE_SMOBS;
   bool init_b_;
   bool accessed_b_;
   int token_code_i_;
   Identifier (Identifier const&);    
   Identifier (int code) ;
   virtual ~Identifier() ;
-
+  
 
   void print() const;
   
@@ -56,7 +59,6 @@ struct Identifier : public Input {
   IDACCESSOR(Midi_def)
   IDACCESSOR(Paper_def)
   IDACCESSOR(Real)
-  IDACCESSOR(String)
   IDACCESSOR(Request)
   IDACCESSOR(Score)
   IDACCESSOR(int)
@@ -85,7 +87,6 @@ struct Class ## _identifier : Identifier {\
 DECLARE_ID_CLASS(Translator_group);
 DECLARE_ID_CLASS(Duration);
 DECLARE_ID_CLASS(Real);
-DECLARE_ID_CLASS(String);
 DECLARE_ID_CLASS(General_script_def);
 DECLARE_ID_CLASS(Music);
 DECLARE_ID_CLASS(int);
@@ -94,5 +95,8 @@ DECLARE_ID_CLASS(Request);
 DECLARE_ID_CLASS(Paper_def);
 DECLARE_ID_CLASS(Midi_def);
 
+Identifier * unsmob_identifier (SCM);
+SCM smobify (Identifier*);
+
 #endif // IDENTIFIER_HH
 
index fc00a1465c1c7f2bee42b27ab355c21c81144fd8..b3113bf94b47cfcfe2b36fa6f8176cfac2a476b9 100644 (file)
@@ -53,13 +53,14 @@ public:
   void start_main_input ();
   void set_chordmodifier_table (Notename_table*tab_p);
   void set_notename_table (Notename_table*tab_p);
-  Identifier*lookup_identifier (String s);
+
+  SCM lookup_identifier (String s);
   void push_note_state();
   void push_chord_state();
   void push_lyric_state();
   void pop_state();
   void LexerError (char const *);
-  void set_identifier (String str, Identifier* i, bool unique_b = true);
+  void set_identifier (String str, SCM);
   bool note_state_b() const;
   bool chord_state_b() const;
   bool lyric_state_b() const;
index 19f5313536f5a3a784ce6846de0d11061db0e3a8..f1f4d8a1dc6619659161a5c57d7825c0a1ef76d1 100644 (file)
 #include "lily-proto.hh"
 #include "lily-guile.hh"
 
-class Protected_scm;
+class Scheme_hash_table;
 class Scope {
-  Hash_table<Protected_scm,Identifier*> *id_dict_;
+  Scheme_hash_table *id_dict_;
 public:
+  SCM to_alist () const; 
   bool elem_b (String ) const;
   bool elem_b (SCM s) const;
-  Identifier *&elem (String);
-  Identifier *&elem (SCM s);  
+  Identifier *elem (String) const;
+  Identifier *elem (SCM) const;
+
+  SCM scm_elem (String) const;
+  SCM scm_elem (SCM) const;
+
+  void set (String, Identifier *);
+  void set (String, SCM);  
   Scope ();
   
   Scope (Scope const &);
   ~Scope ();
   friend class Scope_iter;
 };
-
-class Scope_iter {
-  Hash_table_iter<Protected_scm,Identifier*> * iter_;
-public:
-  void operator ++(int);
-  bool ok ()const;
-  Scope_iter(Scope const&);
-  String key () const;
-  Identifier* val () const;
-  SCM scm_key () const;
-};
-
 #endif /* SCOPE_HH */
 
index 0805e3c2426d782af210e2cd932ca285ff485788..6b4ee8b519d5aa37b3e8ccbc87f25cbefe33437f 100644 (file)
@@ -10,7 +10,7 @@
 #include "debug.hh"
 #include "music-output-def.hh"
 #include "global-translator.hh"
-#include "dictionary-iter.hh"
+
 #include "identifier.hh"
 #include "main.hh"
 #include "lily-guile.hh"
@@ -39,13 +39,6 @@ Music_output_def::Music_output_def (Music_output_def const &s)
 {
   scope_p_ = new Scope (*s.scope_p_);
   translator_p_dict_p_ = new Scope (*s.translator_p_dict_p_);
-  //  default_properties_ = s.default_properties_;
-  
-  for (Scope_iter i (*translator_p_dict_p_);  i.ok (); i++)
-    {
-      Translator * t = i.val ()->access_content_Translator_group (false);
-      t-> output_def_l_ = this;
-    }
 }
 
 void
@@ -56,11 +49,8 @@ Music_output_def::assign_translator (Translator_group*tp)
     {
       tp->warning (_("Interpretation context with empty type"));
     }
-  if (translator_p_dict_p_->elem_b (s))
-    delete translator_p_dict_p_->elem (s);
-  
-  translator_p_dict_p_->elem (s) = new Translator_group_identifier (tp, 0);
-  tp ->output_def_l_ = this;
+  translator_p_dict_p_->set (s, new Translator_group_identifier (tp, 0));
 }
 
 Translator*
@@ -86,6 +76,7 @@ Music_output_def::get_global_translator_p ()
   if (!t)
     error (_f ("can't find `%s' context", "Score"));
   t = t->clone ();
+  t->output_def_l_ = this;
   Global_translator *g = dynamic_cast <Global_translator *> (t);
   t->add_processing ();
   
@@ -102,9 +93,10 @@ Music_output_def::get_default_output () const
 {
   if (safe_global_b || !scope_p_->elem_b ("output"))
     return "";
-  Identifier * id = scope_p_->elem ("output");
+  SCM s =  scope_p_->scm_elem ("output");
 
-  String *p = id->access_content_String (false);
-  return p ? *p : String ("");
+  
+  
+  return gh_string_p (s) ? ly_scm2string (s) : String ("");
 }
 
index 4999f0800ecd3d00d1ec653df93e7df729022e3b..97b542168b6d064e8ff016a852e56af85f1c37b8 100644 (file)
@@ -13,7 +13,6 @@
 #include <iostream.h>
 
 #include "dimensions.hh"
-#include "dictionary-iter.hh"
 #include "virtual-methods.hh"
 #include "paper-outputter.hh"
 #include "paper-stream.hh"
@@ -149,25 +148,32 @@ Paper_outputter::dump_scheme (SCM s)
 void
 Paper_outputter::output_scope (Scope *scope, String prefix)
 {
-  for (Scope_iter i (*scope); i.ok (); i++)
+  SCM al = scope->to_alist ();
+  for (SCM s = al ; gh_pair_p (s); s = gh_cdr (s))
     {
-      if (dynamic_cast<String_identifier*> (i.val ()))
-       {
-         String val = *i.val()->access_content_String (false);
+      SCM k = gh_caar (s);
+      SCM v = gh_cdar (s);
+      String s = ly_symbol2string (k);
 
-         output_String_def (prefix + i.key (), val);
+      
+      if (gh_string_p (v))
+       {
+         output_String_def (prefix + s, ly_scm2string (v));
        }
-      else if(dynamic_cast<Real_identifier*> (i.val ()))
+      
+      Identifier * id = unsmob_identifier (v);
+      
+      if(dynamic_cast<Real_identifier*> (id))
        {
-         Real val  = *i.val ()->access_content_Real (false);
+         Real val  = *id->access_content_Real (false);
 
-         output_Real_def (prefix + i.key (), val);       
+         output_Real_def (prefix + s, val);      
        }
-      else if (dynamic_cast<int_identifier*> (i.val ()))
+      else if (dynamic_cast<int_identifier*> (id))
        {
-         int val  = *i.val ()->access_content_int (false);       
+         int val  = *id->access_content_int (false);     
          
-         output_int_def (prefix + i.key (), val);        
+         output_int_def (prefix + s, val);       
        }
     }
 }
index 917f97344abc93c9e2e6695c80ef1cbaf88fb270..96d1b86d336384b4b2b066bea165f67fde9432fb 100644 (file)
@@ -8,39 +8,32 @@
  */
 
 #include "scope.hh"
-#include "dictionary-iter.hh"
-#include "debug.hh"
 #include "identifier.hh"
-#include "dictionary.hh"
-#include "protected-scm.hh"
+#include "scm-hash.hh"
 
 
 Scope::~Scope ()
 {
-  for (Scope_iter ai (*this); ai.ok(); ai++)
-    delete ai.val ();
   delete id_dict_;
 }
 
 Scope::Scope (Scope const&s)
+  : id_dict_ (new Scheme_hash_table (*s.id_dict_))
 {
+  /*
+    cloning not necessary.
+
   id_dict_ = new Hash_table<Protected_scm,Identifier*> (*s.id_dict_);
   for (Scope_iter ai (s); ai.ok(); ai++)
     {
       id_dict_->elem (ai.scm_key ()) = ai.val ()->clone ();
     }
+  */
 }
 
-unsigned int ly_pscm_hash (Protected_scm s)
-{
-  return ly_scm_hash (s);
-}
-
-
 Scope::Scope ()
 {
-  id_dict_ = new Hash_table<Protected_scm,Identifier*>;
-  id_dict_->hash_func_ = ly_pscm_hash;
+  id_dict_ = new Scheme_hash_table;
 }
 
 bool
@@ -50,57 +43,49 @@ Scope::elem_b (String s) const
 }
 
 
-Identifier *&
-Scope::elem (String s) 
-{
-  return id_dict_->elem (ly_symbol2scm (s.ch_C()));
-}
-
-
-Scope_iter::Scope_iter (Scope const &s)
+bool
+Scope::elem_b (SCM s) const
 {
-  iter_ = new Hash_table_iter<Protected_scm,Identifier*>(*s.id_dict_);
+  return id_dict_->elem_b (s);
 }
-
-String
-Scope_iter::key () const
+Identifier*
+Scope::elem (SCM s)const
 {
-  SCM s= iter_->key ();
-  return ly_symbol2string (s);
+  return unsmob_identifier  (id_dict_->get (s));
 }
 
-bool
-Scope::elem_b (SCM s) const
+SCM
+Scope::scm_elem (SCM s)const
 {
-  return id_dict_->elem_b (s);
+  return id_dict_->get (s);
 }
 
-Identifier* &
-Scope::elem (SCM s)
+SCM
+Scope::scm_elem (String s) const
 {
 return id_dict_->elem (s);
return scm_elem (ly_symbol2scm (s.ch_C()));
 }
 
-SCM
-Scope_iter::scm_key () const
+Identifier*
+Scope::elem (String s)const
 {
-  return iter_->key ();
+  return elem (ly_symbol2scm (s.ch_C()));
 }
 
-bool
-Scope_iter::ok () const
+void
+Scope::set (String s, SCM id)
 {
-  return iter_->ok();
+  return id_dict_->set (ly_symbol2scm (s.ch_C()), id);
 }
 
 void
-Scope_iter::operator ++(int)
+Scope::set (String s, Identifier * id) 
 {
-  (*iter_) ++;
+  return id_dict_->set (ly_symbol2scm (s.ch_C()), smobify (id));
 }
 
-Identifier*
-Scope_iter::val ()const
+SCM
+Scope::to_alist () const
 {
-  return iter_->val ();
+  return id_dict_->to_alist ();
 }