bond- Bond schema compiler and code generator

Copyright(c) Microsoft
Safe HaskellNone




This module defines abstractions for mapping from the Bond type system into the type system of a target programming language.


Mapping context

data MappingContext Source #

The MappingContext encapsulates information about mapping Bond types into types in the target language. A context instance is passed to code generation templates.

data TypeMapping Source #

An opaque type representing a type mapping.

Type mappings

idlTypeMapping :: TypeMapping Source #

The Bond IDL type name mapping.

cppTypeMapping :: TypeMapping Source #

The default C++ type name mapping.

cppCustomAllocTypeMapping :: ToText a => a -> TypeMapping Source #

C++ type name mapping using a custom allocator.

csTypeMapping :: TypeMapping Source #

The default C# type name mapping.

csCollectionInterfacesTypeMapping :: TypeMapping Source #

C# type name mapping using interfaces rather than concrete types to represent collections.

Alias mapping

Type aliases defined in a schema can optionally be mapped to user specified types.

data AliasMapping Source #

Specification of a type alias mapping.




data Fragment Source #

Specification of a fragment of type alias mappings.


Fragment String

hardcoded string fragment

Placeholder Int

placeholder for the n-th type argument of the type alias, applicable only to generic aliases

parseAliasMapping :: String -> Either ParseError AliasMapping Source #

Parse a type alias mapping specification used in command-line arguments of gbc.


> parseAliasMapping "Example.OrderedSet=SortedSet<{0}>"
Right (AliasMapping {aliasName = ["Example","OrderedSet"], aliasTemplate = [Fragment "SortedSet<",Placeholder 0,Fragment ">"]})

Namespace mapping

Schema namespaces can be mapped into languange-specific namespaces in the generated code.

data NamespaceMapping Source #

Specification of namespace mapping.




parseNamespaceMapping :: String -> Either ParseError NamespaceMapping Source #

Parse a namespace mapping specification used in command-line arguments of gbc.


> parseNamespaceMapping "bond=Microsoft.Bond"
Right (NamespaceMapping {fromNamespace = ["bond"], toNamespace = ["Microsoft","Bond"]})

Name builders

getTypeName :: MappingContext -> Type -> Builder Source #

Builds the name of a Type in the specified MappingContext.

getInstanceTypeName :: MappingContext -> Type -> Builder Source #

Builds the name to be used when instantiating a Type. The instance type name may be different than the type name returned by getTypeName when the latter is an interface.

getAnnotatedTypeName :: MappingContext -> Type -> Builder Source #

Builds the annotated name of a Type. The type annotations are used to express type information about a Bond type that doesn't directly map to the target language type system (e.g. distinction between a nullable and non-nullable string in C# type system).

getDeclTypeName :: MappingContext -> Declaration -> Builder Source #

Builds the qualified name for a Declaration in the specified MappingContext.

getQualifiedName :: MappingContext -> QualifiedName -> Builder Source #

Builds a qualified name in the specified MappingContext.

Helper functions

getNamespace :: MappingContext -> QualifiedName Source #

Returns the namespace for the MappingContext. The namespace may be different than specified in the schema definition file due to namespace mapping.

getDeclNamespace :: MappingContext -> Declaration -> QualifiedName Source #

Returns the namespace for a Declaration in the specified MappingContext.

customAliasMapping :: MappingContext -> Declaration -> Bool Source #

Returns True if the alias has a custom mapping in the given MappingContext.