]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
typechecking tweaks.
[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 /* type predicates. */
17 #include "spanner.hh"
18 #include "item.hh"
19
20
21 static SCM doc_hash_table;
22
23 void
24 ly_check_name (string cxx, string scm_name)
25 {
26   string mangle = mangle_cxx_identifier (cxx);
27   if (mangle != scm_name)
28     {
29       programming_error ("wrong cxx name: " + mangle + ", " + cxx +  ", " + scm_name);
30     }
31 }
32
33
34 void
35 ly_add_function_documentation (SCM func,
36                                     string fname,
37                                     string varlist,
38                                     string doc)
39 {
40   if (doc == "")
41     return;
42
43   if (!doc_hash_table)
44     doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
45
46   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
47     + "\n" + doc;
48
49   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
50                                 ly_string2scm (s));
51   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
52   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str ()), entry);
53 }
54
55 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
56            0, 0, 0, (),
57            "Get a hash table with all lilypond Scheme extension functions.")
58 {
59   return doc_hash_table;
60 }
61
62
63 #include <map>
64
65 map<void *, string>  type_names;
66   
67 void
68 ly_add_type_predicate (void *ptr,
69                        string name)
70 {
71   type_names[ptr] = name; 
72 }
73
74 string
75 predicate_to_typename (void *ptr)
76 {
77   if (type_names.find (ptr) == type_names.end ())
78     {
79       programming_error ("Unknown type predicate");
80       return "unknown type";
81     }
82   else
83     return type_names[ptr];
84 }
85
86 static int
87 arg_dir (int a, int b)
88 {
89   if (&a < &b)
90     return 1;
91   else
92     return -1;
93 }
94
95
96 int function_argument_direction;
97 void
98 init_func_doc ()
99 {
100   function_argument_direction = arg_dir (2,3);
101
102   ly_add_type_predicate ((void*) &scm_is_integer, "integer");
103   ly_add_type_predicate ((void*) &scm_is_bool, "boolean");
104   ly_add_type_predicate ((void*) &scm_is_pair, "pair");
105   ly_add_type_predicate ((void*) &is_number_pair, "number pair");
106   ly_add_type_predicate ((void*) &scm_is_number, "number");
107   ly_add_type_predicate ((void*) &scm_is_string, "string");
108   ly_add_type_predicate ((void*) &ly_is_symbol, "symbol");
109   ly_add_type_predicate ((void*) &scm_is_vector, "vector");
110   ly_add_type_predicate ((void*) &is_axis, "axis");
111   ly_add_type_predicate ((void*) &unsmob_spanner, "spanner");
112   ly_add_type_predicate ((void*) &unsmob_item, "item");
113 }
114
115 ADD_SCM_INIT_FUNC (func_doc, init_func_doc);