Copyright | (c) Microsoft |
---|---|
License | MIT |
Maintainer | adamsap@microsoft.com |
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
This module defines abstractions for mapping from the Bond type system into the type system of a target programming language.
- data MappingContext = MappingContext {}
- data TypeMapping = TypeMapping {}
- type TypeNameBuilder = Reader MappingContext Builder
- idlTypeMapping :: TypeMapping
- cppTypeMapping :: TypeMapping
- cppCustomAllocTypeMapping :: ToText a => a -> TypeMapping
- csTypeMapping :: TypeMapping
- csCollectionInterfacesTypeMapping :: TypeMapping
- data AliasMapping = AliasMapping {}
- data Fragment
- parseAliasMapping :: String -> Either ParseError AliasMapping
- data NamespaceMapping = NamespaceMapping {}
- parseNamespaceMapping :: String -> Either ParseError NamespaceMapping
- getTypeName :: MappingContext -> Type -> Builder
- getInstanceTypeName :: MappingContext -> Type -> Builder
- getAnnotatedTypeName :: MappingContext -> Type -> Builder
- getDeclTypeName :: MappingContext -> Declaration -> Builder
- getQualifiedName :: MappingContext -> QualifiedName -> Builder
- getNamespace :: MappingContext -> QualifiedName
- getDeclNamespace :: MappingContext -> Declaration -> QualifiedName
- customAliasMapping :: MappingContext -> Declaration -> Bool
- elementTypeName :: Type -> TypeNameBuilder
- aliasTypeName :: Declaration -> [Type] -> TypeNameBuilder
- declTypeName :: Declaration -> TypeNameBuilder
- declQualifiedTypeName :: Declaration -> TypeNameBuilder
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 #
A type representing a type mapping.
TypeMapping | |
|
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.
AliasMapping | |
|
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.
Examples
> 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.
NamespaceMapping | |
|
parseNamespaceMapping :: String -> Either ParseError NamespaceMapping Source #
Parse a namespace mapping specification used in command-line arguments of gbc.
Examples
> 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
.
TypeMapping helper functions
elementTypeName :: Type -> TypeNameBuilder Source #
Builder for nested element types (e.g. list elements) in context of TypeNameBuilder
monad.
Used to implement mapType
function of TypeMapping
.
aliasTypeName :: Declaration -> [Type] -> TypeNameBuilder Source #
Builder for the type alias name in context of TypeNameBuilder
monad.
Used to implement mapType
function of TypeMapping
.
declTypeName :: Declaration -> TypeNameBuilder Source #
Builder for the name for a Declaration
in context of TypeNameBuilder
monad.
Used to implement mapType
function of TypeMapping
.
declQualifiedTypeName :: Declaration -> TypeNameBuilder Source #
Builder for the qualified name for a Declaration
in context of TypeNameBuilder
monad.
Used to implement mapType
function of TypeMapping
.