lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [07/15] git commit: refs/heads/install-c-library - Move stdint typedefs from charmony.h to parcel.h
Date Sat, 18 May 2013 19:23:52 GMT
Move stdint typedefs from charmony.h to parcel.h

Change ConfWriterC to move global macro definitions, global typedefs,
and system includes into special sections that can be enabled by
defining macros of the form CHY_EMPLOY_MODULE.

Disable the stdint typedefs in Lucy's charmony.h and move them to
parcel.h.


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

Branch: refs/heads/install-c-library
Commit: cf630fcf94cd90392b465efa63bf0280de255be8
Parents: 92dbd8a
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat May 18 04:22:14 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat May 18 19:09:54 2013 +0200

----------------------------------------------------------------------
 charmonizer/src/Charmonizer/Core/ConfWriterC.c |   86 +++++++++++++-----
 charmonizer/src/Charmonizer/Probe/Booleans.c   |    2 +-
 clownfish/compiler/common/charmonizer.main     |    6 ++
 clownfish/compiler/src/CFCBindCore.c           |   87 ++++++++++++++++++-
 common/charmonizer.main                        |    7 ++
 devel/bin/regen_charmonizer.pl                 |    5 +-
 6 files changed, 166 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/cf630fcf/charmonizer/src/Charmonizer/Core/ConfWriterC.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Core/ConfWriterC.c b/charmonizer/src/Charmonizer/Core/ConfWriterC.c
