]> git.donarmstrong.com Git - lilypond.git/blob - lily/undead.cc
Doc: CG - update Bugsquad rota
[lilypond.git] / lily / undead.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "smobs.hh"
21 #include "ly-smobs.icc"
22
23 class Undead
24 {
25   DECLARE_SIMPLE_SMOBS (Undead);
26   SCM object_;
27 public:
28   SCM object () { return object_; }
29   Undead (SCM object = SCM_UNDEFINED) : object_ (object) { };
30 };
31
32 SCM
33 Undead::mark_smob (SCM s)
34 {
35   bool saved = parsed_objects_should_be_dead;
36   parsed_objects_should_be_dead = false;
37   scm_gc_mark (Undead::unsmob (s)->object ());
38   parsed_objects_should_be_dead = saved;
39   return SCM_UNDEFINED;
40 }
41
42 int
43 Undead::print_smob (SCM undead,
44                     SCM port,
45                     scm_print_state *)
46 {
47   scm_puts ("#<Undead ", port);
48   scm_display (Undead::unsmob (undead)->object (), port);
49   scm_puts (" >", port);
50   return 1;
51 }
52
53 IMPLEMENT_SIMPLE_SMOBS (Undead);
54 IMPLEMENT_DEFAULT_EQUAL_P (Undead);
55 IMPLEMENT_TYPE_P (Undead, "ly:undead?")
56
57 LY_DEFINE (ly_make_undead, "ly:make-undead",
58            1, 0, 0, (SCM object),
59            "This packages @var{object} in a manner that keeps it from"
60            " triggering \"Parsed object should be dead\" messages.")
61 {
62   Undead undead (object);
63   return undead.smobbed_copy ();
64 }
65
66 LY_DEFINE (ly_get_undead, "ly:get-undead",
67            1, 0, 0, (SCM undead),
68            "Get back object from @var{undead}.")
69 {
70   LY_ASSERT_SMOB (Undead, undead, 1);
71   return Undead::unsmob (undead)->object ();
72 }
73
74 // '
75 // These are not protected since the means of protecting them would be
76 // problematic to trigger during the mark pass where the array element
77 // references get set.  However, they get set only when in the mark
78 // pass when checking for parsed elements that should be dead, and we
79 // query and clear them immediately afterwards.  So there should be no
80 // way in which the references would have become unprotected in the
81 // mean time.
82
83 vector<parsed_dead *> parsed_dead::elements;
84
85 SCM
86 parsed_dead::readout ()
87 {
88   SCM result = SCM_EOL;
89   for (vsize i = 0; i < elements.size (); i++)
90     {
91       SCM elt = elements[i]->readout_one ();
92       if (!SCM_UNBNDP (elt))
93         result = scm_cons (elt, result);
94     }
95   return result;
96 }
97
98 LY_DEFINE (ly_parsed_undead_list_x, "ly:parsed-undead-list!",
99            0, 0, 0, (),
100            "Return the list of objects that have been found live"
101            " that should have been dead, and clear that list.")
102 {
103   return parsed_dead::readout ();
104 }