]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/translator-def.cc
duh
[lilypond.git] / lily / translator-def.cc
index 1386d0bdd752467f53930d97ea9fbc969e8b54ff..9a69bd38e0362444bb01e0bf29269db4dc9209f2 100644 (file)
@@ -1,5 +1,5 @@
 /*   
-  translator-def.cc --  implement Translator_def
+  translator-def.cc --  implement Context_def
   
   source file of the GNU LilyPond music typesetter
   
@@ -8,18 +8,18 @@
  */
 
 #include "lily-proto.hh"
-#include "translator-def.hh"
+#include "context-def.hh"
 #include "translator-group.hh"
 #include "warn.hh"
 #include "music-output-def.hh"
 #include "ly-smobs.icc"
 
 int
-Translator_def::print_smob (SCM smob, SCM port, scm_print_state*)
+Context_def::print_smob (SCM smob, SCM port, scm_print_state*)
 {
-  Translator_def* me = (Translator_def*) SCM_CELL_WORD_1 (smob);
+  Context_def* me = (Context_def*) SCM_CELL_WORD_1 (smob);
 
-  scm_puts ("#<Translator_def ", port);
+  scm_puts ("#<Context_def ", port);
   scm_display (me->context_name_, port);
   scm_puts (">", port);
   return 1;
@@ -27,9 +27,9 @@ Translator_def::print_smob (SCM smob, SCM port, scm_print_state*)
 
 
 SCM
-Translator_def::mark_smob (SCM smob)
+Context_def::mark_smob (SCM smob)
 {
-  Translator_def* me = (Translator_def*) SCM_CELL_WORD_1 (smob);
+  Context_def* me = (Context_def*) SCM_CELL_WORD_1 (smob);
 
   scm_gc_mark (me->description_);
   scm_gc_mark (me->context_aliases_);
@@ -41,7 +41,7 @@ Translator_def::mark_smob (SCM smob)
 }
 
 
-Translator_def::Translator_def ()
+Context_def::Context_def ()
 {
   context_aliases_ = SCM_EOL;
   translator_group_type_ = SCM_EOL;
@@ -54,11 +54,11 @@ Translator_def::Translator_def ()
   smobify_self();
 }
 
-Translator_def::~Translator_def ()
+Context_def::~Context_def ()
 {
 }
 
-Translator_def::Translator_def (Translator_def const & s)
+Context_def::Context_def (Context_def const & s)
   : Input (s)
 {
   context_aliases_ = SCM_EOL;
@@ -72,7 +72,6 @@ Translator_def::Translator_def (Translator_def const & s)
   smobify_self();
   description_ = s.description_;
 
-
   accept_mods_ = s.accept_mods_;
   property_ops_ = s.property_ops_;
   translator_mods_ = s.translator_mods_;
@@ -83,7 +82,7 @@ Translator_def::Translator_def (Translator_def const & s)
 
 
 void
-Translator_def::add_context_mod (SCM mod)
+Context_def::add_context_mod (SCM mod)
 {
   SCM tag  = gh_car (mod);
   if (ly_symbol2scm ("description")  == tag)
@@ -136,44 +135,21 @@ Translator_def::add_context_mod (SCM mod)
     }
 }
 
-SCM
-Translator_def::get_translator_names () const
-{
-  SCM l1 = SCM_EOL;
-  SCM l2 = SCM_EOL;
 
-  SCM mods = scm_reverse (translator_mods_);
-  for (SCM s = mods; gh_pair_p (s); s = gh_cdr (s))
-    {
-      SCM tag = gh_caar (s);
-      SCM arg = gh_cadar (s);
-
-      if (ly_symbol2scm ("consists") == tag)
-       l1 = gh_cons (arg, l1);
-      else if (ly_symbol2scm ("consists-end") == tag)
-       l2 = gh_cons (arg, l2);
-      else if (ly_symbol2scm ("remove") == tag)
-       {
-         l1 = scm_delete_x (arg, l1);
-         l2 = scm_delete_x (arg, l2);
-       }
-    }
-
-  return scm_append_x (scm_list_2 (l1, l2));
-}
 
 SCM
-Translator_def::get_context_name () const
+Context_def::get_context_name () const
 {
   return context_name_;
 }
 
 SCM
-Translator_def::get_accepted () const
+Context_def::get_accepted (SCM user_mod) const
 {
-  SCM correct_order = scm_reverse (accept_mods_);
+  SCM mods = scm_reverse_x (scm_list_copy (accept_mods_),
+                           user_mod);
   SCM acc = SCM_EOL;
-  for (SCM s = correct_order; gh_pair_p (s); s = gh_cdr (s))
+  for (SCM s = mods; gh_pair_p (s); s = gh_cdr (s))
     {
       SCM tag = gh_caar (s);
       SCM sym = gh_cadar (s);
@@ -186,23 +162,23 @@ Translator_def::get_accepted () const
 }
 
           
-Link_array<Translator_def>
-Translator_def::path_to_acceptable_translator (SCM type_sym, Music_output_def* odef) const
+Link_array<Context_def>
+Context_def::path_to_acceptable_translator (SCM type_sym, Music_output_def* odef) const
 {
   assert (gh_symbol_p (type_sym));
   
-  SCM accepted = get_accepted ();
+  SCM accepted = get_accepted (SCM_EOL);
 
-  Link_array<Translator_def> accepteds;
+  Link_array<Context_def> accepteds;
   for (SCM s = accepted; gh_pair_p (s); s = ly_cdr (s))
     {
-      Translator_def *t = unsmob_translator_def (odef->find_translator (ly_car (s)));
+      Context_def *t = unsmob_context_def (odef->find_translator (ly_car (s)));
       if (!t)
        continue;
       accepteds.push (t);
     }
 
-  Link_array<Translator_def> best_result;
+  Link_array<Context_def> best_result;
   for (int i=0; i < accepteds.size (); i++)
     {
       /*
@@ -218,9 +194,9 @@ Translator_def::path_to_acceptable_translator (SCM type_sym, Music_output_def* o
   int best_depth= INT_MAX;
   for (int i=0; i < accepteds.size (); i++)
     {
-      Translator_def * g = accepteds[i];
+      Context_def * g = accepteds[i];
 
-      Link_array<Translator_def> result
+      Link_array<Context_def> result
        = g->path_to_acceptable_translator (type_sym, odef);
       if (result.size () && result.size () < best_depth)
        {
@@ -238,37 +214,46 @@ Translator_def::path_to_acceptable_translator (SCM type_sym, Music_output_def* o
   return best_result;
 }
 
-IMPLEMENT_SMOBS (Translator_def);
-IMPLEMENT_DEFAULT_EQUAL_P (Translator_def);
+IMPLEMENT_SMOBS (Context_def);
+IMPLEMENT_DEFAULT_EQUAL_P (Context_def);
+
+
 
 
-static SCM
-names_to_translators (SCM namelist, Translator_group*tg)
+SCM
+Context_def::get_translator_names (SCM user_mod) const
 {
-  SCM l = SCM_EOL;
-  for (SCM s = namelist; gh_pair_p (s) ; s = ly_cdr (s))
-    {
-      Translator * t = get_translator (ly_car (s));
-      if (!t)
-       warning (_f ("can't find: `%s'", s));
-      else
-       {
-         Translator * tr = t->clone ();
-         SCM str = tr->self_scm ();
-         l = gh_cons (str, l);
+  SCM l1 = SCM_EOL;
+  SCM l2 = SCM_EOL;
 
-         tr->daddy_trans_ = tg;
-         tr->output_def_  = tg->output_def_;
+  SCM mods = scm_reverse_x (scm_list_copy (translator_mods_),
+                           user_mod);
+  
+  for (SCM s = mods; gh_pair_p (s); s = gh_cdr (s))
+    {
+      SCM tag = gh_caar (s);
+      SCM arg = gh_cadar (s);
 
-         scm_gc_unprotect_object (str);
+      if (gh_string_p (arg))
+       arg = scm_string_to_symbol (arg);
+      
+      if (ly_symbol2scm ("consists") == tag)
+       l1 = gh_cons (arg, l1);
+      else if (ly_symbol2scm ("consists-end") == tag)
+       l2 = gh_cons (arg, l2);
+      else if (ly_symbol2scm ("remove") == tag)
+       {
+         l1 = scm_delete_x (arg, l1);
+         l2 = scm_delete_x (arg, l2);
        }
     }
-  return l; 
+
+  return scm_append_x (scm_list_2 (l1, l2));
 }
 
 
 Translator_group *
-Translator_def::instantiate (Music_output_def* md)
+Context_def::instantiate (Music_output_def* md, SCM ops)
 {
   Translator * g = get_translator (translator_group_type_);
   g = g->clone (); 
@@ -277,56 +262,45 @@ Translator_def::instantiate (Music_output_def* md)
   tg->output_def_ = md;
   tg->definition_ = self_scm ();
 
-  SCM trans_names = get_translator_names (); 
+  SCM trans_names = get_translator_names (ops); 
   tg->simple_trans_list_ = names_to_translators (trans_names, tg);
-  
+  tg->accepts_list_ = get_accepted  (ops);
   return tg;
 }
 
-void
-Translator_def::apply_default_property_operations (Translator_group*tg)
-{
-  apply_property_operations (tg, property_ops_);
-}
-
 
 SCM
-Translator_def::clone_scm () const
+Context_def::clone_scm () const
 {
-  Translator_def * t = new Translator_def (*this);
+  Context_def * t = new Context_def (*this);
   scm_gc_unprotect_object (t->self_scm());
   return t->self_scm();
 }
 
 SCM
-Translator_def::make_scm ()
+Context_def::make_scm ()
 {
-  Translator_def* t = new Translator_def;
+  Context_def* t = new Context_def;
   scm_gc_unprotect_object (t->self_scm());
   return t->self_scm();
 }
 
-
-/*
-  Default child context as a SCM string, or something else if there is
-  none.
-*/
-SCM
-Translator_def::default_child_context_name ()
+void
+Context_def::apply_default_property_operations (Translator_group *tg)
 {
-  SCM d = get_accepted ();
-  return gh_pair_p (d) ? ly_car (scm_last_pair (d)) : SCM_EOL;
+  apply_property_operations (tg , property_ops_);
 }
 
 SCM
-Translator_def::to_alist () const
+Context_def::to_alist () const
 {
   SCM l = SCM_EOL;
 
-  l = gh_cons (gh_cons (ly_symbol2scm ("consists"),  get_translator_names ()), l);
+  l = gh_cons (gh_cons (ly_symbol2scm ("consists"),
+                       get_translator_names (SCM_EOL)), l);
   l = gh_cons (gh_cons (ly_symbol2scm ("description"),  description_), l);
   l = gh_cons (gh_cons (ly_symbol2scm ("aliases"),  context_aliases_), l);
-  l = gh_cons (gh_cons (ly_symbol2scm ("accepts"),  get_accepted ()), l);
+  l = gh_cons (gh_cons (ly_symbol2scm ("accepts"),  get_accepted (SCM_EOL)), l);
   l = gh_cons (gh_cons (ly_symbol2scm ("property-ops"),  property_ops_), l);
   l = gh_cons (gh_cons (ly_symbol2scm ("context-name"),  context_name_), l);
   l = gh_cons (gh_cons (ly_symbol2scm ("group-type"),  translator_group_type_), l);    
@@ -335,7 +309,7 @@ Translator_def::to_alist () const
 }
 
 bool
-Translator_def::is_alias (SCM sym) const
+Context_def::is_alias (SCM sym) const
 {
   bool b  = sym == context_name_;