]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
cce8c666475f95b72e90509dbba8a5a1f4e82241
[lilypond.git] / lily / function-documentation.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2014 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 <cstring>
21 using namespace std;
22
23 #include "std-string.hh"
24 #include "lily-guile.hh"
25 #include "warn.hh"
26
27 static SCM doc_hash_table;
28
29 void
30 ly_check_name (const string &cxx, const string &scm_name)
31 {
32   string mangle = mangle_cxx_identifier (cxx);
33   if (mangle != scm_name)
34     {
35       programming_error ("wrong cxx name: " + mangle + ", " + cxx + ", " + scm_name);
36     }
37 }
38
39 void
40 ly_add_function_documentation (SCM func,
41                                const string &fname,
42                                const string &varlist,
43                                const string &doc)
44 {
45   if (doc == "")
46     return;
47
48   if (!doc_hash_table)
49     doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
50
51   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
52              + "\n" + doc;
53
54   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
55                                 ly_string2scm (s));
56   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
57   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str ()), entry);
58 }
59
60 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
61            0, 0, 0, (),
62            "Get a hash table with all LilyPond Scheme extension functions.")
63 {
64   return doc_hash_table;
65 }
66
67 #include <map>
68
69 map<void *, string> type_names;
70
71 void
72 ly_add_type_predicate (void *ptr,
73                        const string &name)
74 {
75   type_names[ptr] = name;
76 }
77
78 string
79 predicate_to_typename (void *ptr)
80 {
81   if (type_names.find (ptr) == type_names.end ())
82     {
83       programming_error ("Unknown type predicate");
84       return "unknown type";
85     }
86   else
87     return type_names[ptr];
88 }
89
90 /* type predicates. */
91 #include "global-context.hh"
92 #include "input.hh"
93 #include "item.hh"
94 #include "music.hh"
95 #include "music-function.hh"
96 #include "paper-score.hh"
97 #include "performance.hh"
98 #include "spanner.hh"
99 #include "stream-event.hh"
100 #include "unpure-pure-container.hh"
101
102 void
103 init_func_doc ()
104 {
105   ly_add_type_predicate ((void *) &is_direction, "direction");
106   ly_add_type_predicate ((void *) &is_music_function, "Music_function");
107   ly_add_type_predicate ((void *) &ly_is_port, "port");
108   ly_add_type_predicate ((void *) &ly_cheap_is_list, "list");
109   ly_add_type_predicate ((void *) &unsmob_global_context, "Global_context");
110   ly_add_type_predicate ((void *) &unsmob_input, "Input");
111   ly_add_type_predicate ((void *) &unsmob_moment, "Moment");
112   ly_add_type_predicate ((void *) &unsmob_paper_score, "Paper_score");
113   ly_add_type_predicate ((void *) &unsmob_performance, "Performance");
114   ly_add_type_predicate ((void *) &is_unpure_pure_container, "unpure pure container");
115
116   ly_add_type_predicate ((void *) &is_axis, "axis");
117   ly_add_type_predicate ((void *) &is_number_pair, "number pair");
118   ly_add_type_predicate ((void *) &ly_is_list, "list");
119   ly_add_type_predicate ((void *) &ly_is_procedure, "procedure");
120   ly_add_type_predicate ((void *) &ly_is_symbol, "symbol");
121   ly_add_type_predicate ((void *) &scm_is_bool, "boolean");
122   ly_add_type_predicate ((void *) &scm_is_integer, "integer");
123   ly_add_type_predicate ((void *) &scm_is_number, "number");
124   ly_add_type_predicate ((void *) &scm_is_pair, "pair");
125   ly_add_type_predicate ((void *) &scm_is_rational, "rational");
126   ly_add_type_predicate ((void *) &scm_is_string, "string");
127   ly_add_type_predicate ((void *) &scm_is_vector, "vector");
128   ly_add_type_predicate ((void *) &unsmob_item, "Item");
129   ly_add_type_predicate ((void *) &unsmob_music, "Music");
130   ly_add_type_predicate ((void *) &unsmob_spanner, "Spanner");
131   ly_add_type_predicate ((void *) &unsmob_stream_event, "Stream_event");
132 }
133
134 ADD_SCM_INIT_FUNC (func_doc, init_func_doc);