]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-property.cc
* lily/system.cc (do_derived_mark): don't mark from object_alist_
[lilypond.git] / lily / grob-property.cc
1 /*
2   Implement storage and manipulation of grob properties.
3 */
4
5 #include <cstring>
6 #include <math.h>
7
8 #include "main.hh"
9 #include "input-smob.hh"
10 #include "pointer-group-interface.hh"
11 #include "misc.hh"
12 #include "paper-score.hh"
13 #include "output-def.hh"
14 #include "spanner.hh"
15 #include "item.hh"
16 #include "misc.hh"
17 #include "item.hh"
18
19 SCM
20 Grob::get_property_alist_chain (SCM def) const
21 {
22   return scm_list_n (mutable_property_alist_,
23                      immutable_property_alist_,
24                      def,
25                      SCM_UNDEFINED);
26 }
27
28 /*
29   This special add_thing routine is slightly more efficient than
30
31   set_prop (name, cons (thing, get_prop (name)))
32
33   since it can reuse the handle returned by scm_assq ().
34 */
35 // JUNKME.
36 void
37 Grob::add_to_list_property (SCM sym, SCM thing)
38 {
39   SCM handle
40     = scm_sloppy_assq (sym, mutable_property_alist_);
41
42   if (handle != SCM_BOOL_F)
43     {
44       scm_set_cdr_x (handle, scm_cons (thing, scm_cdr (handle)));
45     }
46   else
47     {
48       /*
49         There is no mutable prop yet, so create an entry, and put it in front of the
50         mutable prop list.
51       */
52       handle = scm_sloppy_assq (sym, immutable_property_alist_);
53       SCM tail = (handle != SCM_BOOL_F) ? scm_cdr (handle) : SCM_EOL;
54       SCM val = scm_cons (thing, tail);
55
56       mutable_property_alist_ = scm_cons (scm_cons (sym, val),
57                                           mutable_property_alist_);
58     }
59 }
60
61
62
63 extern void check_interfaces_for_property (Grob const *me, SCM sym);
64
65 void
66 Grob::internal_set_property (SCM sym, SCM v)
67 {
68 #ifndef NDEBUG
69   SCM grob_p = ly_lily_module_constant ("ly:grob?");
70   SCM grob_list_p = ly_lily_module_constant ("grob-list?");
71   SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
72   
73   if (type == grob_p
74       || type == grob_list_p
75       || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
76     {
77       scm_display (scm_list_2 (sym, type), scm_current_output_port());
78       assert (0);
79     }
80 #endif
81
82   /* Perhaps we simply do the assq_set, but what the heck. */
83   if (!is_live ())
84     return;
85
86   if (do_internal_type_checking_global)
87     {
88       if (!type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
89         abort ();
90       check_interfaces_for_property (this, sym);
91     }
92
93   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
94 }
95
96 Protected_scm property_lookup_table;
97 LY_DEFINE(ly_property_lookup_stats, "ly:property-lookup-stats",
98           0,0,0, (),
99           "")
100 {
101   return (SCM) property_lookup_table;
102 }
103
104
105 SCM
106 Grob::internal_get_property (SCM sym) const
107 {
108 #ifndef NDEBUG
109   SCM grob_p = ly_lily_module_constant ("ly:grob?");
110   SCM grob_list_p = ly_lily_module_constant ("grob-list?");
111   SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
112   
113   if (type == grob_p
114       || type == grob_list_p)
115     {
116       scm_display (scm_list_2 (sym, type), scm_current_output_port());
117       assert (0);
118     }
119 #endif
120
121 #if 0
122   /*
123     Statistics: which properties are looked up? 
124   */
125   if (scm_hash_table_p (property_lookup_table) != SCM_BOOL_T)
126     {
127       property_lookup_table = scm_c_make_hash_table (259);
128     }
129
130   SCM hashhandle = scm_hashq_get_handle (property_lookup_table, sym);
131   if (hashhandle == SCM_BOOL_F)
132     {
133       scm_hashq_set_x (property_lookup_table, sym, scm_from_int (0));
134       hashhandle = scm_hashq_get_handle (property_lookup_table, sym);
135     }
136
137   scm_set_cdr_x (hashhandle, scm_from_int (scm_to_int (scm_cdr (hashhandle)) + 1));
138 #endif
139   
140   
141   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
142   if (s != SCM_BOOL_F)
143     return scm_cdr (s);
144   
145   s = scm_sloppy_assq (sym, immutable_property_alist_);
146
147   if (do_internal_type_checking_global && scm_is_pair (s))
148     {
149       if (!type_check_assignment (sym, scm_cdr (s),
150                                   ly_symbol2scm ("backend-type?")))
151         abort ();
152
153       check_interfaces_for_property (this, sym);
154     }
155
156   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
157 }
158
159
160
161 void
162 Grob::internal_set_object (SCM s, SCM v)
163 {
164   /* Perhaps we simply do the assq_set, but what the heck. */
165   if (!is_live ())
166     return;
167
168   object_alist_ = scm_assq_set_x (object_alist_, s, v);
169 }
170
171 SCM
172 Grob::internal_get_object (SCM sym) const
173 {
174   SCM s = scm_sloppy_assq (sym, object_alist_);
175
176   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
177 }
178
179 void
180 Grob::substitute_object_links (SCM crit, SCM orig)
181 {
182   set_break_subsititution (crit);
183   object_alist_ = substitute_object_alist (orig, object_alist_);
184 }
185
186 bool
187 Grob::is_live () const
188 {
189   return immutable_property_alist_ != SCM_EOL;
190 }