From 82e1242e3ad5d276b74e81488a3ffdac25701520 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 31 Aug 2014 15:58:46 +0200 Subject: [PATCH] Issue 4086/1: Reimplement Input in terms of Simple_smob --- lily/book.cc | 4 +-- lily/context-def.cc | 4 +-- lily/include/input.hh | 10 ++++---- lily/input-scheme.cc | 9 ------- lily/input-smob.cc | 60 ++++++++----------------------------------- lily/lexer.ll | 2 +- lily/music.cc | 2 +- lily/parser.yy | 6 ++--- lily/score.cc | 4 +-- lily/stream-event.cc | 2 +- 10 files changed, 27 insertions(+), 76 deletions(-) diff --git a/lily/book.cc b/lily/book.cc index 876a93876e..6a09d77b69 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -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_)) diff --git a/lily/context-def.cc b/lily/context-def.cc index 3ebc45d2a2..3d9caa2734 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -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_; diff --git a/lily/include/input.hh b/lily/include/input.hh index 5a2992fdbe..5cdbdca2e6 100644 --- a/lily/include/input.hh +++ b/lily/include/input.hh @@ -26,18 +26,20 @@ /** Base class for anything that records its poisition in the parse file. */ -class Input +class Input : public Simple_smob { 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 diff --git a/lily/input-scheme.cc b/lily/input-scheme.cc index 814499c470..f8bef3bda8 100644 --- a/lily/input-scheme.cc +++ b/lily/input-scheme.cc @@ -20,15 +20,6 @@ #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" diff --git a/lily/input-smob.cc b/lily/input-smob.cc index 420177e2d7..6700936d44 100644 --- a/lily/input-smob.cc +++ b/lily/input-smob.cc @@ -25,12 +25,12 @@ /* 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_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); diff --git a/lily/lexer.ll b/lily/lexer.ll index 1ec3efd2df..760ab9718d 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -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_); } diff --git a/lily/music.cc b/lily/music.cc index 831e9f3805..7db54d3ed9 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -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 * diff --git a/lily/parser.yy b/lily/parser.yy index 4a805f1970..eac4dad0f3 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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)); } ; diff --git a/lily/score.cc b/lily/score.cc index b531695469..2074f810e7 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -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) diff --git a/lily/stream-event.cc b/lily/stream-event.cc index 3af222c1c7..4351f16a5a 100644 --- a/lily/stream-event.cc +++ b/lily/stream-event.cc @@ -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 -- 2.39.2