]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4086/1: Reimplement Input in terms of Simple_smob
authorDavid Kastrup <dak@gnu.org>
Sun, 31 Aug 2014 13:58:46 +0000 (15:58 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 8 Sep 2014 07:29:17 +0000 (09:29 +0200)
lily/book.cc
lily/context-def.cc
lily/include/input.hh
lily/input-scheme.cc
lily/input-smob.cc
lily/lexer.ll
lily/music.cc
lily/parser.yy
lily/score.cc
lily/stream-event.cc

index 876a93876e6cb39a0f3b9f6e1513d4609a715b62..6a09d77b69b6f85439e39717350614cce1425e8f 100644 (file)
@@ -43,7 +43,7 @@ Book::Book ()
   input_location_ = SCM_EOL;
   smobify_self ();
 
-  input_location_ = make_input (Input ());
+  input_location_ = Input ().smobbed_copy ();
 }
 
 Book::Book (Book const &s)
@@ -61,7 +61,7 @@ Book::Book (Book const &s)
       paper_->unprotect ();
     }
 
-  input_location_ = make_input (*s.origin ());
+  input_location_ = s.origin ()->smobbed_copy ();
 
   header_ = ly_make_module (false);
   if (ly_is_module (s.header_))
index 3ebc45d2a273f9d931b91294777673c053c5798d..3d9caa2734a1258508862ae487d4ca52d6960126 100644 (file)
@@ -43,7 +43,7 @@ Context_def::Context_def ()
 
   smobify_self ();
 
-  input_location_ = make_input (Input ());
+  input_location_ = Input ().smobbed_copy ();
   context_name_ = ly_symbol2scm ("");
 }
 
@@ -67,7 +67,7 @@ Context_def::Context_def (Context_def const &s)
   smobify_self ();
 
   description_ = s.description_;
-  input_location_ = make_input (*s.origin ());
+  input_location_ = s.origin ()->smobbed_copy ();
   default_child_ = s.default_child_;
   accept_mods_ = s.accept_mods_;
   property_ops_ = s.property_ops_;
index 5a2992fdbe2ae54efb936ad5614989e7c07e500b..5cdbdca2e6303c3855176a9ec355d77e56d32064 100644 (file)
 /**
    Base class for anything that records its poisition in the parse file.
 */
-class Input
+class Input : public Simple_smob<Input>
 {
   char const *start_;
   char const *end_;
   Source_file *source_file_;
 public:
+  static const char type_p_name_[];
+  static int print_smob (SCM, SCM, scm_print_state *);
+  static SCM equal_p (SCM, SCM);
+  static SCM mark_smob (SCM);
   Source_file *get_source_file () const;
   char const *start () const;
   char const *end () const;
 
-  static Input *unsmob (SCM);
-
   void set (Source_file *, char const *, char const *);
   void error (const string&) const;
   void programming_error (const string&) const;
@@ -69,8 +71,6 @@ protected:
   string message_string (const string &msg) const;
 };
 
-SCM make_input (Input spot);
-
 extern Input dummy_input_global;
 
 #endif // INPUT_HH
index 814499c4709b7c165bd073d4c459fe4313402e9d..f8bef3bda8aa930e66d915e5e877409d6df2e7c4 100644 (file)
 #include "std-string.hh"
 #include "input.hh"
 
