You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/08/31 15:34:00 UTC

[1/8] git commit: Fix StringIterator documentation

Repository: lucy-clownfish
Updated Branches:
  refs/heads/documentation c66300d41 -> f50b736f9


Fix StringIterator documentation


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/3523d7d2
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3523d7d2
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3523d7d2

Branch: refs/heads/documentation
Commit: 3523d7d250f77cb021a2755444b7ff7dc2ac8eae
Parents: c66300d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 23 19:16:57 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:06 2014 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/String.cfh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3523d7d2/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index a053e99..383f6b7 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -319,8 +319,8 @@ class Clownfish::StringIterator nickname StrIter
     new(String *string, size_t byte_offset);
 
     /** Return the substring between the top and tail iterators.
-     * @param offset Top iterator. Use start of string if NULL.
-     * @param len Tail iterator. Use end of string if NULL.
+     * @param top Top iterator. Use start of string if NULL.
+     * @param tail Tail iterator. Use end of string if NULL.
      */
     inert incremented String*
     substring(StringIterator *top, StringIterator *tail);


[6/8] git commit: Add Perl binding for CFCClass_get_parcel

Posted by nw...@apache.org.
Add Perl binding for CFCClass_get_parcel


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/898e6c11
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/898e6c11
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/898e6c11

Branch: refs/heads/documentation
Commit: 898e6c1114d427b26d02aa5bcf0ca6bb800712b6
Parents: 9a4a214
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Aug 31 14:41:41 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:22 2014 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC.xs | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/898e6c11/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index a306b68..bdc91b2 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -301,6 +301,7 @@ ALIAS:
     fresh_member_vars     = 46
     privacy_symbol        = 48
     included              = 50
+    get_parcel            = 52
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -413,6 +414,11 @@ PPCODE:
         case 50:
             retval = newSViv(CFCClass_included(self));
             break;
+        case 52: {
+                CFCParcel *parcel = CFCClass_get_parcel(self);
+                retval = S_cfcbase_to_perlref(parcel);
+            }
+            break;
     END_SET_OR_GET_SWITCH
 }
 


[2/8] git commit: Don't hardcode POD and man page headers

Posted by nw...@apache.org.
Don't hardcode POD and man page headers

Use the supplied autogen header and footer instead.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/19011e04
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/19011e04
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/19011e04

Branch: refs/heads/documentation
Commit: 19011e0496c63aea525e6b213be4c9bcfe524ffd
Parents: af31761
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 23 17:41:01 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:07 2014 +0200

----------------------------------------------------------------------
 compiler/src/CFCC.c         | 19 ++++++++++----
 compiler/src/CFCCClass.c    | 28 +++++---------------
 compiler/src/CFCPerl.c      | 14 ++++++++--
 compiler/src/CFCPerlClass.c | 55 ++++++++++++++--------------------------
 compiler/src/CFCUtil.c      | 10 ++++++++
 compiler/src/CFCUtil.h      | 10 ++++++++
 6 files changed, 72 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCC.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCC.c b/compiler/src/CFCC.c
