From 775c9117fda462435d6b3554c953d4e080ad7ec0 Mon Sep 17 00:00:00 2001 From: fred Date: Tue, 26 Mar 2002 23:23:02 +0000 Subject: [PATCH] lilypond-1.3.60 --- lily/identifier.cc | 29 ++++++++++++-- lily/include/identifier.hh | 12 ++++-- lily/include/my-lily-lexer.hh | 5 ++- lily/include/scope.hh | 27 +++++-------- lily/music-output-def.cc | 24 ++++------- lily/paper-outputter.cc | 30 ++++++++------ lily/scope.cc | 75 ++++++++++++++--------------------- 7 files changed, 103 insertions(+), 99 deletions(-) diff --git a/lily/identifier.cc b/lily/identifier.cc index 964b33ceeb..4c6284eb01 100644 --- a/lily/identifier.cc +++ b/lily/identifier.cc @@ -19,10 +19,14 @@ #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 () +{ + +} diff --git a/lily/include/identifier.hh b/lily/include/identifier.hh index 002b935202..94bceeebb8 100644 --- a/lily/include/identifier.hh +++ b/lily/include/identifier.hh @@ -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 diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index fc00a1465c..b3113bf94b 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -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; diff --git a/lily/include/scope.hh b/lily/include/scope.hh index 19f5313536..f1f4d8a1dc 100644 --- a/lily/include/scope.hh +++ b/lily/include/scope.hh @@ -13,31 +13,26 @@ #include "lily-proto.hh" #include "lily-guile.hh" -class Protected_scm; +class Scheme_hash_table; class Scope { - Hash_table *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 * 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 */ diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index 0805e3c242..6b4ee8b519 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -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 (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 (""); } diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 4999f0800e..97b542168b 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -13,7 +13,6 @@ #include #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 (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 (i.val ())) + + Identifier * id = unsmob_identifier (v); + + if(dynamic_cast (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 (i.val ())) + else if (dynamic_cast (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); } } } diff --git a/lily/scope.cc b/lily/scope.cc index 917f97344a..96d1b86d33 100644 --- a/lily/scope.cc +++ b/lily/scope.cc @@ -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 (*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; - 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(*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 (); } -- 2.39.5