bond-0.8.0.0: Bond schema compiler and code generator

Copyright(c) Microsoft
LicenseMIT
Maintaineradamsap@microsoft.com
Stabilityprovisional
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Language.Bond.Codegen.TypeMapping

Contents

Description

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

Synopsis

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.

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.

Constructors

AliasMapping 

Fields

data Fragment Source #

Specification of a fragment of type alias mappings.

Constructors

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.

Constructors

NamespaceMapping 

Fields

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.