From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Fri, 1 Sep 2006 10:02:45 +0000 (+0000)
Subject: * lily/include/book.hh (class Book): idem.
X-Git-Tag: release/2.10.0-2~330
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=cfb0511f85f9691bfeebecaaaf962f7e0feb3ce0;p=lilypond.git

* lily/include/book.hh (class Book): idem.

* lily/include/context-def.hh (struct Context_def): idem.

* lily/include/score.hh (class Score): don't derive from Input.

* lily/book.cc (Book): add a copy ctor.
---

diff --git a/ChangeLog b/ChangeLog
index 2d57d37734..9f753356b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2006-09-01  Han-Wen Nienhuys  <hanwen@lilypond.org>
 
+	* lily/include/book.hh (class Book): idem.
+
+	* lily/include/context-def.hh (struct Context_def): idem.
+
+	* lily/include/score.hh (class Score): don't derive from Input.
+
+	* lily/book.cc (Book): add a copy ctor. 
+
 	* buildscripts/output-distance.py (FileLink.calc_distance): count
 	orphans in distance too.
 
diff --git a/Documentation/user/programming-interface.itely b/Documentation/user/programming-interface.itely
index 4536fff21a..8b40fe3140 100644
--- a/Documentation/user/programming-interface.itely
+++ b/Documentation/user/programming-interface.itely
@@ -197,9 +197,8 @@ AltOff = {
 
 @noindent
 This example may be rewritten to pass in music expressions,
-@c fixme
-@ignore
-i@l ilypond[quote,verbatim,ragged-right]
+
+@lilypond[quote,verbatim,ragged-right]
 withAlt = #(define-music-function (parser location mag music) (number? ly:music?)
   #{ \override Stem #'length = #$(* 7.0 mag)
      \override NoteHead #'font-size =
@@ -210,8 +209,7 @@ withAlt = #(define-music-function (parser location mag music) (number? ly:music?
 
 { c'2 \withAlt #0.5 {c'4 c'}
   \withAlt #1.5 {c' c'} c'2 }
-@end l ilypond
-@end ignore
+@end lilypond
 
 @node Void functions
 @subsection Void functions
diff --git a/lily/book.cc b/lily/book.cc
index 87df4efe84..114ef0cdf2 100644
--- a/lily/book.cc
+++ b/lily/book.cc
@@ -30,18 +30,47 @@ using namespace std;
 #include "ly-smobs.icc"
 
 Book::Book ()
-  : Input ()
 {
   paper_ = 0;
   header_ = SCM_EOL;
   scores_ = SCM_EOL;
+  input_location_ = SCM_EOL;
   smobify_self ();
+
+  input_location_ = make_input (Input ());
+}
+
+Book::Book (Book const &s)
+{
+  paper_ = 0;
+  header_ = SCM_EOL;
+  scores_ = SCM_EOL;
+  input_location_ = SCM_EOL;
+  smobify_self ();
+
+  if (s.paper_)
+    paper_ = s.paper_->clone ();
+  
+  input_location_ = make_input (*s.origin ());
+  header_ = ly_make_anonymous_module (false);
+  if (ly_is_module (s.header_))
+    ly_module_copy (header_, s.header_);
+
+  SCM *t = &scores_;
+  for (SCM p = s.scores_; scm_is_pair (p); p = scm_cdr (p))
+    {
+      Score *newscore = unsmob_score (scm_car (p))->clone ();
+
+      *t = scm_cons (newscore->self_scm (), SCM_EOL);
+      t = SCM_CDRLOC(*t);
+      newscore->unprotect ();
+    }
 }
 
-Book* 
-Book::clone () const
+Input *
+Book::origin () const
 {
-  return new Book (*this);
+  return unsmob_input (input_location_);
 }
 
 Book::~Book ()
@@ -64,7 +93,8 @@ Book::mark_smob (SCM s)
   if (book->paper_)
     scm_gc_mark (book->paper_->self_scm ());
   scm_gc_mark (book->scores_);
-
+  scm_gc_mark (book->input_location_);
+  
   return book->header_;
 }
 
diff --git a/lily/context-def.cc b/lily/context-def.cc
index b856486dba..0af5fabf4f 100644
--- a/lily/context-def.cc
+++ b/lily/context-def.cc
@@ -27,14 +27,21 @@ Context_def::Context_def ()
   context_name_ = SCM_EOL;
   default_child_ = SCM_EOL;
   description_ = SCM_EOL;
+  input_location_ = SCM_EOL;
 
   smobify_self ();
 
+  input_location_ = make_input (Input ());
   context_name_ = ly_symbol2scm ("");
 }
 
+Input *
+Context_def::origin () const
+{
+  return unsmob_input (input_location_);
+}
+
 Context_def::Context_def (Context_def const &s)
