From aceda7ad17e22ca0931407171b91fef8e7596c79 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:53:57 +0000 Subject: [PATCH] lilypond-0.1.8 --- lily/identifier.cc | 117 ++++++++++++++---------------- lily/include/identifier.hh | 44 ++++++------ lily/include/my-lily-lexer.hh | 18 ++--- lily/my-lily-lexer.cc | 48 +++++++------ lily/parser.y | 129 +++++++++++++++------------------- 5 files changed, 168 insertions(+), 188 deletions(-) diff --git a/lily/identifier.cc b/lily/identifier.cc index bbeea7ef78..ff75e93311 100644 --- a/lily/identifier.cc +++ b/lily/identifier.cc @@ -13,7 +13,6 @@ #include "identifier.hh" #include "my-lily-lexer.hh" #include "debug.hh" - #include "symtable.hh" #include "lookup.hh" #include "script-def.hh" @@ -26,21 +25,19 @@ IMPLEMENT_IS_TYPE_B(Identifier); Identifier::~Identifier() { if (!accessed_b_ && !init_b_) - warning("Variable not used"); + warning ("Variable not used"); } void -Identifier::error(String expect) +Identifier::error (String expect) { - String e("Wrong identifier type: "); - e += String(name()) + "(expected " + expect + ")"; - ::error(e); + String e ("Wrong identifier type: "); + e += String (name()) + "(expected " + expect + ")"; + ::error (e); } -Identifier::Identifier(String n, int code) - : name_str_(n) +Identifier::Identifier ( int code) { token_code_i_ = code; - data = 0; accessed_b_ = 0; init_b_ = 0; } @@ -48,7 +45,7 @@ Identifier::Identifier(String n, int code) void Identifier::print()const { - mtor << "identifier \'" << name_str_ << "\'="; + DOUT << "identifier "; do_print(); } @@ -56,7 +53,7 @@ Identifier::print()const #define DEFAULT_PRINT(Class, Content_type, accessor) \ void \ Class::do_print() const { \ - ((Class*)this)->accessor(false)->print(); \ + ((Class*)this)->accessor()->print(); \ } \ class Class @@ -74,67 +71,61 @@ DEFAULT_PRINT(Paper_def_id,Paper_def, paperdef); void Real_id::do_print() const { - mtor << *((Real_id*)this)->real(false)<< "\n"; + DOUT << *data_p_<< "\n"; } void Int_id::do_print() const { - mtor << *((Int_id*)this)->intid(false)<< "\n"; + DOUT << *data_p_<< "\n"; } -#define default_accessor(Idclass, Class, accessor)\ +#define DEFAULT_ACCESSOR(Idclass, Class, accessor)\ Class*\ -Idclass::accessor(bool copy) {\ - if (copy){ \ - accessed_b_ = true;\ - return new Class(* (Class*) data);\ - }else\ - return (Class*) data;\ - }\ - -#define virtual_accessor(Idclass, Class, accessor)\ +Idclass::accessor () {\ + accessed_b_ = true;\ + return new Class (*data_p_);\ +} + +#define VIRTUAL_ACCESSOR(Idclass, Class, accessor)\ Class*\ -Idclass::accessor(bool copy) {\ - if (copy){ \ - accessed_b_ = true;\ - return (Class*) ((Class*) data)->clone();\ - }else\ - return (Class*) data;\ - }\ - - -#define implement_id_class(Idclass, Class, accessor) \ -IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\ -Idclass::~Idclass() { delete accessor(false); }\ -Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\ - - -implement_id_class(Input_translator_id, Input_translator, input_translator); -implement_id_class(Int_id, int, intid); -implement_id_class(Real_id, Real, real); -implement_id_class(Script_id, General_script_def, script); -implement_id_class(Lookup_id, Lookup, lookup); -implement_id_class(Symtables_id, Symtables, symtables); -implement_id_class(Music_id, Music, music); -implement_id_class(Score_id, Score, score); -implement_id_class(Request_id, Request, request); -implement_id_class(Midi_def_id, Midi_def, mididef); -implement_id_class(Paper_def_id, Paper_def, paperdef); - -Identifier::Identifier(Identifier const&) +Idclass::accessor () {\ + accessed_b_ = true;\ + return (Class*)data_p_->clone();\ +} + +#define IMPLEMENT_ID_CLASS(Idclass, Class, accessor) \ + IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\ + Idclass::~Idclass() { delete data_p_; }\ + Idclass::Idclass (Class*st, int code):Identifier (code) { data_p_ = st; }\ + + +IMPLEMENT_ID_CLASS(Input_translator_id, Input_translator, input_translator); +IMPLEMENT_ID_CLASS(Int_id, int, intid); +IMPLEMENT_ID_CLASS(Real_id, Real, real); +IMPLEMENT_ID_CLASS(Script_id, General_script_def, script); +IMPLEMENT_ID_CLASS(Lookup_id, Lookup, lookup); +IMPLEMENT_ID_CLASS(Symtables_id, Symtables, symtables); +IMPLEMENT_ID_CLASS(Music_id, Music, music); +IMPLEMENT_ID_CLASS(Score_id, Score, score); +IMPLEMENT_ID_CLASS(Request_id, Request, request); +IMPLEMENT_ID_CLASS(Midi_def_id, Midi_def, mididef); +IMPLEMENT_ID_CLASS(Paper_def_id, Paper_def, paperdef); + +Identifier::Identifier (Identifier const&) { - assert(false); + assert (false); } -default_accessor(Input_translator_id,Input_translator, input_translator); -default_accessor(Int_id, int, intid); -default_accessor(Real_id, Real, real); -virtual_accessor(Script_id, General_script_def, script); -default_accessor(Lookup_id, Lookup, lookup); -default_accessor(Symtables_id, Symtables, symtables); -virtual_accessor(Music_id, Music, music); -default_accessor(Score_id, Score, score); -virtual_accessor(Request_id, Request, request); -default_accessor(Midi_def_id, Midi_def, mididef); -default_accessor(Paper_def_id, Paper_def, paperdef); + +DEFAULT_ACCESSOR(Input_translator_id,Input_translator, input_translator); +DEFAULT_ACCESSOR(Int_id, int, intid); +DEFAULT_ACCESSOR(Real_id, Real, real); +VIRTUAL_ACCESSOR(Script_id, General_script_def, script); +DEFAULT_ACCESSOR(Lookup_id, Lookup, lookup); +DEFAULT_ACCESSOR(Symtables_id, Symtables, symtables); +VIRTUAL_ACCESSOR(Music_id, Music, music); +DEFAULT_ACCESSOR(Score_id, Score, score); +VIRTUAL_ACCESSOR(Request_id, Request, request); +DEFAULT_ACCESSOR(Midi_def_id, Midi_def, mididef); +DEFAULT_ACCESSOR(Paper_def_id, Paper_def, paperdef); diff --git a/lily/include/identifier.hh b/lily/include/identifier.hh index 2088c841f7..08e8346e80 100644 --- a/lily/include/identifier.hh +++ b/lily/include/identifier.hh @@ -12,24 +12,25 @@ #include "input.hh" #include "virtual-methods.hh" -/* boolean argument to accesor is copy_b..*/ #define IDACCESSOR( Input_staff, staff)\ - virtual Input_staff * staff(bool) { error(#Input_staff); return 0; } + virtual Input_staff * staff () { error (#Input_staff); return 0; } +/** + A declarable data structure in mudela. + + */ struct Identifier : public Input { - void *data; - String name_str_; bool init_b_; bool accessed_b_; int token_code_i_; - Identifier(String n, int code) ; + Identifier (int code) ; virtual ~Identifier() ; void print()const; DECLARE_MY_RUNTIME_TYPEINFO; - void error(String); + void error (String); IDACCESSOR(Input_translator, input_translator) IDACCESSOR(Music, music) IDACCESSOR(General_script_def, script) @@ -45,28 +46,29 @@ struct Identifier : public Input { protected: virtual void do_print()const=0; private: - Identifier(Identifier const&); + Identifier (Identifier const&); }; -#define declare_id_class(Idclass, Class, accessor) \ +#define DECLARE_ID_CLASS(Idclass, Class, accessor) \ struct Idclass : Identifier {\ + Class *data_p_; \ DECLARE_MY_RUNTIME_TYPEINFO; \ - Idclass(String s, Class*st, int code);\ - virtual Class* accessor(bool copy);\ + Idclass (Class*st, int code);\ + virtual Class* accessor ();\ ~Idclass();\ virtual void do_print()const; \ }\ -declare_id_class(Input_translator_id, Input_translator, input_translator); -declare_id_class(Real_id, Real, real); -declare_id_class(Script_id, General_script_def, script); -declare_id_class(Lookup_id, Lookup, lookup); -declare_id_class(Symtables_id, Symtables, symtables); -declare_id_class(Music_id, Music, music); -declare_id_class(Int_id, int, intid); -declare_id_class(Score_id, Score, score); -declare_id_class(Request_id, Request, request); -declare_id_class(Paper_def_id,Paper_def, paperdef); -declare_id_class(Midi_def_id,Midi_def, mididef); +DECLARE_ID_CLASS(Input_translator_id, Input_translator, input_translator); +DECLARE_ID_CLASS(Real_id, Real, real); +DECLARE_ID_CLASS(Script_id, General_script_def, script); +DECLARE_ID_CLASS(Lookup_id, Lookup, lookup); +DECLARE_ID_CLASS(Symtables_id, Symtables, symtables); +DECLARE_ID_CLASS(Music_id, Music, music); +DECLARE_ID_CLASS(Int_id, int, intid); +DECLARE_ID_CLASS(Score_id, Score, score); +DECLARE_ID_CLASS(Request_id, Request, request); +DECLARE_ID_CLASS(Paper_def_id,Paper_def, paperdef); +DECLARE_ID_CLASS(Midi_def_id,Midi_def, mididef); #endif // IDENTIFIER_ diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index b214366e7e..d472a3ffa6 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -26,9 +26,9 @@ void set_lexer(); /// lexer for Mudela class My_lily_lexer : public Includable_lexer { - int lookup_keyword(String); - int scan_bare_word(String); - int scan_escaped_word(String); + int lookup_keyword (String); + int scan_bare_word (String); + int scan_escaped_word (String); bool post_quotes_b_; public: @@ -42,18 +42,18 @@ public: /* *************** */ void clear_notenames(); - Identifier*lookup_identifier(String s); - Melodic_req* lookup_melodic_req_l(String s); + Identifier*lookup_identifier (String s); + Melodic_req* lookup_melodic_req_l (String s); void push_note_state(); void push_lyric_state(); void pop_state(); - void LexerError(char const *); + void LexerError (char const *); My_lily_lexer(); - void add_identifier(Identifier*i); + void set_identifier (String,Identifier*i); ~My_lily_lexer(); int yylex(); - void print_declarations(bool init_b) const; - void add_notename(String, Melodic_req*); + void print_declarations (bool init_b) const; + void add_notename (String, Melodic_req*); bool note_state_b() const; bool lyric_state_b() const; }; diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 18155a56e7..1160b86af1 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -71,7 +71,7 @@ static Keyword_ent the_key_tab[]={ My_lily_lexer::My_lily_lexer() { - keytable_p_ = new Keyword_table(the_key_tab); + keytable_p_ = new Keyword_table (the_key_tab); identifier_assoc_p_ = new Assoc; errorlevel_i_ = 0; post_quotes_b_ = false; @@ -79,15 +79,15 @@ My_lily_lexer::My_lily_lexer() } int -My_lily_lexer::lookup_keyword(String s) +My_lily_lexer::lookup_keyword (String s) { - return keytable_p_->lookup(s); + return keytable_p_->lookup (s); } Identifier* -My_lily_lexer::lookup_identifier(String s) +My_lily_lexer::lookup_identifier (String s) { - if (!identifier_assoc_p_->elt_b(s)) + if (!identifier_assoc_p_->elt_b (s)) return 0; return (*identifier_assoc_p_)[s]; @@ -95,10 +95,14 @@ My_lily_lexer::lookup_identifier(String s) void -My_lily_lexer::add_identifier(Identifier*i) +My_lily_lexer::set_identifier (String name_str, Identifier*i) { - delete lookup_identifier(i->name_str_); - (*identifier_assoc_p_)[i->name_str_] = i; + Identifier *old = lookup_identifier (name_str); + if (old) { + old->warning( "redeclaration of \\" + name_str); + delete old; + } + (*identifier_assoc_p_)[name_str] = i; } My_lily_lexer::~My_lily_lexer() @@ -106,47 +110,49 @@ My_lily_lexer::~My_lily_lexer() delete keytable_p_; for (Assoc_iter - ai(*identifier_assoc_p_); ai.ok(); ai++) { - mtor << "deleting: " << ai.key()<<'\n'; + ai (*identifier_assoc_p_); ai.ok(); ai++) { + DOUT << "deleting: " << ai.key()<<'\n'; delete ai.val(); } delete note_tab_p_; delete identifier_assoc_p_; } void -My_lily_lexer::print_declarations(bool init_b)const +My_lily_lexer::print_declarations (bool init_b)const { - for (Assoc_iter ai(*identifier_assoc_p_); ai.ok(); + for (Assoc_iter ai (*identifier_assoc_p_); ai.ok(); ai++) { - if (ai.val()->init_b_ == init_b) - ai.val()->print(); + if (ai.val()->init_b_ == init_b) { + DOUT << ai.key() << '='; + ai.val()->print (); + } } } void -My_lily_lexer::LexerError(char const *s) +My_lily_lexer::LexerError (char const *s) { if (include_stack_.empty()) { *mlog << "error at EOF" << s << '\n'; } else { errorlevel_i_ |= 1; - Input spot(source_file_l(),here_ch_C()); + Input spot (source_file_l(),here_ch_C()); - spot.error( s ); + spot.error (s); } } Melodic_req* -My_lily_lexer::lookup_melodic_req_l(String s) +My_lily_lexer::lookup_melodic_req_l (String s) { - return note_tab_p_->get_l(s); + return note_tab_p_->get_l (s); } void -My_lily_lexer::add_notename(String s, Melodic_req *p) +My_lily_lexer::add_notename (String s, Melodic_req *p) { - note_tab_p_->add(s,p); + note_tab_p_->add (s,p); } void diff --git a/lily/parser.y b/lily/parser.y index b06ca442cd..8722ffb133 100644 --- a/lily/parser.y +++ b/lily/parser.y @@ -184,7 +184,7 @@ yylex(YYSTYPE *s, void * v_l) %type simple_element music_elt full_element lyrics_elt command_elt %type int %type script_dir -%type declaration +%type identifier_init %type explicit_duration notemode_duration entered_notemode_duration %type dinterval %type intastint_list @@ -206,9 +206,7 @@ yylex(YYSTYPE *s, void * v_l) %type score_block score_body %type