]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
more generic SCM arg typechecking
[lilypond.git] / lily / function-documentation.cc
1 /*
2   function-documentation.cc -- Scheme doc strings.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include <cstring>
10 using namespace std;
11
12 #include "std-string.hh"
13 #include "lily-guile.hh"
14 #include "warn.hh"
15
16 static SCM doc_hash_table;
17
18 void
19 ly_check_name (string cxx, string scm_name)
20 {
21   string mangle = mangle_cxx_identifier (cxx);
22   if (mangle != scm_name)
23     {
24       programming_error ("wrong cxx name: " + mangle + ", " + cxx +  ", " + scm_name);
25     }
26 }
27
28
29 void
30 ly_add_function_documentation (SCM func,
31                                     string fname,
32                                     string varlist,
33                                     string doc)
34 {
35   if (doc == "")
36     return;
37
38   if (!doc_hash_table)
39     doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
40
41   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
42     + "\n" + doc;
43
44   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
45                                 ly_string2scm (s));
46   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
47   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str()), entry);
48 }
49
50 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
51            0, 0, 0, (),
52            "Get a hash table with all lilypond Scheme extension functions.")
53 {
54   return doc_hash_table;
55 }
56
57
58 #include <map>
59
60 map<void *, string>  type_names;
61   
62 void
63 ly_add_type_predicate (void *ptr,
64                        string name)
65 {
66   type_names[ptr] = name; 
67 }
68
69 string
70 predicate_to_typename (void *ptr)
71 {
72   if (type_names.find (ptr) == type_names.end ())
73     return "unknown type";
74   else
75     return type_names[ptr];
76 }