-  : Input (s)
 {
   context_aliases_ = SCM_EOL;
   translator_group_type_ = SCM_EOL;
@@ -44,10 +51,11 @@ Context_def::Context_def (Context_def const &s)
   context_name_ = SCM_EOL;
   description_ = SCM_EOL;
   default_child_ = SCM_EOL;
-
+  input_location_ = SCM_EOL;
   smobify_self ();
-  description_ = s.description_;
 
+  description_ = s.description_;
+  input_location_ = make_input (*s.origin ()); 
   default_child_ = s.default_child_;
   accept_mods_ = s.accept_mods_;
   property_ops_ = s.property_ops_;
@@ -88,6 +96,7 @@ Context_def::mark_smob (SCM smob)
   scm_gc_mark (me->property_ops_);
   scm_gc_mark (me->translator_group_type_);
   scm_gc_mark (me->default_child_);
+  scm_gc_mark (me->input_location_);
 
   return me->context_name_;
 }
diff --git a/lily/grob-property.cc b/lily/grob-property.cc
index c4dce927b4..8d7ecc0c19 100644
--- a/lily/grob-property.cc
+++ b/lily/grob-property.cc
@@ -5,7 +5,7 @@
 #include <cstring>
 
 #include "main.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "pointer-group-interface.hh"
 #include "misc.hh"
 #include "paper-score.hh"
diff --git a/lily/grob.cc b/lily/grob.cc
index a1963e5fe4..4b44231e61 100644
--- a/lily/grob.cc
+++ b/lily/grob.cc
@@ -11,7 +11,7 @@
 #include <cstring>
 
 #include "align-interface.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "international.hh"
 #include "item.hh"
 #include "main.hh"
@@ -36,6 +36,7 @@ Grob::Grob (SCM basicprops,
 	    Object_key const *key)
 {
   key_ = key;
+  
   /* FIXME: default should be no callback.  */
   self_scm_ = SCM_EOL;
   layout_ = 0;
diff --git a/lily/include/audio-element.hh b/lily/include/audio-element.hh
index a9d8f7ac47..2941c7d105 100644
--- a/lily/include/audio-element.hh
+++ b/lily/include/audio-element.hh
@@ -16,7 +16,8 @@ class Audio_element
 public:
   Audio_element ();
   virtual ~Audio_element ();
-  VIRTUAL_COPY_CONSTRUCTOR(Audio_element,Audio_element);
+
+  VIRTUAL_COPY_CONSTRUCTOR(Audio_element, Audio_element);
   virtual char const *name () const;
 protected:
 };
diff --git a/lily/include/book-paper-def.hh b/lily/include/book-paper-def.hh
index 55e7a01180..ee0c4a15a3 100644
--- a/lily/include/book-paper-def.hh
+++ b/lily/include/book-paper-def.hh
@@ -18,7 +18,6 @@ class Output_def : public Output_def
 public:
   VIRTUAL_COPY_CONSTRUCTOR (Output_def, Output_def);
   Output_def (Output_def const &);
-
   Output_def ();
 
   virtual void derived_mark ();
diff --git a/lily/include/book.hh b/lily/include/book.hh
index 9ef2ca2130..360276ed08 100644
--- a/lily/include/book.hh
+++ b/lily/include/book.hh
@@ -15,7 +15,7 @@
 #include "object-key.hh"
 #include "std-string.hh"
 