index 132a4e4..d50f779 100644
--- a/charmonizer/src/Charmonizer/Core/ConfWriterC.c
+++ b/charmonizer/src/Charmonizer/Core/ConfWriterC.c
@@ -44,6 +44,7 @@ typedef struct chaz_ConfElem {
 /* Static vars. */
 static struct {
     FILE          *fh;
+    char          *MODULE_NAME;
     chaz_ConfElem *defs;
     size_t         def_cap;
     size_t         def_count;
@@ -141,18 +142,17 @@ chaz_ConfWriterC_vappend_conf(const char *fmt, va_list args) {
 
 static int
 chaz_ConfWriterC_sym_is_uppercase(const char *sym) {
-    unsigned i;
-    for (i = 0; sym[i] != 0; i++) {
-        if (!isupper(sym[i])) {
-            if (islower(sym[i])) {
-                return false;
-            }
-            else if (sym[i] != '_') {
-                return true;
-            }
-        }
+    return isupper(sym[0]);
+}
+
+static char*
+chaz_ConfWriterC_uppercase_string(const char *src) {
+    char *retval = chaz_Util_strdup(src);
+    size_t i;
+    for (i = 0; retval[i]; ++i) {
+        retval[i] = toupper(retval[i]);
     }
-    return true;
+    return retval;
 }
 
 static void
@@ -187,9 +187,10 @@ chaz_ConfWriterC_add_global_def(const char *sym, const char *value) {
 
 static void
 chaz_ConfWriterC_append_global_def_to_conf(const char *sym,
-        const char *value) {
+                                           const char *value) {
     char *name_end = strchr(sym, '(');
     if (name_end == NULL) {
+        if (strcmp(sym, value) == 0) { return; }
         fprintf(chaz_ConfWriterC.fh, "#ifndef %s\n", sym);
     }
     else {
@@ -231,7 +232,8 @@ chaz_ConfWriterC_add_global_typedef(const char *type, const char *alias)
{
 
 static void
 chaz_ConfWriterC_append_global_typedef_to_conf(const char *type,
-        const char *alias) {
+                                               const char *alias) {
+    if (strcmp(type, alias) == 0) { return; }
     fprintf(chaz_ConfWriterC.fh, "typedef %s %s;\n", type, alias);
 }
 
@@ -260,32 +262,37 @@ chaz_ConfWriterC_append_local_include_to_conf(const char *header) {
 static void
 chaz_ConfWriterC_start_module(const char *module_name) {
     fprintf(chaz_ConfWriterC.fh, "\n/* %s */\n", module_name);
+    chaz_ConfWriterC.MODULE_NAME
+        = chaz_ConfWriterC_uppercase_string(module_name);
 }
 
 static void
 chaz_ConfWriterC_end_module(void) {
+    size_t num_globals = 0;
     size_t i;
     chaz_ConfElem *defs = chaz_ConfWriterC.defs;
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
+            case CHAZ_CONFELEM_GLOBAL_DEF:
+                ++num_globals;
+            /* fall through */
             case CHAZ_CONFELEM_DEF:
                 chaz_ConfWriterC_append_def_to_conf(defs[i].str1,
                                                     defs[i].str2);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_DEF:
-                chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
-                                                           defs[i].str2);
-                break;
+            case CHAZ_CONFELEM_GLOBAL_TYPEDEF: {
+                ++num_globals;
+                char *sym = chaz_ConfWriterC_uppercase_string(defs[i].str1);
+                chaz_ConfWriterC_append_def_to_conf(sym, defs[i].str2);
+                free(sym);
+            }
+            /* fall through */
             case CHAZ_CONFELEM_TYPEDEF:
                 chaz_ConfWriterC_append_typedef_to_conf(defs[i].str2,
                                                         defs[i].str1);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
-                chaz_ConfWriterC_append_global_typedef_to_conf(defs[i].str2,
-                                                               defs[i].str1);
-                break;
             case CHAZ_CONFELEM_SYS_INCLUDE:
-                chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                ++num_globals;
                 break;
             case CHAZ_CONFELEM_LOCAL_INCLUDE:
                 chaz_ConfWriterC_append_local_include_to_conf(defs[i].str1);
@@ -303,7 +310,7 @@ chaz_ConfWriterC_end_module(void) {
     );
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
-            case CHAZ_CONFELEM_DEF: 
+            case CHAZ_CONFELEM_DEF:
             case CHAZ_CONFELEM_TYPEDEF:
                 {
                     const char *sym = defs[i].str1;
@@ -330,8 +337,41 @@ chaz_ConfWriterC_end_module(void) {
     }
 
     fprintf(chaz_ConfWriterC.fh, "#endif /* USE_SHORT_NAMES */\n");
+
+    /* Write out global definitions and system includes. */
+    if (num_globals) {
+        fprintf(chaz_ConfWriterC.fh, "\n#ifdef CHY_EMPLOY_%s\n\n",
+                chaz_ConfWriterC.MODULE_NAME);
+        for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
+            switch (defs[i].type) {
+                case CHAZ_CONFELEM_GLOBAL_DEF:
+                    chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
+                                                               defs[i].str2);
+                    break;
+                case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
+                    chaz_ConfWriterC_append_global_typedef_to_conf(
+                            defs[i].str2, defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_SYS_INCLUDE:
+                    chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_DEF:
+                case CHAZ_CONFELEM_TYPEDEF:
+                case CHAZ_CONFELEM_LOCAL_INCLUDE:
+                    /* no-op */
+                    break;
+                default:
+                    chaz_Util_die("Internal error: bad element type %d",
+                                  (int)defs[i].type);
+            }
+        }
+        fprintf(chaz_ConfWriterC.fh, "\n#endif /* EMPLOY_%s */\n",
+                chaz_ConfWriterC.MODULE_NAME);
+    }
+
     fprintf(chaz_ConfWriterC.fh, "\n");
 
+    free(chaz_ConfWriterC.MODULE_NAME);
     chaz_ConfWriterC_clear_def_list();
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/cf630fcf/charmonizer/src/Charmonizer/Probe/Booleans.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Probe/Booleans.c b/charmonizer/src/Charmonizer/Probe/Booleans.c
index 69ba35f..942e36b 100644
--- a/charmonizer/src/Charmonizer/Probe/Booleans.c
+++ b/charmonizer/src/Charmonizer/Probe/Booleans.c
@@ -30,7 +30,7 @@ chaz_Booleans_run(void) {
     }
     else {
         chaz_ConfWriter_append_conf(
-            "#ifndef __cplusplus\n"
+            "#if (defined(CHY_EMPLOY_BOOLEANS) && !defined(__cplusplus))\n"
             "  typedef int bool;\n"
             "  #ifndef true\n"
             "    #define true 1\n"

http://git-wip-us.apache.org/repos/asf/lucy/blob/cf630fcf/clownfish/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/clownfish/compiler/common/charmonizer.main b/clownfish/compiler/common/charmonizer.main
index 460dd7e..b08b7d1 100644
--- a/clownfish/compiler/common/charmonizer.main
+++ b/clownfish/compiler/common/charmonizer.main
@@ -255,12 +255,18 @@ int main(int argc, const char **argv) {
         S_add_compiler_flags(&args);
     }
 
+    /* Define stdint types in charmony.h. */
+    chaz_ConfWriter_append_conf("#define CHY_EMPLOY_INTEGERTYPES\n\n");
+
     /* Run probe modules. */
     chaz_BuildEnv_run();
     chaz_DirManip_run();
     chaz_Headers_run();
+    chaz_FuncMacro_run();
+    chaz_Booleans_run();
     chaz_Integers_run();
     chaz_Strings_run();
+    chaz_SymbolVisibility_run();
     chaz_UnusedVars_run();
 
     if (args.write_makefile) {

http://git-wip-us.apache.org/repos/asf/lucy/blob/cf630fcf/clownfish/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindCore.c b/clownfish/compiler/src/CFCBindCore.c
index 2959349..4dcaf94 100644
--- a/clownfish/compiler/src/CFCBindCore.c
+++ b/clownfish/compiler/src/CFCBindCore.c
@@ -31,6 +31,9 @@
 #include "CFCParcel.h"
 #include "CFCUtil.h"
 
+#define STRING(s)  #s
+#define XSTRING(s) STRING(s)
+
 struct CFCBindCore {
     CFCBase base;
     CFCHierarchy *hierarchy;
@@ -49,6 +52,15 @@ S_write_parcel_h(CFCBindCore *self);
 static void
 S_write_parcel_c(CFCBindCore *self);
 
+static char*
+S_charmony_defines();
+
+static char*
+S_charmony_stdbool_defines();
+
+char*
+S_charmony_stdint_defines();
+
 static const CFCMeta CFCBINDCORE_META = {
     "Clownfish::CFC::Binding::Core",
     sizeof(CFCBindCore),
@@ -119,6 +131,8 @@ S_write_parcel_h(CFCBindCore *self) {
     CFCHierarchy *hierarchy = self->hierarchy;
     CFCParcel    *parcel    = NULL;
 
+    char *charmony_defines = S_charmony_defines();
+
     // Declare object structs for all instantiable classes.
     // Obtain parcel prefix for use in bootstrap function name.
     char *typedefs = CFCUtil_strdup("");
@@ -160,6 +174,9 @@ S_write_parcel_h(CFCBindCore *self) {
         "#include <stdarg.h>\n"
         "#include <stddef.h>\n"
         "#include \"charmony.h\"\n"
+        "\n"
+        "%s"
+        "\n"
         "#include \"hostdefs.h\"\n"
         "\n"
         "#ifdef CFP_LUCY\n"
@@ -266,8 +283,8 @@ S_write_parcel_h(CFCBindCore *self) {
         "%s\n"
         "\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, aliases, typedefs, PREFIX,
-                          prefix, prefix, self->footer);
+        = CFCUtil_sprintf(pattern, self->header, charmony_defines, aliases,
+                          typedefs, PREFIX, prefix, prefix, self->footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
@@ -277,6 +294,7 @@ S_write_parcel_h(CFCBindCore *self) {
     CFCUtil_write_file(filepath, file_content, strlen(file_content));
     FREEMEM(filepath);
 
+    FREEMEM(charmony_defines);
     FREEMEM(aliases);
     FREEMEM(typedefs);
     FREEMEM(file_content);
@@ -458,4 +476,69 @@ CFCBindCore_write_callbacks_h(CFCBindCore *self) {
     FREEMEM(file_content);
 }
 
+static char*
+S_charmony_defines() {
+    char *stdbool_defs = S_charmony_stdbool_defines();
+    char *stdint_defs  = S_charmony_stdint_defines();
+
+    const char *pattern =
+        "#define CFISH_INLINE %s\n"
+        "#define CFISH_EXPORT %s\n"
+        "#define CFISH_IMPORT %s\n"
+        "\n"
+        "%s"
+        "%s";
+    char *defines
+        = CFCUtil_sprintf(pattern, XSTRING(CHY_INLINE), XSTRING(CHY_EXPORT),
+                          XSTRING(CHY_IMPORT), stdbool_defs, stdint_defs);
+
+    FREEMEM(stdbool_defs);
+    FREEMEM(stdint_defs);
+    return defines;
+}
+
+static char*
+S_charmony_stdbool_defines() {
+#ifdef CHY_HAS_STDBOOL_H
+    const char *defines = "#include <stdbool.h>\n";
+#else
+    const char *defines =
+        "#if (!defined(__cplusplus) && !defined(CFISH_HAS_STDBOOL))\n"
+        "  typedef int bool;\n"
+        "  #ifndef true\n"
+        "    #define true 1\n"
+        "  #endif\n"
+        "  #ifndef false\n"
+        "    #define false 0\n"
+        "  #endif\n"
+        "#endif\n";
+#endif
+
+    return CFCUtil_strdup(defines);
+}
+
+char*
+S_charmony_stdint_defines() {
+#ifdef CHY_HAS_STDINT_H
+    return CFCUtil_strdup("#include <stdint.h>\n");
+#else
+    const char *pattern =
+        "#ifndef CFISH_HAS_STDINT\n"
+        "  typedef %s int8_t;\n"
+        "  typedef %s uint8_t;\n"
+        "  typedef %s int16_t;\n"
+        "  typedef %s uint16_t;\n"
+        "  typedef %s int32_t;\n"
+        "  typedef %s uint32_t;\n"
+        "  typedef %s int64_t;\n"
+        "  typedef %s uint64_t;\n"
+        "#endif\n";
+    return CFCUtil_sprintf(pattern,
+                           XSTRING(CHY_INT8_T),  XSTRING(CHY_UINT8_T),
+                           XSTRING(CHY_INT16_T), XSTRING(CHY_UINT16_T),
+                           XSTRING(CHY_INT32_T), XSTRING(CHY_UINT32_T),
+                           XSTRING(CHY_INT64_T), XSTRING(CHY_UINT64_T));
+#endif
+}
+
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/cf630fcf/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/common/charmonizer.main b/common/charmonizer.main
index e357203..a685a54 100644
--- a/common/charmonizer.main
+++ b/common/charmonizer.main
@@ -426,6 +426,13 @@ int main(int argc, const char **argv) {
         }
     }
 
+    /* Employ integer features but don't define stdint types in charmony.h. */
+    chaz_ConfWriter_append_conf(
+        "#define CHY_EMPLOY_INTEGERLIMITS\n"
+        "#define CHY_EMPLOY_INTEGERLITERALS\n"
+        "#define CHY_EMPLOY_INTEGERFORMATSTRINGS\n\n"
+    );
+
     /* Run probe modules. */
     chaz_BuildEnv_run();
     chaz_DirManip_run();

http://git-wip-us.apache.org/repos/asf/lucy/blob/cf630fcf/devel/bin/regen_charmonizer.pl
----------------------------------------------------------------------
diff --git a/devel/bin/regen_charmonizer.pl b/devel/bin/regen_charmonizer.pl
index 6f550cb..1fda312 100755
--- a/devel/bin/regen_charmonizer.pl
+++ b/devel/bin/regen_charmonizer.pl
@@ -29,7 +29,10 @@ my $MELD_EXE = catfile( $CHAZ_DIR, 'buildbin', 'meld.pl' );
 
 # Clownfish compiler.
 {
-    my $probes = "BuildEnv,DirManip,Headers,Integers,Strings,UnusedVars";
+    my $probes = join( ',', qw(
+        Booleans BuildEnv DirManip FuncMacro Headers Integers Strings
+        SymbolVisibility UnusedVars
+    ) );
     my $main   = catfile(qw( clownfish compiler common charmonizer.main ));
     my $out    = $main;
     $out =~ s/\.main/.c/ or die "no match";


Mime
View raw message