-/* We don't use IMPLEMENT_TYPE_P, since the smobification part is
-   implemented separately from the class.  */
-LY_DEFINE (ly_input_location_p, "ly:input-location?", 1, 0, 0,
-           (SCM x),
-           "Is @var{x} an @code{input-location}?")
-{
-  return Input::unsmob (x) ? SCM_BOOL_T : SCM_BOOL_F;
-}
-
 LY_DEFINE (ly_input_warning, "ly:input-warning", 2, 0, 1, (SCM sip, SCM msg, SCM rest),
            "Print @var{msg} as a GNU compliant warning message, pointing"
            " to the location in @var{sip}.  @var{msg} is interpreted"
index 420177e2d71bb92bba1afa63052636da70f69aac..6700936d44cc084c965de39f83f4ea881229927e 100644 (file)
 /* Dummy input location for use if real one is missing.  */
 Input dummy_input_global;
 
-static long input_tag;
+const char Input::type_p_name_[] = "ly:input-location?";
 
-static SCM
-mark_smob (SCM s)
+SCM
+Input::mark_smob (SCM s)
 {
-  Input *sc = (Input *) SCM_CELL_WORD_1 (s);
+  Input *sc = unsmob (s);
 
   if (Source_file *sf = sc->get_source_file ())
     return sf->self_scm ();
@@ -38,26 +38,19 @@ mark_smob (SCM s)
   return SCM_EOL;
 }
 
-static int
-print_smob (SCM s, SCM port, scm_print_state *)
+int
+Input::print_smob (SCM s, SCM port, scm_print_state *)
 {
   string str = "#<location " + Input::unsmob (s)->location_string () + ">";
   scm_puts (str.c_str (), port);
   return 1;
 }
 
-static size_t
-free_smob (SCM s)
-{
-  delete Input::unsmob (s);
-  return 0;
-}
-
-static SCM
-equal_smob (SCM sa, SCM sb)
+SCM
+Input::equal_p (SCM sa, SCM sb)
 {
-  Input *a = (Input *) SCM_CELL_WORD_1 (sa);
-  Input *b = (Input *) SCM_CELL_WORD_1 (sb);
+  Input *a = unsmob (sa);
+  Input *b = unsmob (sb);
   if (a->get_source_file () == b->get_source_file ()
       && a->start () == b->start ()
       && a->end () == b->end ())
@@ -65,36 +58,3 @@ equal_smob (SCM sa, SCM sb)
   else
     return SCM_BOOL_F;
 }
-
-static void
-start_input_smobs ()
-{
-  input_tag = scm_make_smob_type ("input", 0);
-  scm_set_smob_mark (input_tag, mark_smob);
-  scm_set_smob_free (input_tag, free_smob);
-  scm_set_smob_print (input_tag, print_smob);
-  scm_set_smob_equalp (input_tag, equal_smob);
-}
-
-SCM
-make_input (Input ip)
-{
-  Input *nip = new Input (ip);
-  SCM z;
-
-  SCM_NEWSMOB (z, input_tag, nip);
-  return z;
-}
-
-Input *
-Input::unsmob (SCM s)
-{
-  if (SCM_IMP (s))
-    return 0;
-  if (SCM_CAR (s) == (SCM)input_tag) // ugh.
-    return (Input *) SCM_CDR (s);
-  else
-    return 0;
-}
-
-ADD_SCM_INIT_FUNC (input, start_input_smobs);
index 1ec3efd2df2c9a1f9ffac88934645596b4d44500..760ab9718dff0f7349caeb74cbc43d627b9b9703 100644 (file)
@@ -814,7 +814,7 @@ BOM_UTF8    \357\273\277
 void
 Lily_lexer::push_extra_token (Input const &where, int token_type, SCM scm)
 {
-       extra_tokens_ = scm_cons (scm_cons2 (make_input (where),
+       extra_tokens_ = scm_cons (scm_cons2 (where.smobbed_copy (),
                                             scm_from_int (token_type),
                                             scm), extra_tokens_);
 }
index 831e9f38053386dce96601f273337e7f7b0e96c6..7db54d3ed930b334c825faea2f5e6a30738de437 100644 (file)
@@ -246,7 +246,7 @@ Music::transpose (Pitch delta)
 void
 Music::set_spot (Input ip)
 {
-  set_property ("origin", make_input (ip));
+  set_property ("origin", ip.smobbed_copy ());
 }
 
 Input *
index 4a805f1970f7a4c74b832d1c70d96e572ac965b7..eac4dad0f3aa397367160536a3df04907fcc1266 100644 (file)
@@ -194,11 +194,11 @@ Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const str
   scm_apply_0 (proc, args)
 /* Syntactic Sugar. */
 #define MAKE_SYNTAX(name, location, ...)                               \
-       LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
+       LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), parser->lexer_->override_input (location).smobbed_copy (), ##__VA_ARGS__, SCM_UNDEFINED))
 #define START_MAKE_SYNTAX(name, ...)                                   \
        scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
 #define FINISH_MAKE_SYNTAX(start, location, ...)                       \
-       LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
+       LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), parser->lexer_->override_input (location).smobbed_copy (), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
 
 SCM get_next_unique_context_id ();
 SCM get_next_unique_lyrics_context_id ();
@@ -2529,7 +2529,7 @@ music_property_def:
                if (SCM_UNBNDP ($1))
                        $$ = MAKE_SYNTAX ("void-music", @1);
                else
-                       $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
+                       $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), @$.smobbed_copy (), $1));
        }
        ;
 
index b5316954696a1dad0f0166c5a1ef90fd51f986fc..2074f810e7a8c3565e4e76f7d54a0bf926270535 100644 (file)
@@ -52,7 +52,7 @@ Score::Score ()
   error_found_ = false;
 
   smobify_self ();
-  input_location_ = make_input (Input ());
+  input_location_ = Input ().smobbed_copy ();
 }
 
 Score::~Score ()
@@ -90,7 +90,7 @@ Score::Score (Score const &s)
   error_found_ = s.error_found_;
 
   smobify_self ();
-  input_location_ = make_input (*s.origin ());
+  input_location_ = s.origin ()->smobbed_copy ();
 
   Music *m = Music::unsmob (s.music_);
   if (m)
index 3af222c1c7550d4c27830c3f793f9f63e4f5cf96..4351f16a5a3a99165f4f3aa5353377586981cef1 100644 (file)
@@ -61,7 +61,7 @@ Stream_event::origin () const
 void
 Stream_event::set_spot (Input *i)
 {
-  set_property ("origin", make_input (*i));
+  set_property ("origin", i->smobbed_copy ());
 }
 
 bool