#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;
}
Identifier::Identifier (Identifier const&s)
: Input (s)
{
+ self_scm_ = SCM_EOL;
token_code_i_ = s.token_code_i_;
accessed_b_ = s.accessed_b_;
}
STRING_PRINT(Duration);
STRING_PRINT(Real);
STRING_PRINT(int);
-STRING_PRINT(String);
#define DEFAULT_STR(Class) \
String \
DEFAULT_STR(int);
DEFAULT_STR(Real);
-DEFAULT_STR(String);
+
/*
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);
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 ()
+{
+
+}
#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)
class Paper_def_identifier;
class Real_identifier;
class int_identifier;
-class String_identifier;
class Request_identifier;
class Score_identifier;
class Duration_identifier;
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;
IDACCESSOR(Midi_def)
IDACCESSOR(Paper_def)
IDACCESSOR(Real)
- IDACCESSOR(String)
IDACCESSOR(Request)
IDACCESSOR(Score)
IDACCESSOR(int)
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);
DECLARE_ID_CLASS(Paper_def);
DECLARE_ID_CLASS(Midi_def);
+Identifier * unsmob_identifier (SCM);
+SCM smobify (Identifier*);
+
#endif // IDENTIFIER_HH
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;
#include "lily-proto.hh"
#include "lily-guile.hh"
-class Protected_scm;
+class Scheme_hash_table;
class Scope {
- Hash_table<Protected_scm,Identifier*> *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<Protected_scm,Identifier*> * 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 */
#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"
{
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
{
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*
if (!t)
error (_f ("can't find `%s' context", "Score"));
t = t->clone ();
+ t->output_def_l_ = this;
Global_translator *g = dynamic_cast <Global_translator *> (t);
t->add_processing ();
{
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 ("");
}
#include <iostream.h>
#include "dimensions.hh"
-#include "dictionary-iter.hh"
#include "virtual-methods.hh"
#include "paper-outputter.hh"
#include "paper-stream.hh"
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<String_identifier*> (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<Real_identifier*> (i.val ()))
+
+ Identifier * id = unsmob_identifier (v);
+
+ if(dynamic_cast<Real_identifier*> (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<int_identifier*> (i.val ()))
+ else if (dynamic_cast<int_identifier*> (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);
}
}
}
*/
#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<Protected_scm,Identifier*> (*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<Protected_scm,Identifier*>;
- id_dict_->hash_func_ = ly_pscm_hash;
+ id_dict_ = new Scheme_hash_table;
}
bool
}
-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<Protected_scm,Identifier*>(*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 ();
}