From 9c77c9b851b19a8a03c029f7e5a022f600eceaa9 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Mon, 18 Apr 2016 10:56:10 +0200
Subject: [PATCH] ifdefing more typedef stuff due to C-compilation errors.

---
 compiler/2014/C_CodeGen.jrag               | 6 ++++++
 examples/user_types/example_decoder.c      | 6 +++++-
 lib/c/2014/labcomm2014_decoder.c           | 2 +-
 lib/c/2014/labcomm2014_encoder.c           | 8 ++++----
 lib/c/2014/labcomm2014_renaming_registry.c | 4 +++-
 lib/c/2014/labcomm2014_type_signature.c    | 3 +++
 lib/c/2014/labcomm2014_type_signature.h    | 6 ++++--
 7 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/compiler/2014/C_CodeGen.jrag b/compiler/2014/C_CodeGen.jrag
index 0b68620..31b6447 100644
--- a/compiler/2014/C_CodeGen.jrag
+++ b/compiler/2014/C_CodeGen.jrag
@@ -1309,8 +1309,10 @@ aspect C_Signature {
     env.println("0,");
     env.println("NULL,");
     env.println("0,"); // index
+    env.println("#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS");
     env.println("sizeof(signature_tree_" + env.prefix + getName() + "),");
     env.println("signature_tree_" + env.prefix + getName() + "");
+    env.println("#endif");
     env.unindent();
     env.println(" };");
     env.println("const struct labcomm2014_signature " +
@@ -1347,9 +1349,11 @@ aspect C_Signature {
     env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),");
     env.println("signature_bytes_" + env.prefix + getName() + ",");
     env.println("0,"); // index
+    env.println("#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS");
     env.println("sizeof(signature_tree_" + env.prefix + getName() + "),");
     env.println("signature_tree_" + env.prefix + getName() + "");
     env.unindent();
+    env.println("#endif");
     env.println(" };");
     env.println("const struct labcomm2014_signature " +
                 "*labcomm2014_signature_" + env.prefix + getName() + 
@@ -1402,6 +1406,7 @@ aspect C_Signature {
 //
 //}
   public void SignatureList.C_emitSignature(C_env env, boolean decl) { 
+  env.println("#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS");
   env.println("static struct labcomm2014_signature_data signature_tree_" + 
   	 env.prefix + parentDecl().getName() + "[] = {");
   env.indent();
@@ -1413,6 +1418,7 @@ aspect C_Signature {
   env.println("LABCOMM_SIGDEF_END");
   env.println("};");
   env.unindent();
+  env.println("#endif");
   env.println();
   }
 
diff --git a/examples/user_types/example_decoder.c b/examples/user_types/example_decoder.c
index 1874373..0237b76 100644
--- a/examples/user_types/example_decoder.c
+++ b/examples/user_types/example_decoder.c
@@ -28,6 +28,7 @@ static void handle_test_theSecondInt(int *v,void *context) {
   printf("Got theSecondInt. (%d) \n", *v); 
 }
 
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
 static void handle_type_def(struct labcomm2014_raw_type_def *v,void *context) {
   printf("Got type_def. (0x%x) %s\n", v->index, v->name); 
 }
@@ -35,6 +36,7 @@ static void handle_type_def(struct labcomm2014_raw_type_def *v,void *context) {
 static void handle_type_binding(struct labcomm2014_type_binding *v,void *context) {
   printf("Got type binding. 0x%x --> 0x%x\n", v->sample_index, v->type_index); 
 }
+#endif
 
 static void handle_test_twoLines(test_twoLines *v,void *context) {
   printf("Got twoLines. (%d,%d) -> (%d,%d), (%d,%d) -> (%d,%d)\n", v->l1.start.x.val, v->l1.start.y.val, 
@@ -69,9 +71,11 @@ int main(int argc, char *argv[]) {
   labcomm2014_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context);
   labcomm2014_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context);
   labcomm2014_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
   labcomm2014_decoder_register_labcomm2014_type_def(decoder, handle_type_def, context);
   labcomm2014_decoder_register_labcomm2014_type_binding(decoder, handle_type_binding, context);
-
+#endif
+  
   printf("Decoding:\n");
   labcomm2014_decoder_run(decoder);
   printf("--- End Of File ---:\n");
diff --git a/lib/c/2014/labcomm2014_decoder.c b/lib/c/2014/labcomm2014_decoder.c
index e270afc..a4cae4d 100644
--- a/lib/c/2014/labcomm2014_decoder.c
+++ b/lib/c/2014/labcomm2014_decoder.c
@@ -471,7 +471,7 @@ static int do_ioctl(struct labcomm2014_decoder *d,
   return result;
 }
 
-#ifndef LABCOMM_NO_TYPEDECL
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
 //// Code for allowing user code to handle type_defs 
 //// (should perhaps be moved to another file)
 
diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c
index 59a34ef..70a2f9c 100644
--- a/lib/c/2014/labcomm2014_encoder.c
+++ b/lib/c/2014/labcomm2014_encoder.c
@@ -27,7 +27,7 @@
 #include "labcomm2014_dynamic_buffer_writer.h"
 
 //define the following to disable encoding of typedefs
-#undef LABCOMM_WITHOUT_TYPE_DEFS
+#undef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
 
 struct encoder {
   struct labcomm2014_encoder encoder;
@@ -216,7 +216,7 @@ static int do_sample_ref_to_index(
  * Start of code related to sending (hierarchical)
  * typedefs. Define LABCOMM_WITHOUT_TYPEDEFS to disable
  **********************************************************/
-#ifndef LABCOMM_WITHOUT_TYPE_DEFS
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
 
 static void write_sig_tree_byte(char b, const struct labcomm2014_signature *signature,
                            void *context)
@@ -307,7 +307,7 @@ static int do_type_register(
   struct labcomm2014_encoder *e,
   const struct labcomm2014_signature *signature)
 {
-#ifndef LABCOMM_WITHOUT_TYPE_DEFS
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
   return internal_reg_type(e, signature, LABCOMM2014_FALSE);
 #else
   return 0;
@@ -319,7 +319,7 @@ static int do_type_bind(
   const struct labcomm2014_signature *signature,
   char has_deps)
 {
-#ifndef LABCOMM_WITHOUT_TYPE_DEFS
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
   int result = -EINVAL;
   int err;
   int sindex = labcomm2014_get_local_index(signature);
diff --git a/lib/c/2014/labcomm2014_renaming_registry.c b/lib/c/2014/labcomm2014_renaming_registry.c
index 03949e0..c26c89d 100644
--- a/lib/c/2014/labcomm2014_renaming_registry.c
+++ b/lib/c/2014/labcomm2014_renaming_registry.c
@@ -40,7 +40,9 @@ struct labcomm2014_renaming_rename {
   int use_count;
   struct registry *base;
   struct labcomm2014_signature signature;
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
   struct labcomm2014_signature_data s_treedata[2];
+#endif
 };
 
 struct labcomm2014_renaming_registry {
@@ -152,7 +154,7 @@ struct labcomm2014_renaming_rename *labcomm2014_renaming_rename_new(
       entry->signature.size = base->signature->size;
       entry->signature.signature = base->signature->signature;
       entry->signature.index = 0;
-#ifndef LABCOMM_NO_TYPEDECL
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
       struct labcomm2014_signature_data s_treedata[2] = {
         LABCOMM_SIGDEF_SIGNATURE(*base->signature),
         LABCOMM_SIGDEF_END
diff --git a/lib/c/2014/labcomm2014_type_signature.c b/lib/c/2014/labcomm2014_type_signature.c
index dce1836..c1944d5 100644
--- a/lib/c/2014/labcomm2014_type_signature.c
+++ b/lib/c/2014/labcomm2014_type_signature.c
@@ -2,6 +2,8 @@
 #include <string.h>   // for memcmp
 #include <stdio.h>   // for debug printf
 
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
+
 /* Dump signature bytes on stdout 
  */
 
@@ -126,3 +128,4 @@ void map_signature( void(*f)(char, const struct labcomm2014_signature *, void *)
     p+=1;
   }
 }
+#endif
diff --git a/lib/c/2014/labcomm2014_type_signature.h b/lib/c/2014/labcomm2014_type_signature.h
index dfb7934..3bc10d2 100644
--- a/lib/c/2014/labcomm2014_type_signature.h
+++ b/lib/c/2014/labcomm2014_type_signature.h
@@ -11,7 +11,7 @@
 /*
  * Signature entry
  */
-#ifndef LABCOMM_NO_TYPEDECL
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
 #ifdef USE_UNIONS
 
 /* Useful for C99 and up (or GCC without -pedantic) */ 
@@ -54,7 +54,7 @@ struct labcomm2014_signature {
   int size;
   unsigned char *signature; 
   int index;
-#ifndef LABCOMM_NO_TYPEDECL
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
   int tdsize;
   struct labcomm2014_signature_data *treedata;
 #endif  
@@ -63,6 +63,7 @@ struct labcomm2014_signature {
 #endif
 };
 
+#ifdef LABCOMM_USE_UNSUPPORTED_TYPEDEFS
 /* a struct for "raw" type_defs, to be used as an intermediate representation
  * between decoder and signature parser
  */
@@ -137,5 +138,6 @@ labcomm2014_bool labcomm2014_signature_dump(struct labcomm2014_signature_data *s
 void map_signature( void(*f)(char, const struct labcomm2014_signature *, void *), 
                     void *context,
                     const struct labcomm2014_signature *signature, labcomm2014_bool flatten);
+#endif
 
 #endif
-- 
GitLab