You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2012/04/28 21:20:23 UTC

svn commit: r1331810 - in /thrift/trunk: lib/d/src/thrift/codegen/base.d tutorial/d/Makefile

Author: roger
Date: Sat Apr 28 19:20:23 2012
New Revision: 1331810

URL: http://svn.apache.org/viewvc?rev=1331810&view=rev
Log:
THRIFT-1586 Two small D issues
Patch: David Nadlinger

Modified:
    thrift/trunk/lib/d/src/thrift/codegen/base.d
    thrift/trunk/tutorial/d/Makefile

Modified: thrift/trunk/lib/d/src/thrift/codegen/base.d
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/d/src/thrift/codegen/base.d?rev=1331810&r1=1331809&r2=1331810&view=diff
==============================================================================
--- thrift/trunk/lib/d/src/thrift/codegen/base.d (original)
+++ thrift/trunk/lib/d/src/thrift/codegen/base.d Sat Apr 28 19:20:23 2012
@@ -368,7 +368,7 @@ mixin template TStructHelpers(alias fiel
   static assert(is(This == struct) || is(This : Exception),
     "TStructHelpers can only be used inside a struct or an Exception class.");
 
-  static if (is(TIsSetFlags!(This, fieldMetaData))) {
+  static if (TIsSetFlags!(This, fieldMetaData).tupleof.length > 0) {
     // If we need to keep isSet flags around, create an instance of the
     // container struct.
     TIsSetFlags!(This, fieldMetaData) isSetFlags;
@@ -530,38 +530,35 @@ unittest {
   assert(f.toString() == `Foo(a: a string, b: 0 (unset), c: 4)`);
 }
 
+
 /**
  * Generates an eponymous struct with boolean flags for the non-required
- * non-nullable fields of T, if any, or nothing otherwise (i.e. the template
- * body is empty).
+ * non-nullable fields of T.
  *
- * Nullable fields are just set to null to signal »not set«.
+ * Nullable fields are just set to null to signal »not set«, so no flag is
+ * emitted for them, even if they are optional.
  *
  * In most cases, you do not want to use this directly, but via TStructHelpers
  * instead.
  */
-// DMD @@BUG@@: Using getFieldMeta!T in here horribly breaks things to the point
-// where getFieldMeta is *instantiated twice*, with different bodies. This is
-// connected to the position of »enum fieldMeta« in TStructHelpers.
 template TIsSetFlags(T, alias fieldMetaData) {
   mixin({
-    string boolDefinitions;
-    foreach (name; __traits(derivedMembers, T)) {
-      static if (!is(MemberType!(T, name)) || is(MemberType!(T, name) == void)) {
-        // We hit something strange like the TStructHelpers template itself,
-        // just ignore.
-      } else static if (isNullable!(MemberType!(T, name))) {
-        // If the field is nullable, we don't need an isSet flag as we can map
-        // unset to null.
-      } else static if (memberReq!(T, name, fieldMetaData) != TReq.REQUIRED) {
-        boolDefinitions ~= "bool " ~ name ~ ";\n";
+    string code = "struct TIsSetFlags {\n";
+    foreach (meta; fieldMetaData) {
+      code ~= "static if (!is(MemberType!(T, `" ~ meta.name ~ "`))) {\n";
+      code ~= q{
+        static assert(false, "Field '" ~ meta.name ~
+          "' referenced in metadata not present in struct '" ~ T.stringof ~ "'.");
+      };
+      code ~= "}";
+      if (meta.req == TReq.OPTIONAL || meta.req == TReq.OPT_IN_REQ_OUT) {
+        code ~= "else static if (!isNullable!(MemberType!(T, `" ~ meta.name ~ "`))) {\n";
+        code ~= "  bool " ~ meta.name ~ ";\n";
+        code ~= "}\n";
       }
     }
-    if (!boolDefinitions.empty) {
-      return "struct TIsSetFlags {\n" ~ boolDefinitions ~ "}";
-    } else {
-      return "";
-    }
+    code ~= "}";
+    return code;
   }());
 }
 

Modified: thrift/trunk/tutorial/d/Makefile
URL: http://svn.apache.org/viewvc/thrift/trunk/tutorial/d/Makefile?rev=1331810&r1=1331809&r2=1331810&view=diff
==============================================================================
--- thrift/trunk/tutorial/d/Makefile (original)
+++ thrift/trunk/tutorial/d/Makefile Sat Apr 28 19:20:23 2012
@@ -31,7 +31,7 @@ client: client.d
 	dmd -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd client.d ${GEN_SRC}
 
 async_client: async_client.d
-	dmd -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd -L-lthriftd-event -L-levent async_client.d ${GEN_SRC}
+	dmd -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd-event -L-lthriftd -L-levent async_client.d ${GEN_SRC}
 
 clean:
 	$(RM) -f server client async_client