2 Implement storage and manipulation of grob properties.
8 #include "input-smob.hh"
9 #include "pointer-group-interface.hh"
11 #include "paper-score.hh"
12 #include "output-def.hh"
17 #include "program-option.hh"
19 #include "simple-closure.hh"
22 Grob::get_property_alist_chain (SCM def) const
24 return scm_list_n (mutable_property_alist_,
25 immutable_property_alist_,
31 Grob::get_interfaces () const
37 extern void check_interfaces_for_property (Grob const *me, SCM sym);
40 Grob::internal_set_property (SCM sym, SCM v)
43 SCM grob_p = ly_lily_module_constant ("ly:grob?");
44 SCM grob_list_p = ly_lily_module_constant ("grob-list?");
45 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
48 || type == grob_list_p
49 || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
51 scm_display (scm_list_2 (sym, type), scm_current_output_port ());
56 /* Perhaps we simply do the assq_set, but what the heck. */
60 if (do_internal_type_checking_global)
62 if (!ly_is_procedure (v)
63 && !is_simple_closure (v)
64 && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
66 check_interfaces_for_property (this, sym);
69 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
72 //#define PROFILE_PROPERTY_ACCESSES
74 Grob::get_property_data (SCM sym) const
77 if (profile_property_accesses)
78 note_property_access (&grob_property_lookup_table, sym);
81 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
82 if (handle != SCM_BOOL_F)
83 return scm_cdr (handle);
85 handle = scm_sloppy_assq (sym, immutable_property_alist_);
87 if (do_internal_type_checking_global && scm_is_pair (handle))
89 SCM val = scm_cdr (handle);
90 if (!ly_is_procedure (val)
91 && !is_simple_closure (val)
92 && !type_check_assignment (sym, val,
93 ly_symbol2scm ("backend-type?")))
96 check_interfaces_for_property (this, sym);
99 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
103 Grob::internal_get_property (SCM sym) const
105 SCM val = get_property_data (sym);
106 if (ly_is_procedure (val)
107 || is_simple_closure (val))
109 val = ((Grob*)this)->try_callback (sym, val);
116 #include "protected-scm.hh"
117 Protected_scm grob_property_callback_stack = SCM_EOL;
118 bool debug_property_callbacks = 0;
122 Grob::try_callback (SCM sym, SCM proc)
124 SCM marker = ly_symbol2scm ("calculation-in-progress");
126 need to put a value in SYM to ensure that we don't get a
129 mutable_property_alist_
130 = scm_assq_set_x (mutable_property_alist_, sym, marker);
133 if (debug_property_callbacks)
134 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
138 if (ly_is_procedure (proc))
139 value = scm_call_1 (proc, self_scm ());
140 else if (is_simple_closure (proc))
142 value = evaluate_with_simple_closure (self_scm (),
143 simple_closure_expression (proc));
146 if (debug_property_callbacks)
147 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
151 If the function returns SCM_UNSPECIFIED, we assume the
152 property has been set with an explicit set_property()
155 if (value == SCM_UNSPECIFIED)
157 value = internal_get_property (sym);
159 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
162 internal_set_property (sym, value);
168 Grob::internal_set_object (SCM s, SCM v)
170 /* Perhaps we simply do the assq_set, but what the heck. */
174 object_alist_ = scm_assq_set_x (object_alist_, s, v);
178 Grob::del_property (SCM sym)
180 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, sym);
184 Grob::internal_get_object (SCM sym) const
186 #ifdef PROFILE_PROPERTY_ACCESSES
187 note_property_access (&grob_property_lookup_table, sym);
190 SCM s = scm_sloppy_assq (sym, object_alist_);
192 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
196 Grob::substitute_object_links (SCM crit, SCM orig)
198 set_break_subsititution (crit);
199 object_alist_ = substitute_object_alist (orig, object_alist_);
203 Grob::is_live () const
205 return immutable_property_alist_ != SCM_EOL;