Add 'Booleans' module to Charmonizer

The 'Booleans' module first tries to include stdbool.h. If this
header is not available, 'bool', 'true' and 'false' are defined.


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

Branch: refs/heads/c99-types
Commit: 64c12d43fabfeaaf577a48477adc069bc1fa2f38
Parents: 2e4a2e4
Author: Nick Wellnhofer <[email protected]>
Authored: Sun Nov 18 02:01:34 2012 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Sun Nov 18 16:37:40 2012 +0100

----------------------------------------------------------------------
 charmonizer/src/Charmonizer/Probe/Booleans.c |   47 +++++++++++++++++++
 charmonizer/src/Charmonizer/Probe/Booleans.h |   50 +++++++++++++++++++++
 charmonizer/src/Charmonizer/Probe/Integers.c |   10 ----
 clownfish/runtime/common/charmonizer.main    |    1 +
 common/charmonizer.main                      |    1 +
 5 files changed, 99 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/64c12d43/charmonizer/src/Charmonizer/Probe/Booleans.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Probe/Booleans.c 
b/charmonizer/src/Charmonizer/Probe/Booleans.c
new file mode 100644
index 0000000..69ba35f
--- /dev/null
+++ b/charmonizer/src/Charmonizer/Probe/Booleans.c
@@ -0,0 +1,47 @@
+/* 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 "Charmonizer/Core/HeaderChecker.h"
+#include "Charmonizer/Core/ConfWriter.h"
+#include "Charmonizer/Probe/Booleans.h"
+
+void
+chaz_Booleans_run(void) {
+    int has_stdbool = chaz_HeadCheck_check_header("stdbool.h");
+
+    chaz_ConfWriter_start_module("Booleans");
+
+    if (has_stdbool) {
+        chaz_ConfWriter_add_def("HAS_STDBOOL_H", NULL);
+        chaz_ConfWriter_add_sys_include("stdbool.h");
+    }
+    else {
+        chaz_ConfWriter_append_conf(
+            "#ifndef __cplusplus\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");
+    }
+
+    chaz_ConfWriter_end_module();
+}
+
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/64c12d43/charmonizer/src/Charmonizer/Probe/Booleans.h
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Probe/Booleans.h 
b/charmonizer/src/Charmonizer/Probe/Booleans.h
new file mode 100644
index 0000000..e14f31b
--- /dev/null
+++ b/charmonizer/src/Charmonizer/Probe/Booleans.h
@@ -0,0 +1,50 @@
+/* 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.
+ */
+
+/* Charmonizer/Probe/Booleans.h -- bool type.
+ *
+ * If stdbool.h is is available, it will be pound-included in the configuration
+ * header.  If it is not, the following typedef will be defined:
+ *
+ * bool
+ *
+ * These symbols will be defined if they are not already:
+ *
+ * true
+ * false
+ */
+
+#ifndef H_CHAZ_BOOLEANS
+#define H_CHAZ_BOOLEANS
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+/* Run the Booleans module.
+ */
+void chaz_Booleans_run(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CHAZ_BOOLEANS */
+
+
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/64c12d43/charmonizer/src/Charmonizer/Probe/Integers.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Probe/Integers.c 
b/charmonizer/src/Charmonizer/Probe/Integers.c
index 570c305..0d50042 100644
--- a/charmonizer/src/Charmonizer/Probe/Integers.c
+++ b/charmonizer/src/Charmonizer/Probe/Integers.c
@@ -419,16 +419,6 @@ chaz_Integers_run(void) {
             "(double)(int64_t)(num))");
     }
 
-    /* True and false. */
-    chaz_ConfWriter_append_conf(
-        "#ifndef true\n"
-        "  #define true 1\n"
-        "#endif\n"
-        "#ifndef false\n"
-        "  #define false 0\n"
-        "#endif\n"
-    );
-
     chaz_ConfWriter_end_module();
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/64c12d43/clownfish/runtime/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/clownfish/runtime/common/charmonizer.main 
b/clownfish/runtime/common/charmonizer.main
index 1c91468..477b451 100644
--- a/clownfish/runtime/common/charmonizer.main
+++ b/clownfish/runtime/common/charmonizer.main
@@ -130,6 +130,7 @@ int main(int argc, char **argv) {
     chaz_Headers_run();
     chaz_AtomicOps_run();
     chaz_FuncMacro_run();
+    chaz_Booleans_run();
     chaz_Integers_run();
     chaz_Floats_run();
     chaz_LargeFiles_run();

http://git-wip-us.apache.org/repos/asf/lucy/blob/64c12d43/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/common/charmonizer.main b/common/charmonizer.main
index 4483731..b9463ac 100644
--- a/common/charmonizer.main
+++ b/common/charmonizer.main
@@ -130,6 +130,7 @@ int main(int argc, char **argv) {
     chaz_Headers_run();
     chaz_AtomicOps_run();
     chaz_FuncMacro_run();
+    chaz_Booleans_run();
     chaz_Integers_run();
     chaz_Floats_run();
     chaz_LargeFiles_run();

Reply via email to