index e0a355d..60a949b 100644
--- a/compiler/src/CFCC.c
+++ b/compiler/src/CFCC.c
@@ -32,6 +32,8 @@ struct CFCC {
     CFCHierarchy *hierarchy;
     char         *c_header;
     char         *c_footer;
+    char         *man_header;
+    char         *man_footer;
 };
 
 static const CFCMeta CFCC_META = {
@@ -52,9 +54,11 @@ CFCC_init(CFCC *self, CFCHierarchy *hierarchy, const char *header,
     CFCUTIL_NULL_CHECK(hierarchy);
     CFCUTIL_NULL_CHECK(header);
     CFCUTIL_NULL_CHECK(footer);
-    self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
-    self->c_header  = CFCUtil_make_c_comment(header);
-    self->c_footer  = CFCUtil_make_c_comment(footer);
+    self->hierarchy  = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
+    self->c_header   = CFCUtil_make_c_comment(header);
+    self->c_footer   = CFCUtil_make_c_comment(footer);
+    self->man_header = CFCUtil_make_troff_comment(header);
+    self->man_footer = CFCUtil_make_troff_comment(footer);
     return self;
 }
 
@@ -63,6 +67,8 @@ CFCC_destroy(CFCC *self) {
     CFCBase_decref((CFCBase*)self->hierarchy);
     FREEMEM(self->c_header);
     FREEMEM(self->c_footer);
+    FREEMEM(self->man_header);
+    FREEMEM(self->man_footer);
     CFCBase_destroy((CFCBase*)self);
 }
 
@@ -151,8 +157,10 @@ CFCC_write_man_pages(CFCC *self) {
         CFCClass *klass = ordered[i];
         if (CFCClass_included(klass)) { continue; }
 
-        char *man_page = man_pages[j++];
-        if (!man_page) { continue; }
+        char *raw_man_page = man_pages[j++];
+        if (!raw_man_page) { continue; }
+        char *man_page = CFCUtil_sprintf("%s%s%s", self->man_header,
+                                         raw_man_page, self->man_footer);
 
         const char *full_struct_sym = CFCClass_full_struct_sym(klass);
         char *filename = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.3", man3_path,
@@ -160,6 +168,7 @@ CFCC_write_man_pages(CFCC *self) {
         CFCUtil_write_if_changed(filename, man_page, strlen(man_page));
         FREEMEM(filename);
         FREEMEM(man_page);
+        FREEMEM(raw_man_page);
     }
 
     FREEMEM(man3_path);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCCClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCCClass.c b/compiler/src/CFCCClass.c
index b6def3b..8dfe9db 100644
--- a/compiler/src/CFCCClass.c
+++ b/compiler/src/CFCCClass.c
@@ -121,27 +121,13 @@ CFCCClass_create_man_page(CFCClass *klass) {
 
     // Put it all together.
     const char pattern[] =
-    ".\\\" Licensed to the Apache Software Foundation (ASF) under one or more\n"
-    ".\\\" contributor license agreements.  See the NOTICE file distributed with\n"
-    ".\\\" this work for additional information regarding copyright ownership.\n"
-    ".\\\" The ASF licenses this file to You under the Apache License, Version 2.0\n"
-    ".\\\" (the \"License\"); you may not use this file except in compliance with\n"
-    ".\\\" the License.  You may obtain a copy of the License at\n"
-    ".\\\"\n"
-    ".\\\"     http://www.apache.org/licenses/LICENSE-2.0\n"
-    ".\\\"\n"
-    ".\\\" Unless required by applicable law or agreed to in writing, software\n"
-    ".\\\" distributed under the License is distributed on an \"AS IS\" BASIS,\n"
-    ".\\\" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
-    ".\\\" See the License for the specific language governing permissions and\n"
-    ".\\\" limitations under the License.\n"
-    ".TH %s 3\n"
-    "%s"
-    "%s"
-    "%s"
-    "%s"
-    "%s"
-    "%s";
+        ".TH %s 3\n"
+        "%s"
+        "%s"
+        "%s"
+        "%s"
+        "%s"
+        "%s";
     char *man_page
         = CFCUtil_sprintf(pattern, class_name, name, synopsis, description,
                           functions_man, methods_man, inheritance);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index c78fcbf..a04bb61 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -43,6 +43,8 @@ struct CFCPerl {
     char *footer;
     char *c_header;
     char *c_footer;
+    char *pod_header;
+    char *pod_footer;
     char *xs_path;
     char *boot_func;
 };
@@ -82,6 +84,8 @@ CFCPerl_init(CFCPerl *self, CFCHierarchy *hierarchy, const char *lib_dir,
     self->footer     = CFCUtil_strdup(footer);
     self->c_header   = CFCUtil_make_c_comment(header);
     self->c_footer   = CFCUtil_make_c_comment(footer);
+    self->pod_header = CFCUtil_make_perl_comment(header);
+    self->pod_footer = CFCUtil_make_perl_comment(footer);
 
     // Derive path to generated .xs file.
     self->xs_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.xs", lib_dir,
@@ -108,6 +112,8 @@ CFCPerl_destroy(CFCPerl *self) {
     FREEMEM(self->footer);
     FREEMEM(self->c_header);
     FREEMEM(self->c_footer);
+    FREEMEM(self->pod_header);
+    FREEMEM(self->pod_footer);
     FREEMEM(self->xs_path);
     FREEMEM(self->boot_func);
     CFCBase_destroy((CFCBase*)self);
@@ -141,8 +147,10 @@ CFCPerl_write_pod(CFCPerl *self) {
     // generating pod, we leak memory but don't clutter up the file system.
     for (size_t i = 0; i < num_registered; i++) {
         const char *class_name = CFCPerlClass_get_class_name(registry[i]);
-        char *pod = CFCPerlClass_create_pod(registry[i]);
-        if (!pod) { continue; }
+        char *raw_pod = CFCPerlClass_create_pod(registry[i]);
+        if (!raw_pod) { continue; }
+        char *pod = CFCUtil_sprintf("%s\n%s%s", self->pod_header, raw_pod,
+                                    self->pod_footer);
         char *pod_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.pod",
                                          self->lib_dir, class_name);
         S_replace_double_colons(pod_path, CHY_DIR_SEP_CHAR);
@@ -150,6 +158,8 @@ CFCPerl_write_pod(CFCPerl *self) {
         pods[count] = pod;
         pod_paths[count] = pod_path;
         count++;
+
+        FREEMEM(raw_pod);
     }
 
     // Write out any POD files that have changed.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c
index 7c018de..a71de04 100644
--- a/compiler/src/CFCPerlClass.c
+++ b/compiler/src/CFCPerlClass.c
@@ -432,42 +432,25 @@ CFCPerlClass_create_pod(CFCPerlClass *self) {
     }
 
     // Put it all together.
-    const char pattern[] = 
-    "# Auto-generated file -- DO NOT EDIT!!!!!\n"
-    "\n"
-    "# Licensed to the Apache Software Foundation (ASF) under one or more\n"
-    "# contributor license agreements.  See the NOTICE file distributed with\n"
-    "# this work for additional information regarding copyright ownership.\n"
-    "# The ASF licenses this file to You under the Apache License, Version 2.0\n"
-    "# (the \"License\"); you may not use this file except in compliance with\n"
-    "# the License.  You may obtain a copy of the License at\n"
-    "#\n"
-    "#     http://www.apache.org/licenses/LICENSE-2.0\n"
-    "#\n"
-    "# Unless required by applicable law or agreed to in writing, software\n"
-    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n"
-    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
-    "# See the License for the specific language governing permissions and\n"
-    "# limitations under the License.\n"
-    "\n"
-    "=head1 NAME\n"
-    "\n"
-    "%s - %s\n"
-    "\n"
-    "%s\n"
-    "\n"
-    "=head1 DESCRIPTION\n"
-    "\n"
-    "%s\n"
-    "\n"
-    "%s\n"
-    "\n"
-    "%s\n"
-    "\n"
-    "%s\n"
-    "\n"
-    "=cut\n"
-    "\n";
+    const char pattern[] =
+        "=head1 NAME\n"
+        "\n"
+        "%s - %s\n"
+        "\n"
+        "%s\n"
+        "\n"
+        "=head1 DESCRIPTION\n"
+        "\n"
+        "%s\n"
+        "\n"
+        "%s\n"
+        "\n"
+        "%s\n"
+        "\n"
+        "%s\n"
+        "\n"
+        "=cut\n"
+        "\n";
     char *pod
         = CFCUtil_sprintf(pattern, class_name, brief, synopsis, description,
                           constructor_pod, methods_pod, inheritance);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCUtil.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.c b/compiler/src/CFCUtil.c
index 3b62408..b7e37b5 100644
--- a/compiler/src/CFCUtil.c
+++ b/compiler/src/CFCUtil.c
@@ -194,6 +194,16 @@ CFCUtil_make_c_comment(const char *text) {
     return CFCUtil_enclose_lines(text, " * ", "", "/*\n", " */\n");
 }
 
+char*
+CFCUtil_make_perl_comment(const char *text) {
+    return CFCUtil_enclose_lines(text, "# ", "", "", "");
+}
+
+char*
+CFCUtil_make_troff_comment(const char *text) {
+    return CFCUtil_enclose_lines(text, ".\\\" ", "", "", "");
+}
+
 void*
 CFCUtil_wrapped_malloc(size_t count, const char *file, int line) {
     void *pointer = malloc(count);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCUtil.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.h b/compiler/src/CFCUtil.h
index 6012b3d..6540672 100644
--- a/compiler/src/CFCUtil.h
+++ b/compiler/src/CFCUtil.h
@@ -82,6 +82,16 @@ CFCUtil_enclose_lines(const char *text, const char *line_prefix,
 char*
 CFCUtil_make_c_comment(const char *text);
 
+/** Create a Perl comment.
+ */
+char*
+CFCUtil_make_perl_comment(const char *text);
+
+/** Create a troff comment.
+ */
+char*
+CFCUtil_make_troff_comment(const char *text);
+
 /** Attempt to allocate memory with malloc, but print an error and exit if the
  * call fails.
  */


[4/8] git commit: Add function to write custom POD

Posted by nw...@apache.org.
Add function to write custom POD


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/9a4a2147
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/9a4a2147
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/9a4a2147

Branch: refs/heads/documentation
Commit: 9a4a2147f98b6d7634aefafa65cb19d1544c019e
Parents: 1a19ac4
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Aug 31 14:37:26 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:07 2014 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC.xs |  8 +++
 compiler/src/CFCPerl.c             | 87 ++++++++++++++++++++++++++++-----
 compiler/src/CFCPerl.h             |  5 ++
 3 files changed, 87 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9a4a2147/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index 38aa3fc..a306b68 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -2046,6 +2046,14 @@ CODE:
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
 
+void
+add_custom_pod(self, pod_name, pod)
+    CFCPerl    *self;
+    const char *pod_name;
+    const char *pod;
+PPCODE:
+    CFCPerl_add_custom_pod(self, pod_name, pod);
+
 SV*
 write_pod(self)
     CFCPerl *self;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9a4a2147/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index a04bb61..7e05fd8 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -37,16 +37,20 @@
 struct CFCPerl {
     CFCBase base;
     CFCHierarchy *hierarchy;
-    char *lib_dir;
-    char *boot_class;
-    char *header;
-    char *footer;
-    char *c_header;
-    char *c_footer;
-    char *pod_header;
-    char *pod_footer;
-    char *xs_path;
-    char *boot_func;
+    char    *lib_dir;
+    char    *boot_class;
+    char    *header;
+    char    *footer;
+    char    *c_header;
+    char    *c_footer;
+    char    *pod_header;
+    char    *pod_footer;
+    char    *xs_path;
+    char    *boot_func;
+    char   **custom_pod_names;
+    char   **custom_pods;
+    size_t   num_custom_pods;
+
 };
 
 // Modify a string in place, swapping out "::" for the supplied character.
@@ -100,6 +104,11 @@ CFCPerl_init(CFCPerl *self, CFCHierarchy *hierarchy, const char *lib_dir,
         }
     }
 
+    // Initialize custom PODs.
+    self->custom_pod_names = (char**)CALLOCATE(1, sizeof(char*));
+    self->custom_pods      = (char**)CALLOCATE(1, sizeof(char*));
+    self->num_custom_pods  = 0;
+
     return self;
 }
 
@@ -116,6 +125,14 @@ CFCPerl_destroy(CFCPerl *self) {
     FREEMEM(self->pod_footer);
     FREEMEM(self->xs_path);
     FREEMEM(self->boot_func);
+    for (size_t i = 0; self->custom_pod_names[i]; ++i) {
+        FREEMEM(self->custom_pod_names[i]);
+    }
+    FREEMEM(self->custom_pod_names);
+    for (size_t i = 0; self->custom_pods[i]; ++i) {
+        FREEMEM(self->custom_pods[i]);
+    }
+    FREEMEM(self->custom_pods);
     CFCBase_destroy((CFCBase*)self);
 }
 
@@ -134,14 +151,33 @@ S_replace_double_colons(char *text, char replacement) {
     text[pos] = '\0';
 }
 
+void
+CFCPerl_add_custom_pod(CFCPerl *self, const char *pod_name, const char *pod) {
+    size_t num_custom_pods = self->num_custom_pods;
+
+    size_t new_size = (num_custom_pods + 2) * sizeof(char*);
+    self->custom_pod_names = (char**)REALLOCATE(self->custom_pod_names,
+                                                new_size);
+    self->custom_pods      = (char**)REALLOCATE(self->custom_pods, new_size);
+
+    self->custom_pod_names[num_custom_pods]   = CFCUtil_strdup(pod_name);
+    self->custom_pods[num_custom_pods]        = CFCUtil_strdup(pod);
+    self->custom_pod_names[num_custom_pods+1] = NULL;
+    self->custom_pods[num_custom_pods+1]      = NULL;
+
+    self->num_custom_pods = num_custom_pods + 1;
+}
+
 char**
 CFCPerl_write_pod(CFCPerl *self) {
     CFCPerlClass **registry  = CFCPerlClass_registry();
     size_t num_registered = 0;
     while (registry[num_registered] != NULL) { num_registered++; }
-    char     **pod_paths = (char**)CALLOCATE(num_registered + 1, sizeof(char*));
-    char     **pods      = (char**)CALLOCATE(num_registered + 1, sizeof(char*));
-    size_t     count     = 0;
+
+    size_t   max_pods  = num_registered + self->num_custom_pods;
+    char   **pod_paths = (char**)CALLOCATE(max_pods + 1, sizeof(char*));
+    char   **pods      = (char**)CALLOCATE(max_pods + 1, sizeof(char*));
+    size_t   count     = 0;
 
     // Generate POD, but don't write.  That way, if there's an error while
     // generating pod, we leak memory but don't clutter up the file system.
@@ -162,11 +198,36 @@ CFCPerl_write_pod(CFCPerl *self) {
         FREEMEM(raw_pod);
     }
 
+    for (size_t i = 0; i < self->num_custom_pods; i++) {
+        char *pod = CFCUtil_sprintf("%s\n%s%s", self->pod_header,
+                                    self->custom_pods[i], self->pod_footer);
+        char *pod_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.pod",
+                                         self->lib_dir,
+                                         self->custom_pod_names[i]);
+        S_replace_double_colons(pod_path, CHY_DIR_SEP_CHAR);
+
+        pods[count] = pod;
+        pod_paths[count] = pod_path;
+        count++;
+    }
+
     // Write out any POD files that have changed.
     size_t num_written = 0;
     for (size_t i = 0; i < count; i++) {
         char *pod      = pods[i];
         char *pod_path = pod_paths[i];
+
+        // Create directory if it doesn't exist.
+        char *dir = CFCUtil_strdup(pod_path);
+        char *last_sep = strrchr(dir, CHY_DIR_SEP_CHAR);
+        if (last_sep) {
+            *last_sep = '\0';
+            if (!CFCUtil_is_dir(dir)) {
+                CFCUtil_make_path(dir);
+            }
+        }
+        FREEMEM(dir);
+
         if (CFCUtil_write_if_changed(pod_path, pod, strlen(pod))) {
             pod_paths[num_written] = pod_path;
             num_written++;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9a4a2147/compiler/src/CFCPerl.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.h b/compiler/src/CFCPerl.h
index eef10ac..9ed6b9f 100644
--- a/compiler/src/CFCPerl.h
+++ b/compiler/src/CFCPerl.h
@@ -78,6 +78,11 @@ CFCPerl_init(CFCPerl *self, struct CFCHierarchy *hierarchy,
 void
 CFCPerl_destroy(CFCPerl *self);
 
+/** Add a custom POD file.
+ */
+void
+CFCPerl_add_custom_pod(CFCPerl *self, const char *pod_name, const char *pod);
+
 /** Auto-generate POD for all class bindings where pod specs were created.
  * See whether a .pod file exists and is up-to-date; if not, write it out.
  * 


[8/8] git commit: Create Clownfish C API POD

Posted by nw...@apache.org.
Create Clownfish C API POD

Create documentation for all Clownfish classes for now.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/f50b736f
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/f50b736f
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/f50b736f

Branch: refs/heads/documentation
Commit: f50b736f9fd6caecc2ba475e345df650932c1b66
Parents: a3062c1
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Aug 31 15:20:48 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:33:06 2014 +0200

----------------------------------------------------------------------
 runtime/perl/buildlib/Clownfish/Build/Binding.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/f50b736f/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index 98c7f0d..9e33a85 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -20,7 +20,8 @@ our $VERSION = '0.004000';
 $VERSION = eval $VERSION;
 
 sub bind_all {
-    my $class = shift;
+    my ($class, $hierarchy, $binding) = @_;
+
     $class->bind_clownfish;
     $class->bind_test;
     $class->bind_test_alias_obj;
@@ -34,6 +35,14 @@ sub bind_all {
     $class->bind_varray;
     $class->bind_class;
     $class->bind_stringhelper;
+
+    for my $class (@{ $hierarchy->ordered_classes }) {
+        next if $class->get_parcel->get_name ne 'Clownfish';
+        my $c_api_pod = Clownfish::CFC::Binding::Perl::CPod->c_api_pod($class);
+        my $pod_name = $class->get_class_name;
+        $pod_name =~ s/^Clownfish::/Clownfish::Docs::C::/;
+        $binding->add_custom_pod($pod_name, $c_api_pod);
+    }
 }
 
 sub bind_clownfish {


[3/8] git commit: Automate creation of C comments from autogen headers

Posted by nw...@apache.org.
Automate creation of C comments from autogen headers


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/af31761e
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/af31761e
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/af31761e

Branch: refs/heads/documentation
Commit: af31761efeafb13dbf2559e88a3e3221d6b0247f
Parents: 3523d7d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 23 17:17:36 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:07 2014 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC/Perl/Build.pm |  9 ++--
 compiler/src/CFCBindCore.c                    | 32 +++++++-------
 compiler/src/CFCC.c                           | 18 ++++----
 compiler/src/CFCPerl.c                        | 24 +++++++----
 compiler/src/CFCRuby.c                        | 26 +++++------
 compiler/src/CFCUtil.c                        | 50 ++++++++++++++++++++++
 compiler/src/CFCUtil.h                        | 13 ++++++
 runtime/c/cfc_header                          | 37 ++++++++--------
 runtime/perl/buildlib/Clownfish/Build.pm      | 44 +++++++++----------
 runtime/ruby/Rakefile.common                  |  8 ++--
 10 files changed, 163 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
index 939ea9d..046fc0d 100644
--- a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+++ b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
@@ -97,14 +97,13 @@ sub new {
     my $autogen_header = $self->clownfish_params('autogen_header');
     if ( !defined($autogen_header) ) {
         $self->clownfish_params( autogen_header => <<'END_AUTOGEN' );
-/***********************************************
+***********************************************
 
- !!!! DO NOT EDIT !!!!
+!!!! DO NOT EDIT !!!!
 
- This file was auto-generated by Build.PL.
-
- ***********************************************/
+This file was auto-generated by Build.PL.
 
+***********************************************
 END_AUTOGEN
     }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index 774b1a3..679da04 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -36,8 +36,8 @@
 struct CFCBindCore {
     CFCBase base;
     CFCHierarchy *hierarchy;
-    char         *header;
-    char         *footer;
+    char         *c_header;
+    char         *c_footer;
 };
 
 /* Write the "parcel.h" header file, which contains common symbols needed by
@@ -92,24 +92,24 @@ CFCBindCore_init(CFCBindCore *self, CFCHierarchy *hierarchy,
     CFCUTIL_NULL_CHECK(header);
     CFCUTIL_NULL_CHECK(footer);
     self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
-    self->header    = CFCUtil_strdup(header);
-    self->footer    = CFCUtil_strdup(footer);
+    self->c_header  = CFCUtil_make_c_comment(header);
+    self->c_footer  = CFCUtil_make_c_comment(footer);
     return self;
 }
 
 void
 CFCBindCore_destroy(CFCBindCore *self) {
     CFCBase_decref((CFCBase*)self->hierarchy);
-    FREEMEM(self->header);
-    FREEMEM(self->footer);
+    FREEMEM(self->c_header);
+    FREEMEM(self->c_footer);
     CFCBase_destroy((CFCBase*)self);
 }
 
 int
 CFCBindCore_write_all_modified(CFCBindCore *self, int modified) {
     CFCHierarchy *hierarchy = self->hierarchy;
-    const char   *header    = self->header;
-    const char   *footer    = self->footer;
+    const char   *header    = self->c_header;
+    const char   *footer    = self->c_footer;
 
     // Discover whether files need to be regenerated.
     modified = CFCHierarchy_propagate_modified(hierarchy, modified);
@@ -330,10 +330,10 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
         "%s\n"
         "\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, PREFIX, PREFIX,
+        = CFCUtil_sprintf(pattern, self->c_header, PREFIX, PREFIX,
                           extra_includes, privacy_sym, PREFIX, PREFIX,
                           typedefs, extra_defs, PREFIX, prefix, PREFIX, prefix,
-                          prefix, PREFIX, self->footer);
+                          prefix, PREFIX, self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
@@ -467,10 +467,10 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
         "\n"
         "%s\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, privacy_syms, prefix,
+        = CFCUtil_sprintf(pattern, self->c_header, privacy_syms, prefix,
                           includes, c_data, class_specs, prefix, inh_bootstrap,
                           num_specs, prefix, prefix, prereq_bootstrap, prefix,
-                          self->footer);
+                          self->c_footer);
 
     // Unlink then open file.
     const char *src_dest = CFCHierarchy_get_source_dest(hierarchy);
@@ -539,8 +539,8 @@ CFCBindCore_write_callbacks_h(CFCBindCore *self) {
         "%s\n"
         "\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, includes, all_cb_decs,
-                          self->footer);
+        = CFCUtil_sprintf(pattern, self->c_header, includes, all_cb_decs,
+                          self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
@@ -592,9 +592,9 @@ S_write_platform_h(CFCBindCore *self) {
         "%s"
         "\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, feature_defs, string_defs,
+        = CFCUtil_sprintf(pattern, self->c_header, feature_defs, string_defs,
                           stdbool_defs, stdint_defs, alloca_defs,
-                          self->footer);
+                          self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/src/CFCC.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCC.c b/compiler/src/CFCC.c
index 3f21a0d..e0a355d 100644
--- a/compiler/src/CFCC.c
+++ b/compiler/src/CFCC.c
@@ -30,8 +30,8 @@
 struct CFCC {
     CFCBase base;
     CFCHierarchy *hierarchy;
-    char         *header;
-    char         *footer;
+    char         *c_header;
+    char         *c_footer;
 };
 
 static const CFCMeta CFCC_META = {
@@ -53,16 +53,16 @@ CFCC_init(CFCC *self, CFCHierarchy *hierarchy, const char *header,
     CFCUTIL_NULL_CHECK(header);
     CFCUTIL_NULL_CHECK(footer);
     self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
-    self->header    = CFCUtil_strdup(header);
-    self->footer    = CFCUtil_strdup(footer);
+    self->c_header  = CFCUtil_make_c_comment(header);
+    self->c_footer  = CFCUtil_make_c_comment(footer);
     return self;
 }
 
 void
 CFCC_destroy(CFCC *self) {
     CFCBase_decref((CFCBase*)self->hierarchy);
-    FREEMEM(self->header);
-    FREEMEM(self->footer);
+    FREEMEM(self->c_header);
+    FREEMEM(self->c_footer);
     CFCBase_destroy((CFCBase*)self);
 }
 
@@ -99,8 +99,8 @@ CFCC_write_callbacks(CFCC *self) {
         "\n"
         "%s\n"
         "\n";
-    char *file_content = CFCUtil_sprintf(pattern, self->header, all_cb_decs,
-                                         self->footer);
+    char *file_content = CFCUtil_sprintf(pattern, self->c_header, all_cb_decs,
+                                         self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
@@ -182,7 +182,7 @@ CFCC_write_hostdefs(CFCC *self) {
         "\n"
         "%s\n";
     char *content
-        = CFCUtil_sprintf(pattern, self->header, self->footer);
+        = CFCUtil_sprintf(pattern, self->c_header, self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index 41fce09..c78fcbf 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -41,6 +41,8 @@ struct CFCPerl {
     char *boot_class;
     char *header;
     char *footer;
+    char *c_header;
+    char *c_footer;
     char *xs_path;
     char *boot_func;
 };
@@ -78,6 +80,8 @@ CFCPerl_init(CFCPerl *self, CFCHierarchy *hierarchy, const char *lib_dir,
     self->boot_class = CFCUtil_strdup(boot_class);
     self->header     = CFCUtil_strdup(header);
     self->footer     = CFCUtil_strdup(footer);
+    self->c_header   = CFCUtil_make_c_comment(header);
+    self->c_footer   = CFCUtil_make_c_comment(footer);
 
     // Derive path to generated .xs file.
     self->xs_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.xs", lib_dir,
@@ -102,6 +106,8 @@ CFCPerl_destroy(CFCPerl *self) {
     FREEMEM(self->boot_class);
     FREEMEM(self->header);
     FREEMEM(self->footer);
+    FREEMEM(self->c_header);
+    FREEMEM(self->c_footer);
     FREEMEM(self->xs_path);
     FREEMEM(self->boot_func);
     CFCBase_destroy((CFCBase*)self);
@@ -196,8 +202,8 @@ S_write_boot_h(CFCPerl *self) {
         "\n"
         "%s\n";
     char *content
-        = CFCUtil_sprintf(pattern, self->header, guard, guard, self->boot_func,
-                          guard, self->footer);
+        = CFCUtil_sprintf(pattern, self->c_header, guard, guard,
+                          self->boot_func, guard, self->c_footer);
 
     const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy);
     char *boot_h_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "boot.h", inc_dest);
@@ -303,9 +309,9 @@ S_write_boot_c(CFCPerl *self) {
         "%s\n"
         "\n";
     char *content
-        = CFCUtil_sprintf(pattern, self->header, pound_includes,
+        = CFCUtil_sprintf(pattern, self->c_header, pound_includes,
                           self->boot_func, bootstrap_code, alias_adds,
-                          isa_pushes, self->footer);
+                          isa_pushes, self->c_footer);
 
     const char *src_dest = CFCHierarchy_get_source_dest(self->hierarchy);
     char *boot_c_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "boot.c", src_dest);
@@ -341,7 +347,7 @@ CFCPerl_write_hostdefs(CFCPerl *self) {
         "\n"
         "%s\n";
     char *content
-        = CFCUtil_sprintf(pattern, self->header, self->footer);
+        = CFCUtil_sprintf(pattern, self->c_header, self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy);
@@ -381,9 +387,9 @@ S_xs_file_contents(CFCPerl *self, const char *generated_xs,
         "\n"
         "%s";
     char *contents
-        = CFCUtil_sprintf(pattern, self->header, generated_xs,
+        = CFCUtil_sprintf(pattern, self->c_header, generated_xs,
                           self->boot_class, self->boot_class, self->boot_func,
-                          xs_init, hand_rolled_xs, self->footer);
+                          xs_init, hand_rolled_xs, self->c_footer);
 
     return contents;
 }
@@ -577,7 +583,7 @@ S_write_callbacks_c(CFCPerl *self) {
         "    return retval;\n"
         "}\n"
         "\n";
-    char *content = CFCUtil_sprintf(pattern, self->header);
+    char *content = CFCUtil_sprintf(pattern, self->c_header);
 
     for (size_t i = 0; ordered[i] != NULL; i++) {
         CFCClass *klass = ordered[i];
@@ -597,7 +603,7 @@ S_write_callbacks_c(CFCPerl *self) {
         FREEMEM(fresh_methods);
     }
 
-    content = CFCUtil_cat(content, self->footer, NULL);
+    content = CFCUtil_cat(content, self->c_footer, NULL);
 
     // Write if changed.
     const char *src_dest = CFCHierarchy_get_source_dest(self->hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/src/CFCRuby.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCRuby.c b/compiler/src/CFCRuby.c
index c185218..ec3dd9a 100644
--- a/compiler/src/CFCRuby.c
+++ b/compiler/src/CFCRuby.c
@@ -33,8 +33,8 @@ struct CFCRuby {
     CFCHierarchy *hierarchy;
     char *lib_dir;
     char *boot_class;
-    char *header;
-    char *footer;
+    char *c_header;
+    char *c_footer;
     char *boot_h_file;
     char *boot_c_file;
     char *boot_h_path;
@@ -74,8 +74,8 @@ CFCRuby_init(CFCRuby *self, CFCParcel *parcel, CFCHierarchy *hierarchy,
     self->hierarchy  = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
     self->lib_dir    = CFCUtil_strdup(lib_dir);
     self->boot_class = CFCUtil_strdup(boot_class);
-    self->header     = CFCUtil_strdup(header);
-    self->footer     = CFCUtil_strdup(footer);
+    self->c_header   = CFCUtil_make_c_comment(header);
+    self->c_footer   = CFCUtil_make_c_comment(footer);
 
     const char *prefix   = CFCParcel_get_prefix(parcel);
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
@@ -103,8 +103,8 @@ CFCRuby_destroy(CFCRuby *self) {
     CFCBase_decref((CFCBase*)self->hierarchy);
     FREEMEM(self->lib_dir);
     FREEMEM(self->boot_class);
-    FREEMEM(self->header);
-    FREEMEM(self->footer);
+    FREEMEM(self->c_header);
+    FREEMEM(self->c_footer);
     FREEMEM(self->boot_h_file);
     FREEMEM(self->boot_c_file);
     FREEMEM(self->boot_h_path);
@@ -153,16 +153,16 @@ S_write_boot_h(CFCRuby *self) {
         "%s\n";
 
     size_t size = sizeof(pattern)
-                  + strlen(self->header)
+                  + strlen(self->c_header)
                   + strlen(guard)
                   + strlen(guard)
                   + strlen(self->boot_func)
                   + strlen(guard)
-                  + strlen(self->footer)
+                  + strlen(self->c_footer)
                   + 20;
     char *content = (char*)MALLOCATE(size);
-    sprintf(content, pattern, self->header, guard, guard, self->boot_func,
-            guard, self->footer);
+    sprintf(content, pattern, self->c_header, guard, guard, self->boot_func,
+            guard, self->c_footer);
     CFCUtil_write_file(self->boot_h_path, content, strlen(content));
 
     FREEMEM(content);
@@ -212,9 +212,9 @@ S_write_boot_c(CFCRuby *self) {
         "\n";
 
     char *content
-        = CFCUtil_sprintf(pattern, self->header, self->boot_h_file, prefix,
+        = CFCUtil_sprintf(pattern, self->c_header, self->boot_h_file, prefix,
                           pound_includes, self->boot_func, prefix,
-                          self->footer);
+                          self->c_footer);
     CFCUtil_write_file(self->boot_c_path, content, strlen(content));
 
     FREEMEM(content);
@@ -249,7 +249,7 @@ CFCRuby_write_hostdefs(CFCRuby *self) {
         "\n"
         "%s\n";
     char *content
-        = CFCUtil_sprintf(pattern, self->header, self->footer);
+        = CFCUtil_sprintf(pattern, self->c_header, self->c_footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/src/CFCUtil.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.c b/compiler/src/CFCUtil.c
index fdcfe7a..3b62408 100644
--- a/compiler/src/CFCUtil.c
+++ b/compiler/src/CFCUtil.c
@@ -144,6 +144,56 @@ CFCUtil_trim_whitespace(char *text) {
     *text = '\0';
 }
 
+char*
+CFCUtil_enclose_lines(const char *text, const char *line_prefix,
+                      const char *line_postfix, const char *prefix,
+                      const char *postfix) {
+    if (!text) { return NULL; }
+
+    if (!line_prefix)  { line_prefix  = ""; }
+    if (!line_postfix) { line_postfix = ""; }
+    if (!prefix)       { prefix       = ""; }
+    if (!postfix)      { postfix      = ""; }
+
+    char *result = CFCUtil_strdup(prefix);
+
+    const char *line_start = text;
+    const char *text_end   = text + strlen(text);
+
+    while (line_start < text_end) {
+        const char *line_end = strchr(line_start, '\n');
+        const char *next_start;
+        size_t      line_len;
+
+        if (line_end == NULL) {
+            line_len   = text_end - line_start;
+            next_start = text_end;
+        }
+        else {
+            line_len   = line_end - line_start;
+            next_start = line_end + 1;
+        }
+
+        char *line = (char*)MALLOCATE(line_len + 1);
+        memcpy(line, line_start, line_len);
+        line[line_len] = '\0';
+        result = CFCUtil_cat(result, line_prefix, line, line_postfix, "\n",
+                             NULL);
+        FREEMEM(line);
+
+        line_start = next_start;
+    }
+
+    result = CFCUtil_cat(result, postfix, NULL);
+
+    return result;
+}
+
+char*
+CFCUtil_make_c_comment(const char *text) {
+    return CFCUtil_enclose_lines(text, " * ", "", "/*\n", " */\n");
+}
+
 void*
 CFCUtil_wrapped_malloc(size_t count, const char *file, int line) {
     void *pointer = malloc(count);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/compiler/src/CFCUtil.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.h b/compiler/src/CFCUtil.h
index 961bccf..6012b3d 100644
--- a/compiler/src/CFCUtil.h
+++ b/compiler/src/CFCUtil.h
@@ -69,6 +69,19 @@ CFCUtil_cat(char *string, ...);
 void
 CFCUtil_trim_whitespace(char *text);
 
+/** Enclose every line in text with line_prefix and line_postfix and the
+ * whole text with prefix and postfix.
+ */
+char*
+CFCUtil_enclose_lines(const char *text, const char *line_prefix,
+                      const char *line_postfix, const char *prefix,
+                      const char *postfix);
+
+/** Create a C comment.
+ */
+char*
+CFCUtil_make_c_comment(const char *text);
+
 /** Attempt to allocate memory with malloc, but print an error and exit if the
  * call fails.
  */

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/runtime/c/cfc_header
----------------------------------------------------------------------
diff --git a/runtime/c/cfc_header b/runtime/c/cfc_header
index d982cf9..f2fff7c 100644
--- a/runtime/c/cfc_header
+++ b/runtime/c/cfc_header
@@ -1,23 +1,22 @@
-/***********************************************
+***********************************************
 
- !!!! DO NOT EDIT !!!!
+!!!! DO NOT EDIT !!!!
 
- This file was auto-generated by cfc.
+This file was auto-generated by cfc.
 
- ***********************************************/
+***********************************************
 
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/runtime/perl/buildlib/Clownfish/Build.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build.pm b/runtime/perl/buildlib/Clownfish/Build.pm
index 0b7da01..b0743e2 100644
--- a/runtime/perl/buildlib/Clownfish/Build.pm
+++ b/runtime/perl/buildlib/Clownfish/Build.pm
@@ -246,30 +246,28 @@ sub ACTION_test_valgrind {
 
 sub _autogen_header {
     return <<"END_AUTOGEN";
-/***********************************************
-
- !!!! DO NOT EDIT !!!!
-
- This file was auto-generated by Build.PL.
-
- ***********************************************/
-
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+***********************************************
 
+!!!! DO NOT EDIT !!!!
+
+This file was auto-generated by Build.PL.
+
+***********************************************
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
 END_AUTOGEN
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/af31761e/runtime/ruby/Rakefile.common
----------------------------------------------------------------------
diff --git a/runtime/ruby/Rakefile.common b/runtime/ruby/Rakefile.common
index cca6c09..3e61582 100644
--- a/runtime/ruby/Rakefile.common
+++ b/runtime/ruby/Rakefile.common
@@ -136,13 +136,13 @@ end
 
 def autogen_header
   "
-/***********************************************
+***********************************************
 
- !!!! DO NOT EDIT !!!!
+!!!! DO NOT EDIT !!!!
 
- This file was auto-generated by Rakefile.
+This file was auto-generated by Rakefile.
 
- ***********************************************/
+***********************************************
  "
 
 end


[7/8] git commit: Pass Binding::Perl object to bind_all

Posted by nw...@apache.org.
Pass Binding::Perl object to bind_all


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/a3062c1c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/a3062c1c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/a3062c1c

Branch: refs/heads/documentation
Commit: a3062c1ca4307fc2629a79ea0ffd938b92debcd0
Parents: 898e6c1
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Aug 31 14:42:05 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:22 2014 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC/Perl/Build.pm | 23 +++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a3062c1c/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
index 046fc0d..e7ca4e1 100644
--- a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+++ b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
@@ -221,6 +221,14 @@ sub _compile_clownfish {
     }
     $hierarchy->build;
 
+    my $binding = Clownfish::CFC::Binding::Perl->new(
+        hierarchy  => $hierarchy,
+        lib_dir    => $LIB_DIR,
+        boot_class => $self->module_name,
+        header     => $self->clownfish_params('autogen_header'),
+        footer     => '',
+    );
+
     # Process all Binding classes in buildlib.
     my $pm_filepaths = $self->rscan_dir( $BUILDLIB_DIR, qr/\.pm$/ );
     for my $pm_filepath (@$pm_filepaths) {
@@ -229,17 +237,9 @@ sub _compile_clownfish {
         my $package_name = $pm_filepath;
         $package_name =~ s/buildlib\/(.*)\.pm$/$1/;
         $package_name =~ s/\//::/g;
-        $package_name->bind_all($hierarchy);
+        $package_name->bind_all($hierarchy, $binding);
     }
 
-    my $binding = Clownfish::CFC::Binding::Perl->new(
-        hierarchy  => $hierarchy,
-        lib_dir    => $LIB_DIR,
-        boot_class => $self->module_name,
-        header     => $self->clownfish_params('autogen_header'),
-        footer     => '',
-    );
-
     return ( $hierarchy, $binding );
 }
 
@@ -601,7 +601,8 @@ Clownfish::CFC::Perl::Build defines the following build actions.
 Build the whole project. The C<code> action searches the C<buildlib>
 directory for .pm files whose path contains the string C<Binding>. For each
 module found, the class method C<bind_all> will be called with a
-L<Clownfish::CFC::Model::Hierarchy> object as argument. This method
+L<Clownfish::CFC::Model::Hierarchy> object and a
+L<Clownfish::CFC::Binding::Perl> object as arguments. This method
 should register all the L<Clownfish::CFC::Binding::Perl::Class> objects
 for which bindings should be generated.
 
@@ -610,7 +611,7 @@ For example, the file C<buildlib/My/Module/Binding.pm> could look like:
     package My::Module::Binding;
 
     sub bind_all {
-        my ($class, $hierarchy) = @_;
+        my ($class, $hierarchy, $perl_binding) = @_;
 
         my $binding = Clownfish::CFC::Binding::Perl::Class->new(
             parcel     => 'MyModule',


[5/8] git commit: Add functions to create C API POD

Posted by nw...@apache.org.
Add functions to create C API POD


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/1a19ac4d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/1a19ac4d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/1a19ac4d

Branch: refs/heads/documentation
Commit: 1a19ac4de9824b7b8a81a3fdefd4a0556da31b3c
Parents: 19011e0
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Aug 31 14:36:30 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:07 2014 +0200

----------------------------------------------------------------------
 compiler/include/CFC.h             |   1 +
 compiler/perl/lib/Clownfish/CFC.xs |  11 ++
 compiler/src/CFCPerlCPod.c         | 275 ++++++++++++++++++++++++++++++++
 compiler/src/CFCPerlCPod.h         |  36 +++++
 4 files changed, 323 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1a19ac4d/compiler/include/CFC.h
----------------------------------------------------------------------
diff --git a/compiler/include/CFC.h b/compiler/include/CFC.h
index 9a13607..996e2d3 100644
--- a/compiler/include/CFC.h
+++ b/compiler/include/CFC.h
@@ -47,6 +47,7 @@
 #include "CFCPerlClass.h"
 #include "CFCPerlConstructor.h"
 #include "CFCPerlPod.h"
+#include "CFCPerlCPod.h"
 #include "CFCPerlTypeMap.h"
 
 #include "CFCRuby.h"

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1a19ac4d/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index a6ea249..38aa3fc 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -2487,6 +2487,17 @@ CODE:
 OUTPUT: RETVAL
 
 
+MODULE = Clownfish   PACKAGE = Clownfish::CFC::Binding::Perl::CPod
+
+SV*
+c_api_pod(unused, klass)
+    SV       *unused;
+    CFCClass *klass;
+CODE:
+    RETVAL = S_sv_eat_c_string(CFCPerlCPod_c_api_pod(klass));
+OUTPUT: RETVAL
+
+
 MODULE = Clownfish   PACKAGE = Clownfish::CFC::Binding::Perl::TypeMap
 
 SV*

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1a19ac4d/compiler/src/CFCPerlCPod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlCPod.c b/compiler/src/CFCPerlCPod.c
new file mode 100644
index 0000000..b58fa2f
--- /dev/null
+++ b/compiler/src/CFCPerlCPod.c
@@ -0,0 +1,275 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+#include "CFCPerlCPod.h"
+
+#include "CFCClass.h"
+#include "CFCDocuComment.h"
+#include "CFCFunction.h"
+#include "CFCMethod.h"
+#include "CFCParamList.h"
+#include "CFCType.h"
+#include "CFCUtil.h"
+#include "CFCVariable.h"
+
+static char*
+S_name_pod(CFCClass *klass);
+
+static char*
+S_description_pod(CFCClass *klass);
+
+static char*
+S_functions_pod(CFCClass *klass);
+
+static char*
+S_methods_pod(CFCClass *klass);
+
+static char*
+S_function_pod(CFCClass *klass, CFCFunction *func, const char *short_sym,
+                 const char *full_sym);
+
+static char*
+S_param_list_pod(CFCFunction *func);
+
+char*
+CFCPerlCPod_c_api_pod(CFCClass *klass) {
+    const char *full_struct_sym = CFCClass_full_struct_sym(klass);
+    char       *name_pod        = S_name_pod(klass);
+    char       *description_pod = S_description_pod(klass);
+    char       *functions_pod   = S_functions_pod(klass);
+    char       *methods_pod     = S_methods_pod(klass);
+
+    const char pattern[] =
+        "%s"
+        "%s"
+        "%s"
+        "%s";
+    char *result
+        = CFCUtil_sprintf(pattern, name_pod, description_pod, functions_pod,
+                          methods_pod);
+
+    FREEMEM(methods_pod);
+    return result;
+}
+
+static char*
+S_name_pod(CFCClass *klass) {
+    char *result = CFCUtil_sprintf("=head1 NAME\n\n%s",
+                                   CFCClass_get_class_name(klass));
+
+    CFCDocuComment *docucom = CFCClass_get_docucomment(klass);
+    if (docucom) {
+        const char *brief = CFCDocuComment_get_brief(docucom);
+        if (brief && brief[0] != '\0') {
+            result = CFCUtil_cat(result, " - ", brief, NULL);
+        }
+    }
+
+    result = CFCUtil_cat(result, "\n\n", NULL);
+
+    return result;
+}
+
+static char*
+S_description_pod(CFCClass *klass) {
+    char *result  = CFCUtil_strdup("");
+
+    CFCDocuComment *docucom = CFCClass_get_docucomment(klass);
+    if (!docucom) { return result; }
+
+    const char *description = CFCDocuComment_get_long(docucom);
+    if (description && description[0] != '\0') {
+        result = CFCUtil_cat(result, "=head1 DESCRIPTION\n\n", description,
+                             "\n\n", NULL);
+    }
+
+    return result;
+}
+
+static char*
+S_functions_pod(CFCClass *klass) {
+    CFCFunction **functions = CFCClass_functions(klass);
+    char         *result    = CFCUtil_strdup("");
+
+    for (int func_num = 0; functions[func_num] != NULL; func_num++) {
+        CFCFunction *func = functions[func_num];
+
+        if (result[0] == '\0') {
+            result = CFCUtil_cat(result, "=head1 FUNCTIONS\n\n", NULL);
+        }
+
+        const char *micro_sym     = CFCFunction_micro_sym(func);
+        const char *full_func_sym = CFCFunction_full_func_sym(func);
+
+        char *function_pod = S_function_pod(klass, func, micro_sym,
+                                              full_func_sym);
+        result = CFCUtil_cat(result, function_pod, NULL);
+        FREEMEM(function_pod);
+    }
+
+    return result;
+}
+
+static char*
+S_methods_pod(CFCClass *klass) {
+    CFCMethod **fresh_methods = CFCClass_fresh_methods(klass);
+    char       *abstract_pod  = CFCUtil_strdup("");
+    char       *novel_pod     = CFCUtil_strdup("");
+
+    for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) {
+        CFCMethod *method = fresh_methods[meth_num];
+        if (!CFCMethod_novel(method)) {
+            continue;
+        }
+
+        const char *macro_sym = CFCMethod_get_macro_sym(method);
+        char *full_method_sym = CFCMethod_full_method_sym(method, NULL);
+        char *method_pod = S_function_pod(klass, (CFCFunction*)method,
+                                            macro_sym, full_method_sym);
+
+        if (CFCMethod_abstract(method)) {
+            if (abstract_pod[0] == '\0') {
+                abstract_pod
+                    = CFCUtil_cat(abstract_pod, "=head1 ABSTRACT METHODS\n\n",
+                                  NULL);
+            }
+            abstract_pod = CFCUtil_cat(abstract_pod, method_pod, NULL);
+        }
+        else {
+            if (novel_pod[0] == '\0') {
+                novel_pod
+                    = CFCUtil_cat(novel_pod, "=head1 NOVEL METHODS\n\n", NULL);
+            }
+            novel_pod = CFCUtil_cat(novel_pod, method_pod, NULL);
+        }
+
+        FREEMEM(method_pod);
+        FREEMEM(full_method_sym);
+    }
+
+    char *result = CFCUtil_sprintf("%s%s", abstract_pod, novel_pod);
+
+    FREEMEM(abstract_pod);
+    FREEMEM(novel_pod);
+    FREEMEM(fresh_methods);
+    return result;
+}
+
+static char*
+S_function_pod(CFCClass *klass, CFCFunction *func, const char *short_sym,
+                 const char *full_sym) {
+    CFCType    *return_type   = CFCFunction_get_return_type(func);
+    const char *return_type_c = CFCType_to_c(return_type);
+    const char *incremented   = "";
+
+    if (CFCType_incremented(return_type)) {
+        incremented = " // incremented";
+    }
+
+    char *param_list = S_param_list_pod(func);
+
+    const char *pattern =
+        "=head2 %s\n"
+        "\n"
+        "    %s%s\n"
+        "    %s%s;\n\n";
+    char *result = CFCUtil_sprintf(pattern, short_sym, return_type_c,
+                                   incremented, full_sym, param_list);
+
+    FREEMEM(param_list);
+
+    // Get documentation, which may be inherited.
+    CFCDocuComment *docucomment = CFCFunction_get_docucomment(func);
+    if (!docucomment) {
+        const char *micro_sym = CFCFunction_micro_sym(func);
+        CFCClass *parent = klass;
+        while (NULL != (parent = CFCClass_get_parent(parent))) {
+            CFCFunction *parent_func
+                = (CFCFunction*)CFCClass_method(parent, micro_sym);
+            if (!parent_func) { break; }
+            docucomment = CFCFunction_get_docucomment(parent_func);
+            if (docucomment) { break; }
+        }
+    }
+
+    if (docucomment) {
+        // Description
+        const char *desc = CFCDocuComment_get_description(docucomment);
+        if (desc && desc[0] != '\0') {
+            result = CFCUtil_cat(result, desc, "\n\n", NULL);
+        }
+
+        // Params
+        const char **param_names
+            = CFCDocuComment_get_param_names(docucomment);
+        const char **param_docs
+            = CFCDocuComment_get_param_docs(docucomment);
+        if (param_names[0]) {
+            result = CFCUtil_cat(result, "=over\n\n", NULL);
+            for (size_t i = 0; param_names[i] != NULL; i++) {
+                result = CFCUtil_cat(result, "=item *\n\nB<", param_names[i],
+                                     "> - ", param_docs[i], "\n\n", NULL);
+            }
+            result = CFCUtil_cat(result, "=back\n\n", NULL);
+        }
+
+        // Return value
+        const char *retval_doc = CFCDocuComment_get_retval(docucomment);
+        if (retval_doc && strlen(retval_doc)) {
+            result = CFCUtil_cat(result, "Returns: ", retval_doc, "\n\n",
+                                 NULL);
+        }
+    }
+
+    return result;
+}
+
+static char*
+S_param_list_pod(CFCFunction *func) {
+    CFCParamList  *param_list = CFCFunction_get_param_list(func);
+    CFCVariable  **variables  = CFCParamList_get_variables(param_list);
+
+    if (!variables[0]) {
+        return CFCUtil_strdup("(void);\n");
+    }
+
+    char *result = CFCUtil_strdup("(");
+
+    for (int i = 0; variables[i]; ++i) {
+        CFCVariable *variable = variables[i];
+        CFCType     *type     = CFCVariable_get_type(variable);
+        const char  *type_c   = CFCType_to_c(type);
+        const char  *name     = CFCVariable_micro_sym(variable);
+
+        result = CFCUtil_cat(result, "\n        ", type_c, " ", name,
+                             NULL);
+
+        if (variables[i+1]) {
+            result = CFCUtil_cat(result, ",", NULL);
+        }
+        if (CFCType_decremented(type)) {
+            result = CFCUtil_cat(result, " // decremented", NULL);
+        }
+    }
+
+    result = CFCUtil_cat(result, "\n    )", NULL);
+
+    return result;
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1a19ac4d/compiler/src/CFCPerlCPod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlCPod.h b/compiler/src/CFCPerlCPod.h
new file mode 100644
index 0000000..b687167
--- /dev/null
+++ b/compiler/src/CFCPerlCPod.h
@@ -0,0 +1,36 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_CFCPERLCPOD
+#define H_CFCPERLCPOD
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct CFCClass;
+
+/** Create POD for the C API of a class.
+ */
+char*
+CFCPerlCPod_c_api_pod(struct CFCClass *klass);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCPERL */
+