-class Book : public Input
+class Book
 {
   DECLARE_SMOBS (Book, foo);
 
@@ -24,8 +24,11 @@ public:
   SCM header_;
   Output_def *paper_;
   SCM scores_;
+  SCM input_location_;
 
-  Book *clone () const;
+  Book (Book const &);
+  Input *origin() const;
+  VIRTUAL_COPY_CONSTRUCTOR(Book, Book);
   Book ();
   void add_score (SCM);
   Paper_book *process (Output_def *def_paper,
diff --git a/lily/include/context-def.hh b/lily/include/context-def.hh
index a92ad4fee5..dd7045015b 100644
--- a/lily/include/context-def.hh
+++ b/lily/include/context-def.hh
@@ -18,7 +18,7 @@
   The definition of a interpretation context as given in the
   input. The lists are stored in order of definition.
 */
-struct Context_def : public Input
+struct Context_def
 {
 private:
   /*
@@ -32,8 +32,9 @@ private:
   SCM context_aliases_;
   SCM translator_group_type_;
   SCM default_child_;
-
+  SCM input_location_;
 public:
+  Input *origin () const;
   void add_context_mod (SCM);
   SCM get_default_child (SCM user_mods) const;
   SCM get_context_name () const { return context_name_; }
diff --git a/lily/include/engraver-group.hh b/lily/include/engraver-group.hh
index 938fde0492..3fa99e638e 100644
--- a/lily/include/engraver-group.hh
+++ b/lily/include/engraver-group.hh
@@ -21,6 +21,7 @@ protected:
   DECLARE_LISTENER (revert);
 public:
   VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Engraver_group);
+
   Engraver_group ();
   virtual void derived_mark () const;
   void do_announces ();
diff --git a/lily/include/input-smob.hh b/lily/include/input-smob.hh
deleted file mode 100644
index 6b80f26832..0000000000
--- a/lily/include/input-smob.hh
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
-  input-smob.hh -- declare input smob
-
-  source file of the GNU LilyPond music typesetter
-
-  (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#ifndef INPUT_SMOB_HH
-#define INPUT_SMOB_HH
-
-#include "input.hh"
-#include "smobs.hh"
-
-SCM make_input (Input spot);
-Input *unsmob_input (SCM);
-
-extern Input dummy_input_global;
-
-#endif /* INPUT_SMOB_HH */
-
diff --git a/lily/include/input.hh b/lily/include/input.hh
index f7224ec7d3..625910ea74 100644
--- a/lily/include/input.hh
+++ b/lily/include/input.hh
@@ -52,4 +52,14 @@ public:
   Input ();
 };
 
+
+
+#include "input.hh"
+#include "smobs.hh"
+
+SCM make_input (Input spot);
+Input *unsmob_input (SCM);
+
+extern Input dummy_input_global;
+
 #endif // INPUT_HH
diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh
index de190a7c86..a31dcd48fc 100644
--- a/lily/include/output-def.hh
+++ b/lily/include/output-def.hh
@@ -42,6 +42,7 @@ class Output_def
 public:
   VIRTUAL_COPY_CONSTRUCTOR (Output_def, Output_def);
   DECLARE_SMOBS (Output_def, );
+
 public:
   SCM scope_;
   Output_def *parent_;
diff --git a/lily/include/score.hh b/lily/include/score.hh
index 004e251dd9..fcc5752e52 100644
--- a/lily/include/score.hh
+++ b/lily/include/score.hh
@@ -17,13 +17,15 @@
 #include "virtual-methods.hh"
 #include "std-string.hh"
 
-class Score : public Input
+class Score
 {
   DECLARE_SMOBS (Score, foo);
 
   SCM music_;
-
+  SCM input_location_;
 public:
+  Input *origin() const;
+ 
   vector<Output_def*> defs_;
   string user_key_;
   SCM header_;
@@ -32,6 +34,7 @@ public:
   Score ();
   Score (Score const &);
 
+  VIRTUAL_COPY_CONSTRUCTOR (Score, Score);
   
   SCM get_music () const;
   void add_output_def (Output_def *def);
diff --git a/lily/input-scheme.cc b/lily/input-scheme.cc
index 6e954ef162..c24d2ed1b0 100644
--- a/lily/input-scheme.cc
+++ b/lily/input-scheme.cc
@@ -7,7 +7,7 @@
 */
 
 #include "std-string.hh"
-#include "input-smob.hh"
+#include "input.hh"
 
 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
    implemented separately from the class.  */
diff --git a/lily/input-smob.cc b/lily/input-smob.cc
index 72b293f10c..7f66bcd3d3 100644
--- a/lily/input-smob.cc
+++ b/lily/input-smob.cc
@@ -6,7 +6,7 @@
   (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-#include "input-smob.hh"
+#include "input.hh"
 #include "source-file.hh"
 #include "std-string.hh"
 
diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc
index 0e844d2bc0..7c66507997 100644
--- a/lily/lily-parser-scheme.cc
+++ b/lily/lily-parser-scheme.cc
@@ -11,7 +11,7 @@
 #include "file-name-map.hh"
 #include "file-name.hh"
 #include "file-path.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "international.hh"
 #include "lily-lexer.hh"
 #include "lily-parser.hh"
diff --git a/lily/music.cc b/lily/music.cc
index 8a169a217b..4d71d99d98 100644
--- a/lily/music.cc
+++ b/lily/music.cc
@@ -11,7 +11,7 @@
 #include "context.hh"
 #include "dispatcher.hh"
 #include "duration.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "international.hh"
 #include "ly-smobs.icc"
 #include "main.hh"
diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc
index c321c6f8df..f11f40d905 100644
--- a/lily/paper-outputter.cc
+++ b/lily/paper-outputter.cc
@@ -17,7 +17,7 @@ using namespace std;
 #include "dimensions.hh"
 #include "file-name.hh"
 #include "font-metric.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "lily-version.hh"
 #include "main.hh"
 #include "output-def.hh"
diff --git a/lily/parser.yy b/lily/parser.yy
index 17b0cd25a7..dff3ee921d 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -74,7 +74,6 @@ using namespace std;
 #include "context-def.hh"
 #include "dimensions.hh"
 #include "file-path.hh"
-#include "input-smob.hh"
 #include "input.hh"
 #include "international.hh"
 #include "lily-guile.hh"
@@ -606,11 +605,11 @@ context_def_spec_block:
 context_def_spec_body:
 	/**/ {
 		$$ = Context_def::make_scm ();
-		unsmob_context_def ($$)->set_spot (@$);
+		unsmob_context_def ($$)->origin ()->set_spot (@$);
 	}
 	| CONTEXT_DEF_IDENTIFIER {
 		$$ = $1;
-		unsmob_context_def ($$)->set_spot (@$);
+		unsmob_context_def ($$)->origin ()->set_spot (@$);
 	}
 	| context_def_spec_body GROBDESCRIPTIONS embedded_scm {
 		Context_def*td = unsmob_context_def ($$);
@@ -642,14 +641,15 @@ book_block:
 book_body:
 	{
 		$$ = new Book;
-		$$->set_spot (@$);
+		$$->origin ()->set_spot (@$);
 		$$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
 		$$->paper_->unprotect ();
 		$$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader"); 
 	}
 	| BOOK_IDENTIFIER {
 		$$ = unsmob_book ($1);
-		$$->set_spot (@$);
+		$$->protect ();
+		$$->origin ()->set_spot (@$);
 	}
 	| book_body paper_block {
 		$$->paper_ = $2;
@@ -690,12 +690,12 @@ score_body:
 		// pass ownernship to C++ again.
 		$$ = unsmob_score (score);
 		$$->protect ();
-		$$->set_spot (@$);
+		$$->origin ()->set_spot (@$);
 	}
 	| SCORE_IDENTIFIER {
 		$$ = unsmob_score ($1);
 		$$->protect ();
-		$$->set_spot (@$);
+		$$->origin ()->set_spot (@$);
 	}
 	| score_body object_id_setting {
 		$$->user_key_ = ly_scm2string ($2);
diff --git a/lily/score.cc b/lily/score.cc
index 99ec51880a..3f00330e61 100644
--- a/lily/score.cc
+++ b/lily/score.cc
@@ -28,13 +28,21 @@ using namespace std;
 
 #include "ly-smobs.icc"
 
+Input *
+Score::origin () const
+{
+  return unsmob_input (input_location_);
+}
+
+
 Score::Score ()
-  : Input ()
 {
   header_ = SCM_EOL;
   music_ = SCM_EOL;
   error_found_ = false;
+  input_location_ = SCM_EOL;
   smobify_self ();
+  input_location_ = make_input (Input ());
 }
 
 Score::~Score ()
@@ -53,6 +61,8 @@ Score::mark_smob (SCM s)
   scm_gc_mark (sc->header_);
   for (vsize i = sc->defs_.size (); i--;)
     scm_gc_mark (sc->defs_[i]->self_scm ());
+
+  scm_gc_mark (sc->input_location_);
   return sc->music_;
 }
 
@@ -65,12 +75,13 @@ Score::print_smob (SCM, SCM p, scm_print_state*)
 }
 
 Score::Score (Score const &s)
-  : Input (s)
 {
   header_ = SCM_EOL;
   music_ = SCM_EOL;
   error_found_ = s.error_found_;
+  input_location_ = SCM_EOL;
   smobify_self ();
+  input_location_ = make_input (*s.origin ()); 
 
   Music *m = unsmob_music (s.music_);
   if (m)
diff --git a/lily/source-file.cc b/lily/source-file.cc
index 186ea1eaf8..cead386ae9 100644
--- a/lily/source-file.cc
+++ b/lily/source-file.cc
@@ -78,10 +78,9 @@ gulp_file (string filename, int desired_size)
   vector<char> cxx_arr;
   cxx_arr.resize (filesize);
 
-
   copy (str, str + filesize, cxx_arr.begin ());
   
-  free (str);
+  delete[] str;
   return cxx_arr;
 }
 
diff --git a/lily/stencil.cc b/lily/stencil.cc
index 294894d5f1..329c5cae61 100644
--- a/lily/stencil.cc
+++ b/lily/stencil.cc
@@ -10,7 +10,7 @@
 
 #include "main.hh"
 #include "font-metric.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "string-convert.hh"
 #include "warn.hh"
 
diff --git a/lily/stream-event.cc b/lily/stream-event.cc
index 1019c9e85b..7a1118e65a 100644
--- a/lily/stream-event.cc
+++ b/lily/stream-event.cc
@@ -11,7 +11,7 @@
 #include "ly-smobs.icc"
 #include "context.hh"
 #include "input.hh"
-#include "input-smob.hh"
+#include "input.hh"
 
 /* TODO: Rename Stream_event -> Event */