packages feed

bond 0.12.0.1 → 0.12.1.0

raw patch · 7 files changed

+56/−78 lines, 7 files

Files

bond.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12
 
--- This file has been generated from package.yaml by hpack version 0.31.2.
+-- This file has been generated from package.yaml by hpack version 0.33.0.
 --
 -- see: https://github.com/sol/hpack
 --
--- hash: b913222488b7035eec255444fe3bf82606f82eb0940c6ae5a4a3af784638c527
+-- hash: 5f829cf187d9630385924b752fae193c51da82b2d9bfc0ef8f38f23a638fc604
 
 name:           bond
-version:        0.12.0.1
+version:        0.12.1.0
 synopsis:       Bond schema compiler and code generator
 description:    Bond is a cross-platform framework for handling schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. . This package contains a library for parsing the Bond schema definition language and performing template-based code generation. The library includes built-in templates for generating standard Bond C++ and C# code, as well as utilities for writing custom codegen templates. . The package also contains a command-line compiler/codegen tool, named gbc, which is primarily used to generate code for C++ and C# programs using Bond.
 category:       Language, Compiler, Code Generation
src/Language/Bond/Codegen/Cpp/Grpc_h.hs view
@@ -79,7 +79,7 @@ 
         public: struct service
         {
-            #{newlineSep 3 methodTemplate serviceMethods}
+            #{newlineSep 3 (uncurry methodTemplate) (zip serviceMethods uniqueMethodTemplateStructNames)}
         };
 
         private: typedef boost::mpl::list<> methods0;
