]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.1.8
authorfred <fred>
Sun, 24 Mar 2002 19:53:57 +0000 (19:53 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:53:57 +0000 (19:53 +0000)
lily/identifier.cc
lily/include/identifier.hh
lily/include/my-lily-lexer.hh
lily/my-lily-lexer.cc
lily/parser.y

index bbeea7ef787d004b29e0d9f7d9741d78775f17d6..ff75e9331158187935a11bc3247b966dc74b42e0 100644 (file)
@@ -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);
index 2088c841f7d3ddeccfbd9707c0d682ee25044c7b..08e8346e80ccbc974114196b799db2d02a48b663 100644 (file)
 #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_
index b214366e7e1fbbc996954d4fd8db3ea3cfb5feb9..d472a3ffa674b87dcd18e5f28e870f5fdc8b63eb 100644 (file)
@@ -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;
 };
index 18155a56e7584574c8faf79fdaec026d8999d632..1160b86af148ea0625f1ca443f478e5f9713f2da 100644 (file)
@@ -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<String, Identifier*>;
     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<String,Identifier*>
-            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<String,Identifier*> ai(*identifier_assoc_p_); ai.ok(); 
+    for (Assoc_iter<String,Identifier*> 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
index b06ca442cd48495f9089543185a824688b65cd53..8722ffb133c0bed1d6b8e1e3aea7fdbba97b18dd 100644 (file)
@@ -184,7 +184,7 @@ yylex(YYSTYPE *s,  void * v_l)
 %type <music>  simple_element music_elt full_element lyrics_elt command_elt
 %type <i>      int
 %type <i>      script_dir
-%type <id>     declaration
+%type <id>     identifier_init
 %type <duration>       explicit_duration notemode_duration entered_notemode_duration
 %type <interval>       dinterval
 %type <intvec> intastint_list
@@ -206,9 +206,7 @@ yylex(YYSTYPE *s,  void * v_l)
 %type <score>  score_block score_body
 %type <script> script_definition script_body mudela_script gen_script_def
 %type <textdef> text_def
-%type <string> declarable_identifier
 %type <string> script_abbreviation
-%type <id>     old_identifier
 %type <symbol> symboldef
 %type <symtable>       symtable symtable_body
 %type <itrans> input_translator_spec input_translator_spec_body
@@ -258,81 +256,60 @@ notenames_body:
 /*
        DECLARATIONS
 */
-add_declaration: declaration   {
-               THIS->lexer_p_->add_identifier($1);
-               $1->init_b_ = THIS->init_parse_b_;
-               $1->set_spot(THIS->pop_spot());
-       }
-       ;
 
-declarable_identifier:
+add_declaration:
        STRING {
                THIS->remember_spot();
-           $$ = $1;
        }
-       | old_identifier { 
-               THIS->remember_spot();
-               $$ = new String($1->name_str_); 
-               THIS->here_input().warning("redeclaration of `" + *$$ + "'");
+       /* cont */ '=' identifier_init {
+           THIS->lexer_p_->set_identifier(*$1, $4);
+           $4->init_b_ = THIS->init_parse_b_;
+           $4->set_spot(THIS->pop_spot());
        }
        ;
-
-
-old_identifier:
-       IDENTIFIER
-       |       INPUT_TRANS_IDENTIFIER
-       |       MELODIC_REQUEST_IDENTIFIER 
-       |       POST_REQUEST_IDENTIFIER
-       |       SCRIPT_IDENTIFIER
-       |       REAL_IDENTIFIER
-       |       SCORE_IDENTIFIER
-       |       REQUEST_IDENTIFIER
-       ;
-
-declaration:
-       declarable_identifier '=' score_block {
-               $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
-               delete $1;
+identifier_init:
+       score_block {
+               $$ = new Score_id($1, SCORE_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' paper_block {
-               $$ = new Paper_def_id(*$1, $3, PAPER_IDENTIFIER);
-               delete $1;
+       | paper_block {
+               $$ = new Paper_def_id($1, PAPER_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' midi_block {
-               $$ = new Midi_def_id(*$1, $3, MIDI_IDENTIFIER);
-               delete $1;
+       | midi_block {
+               $$ = new Midi_def_id($1, MIDI_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' script_definition {
-               $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
-               delete $1;
+       | script_definition {
+               $$ = new Script_id($1, SCRIPT_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' Music  {
-               $$ = new Music_id(*$1, $3, MUSIC_IDENTIFIER);
-               delete $1;
+       | Music  {
+               $$ = new Music_id($1, MUSIC_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' symtables {
-               $$ = new Lookup_id(*$1, $3, IDENTIFIER);
-               delete $1;
+       | symtables {
+               $$ = new Lookup_id($1, IDENTIFIER);
+               
        }
-       | declarable_identifier '=' real        {
-               $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
-               delete $1;
+       | real  {
+               $$ = new Real_id(new Real($1), REAL_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' int {
-               $$ = new Int_id(*$1, new int($3), INT_IDENTIFIER);
-               delete $1;
+       | int   {
+               $$ = new Int_id(new int($1), INT_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' post_request {
-               $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
-               delete $1;
+       | post_request {
+               $$ = new Request_id($1, POST_REQUEST_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' melodic_request {
-               $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
-               delete $1;
+       | melodic_request {
+               $$ = new Request_id($1, MELODIC_REQUEST_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' input_translator_spec {
-               $$ = new Input_translator_id ( *$1, $3, INPUT_TRANS_IDENTIFIER);
-               delete $1;
+       | input_translator_spec {
+               $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
        }
        ;
 
@@ -345,7 +322,7 @@ input_translator_spec:
 
 input_translator_spec_body:
        INPUT_TRANS_IDENTIFIER  {
-               $$ = $1->input_translator(true);
+               $$ = $1->input_translator();
                $$-> set_spot( THIS->here_input() );
        }
        | STRING STRING { 
@@ -394,7 +371,7 @@ score_body:         {
                $$ = new Score; 
        }
        | SCORE_IDENTIFIER {
-               $$ = $1->score(true);
+               $$ = $1->score();
        }
        | score_body Music      {
                $$->music_p_ = $2;
@@ -516,7 +493,7 @@ Music:
        | Voice         { $$ = $1; }
        | Chord                 { $$ = $1; }
        | transposed_music      { $$ = $1; }
-       | MUSIC_IDENTIFIER      { $$ = $1->music(true); }
+       | MUSIC_IDENTIFIER      { $$ = $1->music(); }
        | MELODIC 
                { THIS->lexer_p_->push_note_state(); } 
        Music
@@ -597,7 +574,7 @@ abbrev_command_req:
                $$ = new Barcheck_req;
        }
        | COMMAND_IDENTIFIER    {
-               $$ = $1->request(true);
+               $$ = $1->request();
        }
        ;
 
@@ -669,7 +646,7 @@ post_requests:
 
 post_request:
        POST_REQUEST_IDENTIFIER {
-               $$ = (Request*)$1->request(true);
+               $$ = (Request*)$1->request();
        }
        |close_request_parens   { 
                $$ = THIS->get_parens_request($1); 
@@ -839,10 +816,10 @@ script_abbreviation:
        ;
        
 mudela_script:
-       SCRIPT_IDENTIFIER               { $$ = $1->script(true); }
+       SCRIPT_IDENTIFIER               { $$ = $1->script(); }
        | script_definition             { $$ = $1; }
        | script_abbreviation           { 
-               $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
+               $$ = THIS->lexer_p_->lookup_identifier(*$1)->script();
                delete $1;
        }
        ;
@@ -993,7 +970,9 @@ int:
                $$ = $1;
        }
        | INT_IDENTIFIER        {
-               $$ = * $1->intid(0);
+               int *i_p = $1->intid();
+               $$ = *i_p;
+               delete i_p;
        }
        ;
 
@@ -1003,7 +982,9 @@ real:
                $$ = $1;
        }
        | REAL_IDENTIFIER               {
-               $$ = * $1->real(0);             
+               Real *r_p = $1->real();
+               $$ = * r_p;
+               delete r_p;
        }
        ;
        
@@ -1032,7 +1013,7 @@ symtables_body:
                $$ = new Lookup;
        }
        | IDENTIFIER            {
-               $$ = $1->lookup(true);
+               $$ = $1->lookup();
        }
        | symtables_body TEXID STRING           {
                $$->texsetting = *$3;
@@ -1102,13 +1083,13 @@ Paper_def*
 My_lily_parser::default_paper()
 {
        Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
-       return id ? id->paperdef(true) : new Paper_def ;
+       return id ? id->paperdef() : new Paper_def ;
 }
 
 Midi_def*
 My_lily_parser::default_midi()
 {
        Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
-       return id ? id->mididef(true) : new Midi_def ;
+       return id ? id->mididef() : new Midi_def ;
 }