bond 0.7.0.0 → 0.8.0.0
raw patch · 14 files changed
+108/−78 lines, 14 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Language.Bond.Codegen.Templates: types_comm_cpp :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text)
+ Language.Bond.Codegen.Templates: comm_cpp :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text)
- Language.Bond.Codegen.Templates: comm_h :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text)
+ Language.Bond.Codegen.Templates: comm_h :: Maybe String -> MappingContext -> String -> [Import] -> [Declaration] -> (String, Text)
- Language.Bond.Codegen.Templates: reflection_h :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text)
+ Language.Bond.Codegen.Templates: reflection_h :: Maybe String -> MappingContext -> String -> [Import] -> [Declaration] -> (String, Text)
Files
- Main.hs +5/−5
- Options.hs +2/−3
- bond.cabal +2/−2
- src/Language/Bond/Codegen/Cpp/Apply_h.hs +4/−4
- src/Language/Bond/Codegen/Cpp/Comm_cpp.hs +34/−0
- src/Language/Bond/Codegen/Cpp/Comm_h.hs +8/−4
- src/Language/Bond/Codegen/Cpp/Reflection_h.hs +8/−4
- src/Language/Bond/Codegen/Cpp/Types_Comm_cpp.hs +0/−34
- src/Language/Bond/Codegen/Cpp/Types_h.hs +3/−5
- src/Language/Bond/Codegen/Cpp/Util.hs +1/−0
- src/Language/Bond/Codegen/Cs/Comm_cs.hs +1/−1
- src/Language/Bond/Codegen/Templates.hs +2/−2
- tests/Main.hs +15/−6
- tests/Tests/Codegen.hs +23/−8
Main.hs view
@@ -70,13 +70,13 @@ cppCodegen options@Cpp {..} = do let typeMapping = maybe cppTypeMapping cppCustomAllocTypeMapping allocator concurrentlyFor_ files $ codeGen options typeMapping $ - [ reflection_h - , types_cpp - , types_comm_cpp + [ reflection_h export_attribute , types_h header enum_header allocator - , apply_h applyProto apply_attribute + , types_cpp + , apply_h applyProto export_attribute , apply_cpp applyProto - , comm_h + , comm_h export_attribute + , comm_cpp ] <> [ enum_h | enum_header] where
Options.hs view
@@ -35,7 +35,7 @@ , enum_header :: Bool , allocator :: Maybe String , apply :: [ApplyOptions] - , apply_attribute :: Maybe String + , export_attribute :: Maybe String , jobs :: Maybe Int , no_banner :: Bool } @@ -71,7 +71,7 @@ , enum_header = def &= name "e" &= help "Generate enums into a separate header file" , allocator = def &= typ "ALLOCATOR" &= help "Generate types using the specified allocator" , apply = def &= typ "PROTOCOL" &= help "Generate Apply function overloads for the specified protocol only; supported protocols: compact, fast and simple" - , apply_attribute = def &= typ "ATTRIBUTE" &= help "Prefix the declarations of Apply functions with the specified C++ attribute/declspec" + , export_attribute = def &= typ "ATTRIBUTE" &= explicit &= name "apply-attribute" &= name "export-attribute" &= help "Prefix declarations for library export with the specified C++ attribute/declspec. apply-attribute is a deprecated synonym." , jobs = def &= opt "0" &= typ "NUM" &= name "j" &= help "Run NUM jobs simultaneously (or '$ncpus' if no NUM is not given)" , no_banner = def &= help "Omit the banner at the top of generated files" } &= @@ -93,7 +93,6 @@ } &= name "schema" &= help "Output the JSON representation of the schema" - mode :: Mode (CmdArgs Options) mode = cmdArgsMode $ modes [cpp, cs, schema] &=
bond.cabal view
@@ -2,7 +2,7 @@ -- Licensed under the MIT license. See LICENSE file in the project root for full license information. name: bond -version: 0.7.0.0 +version: 0.8.0.0 cabal-version: >= 1.8 tested-with: GHC>=7.4.1 synopsis: Bond schema compiler and code generator @@ -62,8 +62,8 @@ Language.Bond.Codegen.Cpp.Enum_h Language.Bond.Codegen.Cpp.Reflection_h Language.Bond.Codegen.Cpp.Types_cpp - Language.Bond.Codegen.Cpp.Types_Comm_cpp Language.Bond.Codegen.Cpp.Types_h + Language.Bond.Codegen.Cpp.Comm_cpp Language.Bond.Codegen.Cpp.Comm_h Language.Bond.Codegen.Cs.Types_cs Language.Bond.Codegen.Cs.Comm_cs
src/Language/Bond/Codegen/Cpp/Apply_h.hs view
@@ -22,7 +22,7 @@ apply_h :: [Protocol] -- ^ List of protocols for which @Apply@ overloads should be generated -> Maybe String -- ^ Optional attribute to decorate the @Apply@ function declarations -> MappingContext -> String -> [Import] -> [Declaration] -> (String, Text) -apply_h protocols attribute cpp file imports declarations = ("_apply.h", [lt| +apply_h protocols export_attribute cpp file imports declarations = ("_apply.h", [lt| #pragma once #include "#{file}_types.h" @@ -31,14 +31,14 @@ #{newlineSep 0 includeImport imports} #{CPP.openNamespace cpp} - #{newlineSepEnd 1 (applyOverloads protocols cpp attr semi) declarations} + #{newlineSepEnd 1 (applyOverloads protocols cpp export_attr semi) declarations} #{CPP.closeNamespace cpp} |]) where includeImport (Import path) = [lt|#include "#{dropExtension path}_apply.h"|] - attr = optional (\a -> [lt|#{a} - |]) attribute + export_attr = optional (\a -> [lt|#{a} + |]) export_attribute semi = [lt|;|]
+ src/Language/Bond/Codegen/Cpp/Comm_cpp.hs view
@@ -0,0 +1,34 @@+-- Copyright (c) Microsoft. All rights reserved. +-- Licensed under the MIT license. See LICENSE file in the project root for full license information. + +{-# LANGUAGE QuasiQuotes, OverloadedStrings, RecordWildCards #-} + +module Language.Bond.Codegen.Cpp.Comm_cpp (comm_cpp) where + +import Data.Monoid +import Prelude +import Data.Text.Lazy (Text) +import Text.Shakespeare.Text +import Language.Bond.Syntax.Types +import Language.Bond.Codegen.TypeMapping +import Language.Bond.Codegen.Util +import qualified Language.Bond.Codegen.Cpp.Util as CPP + +-- | Codegen template for generating /base_name/_comm.cpp containing +-- definitions of helper functions and schema metadata static variables. +comm_cpp :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text) +comm_cpp cpp file _imports declarations = ("_comm.cpp", [lt| +#include "#{file}_reflection.h" +#include "#{file}_comm.h" +#include <bond/core/exception.h> + +#{CPP.openNamespace cpp} + #{doubleLineSepEnd 1 statics declarations} +#{CPP.closeNamespace cpp} +|]) + where + -- definitions of Schema statics for non-generic services + statics s@Service {..} = + if null declParams then CPP.schemaMetadata cpp s else mempty + + statics _ = mempty
src/Language/Bond/Codegen/Cpp/Comm_h.hs view
@@ -11,6 +11,7 @@ import qualified Data.Text.Lazy as L import Data.Text.Lazy.Builder import Text.Shakespeare.Text +import Language.Bond.Util import Language.Bond.Syntax.Types import Language.Bond.Syntax.Util import Language.Bond.Codegen.Util @@ -20,8 +21,8 @@ -- | Codegen template for generating /base_name/_comm.h containing declarations of -- of service interface and proxy. -comm_h :: MappingContext -> String -> [Import] -> [Declaration] -> (String, L.Text) -comm_h cpp file imports declarations = ("_comm.h", [lt| +comm_h :: Maybe String -> MappingContext -> String -> [Import] -> [Declaration] -> (String, L.Text) +comm_h export_attribute cpp file imports declarations = ("_comm.h", [lt| #pragma once #include <bond/comm/services.h> @@ -72,7 +73,7 @@ #{template}struct #{className}::Schema { - static const ::bond::Metadata metadata; + #{export_attr}static const ::bond::Metadata metadata; #{newlineSep 2 methodMetadata serviceMethods} @@ -173,10 +174,13 @@ onlyTemplate x = if null declParams then mempty else x typename = onlyTemplate [lt|typename |] + export_attr = optional (\a -> [lt|#{a} + |]) export_attribute + methodMetadataVar m = [lt|s_#{methodName m}_metadata|] methodMetadata m = - [lt|private: static const ::bond::Metadata #{methodMetadataVar m};|] + [lt|private: #{export_attr}static const ::bond::Metadata #{methodMetadataVar m};|] -- reversed list of method names zipped with indexes indexedMethods :: [(String, Int)]
src/Language/Bond/Codegen/Cpp/Reflection_h.hs view
@@ -11,6 +11,7 @@ import Data.Text.Lazy (Text) import qualified Data.Foldable as F import Text.Shakespeare.Text +import Language.Bond.Util import Language.Bond.Syntax.Types import Language.Bond.Codegen.TypeMapping import Language.Bond.Codegen.Util @@ -18,8 +19,8 @@ -- | Codegen template for generating /base_name/_reflection.h containing schema -- metadata definitions. -reflection_h :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text) -reflection_h cpp file imports declarations = ("_reflection.h", [lt| +reflection_h :: Maybe String -> MappingContext -> String -> [Import] -> [Declaration] -> (String, Text) +reflection_h export_attribute cpp file imports declarations = ("_reflection.h", [lt| #pragma once #include "#{file}_types.h" @@ -46,7 +47,7 @@ { typedef #{baseType structBase} base; - static const ::bond::Metadata metadata; + #{export_attr}static const ::bond::Metadata metadata; #{newlineBeginSep 2 fieldMetadata structFields} public: struct var @@ -71,6 +72,9 @@ className = CPP.className s + export_attr = optional (\a -> [lt|#{a} + |]) export_attribute + onlyTemplate x = if null declParams then mempty else x metadataInitArgs = onlyTemplate [lt|<boost::mpl::list#{classParams} >|] @@ -99,7 +103,7 @@ [lt|private: typedef #{typename}boost::mpl::push_front<fields#{i}, #{typename}var::#{field}>::type fields#{i + 1};|] fieldMetadata Field {..} = - [lt|private: static const ::bond::Metadata s_#{fieldName}_metadata;|] + [lt|private: #{export_attr}static const ::bond::Metadata s_#{fieldName}_metadata;|] fieldTemplates = F.foldMap $ \ f@Field {..} -> [lt| // #{fieldName}
− src/Language/Bond/Codegen/Cpp/Types_Comm_cpp.hs
@@ -1,34 +0,0 @@--- Copyright (c) Microsoft. All rights reserved. --- Licensed under the MIT license. See LICENSE file in the project root for full license information. - -{-# LANGUAGE QuasiQuotes, OverloadedStrings, RecordWildCards #-} - -module Language.Bond.Codegen.Cpp.Types_Comm_cpp (types_comm_cpp) where - -import Data.Monoid -import Prelude -import Data.Text.Lazy (Text) -import Text.Shakespeare.Text -import Language.Bond.Syntax.Types -import Language.Bond.Codegen.TypeMapping -import Language.Bond.Codegen.Util -import qualified Language.Bond.Codegen.Cpp.Util as CPP - --- | Codegen template for generating /base_name/_comm_types.cpp containing --- definitions of helper functions and schema metadata static variables. -types_comm_cpp :: MappingContext -> String -> [Import] -> [Declaration] -> (String, Text) -types_comm_cpp cpp file _imports declarations = ("_comm.cpp", [lt| -#include "#{file}_reflection.h" -#include "#{file}_comm.h" -#include <bond/core/exception.h> - -#{CPP.openNamespace cpp} - #{doubleLineSepEnd 1 statics declarations} -#{CPP.closeNamespace cpp} -|]) - where - -- definitions of Schema statics for non-generic services - statics s@Service {..} = - if null declParams then CPP.schemaMetadata cpp s else mempty - - statics _ = mempty
src/Language/Bond/Codegen/Cpp/Types_h.hs view
@@ -35,14 +35,12 @@ #{newlineBeginSep 0 includeHeader userHeaders} #include <bond/core/bond_version.h> -#if BOND_VERSION < 0x0422 -#error This file was generated by a newer version of Bond compiler -#error and is incompatible with your version Bond library. +#if BOND_VERSION < 0x0520 +#error This file was generated by a newer version of the Bond compiler and is incompatible with your version of the Bond library. #endif #if BOND_MIN_CODEGEN_VERSION > 0x#{hexVersion version} -#error This file was generated by an older version of Bond compiler -#error and is incompatible with your version Bond library. +#error This file was generated by an older version of the Bond compiler and is incompatible with your version of the Bond library. #endif #include <bond/core/config.h>
src/Language/Bond/Codegen/Cpp/Util.hs view
@@ -103,6 +103,7 @@ enumValue :: ToText a => MappingContext -> Type -> a -> Text enumValue cpp (BT_UserDefined e@Enum {..} _) x = [lt|#{getQualifiedName cpp $ getDeclNamespace cpp e}::_bond_enumerators::#{declName}::#{x}|] +enumValue cpp (BT_UserDefined a@Alias {..} args) e = enumValue cpp (resolveAlias a args) e enumValue _ _ _ = error "enumValue: impossible happened." -- schema metadata static member definitions
src/Language/Bond/Codegen/Cs/Comm_cs.hs view
@@ -49,7 +49,7 @@ where csNamespace = sepBy "." toText $ getNamespace cs - comm s@Service{..} = [lt|#{CS.typeAttributes cs s}interface I#{declName}#{generics} + comm s@Service{..} = [lt|#{CS.typeAttributes cs s}public interface I#{declName}#{generics} { #{doubleLineSep 2 methodDeclaration serviceMethods} }
src/Language/Bond/Codegen/Templates.hs view
@@ -36,7 +36,6 @@ -- ** C++ types_h , types_cpp - , types_comm_cpp , reflection_h , enum_h , apply_h @@ -44,6 +43,7 @@ , Protocol(..) -- ** C++ Comm , comm_h + , comm_cpp -- ** C# , FieldMapping(..) , StructMapping(..) @@ -60,8 +60,8 @@ import Language.Bond.Codegen.Cpp.Enum_h import Language.Bond.Codegen.Cpp.Reflection_h import Language.Bond.Codegen.Cpp.Types_cpp -import Language.Bond.Codegen.Cpp.Types_Comm_cpp import Language.Bond.Codegen.Cpp.Types_h +import Language.Bond.Codegen.Cpp.Comm_cpp import Language.Bond.Codegen.Cpp.Comm_h import Language.Bond.Codegen.Cs.Types_cs import Language.Bond.Codegen.Cs.Comm_cs
tests/Main.hs view
@@ -92,12 +92,20 @@ , "--using=String=my::string" ] "custom_alias_without_allocator" - , verifyApplyCodegen - [ "c++" - , "--apply-attribute=DllExport" + , testGroup "Apply" + [ verifyApplyCodegen + [ "c++" + , "--apply-attribute=DllExport" + ] + "basic_types" ] - "basic_types" - ] + , testGroup "Exports" + [ verifyExportsCodegen + [ "c++" + , "--export-attribute=DllExport" + ] + "service" + ] , testGroup "Comm" [ verifyCppCommCodegen [ "c++" @@ -112,7 +120,8 @@ ] "service_attributes" ] - , testGroup "C#" + ] + , testGroup "C#" [ verifyCsCodegen "attributes" , verifyCsCodegen "basic_types" , verifyCsCodegen "bond_meta"
tests/Tests/Codegen.hs view
@@ -9,6 +9,7 @@ , verifyCppCodegen , verifyCppCommCodegen , verifyApplyCodegen + , verifyExportsCodegen , verifyCsCodegen , verifyCsCommCodegen ) where @@ -50,7 +51,7 @@ where options = processOptions args templates = - [ apply_h protocols (apply_attribute options) + [ apply_h protocols (export_attribute options) , apply_cpp protocols ] protocols = @@ -62,14 +63,28 @@ "bond::SimpleBinaryWriter<bond::OutputBuffer>" ] +verifyExportsCodegen :: [String] -> FilePath -> TestTree +verifyExportsCodegen args baseName = + testGroup baseName $ + map (verifyFile options baseName cppTypeMapping "exports") templates + where + options = processOptions args + templates = + [ reflection_h (export_attribute options) + , comm_h (export_attribute options) + ] + verifyCppCommCodegen :: [String] -> FilePath -> TestTree verifyCppCommCodegen args baseName = testGroup baseName $ - map (verifyFile (processOptions args) baseName cppTypeMapping "") - [ comm_h - , types_cpp - , types_comm_cpp - ] + map (verifyFile options baseName cppTypeMapping "") templates + where + options = processOptions args + templates = + [ comm_h (export_attribute options) + , comm_cpp + , types_cpp + ] verifyCsCommCodegen :: [String] -> FilePath -> TestTree verifyCsCommCodegen args baseName = @@ -102,9 +117,9 @@ typeMapping Cpp {..} = maybe cppTypeMapping cppCustomAllocTypeMapping allocator typeMapping Cs {} = csTypeMapping templates Cpp {..} = - [ reflection_h + [ (reflection_h export_attribute) , types_cpp - , types_comm_cpp + , comm_cpp , types_h header enum_header allocator ] templates Cs {..} =