@@ -167,7 +167,18 @@           where
             static m = [lt|(void)#{methodMetadataVar m};|]
 
-        methodTemplate m = [lt|typedef struct : ::bond::ext::grpc::reflection::MethodTemplate<#{declName}, #{payload $ methodTypeToMaybe (methodInput m)}, #{resultType m}, &#{methodMetadataVar m}> {} #{methodName m};|]
+        -- unique names for each of the MethodTemplate derived structs that
+        -- we need to generate in the same order as serviceMethods.
+        uniqueMethodTemplateStructNames :: [String]
+        uniqueMethodTemplateStructNames = uniqueNames (map (\n -> n ++ "_type") methodNames) reservedNames
+          where
+            methodNames = map methodName serviceMethods
+            reservedNames = methodTemplateReservedNames ++ methodNames
+            -- methodTemplateReservedNames are names used in ::bond::reflection::MethodTemplate<>
+            methodTemplateReservedNames = ["MethodTemplate", "service_type", "input_type", "result_type", "metadata", "method"]
+
+        methodTemplate :: Method -> String -> L.Text
+        methodTemplate m methodTemplateStructName = [lt|typedef struct #{methodTemplateStructName} : ::bond::ext::grpc::reflection::MethodTemplate<#{declName}, #{payload $ methodTypeToMaybe (methodInput m)}, #{resultType m}, &#{methodMetadataVar m}> {} #{methodName m};|]
 
         proxyName = "Client" :: String
         serviceName = "Service" :: String
src/Language/Bond/Codegen/Cpp/Reflection_h.hs view
@@ -31,7 +31,7 @@ #{CPP.closeNamespace cpp}
 |])
   where
-    idl = MappingContext idlTypeMapping [] [] []  
+    idl = MappingContext idlTypeMapping [] [] []
 
     -- C++ type
     cppType = getTypeName cpp
@@ -51,7 +51,7 @@         #{newlineBeginSep 2 fieldMetadata structFields}
 
         public: struct var
-        {#{fieldTemplates structFields}};
+        {#{fieldTemplates (zip structFields uniqueFieldTemplateStructNames)}};
 
         private: typedef boost::mpl::list<> fields0;
         #{newlineSep 2 pushField indexedFields}
@@ -92,7 +92,7 @@         }|]
           where
             static Field {..} = [lt|(void)s_#{fieldName}_metadata;|]
-        
+
         -- reversed list of field names zipped with indexes
         indexedFields :: [(String, Int)]
         indexedFields = zipWith ((,) . fieldName) (reverse structFields) [0..]
@@ -106,16 +106,25 @@         fieldMetadata Field {..} =
             [lt|private: #{export_attr}static const ::bond::Metadata s_#{fieldName}_metadata;|]
 
-        fieldTemplates = F.foldMap $ \ f@Field {..} -> [lt|
+        -- fieldTemplateReservedNames are names used in ::bond::reflection::FieldTemplate<>
+        fieldTemplateReservedNames = ["FieldTemplate", "struct_type", "field_pointer", "field_type", "value_type", "field_modifier", "metadata", "field", "id", "GetVariable"]
+
+        fieldNames = map (\f -> fieldName f) structFields
+
+        fieldTemplateStructReservedNames = fieldTemplateReservedNames ++ fieldNames
+
+        uniqueFieldTemplateStructNames = uniqueNames (map (\n -> n ++ "_type") fieldNames) fieldTemplateStructReservedNames
+
+        fieldTemplates = F.foldMap $ \ (f@Field {..}, sn) -> [lt|
             // #{fieldName}
-            typedef struct : ::bond::reflection::FieldTemplate<
+            typedef struct #{sn} : ::bond::reflection::FieldTemplate<
                 #{fieldOrdinal},
                 #{CPP.modifierTag f},
                 #{className},
                 #{cppType fieldType},
                 &#{className}::#{fieldName},
                 &s_#{fieldName}_metadata
-            > {}  #{fieldName};
+            > {} #{fieldName};
         |]
 
 
src/Language/Bond/Codegen/Cpp/Types_cpp.hs view
@@ -38,22 +38,11 @@     -- ToString is intentionally not implemented in terms of FromEnum, as
     -- ToString returns a reference to the name stored in the map. FromEnum
     -- copies this name into the output paramater.
-    statics e@Enum {..} = [lt|
+    statics Enum {..} = [lt|
     namespace _bond_enumerators
     {
     namespace #{declName}
     {
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-        const std::map<std::string, enum #{declName}> _name_to_value_#{declName}
-            {
-                #{CPP.enumNameToValueInitList 4 e}
-            };
-
-        const std::map<enum #{declName}, std::string> _value_to_name_#{declName}
-            {
-                #{CPP.enumValueToNameInitList 4 e}
-            };
-#else
         namespace
         {
             struct _hash_#{declName}
@@ -64,14 +53,9 @@                 }
             };
         }
-#endif
         const std::string& ToString(enum #{declName} value)
         {
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-            const auto& map = GetValueToNameMap(value);
-#else
             const auto& map = GetValueToNameMap<std::unordered_map<enum #{declName}, std::string, _hash_#{declName}> >(value);
-#endif
             auto it = map.find(value);
 
             if (map.end() == it)
@@ -88,11 +72,7 @@ 
         bool ToEnum(enum #{declName}& value, const std::string& name)
         {
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-            const auto& map = GetNameToValueMap(value);
-#else
             const auto& map = GetNameToValueMap<std::unordered_map<std::string, enum #{declName}> >(value);
-#endif
             auto it = map.find(name);
 
             if (map.end() == it)
@@ -105,11 +85,7 @@ 
         bool FromEnum(std::string& name, enum #{declName} value)
         {
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-            const auto& map = GetValueToNameMap(value);
-#else
             const auto& map = GetValueToNameMap<std::unordered_map<enum #{declName}, std::string, _hash_#{declName}> >(value);
-#endif
             auto it = map.find(value);
 
             if (map.end() == it)
src/Language/Bond/Codegen/Cpp/Types_h.hs view
@@ -39,7 +39,7 @@ #{newlineBeginSep 0 includeHeader userHeaders}
 #include <bond/core/bond_version.h>
 
-#if BOND_VERSION < 0x0800
+#if BOND_VERSION < 0x0900
 #error This file was generated by a newer version of the Bond compiler and is incompatible with your version of the Bond library.
 #endif
 
@@ -209,15 +209,12 @@ 
         -- default constructor
         defaultCtor = [lt|
-        #{dummyTemplateTag}#{declName}(#{vc12WorkaroundParam})#{initList}#{ctorBody}|]
+        #{dummyTemplateTag}#{declName}()#{initList}#{ctorBody}|]
           where
             needAllocParam = maybe False needAlloc allocator
 
-            vc12WorkaroundParam = if needAllocParam then [lt|_bond_vc12_ctor_workaround_ = {}|] else mempty
-
             dummyTemplateTag = if needAllocParam
-                then [lt|struct _bond_vc12_ctor_workaround_ {};
-        template <int = 0> // Workaround to avoid compilation if not used
+                then [lt|template <int = 0> // Workaround to avoid compilation if not used
         |]
                 else mempty
 
@@ -305,14 +302,8 @@         -- move constructor
         moveCtor = if hasMetaFields then [lt|
         #{explicit}|]
-            -- even if implicit would be okay, fall back to explicit for
-            -- compilers that don't support = default for move constructors
                                     else [lt|
-#if defined(_MSC_VER) && (_MSC_VER < 1900)  // Versions of MSVC prior to 1900 do not support = default for move ctors
-        #{explicit}
-#else
-        #{implicit}
-#endif|]
+        #{implicit}|]
           where
             -- default OK when there are no meta fields
             implicit = [lt|#{declName}(#{declName}&&) = default;|]
@@ -335,13 +326,9 @@           where
             -- default OK when there are no meta fields
             implicitlyDeclared = [lt|
-#if defined(_MSC_VER) && (_MSC_VER < 1900)  // Versions of MSVC prior to 1900 do not support = default for move ctors
-        #{define}
-#else
         // Compiler generated operator= OK
         #{declName}& operator=(const #{declName}&) = default;
-        #{declName}& operator=(#{declName}&&) = default;
-#endif|]
+        #{declName}& operator=(#{declName}&&) = default;|]
 
             -- define operator= using swap
             define = [lt|#{declName}& operator=(#{declName} #{otherParamName})
@@ -386,21 +373,7 @@             return "#{getDeclTypeName idl e}";
         }
 
-#if defined(_MSC_VER) && (_MSC_VER < 1900) // Versions of MSVC prior to 1900 do not support magic statics
-        extern const std::map<enum #{declName}, std::string> _value_to_name_#{declName};
 
-        inline const std::map<enum #{declName}, std::string>& GetValueToNameMap(enum #{declName})
-        {
-            return _value_to_name_#{declName};
-        }
-
-        extern const std::map<std::string, enum #{declName}> _name_to_value_#{declName};
-
-        inline const std::map<std::string, enum #{declName}>& GetNameToValueMap(enum #{declName})
-        {
-            return _name_to_value_#{declName};
-        }
-#else
         template <typename Map = std::map<enum #{declName}, std::string> >
         inline const Map& GetValueToNameMap(enum #{declName}, ::bond::detail::mpl::identity<Map> = {})
         {
@@ -420,7 +393,6 @@                 };
             return s_nameToValueMap;
         }
-#endif
         #{export_attr}const std::string& ToString(enum #{declName} value);
 
         #{export_attr}void FromString(const std::string& name, enum #{declName}& value);
src/Language/Bond/Codegen/Cs/Types_cs.hs view
@@ -126,7 +126,10 @@         constructorWithParameters = if not noMetaFields
             then error $ "bond_meta usage in Struct " ++ (show declName) ++ " Field " ++ (show $ fieldName $ head metaFields) ++ " is incompatible with --preview--constructor-parameters"
             else if (null baseFieldList)
-                then [lt|
+                then if (null structFields) 
+                     then [lt|
+        #{defaultConstructor}|]
+                     else [lt|
 
         public #{declName}(
             #{commaLineSep 3 paramDecl fieldNameList})
@@ -134,10 +137,7 @@             #{newlineSep 3 paramBasedInitializer fieldNameList}
         }
 
-        public #{declName}()
-        {
-            #{newlineSep 3 initializer structFields}
-        }|]
+        #{defaultConstructor}|]
                 else [lt|
 
         public #{declName}(
@@ -149,10 +149,7 @@             #{newlineSep 3 paramBasedInitializer (zip structFields uniqueThisFieldNames)}
         }
 
-        public #{declName}()
-        {
-            #{newlineSep 3 initializer structFields}
-        }|]
+        #{defaultConstructor}|]
 
         thisParamBlock = if null structFields
             then mempty
@@ -160,6 +157,11 @@ 
             // This class parameters
             #{commaLineSep 3 paramDecl (zip structFields uniqueThisFieldNames)}|]
+
+        defaultConstructor = [lt|public #{declName}()
+        {
+            #{newlineSep 3 initializer structFields}
+        }|]
 
         baseFieldList = concat $ baseFields s
 
tests/TestMain.hs view
@@ -76,6 +76,7 @@             , verifyCppCodegen "aliases"
             , verifyCppCodegen "alias_key"
             , verifyCppCodegen "maybe_blob"
+            , verifyCppCodegen "metadata_edge_cases"
             , verifyCodegen
                 [ "c++"
                 , "--enum-header"
@@ -191,6 +192,13 @@                  , "--import-dir=tests/schema/imports"
                  ]
                  "import"
+            , verifyCodegenVariation
+                [ "c#"
+                , "--preview-constructor-parameters"
+                , "--readonly-properties"
+                ]
+                "empty_struct"
+                "constructor-parameters"
             , testGroup "Grpc"
                 [ verifyCsGrpcCodegen
                     [ "c#"