]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/function-documentation.cc
Merge with master
[lilypond.git] / lily / function-documentation.cc
index 8daf4baf0cf73f87cbbfa508a91817f27400ccd8..38e85837c0f6397b894c3f14b29cf67b59e6c5bc 100644 (file)
@@ -3,34 +3,53 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include <cstring>
+using namespace std;
 
-#include "protected-scm.hh"
-#include "string.hh"
+#include "std-string.hh"
+#include "lily-guile.hh"
+#include "warn.hh"
 
-static Protected_scm doc_hash_table;
+/* type predicates. */
+#include "spanner.hh"
+#include "item.hh"
 
-void ly_add_function_documentation (SCM func,
-                                   char const *fname,
-                                   char const *varlist,
-                                   char const *doc)
+
+static SCM doc_hash_table;
+
+void
+ly_check_name (string cxx, string scm_name)
+{
+  string mangle = mangle_cxx_identifier (cxx);
+  if (mangle != scm_name)
+    {
+      programming_error ("wrong cxx name: " + mangle + ", " + cxx +  ", " + scm_name);
+    }
+}
+
+
+void
+ly_add_function_documentation (SCM func,
+                                   string fname,
+                                   string varlist,
+                                   string doc)
 {
-  if (!strlen (doc))
+  if (doc == "")
     return;
 
-  if (!scm_is_vector (doc_hash_table))
-    doc_hash_table = scm_make_vector (scm_int2num (59), SCM_EOL);
+  if (!doc_hash_table)
+    doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
 
-  String s = String (" - ") + "LilyPond procedure: " + fname + " " + varlist
+  string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
     + "\n" + doc;
 
   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
-                               scm_makfrom0str (s.to_str0 ()));
-  SCM entry = scm_cons (scm_makfrom0str (varlist), scm_makfrom0str (doc));
-  scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname), entry);
+                               ly_string2scm (s));
+  SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
+  scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str()), entry);
 }
 
 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
@@ -39,3 +58,55 @@ LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation
 {
   return doc_hash_table;
 }
+
+
+#include <map>
+
+map<void *, string>  type_names;
+  
+void
+ly_add_type_predicate (void *ptr,
+                      string name)
+{
+  type_names[ptr] = name; 
+}
+
+string
+predicate_to_typename (void *ptr)
+{
+  if (type_names.find (ptr) == type_names.end ())
+    return "unknown type";
+  else
+    return type_names[ptr];
+}
+
+static int
+arg_dir (int a, int b)
+{
+  if (&a < &b)
+    return 1;
+  else
+    return -1;
+}
+
+
+int function_argument_direction;
+void
+init_func_doc ()
+{
+  function_argument_direction = arg_dir (2,3);
+
+  ly_add_type_predicate ((void*) &scm_is_integer, "integer");
+  ly_add_type_predicate ((void*) &scm_is_bool, "boolean");
+  ly_add_type_predicate ((void*) &scm_is_pair, "pair");
+  ly_add_type_predicate ((void*) &is_number_pair, "number pair");
+  ly_add_type_predicate ((void*) &scm_is_number, "number");
+  ly_add_type_predicate ((void*) &scm_is_string, "string");
+  ly_add_type_predicate ((void*) &ly_is_symbol, "symbol");
+  ly_add_type_predicate ((void*) &scm_is_vector, "vector");
+  ly_add_type_predicate ((void*) &is_axis, "axis");
+  ly_add_type_predicate ((void*) &unsmob_spanner, "spanner");
+  ly_add_type_predicate ((void*) &unsmob_item, "item");
+}
+
+ADD_SCM_INIT_FUNC(func_doc, init_func_doc);