hoppy-generator-0.3.3: C++ FFI generator - Code generator

Safe HaskellNone
LanguageHaskell2010

Foreign.Hoppy.Generator.Spec

Contents

Description

The primary data types for specifying C++ interfaces.

Show instances in this module produce strings of the form "<TypeOfObject nameOfObject otherInfo...>". They can be used in error messages without specifying a noun separately, i.e. write show cls instead of "the class " ++ show cls.

Synopsis

Interfaces

data Interface #

A complete specification of a C++ API. Generators for different languages, including the binding generator for C++, use these to produce their output.

Interface does not have a HandlesExceptions instance because modifyExceptionHandlers does not work for it (handled exceptions cannot be modified after an Interface is constructed).

type ErrorMsg = String #

Indicates strings that are error messages.

data InterfaceOptions #

Optional parameters when constructing an Interface with interface.

defaultInterfaceOptions :: InterfaceOptions #

Options used by interface. This contains no exception handlers.

interface #

Constructs an Interface from the required parts. Some validation is performed; if the resulting interface would be invalid, an error message is returned instead.

This function passes defaultInterfaceOptions to interface'.

interface' #

Same as interface, but accepts some optional arguments.

interfaceName :: Interface -> String #

The textual name of the interface.

interfaceModules :: Interface -> Map String Module #

All of the individual modules, by moduleName.

interfaceNamesToModules :: Interface -> Map ExtName Module #

Maps each ExtName exported by some module to the module that exports the name.

interfaceHaskellModuleBase :: Interface -> [String] #

The name of the parent Haskell module under which a Haskell module will be generated for a Hoppy Module. This is a list of Haskell module path components, in other words, intercalate "." on the list produces a Haskell module name. Defaults to interfaceDefaultHaskellModuleBase, and may be overridden with interfaceAddHaskellModuleBase.

interfaceDefaultHaskellModuleBase :: [String] #

The default Haskell module under which Hoppy modules will be generated. This is Foreign.Hoppy.Generated, that is:

["Foreign", "Hoppy", "Generated"]

interfaceAddHaskellModuleBase :: [String] -> Interface -> Either String Interface #

Sets an interface to generate all of its modules under the given Haskell module prefix. See interfaceHaskellModuleBase.

interfaceHaskellModuleImportNames :: Interface -> Map Module String #

Short qualified module import names that generated modules use to refer to each other tersely.

interfaceExceptionHandlers :: Interface -> ExceptionHandlers #

Exceptions that all functions in the interface may throw.

interfaceCallbacksThrow :: Interface -> Bool #

Whether callbacks within the interface support throwing C++ exceptions from Haskell into C++ during their execution. This may be overridden by moduleCallbacksThrow and callbackThrows.

interfaceSetCallbacksThrow :: Bool -> Interface -> Interface #

Changes callbackThrows for all callbacks in an interface that don't have it set explicitly at the module or callback level.

interfaceExceptionClassId :: Interface -> Class -> Maybe ExceptionId #

Returns the the exception ID for a class in an interface, if it has one (i.e. if it's been marked as an exception class with classMakeException).

interfaceExceptionSupportModule :: Interface -> Maybe Module #

When an interface uses C++ exceptions, then one module needs to manually be selected to contain some interface-specific runtime support. This is the selected module.

interfaceSetExceptionSupportModule :: Module -> Interface -> Interface #

Sets an interface's exception support module, for interfaces that use exceptions.

C++ includes

data Include #

An #include directive in a C++ file.

includeStd :: String -> Include #

Creates an #include <...> directive.

includeLocal :: String -> Include #

Creates an #include "..." directive.

includeToString :: Include -> String #

Returns the complete #include ... line for an include, including trailing newline.

Modules

data Module #

A portion of functionality in a C++ API. An Interface is composed of multiple modules. A module will generate a single compilation unit containing bindings for all of the module's exports. The C++ code for a generated module will #include everything necessary for what is written to the header and source files separately. You can declare include dependencies with e.g. addReqIncludes, either for individual exports or at the module level. Dependencies between modules are handled automatically, and circularity is supported to a certain extent. See the documentation for the individual language modules for further details.

moduleName :: Module -> String #

The module's name. A module name must identify a unique module within an Interface.

moduleHppPath :: Module -> String #

A relative path under a C++ sources root to which the generator will write a header file for the module's C++ bindings.

moduleCppPath :: Module -> String #

A relative path under a C++ sources root to which the generator will write a source file for the module's C++ bindings.

moduleExports :: Module -> Map ExtName Export #

All of the exports in a module.

moduleReqs :: Module -> Reqs #

Module-level requirements.

moduleExceptionHandlers :: Module -> ExceptionHandlers #

Exceptions that all functions in the module may throw.

moduleCallbacksThrow :: Module -> Maybe Bool #

Whether callbacks exported from the module support exceptions being thrown during their execution. When present, this overrides interfaceCallbacksThrow. This maybe overridden by callbackThrows.

moduleSetCallbacksThrow :: MonadState Module m => Maybe Bool -> m () #

Changes callbackThrows for all callbacks in a module that don't have it set explicitly.

moduleAddendum :: Module -> Addendum #

The module's addendum.

moduleHaskellName :: Module -> Maybe [String] #

The generated Haskell module name, underneath the interfaceHaskellModuleBase. If absent (by default), the moduleName is used. May be modified with moduleAddHaskellName.

makeModule #

Creates an empty module, ready to be configured with moduleModify.

moduleModify :: Module -> StateT Module (Either String) () -> Either ErrorMsg Module #

Extends a module. To be used with the module state-monad actions in this package.

moduleModify' :: Module -> StateT Module (Either String) () -> Module #

Same as moduleModify, but calls error in the case of failure, which is okay in for a generator which would abort in this case anyway.

moduleSetHppPath :: MonadState Module m => String -> m () #

Replaces a module's moduleHppPath.

moduleSetCppPath :: MonadState Module m => String -> m () #

Replaces a module's moduleCppPath.

moduleAddExports :: (MonadError String m, MonadState Module m) => [Export] -> m () #

Adds exports to a module. An export must only be added to any module at most once, and must not be added to multiple modules.

moduleAddHaskellName :: (MonadError String m, MonadState Module m) => [String] -> m () #

Changes a module's moduleHaskellName from the default. This can only be called once on a module.

Requirements

data Reqs #

A set of requirements of needed to use an identifier in C++ (function, type, etc.), via a set of Includes. The monoid instance has mempty as an empty set of includes, and mappend unions two include sets.

Instances

Show Reqs # 

Methods

showsPrec :: Int -> Reqs -> ShowS #

show :: Reqs -> String #

showList :: [Reqs] -> ShowS #

Monoid Reqs # 

Methods

mempty :: Reqs #

mappend :: Reqs -> Reqs -> Reqs #

mconcat :: [Reqs] -> Reqs #

reqsIncludes :: Reqs -> Set Include #

The includes specified by a Reqs.

reqInclude :: Include -> Reqs #

Creates a Reqs that contains the given include.

class HasReqs a where #

C++ types that have requirements in order to use them in generated bindings.

Minimal complete definition

getReqs, (setReqs | modifyReqs)

Methods

getReqs :: a -> Reqs #

Returns an object's requirements.

setReqs :: Reqs -> a -> a #

Replaces an object's requirements with new ones.

modifyReqs :: (Reqs -> Reqs) -> a -> a #

Modifies an object's requirements.

addReqs :: HasReqs a => Reqs -> a -> a #

Adds to a object's requirements.

addReqIncludes :: HasReqs a => [Include] -> a -> a #

Adds a list of includes to the requirements of an object.

Names and exports

data ExtName #

An external name is a string that generated bindings use to uniquely identify an object at runtime. An external name must start with an alphabetic character, and may only contain alphanumeric characters and '_'. You are free to use whatever naming style you like; case conversions will be performed automatically when required. Hoppy does make use of some conventions though, for example with Operators and in the provided bindings for the C++ standard library.

External names must be unique within an interface. They may not be reused between modules. This assumption is used for symbol naming in compiled shared objects and to freely import modules in Haskell bindings.

toExtName :: String -> ExtName #

Creates an ExtName that contains the given string, erroring if the string is an invalid ExtName.

isValidExtName :: String -> Bool #

Returns true if the given string is represents a valid ExtName.

fromExtName :: ExtName -> String #

Returns the string an an ExtName contains.

class HasExtNames a where #

Types that have an external name, and also optionally have nested entities with external names as well. See getAllExtNames.

Minimal complete definition

getPrimaryExtName

Methods

getPrimaryExtName :: a -> ExtName #

Returns the external name by which a given entity is referenced.

getNestedExtNames :: a -> [ExtName] #

Returns external names nested within the given entity. Does not include the primary external name.

getAllExtNames :: HasExtNames a => a -> [ExtName] #

Returns a list of all of the external names an entity contains. This combines both getPrimaryExtName and getNestedExtNames.

data FnName name #

The C++ name of a function or method.

Constructors

FnName name

A regular, "alphanumeric" name. The exact type depends on what kind of object is being named.

FnOp Operator

An operator name.

Instances

IsFnName t (FnName t) # 

Methods

toFnName :: FnName t -> FnName t #

Eq name => Eq (FnName name) # 

Methods

(==) :: FnName name -> FnName name -> Bool #

(/=) :: FnName name -> FnName name -> Bool #

Ord name => Ord (FnName name) # 

Methods

compare :: FnName name -> FnName name -> Ordering #

(<) :: FnName name -> FnName name -> Bool #

(<=) :: FnName name -> FnName name -> Bool #

(>) :: FnName name -> FnName name -> Bool #

(>=) :: FnName name -> FnName name -> Bool #

max :: FnName name -> FnName name -> FnName name #

min :: FnName name -> FnName name -> FnName name #

Show name => Show (FnName name) # 

Methods

showsPrec :: Int -> FnName name -> ShowS #

show :: FnName name -> String #

showList :: [FnName name] -> ShowS #

class IsFnName t a where #

Enables implementing automatic conversions to a FnName t.

Minimal complete definition

toFnName

Methods

toFnName :: a -> FnName t #

Instances

IsFnName t Operator # 

Methods

toFnName :: Operator -> FnName t #

IsFnName t t # 

Methods

toFnName :: t -> FnName t #

IsFnName t (FnName t) # 

Methods

toFnName :: FnName t -> FnName t #

data Operator #

Overloadable C++ operators.

data OperatorType #

The arity and syntax of an operator.

Constructors

UnaryPrefixOperator String

Prefix unary operators. Examples: !x, *x, ++x.

UnaryPostfixOperator String

Postfix unary operators. Examples: x--, x++.

BinaryOperator String

Infix binary operators. Examples: x * y, x >>= y.

CallOperator

x(...) with arbitrary arity.

ArrayOperator

x[y], a binary operator with non-infix syntax.

operatorPreferredExtName :: Operator -> ExtName #

Returns a conventional string to use for the ExtName of an operator.

operatorPreferredExtName' :: Operator -> String #

Returns a conventional name for an operator, as with operatorPreferredExtName, but as a string.

operatorType :: Operator -> OperatorType #

Returns the type of an operator.

data Export #

Specifies some C++ object (function or class) to give access to.

Constructors

ExportVariable Variable

Exports a variable.

ExportEnum CppEnum

Exports an enum.

ExportBitspace Bitspace

Exports a bitspace.

ExportFn Function

Exports a function.

ExportClass Class

Exports a class with all of its contents.

ExportCallback Callback

Exports a callback.

exportAddendum :: Export -> Addendum #

Returns the export's addendum. Export doesn't have a HasAddendum instance because you normally wouldn't want to modify the addendum of one.

data Identifier #

A path to some C++ object, including namespaces. An identifier consists of multiple parts separated by "::". Each part has a name string followed by an optional template argument list, where each argument gets rendered from a Type (non-type arguments for template metaprogramming are not supported).

identifierParts :: Identifier -> [IdPart] #

The separate parts of the identifier, between ::s.

data IdPart #

A single component of an Identifier, between ::s.

Instances

Eq IdPart # 

Methods

(==) :: IdPart -> IdPart -> Bool #

(/=) :: IdPart -> IdPart -> Bool #

Show IdPart # 

idPartBase :: IdPart -> String #

The name within the enclosing scope.

idPartArgs :: IdPart -> Maybe [Type] #

Template arguments, if present.

ident :: String -> Identifier #

Creates an identifier of the form a.

ident' :: [String] -> Identifier #

Creates an identifier of the form a1::a2::...::aN.

ident1 :: String -> String -> Identifier #

Creates an identifier of the form a::b.

ident2 :: String -> String -> String -> Identifier #

Creates an identifier of the form a::b::c.

ident3 :: String -> String -> String -> String -> Identifier #

Creates an identifier of the form a::b::c::d.

ident4 :: String -> String -> String -> String -> String -> Identifier #

Creates an identifier of the form a::b::c::d::e.

ident5 :: String -> String -> String -> String -> String -> String -> Identifier #

Creates an identifier of the form a::b::c::d::e::f.

identT :: String -> [Type] -> Identifier #

Creates an identifier of the form a<...>.

identT' :: [(String, Maybe [Type])] -> Identifier #

Creates an identifier with arbitrary many templated and non-templated parts.

ident1T :: String -> String -> [Type] -> Identifier #

Creates an identifier of the form a::b<...>.

ident2T :: String -> String -> String -> [Type] -> Identifier #

Creates an identifier of the form a::b::c<...>.

ident3T :: String -> String -> String -> String -> [Type] -> Identifier #

Creates an identifier of the form a::b::c::d<...>.

ident4T :: String -> String -> String -> String -> String -> [Type] -> Identifier #

Creates an identifier of the form a::b::c::d::e<...>.

ident5T :: String -> String -> String -> String -> String -> String -> [Type] -> Identifier #

Creates an identifier of the form a::b::c::d::e::f<...>.

Basic types

normalizeType :: Type -> Type #

Canonicalizes a Type without changing its meaning. Multiple nested Internal_TConsts are collapsed into a single one.

stripConst :: Type -> Type #

Strips leading Internal_TConsts off of a type.

Variables

makeVariable :: Identifier -> Maybe ExtName -> Type -> Variable #

Creates a binding for a C++ variable.

varIdentifier :: Variable -> Identifier #

The identifier used to refer to the variable.

varExtName :: Variable -> ExtName #

The variable's external name.

varType :: Variable -> Type #

The variable's type. This may be constT to indicate that the variable is read-only.

varReqs :: Variable -> Reqs #

Requirements for bindings to use this variable.

varIsConst :: Variable -> Bool #

Returns whether the variable is constant, i.e. whether its type is constT ....

varGetterExtName :: Variable -> ExtName #

Returns the external name of the getter function for the variable.

varSetterExtName :: Variable -> ExtName #

Returns the external name of the setter function for the variable.

Enums

data CppEnum #

A C++ enum declaration. An enum should actually be enumerable (in the sense of Haskell's Enum); if it's not, consider using a Bitspace instead.

makeEnum #

Arguments

:: Identifier

enumIdentifier

-> Maybe ExtName

An optional external name; will be automatically derived from the identifier if absent.

-> [(Int, [String])]

enumValueNames

-> CppEnum 

Creates a binding for a C++ enum.

enumIdentifier :: CppEnum -> Identifier #

The identifier used to refer to the enum.

enumExtName :: CppEnum -> ExtName #

The enum's external name.

enumValueNames :: CppEnum -> [(Int, [String])] #

The numeric values and names of the enum values. A single value's name is broken up into words. How the words and ext name get combined to make a name in a particular foreign language depends on the language.

enumReqs :: CppEnum -> Reqs #

Requirements for a Type to reference this enum.

enumValuePrefix :: CppEnum -> String #

The prefix applied to value names (enumValueNames) when determining the names of values in foreign languages. This defaults to the external name of the enum, plus an underscore.

See enumSetValuePrefix.

enumSetValuePrefix :: String -> CppEnum -> CppEnum #

Sets the prefix applied to the names of enum values' identifiers in foreign languages.

See enumValuePrefix.

Bitspaces

data Bitspace #

A C++ numeric space with bitwise operations. This is similar to a CppEnum, but in addition to the extra operations, this differs in that these values aren't enumerable.

Additionally, as a kludge for Qtah, a bitspace may have a C++ type (bitspaceCppTypeIdentifier) separate from its numeric type (bitspaceType). Qt bitspaces aren't raw numbers but are instead type-safe QFlags objects that don't implicitly convert from integers, so we need a means to do so manually. Barring general ad-hoc argument and return value conversion support, we allow this as follows: when given a C++ type, then a bitspace may also have a conversion function between the numeric and C++ type, in each direction. If a conversion function is present, it will be used for conversions in its respective direction. The C++ type is not a full Type, but only an Identifier, since additional information is not needed. See bitspaceAddCppType.

makeBitspace #

Creates a binding for a C++ bitspace.

bitspaceExtName :: Bitspace -> ExtName #

The bitspace's external name.

bitspaceType :: Bitspace -> Type #

The C++ type used for bits values. This should be a primitive numeric type, usually intT.

bitspaceValueNames :: Bitspace -> [(Int, [String])] #

The numeric values and names of the bitspace values. See enumValueNames.

bitspaceEnum :: Bitspace -> Maybe CppEnum #

An associated enum, whose values may be converted to values in the bitspace.

bitspaceAddEnum :: CppEnum -> Bitspace -> Bitspace #

Associates an enum with the bitspace. See bitspaceEnum.

bitspaceCppTypeIdentifier :: Bitspace -> Maybe Identifier #

The optional C++ type for a bitspace.

bitspaceFromCppValueFn :: Bitspace -> Maybe String #

The name of a C++ function to convert from the bitspace's C++ type to bitspaceType.

bitspaceToCppValueFn :: Bitspace -> Maybe String #

The name of a C++ function to convert from bitspaceType to the bitspace's C++ type.

bitspaceAddCppType :: Identifier -> Maybe String -> Maybe String -> Bitspace -> Bitspace #

bitspaceAddCppType cppTypeIdentifier toCppValueFn fromCppValueFn associates a C++ type (plus optional conversion functions) with a bitspace. At least one conversion should be specified, otherwise adding the C++ type will mean nothing. You should also add use requirements to the bitspace for all of these arguments; see HasReqs.

bitspaceReqs :: Bitspace -> Reqs #

Requirements for emitting the bindings for a bitspace, i.e. what's necessary to reference bitspaceCppTypeIdentifier, bitspaceFromCppValueFn, and bitspaceToCppValueFn. bitspaceType can take some numeric types that require includes as well, but you don't need to list these here.

bitspaceValuePrefix :: Bitspace -> String #

The prefix applied to value names (bitspaceValueNames) when determining the names of values in foreign languages. This defaults to the external name of the bitspace, plus an underscore.

See bitspaceSetValuePrefix.

bitspaceSetValuePrefix :: String -> Bitspace -> Bitspace #

Sets the prefix applied to the names of enum values' identifiers in foreign languages.

See enumValuePrefix.

Functions

data Purity #

Whether or not a function may cause side-effects.

Haskell bindings for pure functions will not be in IO, and calls to pure functions will be executed non-strictly. Calls to impure functions will execute in the IO monad.

Member functions for mutable classes should not be made pure, because it is difficult in general to control when the call will be made.

Constructors

Nonpure

Side-affects are possible.

Pure

Side-affects will not happen.

Instances

Eq Purity # 

Methods

(==) :: Purity -> Purity -> Bool #

(/=) :: Purity -> Purity -> Bool #

Show Purity # 

makeFn #

Arguments

:: IsFnName Identifier name 
=> name 
-> Maybe ExtName

An optional external name; will be automatically derived from the identifier if absent.

-> Purity 
-> [Type]

Parameter types.

-> Type

Return type.

-> Function 

Creates a binding for a C++ function.

fnCName :: Function -> FnName Identifier #

The identifier used to call the function.

fnExtName :: Function -> ExtName #

The function's external name.

fnPurity :: Function -> Purity #

Whether the function is pure.

fnParams :: Function -> [Type] #

The function's parameter types.

fnReturn :: Function -> Type #

The function's return type.

fnReqs :: Function -> Reqs #

Requirements for a binding to call the function.

fnExceptionHandlers :: Function -> ExceptionHandlers #

Exceptions that the function might throw.

Classes

data Class #

A C++ class declaration. See IsClassEntity for more information about the interaction between a class's names and the names of entities within the class.

makeClass #

Arguments

:: Identifier 
-> Maybe ExtName

An optional external name; will be automatically derived from the identifier if absent by dropping leading namespaces, and taking the last component (sans template arguments).

-> [Class]

Superclasses.

-> [ClassEntity] 
-> Class 

Creates a binding for a C++ class and its contents.

classIdentifier :: Class -> Identifier #

The identifier used to refer to the class.

classExtName :: Class -> ExtName #

The class's external name.

classSuperclasses :: Class -> [Class] #

The class's public superclasses.

classEntities :: Class -> [ClassEntity] #

The class's entities.

classAddEntities :: [ClassEntity] -> Class -> Class #

Adds constructors to a class.

classVariables :: Class -> [ClassVariable] #

Returns all of the class's variables.

classCtors :: Class -> [Ctor] #

Returns all of the class's constructors.

classMethods :: Class -> [Method] #

Returns all of the class's methods, including methods generated from Props.

classDtorIsPublic :: Class -> Bool #

The class's methods.

classSetDtorPrivate :: Class -> Class #

Marks a class's destructor as private, so that a binding for it won't be generated.

classConversion :: Class -> ClassConversion #

Behaviour for converting objects to and from foriegn values.

classReqs :: Class -> Reqs #

Requirements for a Type to reference this class.

classEntityPrefix :: Class -> String #

The prefix applied to the external names of entities (methods, etc.) within this class when determining the names of foreign languages' corresponding bindings. This defaults to the external name of the class, plus an underscore. Changing this allows you to potentially have entities with the same foreign name in separate modules. This may be the empty string, in which case the foreign name will simply be the external name of the entity.

This does not affect the things' external names themselves; external names must still be unique in an interface. For instance, a method with external name bar in a class with external name Flab and prefix Flob_ will use the effective external name Flab_bar, but the generated name in say Haskell would be Flob_bar.

See IsClassEntity and classSetEntityPrefix.

classSetEntityPrefix :: String -> Class -> Class #

Sets the prefix applied to foreign languages' entities generated from methods, etc. within the class.

See IsClassEntity and classEntityPrefix.

classIsMonomorphicSuperclass :: Class -> Bool #

This is true for classes passed through classSetMonomorphicSuperclass.

classSetMonomorphicSuperclass :: Class -> Class #

Explicitly marks a class as being monomorphic (i.e. not having any virtual methods or destructors). By default, Hoppy assumes that a class that is derived is also polymorphic, but it can happen that this is not the case. Downcasting with dynamic_cast from such classes is not available. See also classSetSubclassOfMonomorphic.

classIsSubclassOfMonomorphic :: Class -> Bool #

This is true for classes passed through classSetSubclassOfMonomorphic.

classSetSubclassOfMonomorphic :: Class -> Class #

Marks a class as being derived from some monomorphic superclass. This prevents any downcasting to this class. Generally it is better to use classSetMonomorphicSuperclass on the specific superclasses that are monomorphic, but in cases where this is not possible, this function can be applied to the subclass instead.

classIsException :: Class -> Bool #

Whether to support using the class as a C++ exception.

classMakeException :: Class -> Class #

Marks a class as being used as an exception. This makes the class throwable and catchable.

data ClassEntity #

A C++ entity that belongs to a class.

class IsClassEntity a where #

Things that live inside of a class, and have the class's external name prepended to their own in generated code. With an external name of "bar" and a class with external name "foo", the resulting name will be "foo_bar".

See classEntityPrefix and classSetEntityPrefix.

Minimal complete definition

classEntityExtNameSuffix

Methods

classEntityExtNameSuffix :: a -> ExtName #

Extracts the external name of the object, without the class name added.

classEntityExtName :: IsClassEntity a => Class -> a -> ExtName #

Computes the external name to use in generated code, containing both the class's and object's external names. This is the concatenation of the class's and entity's external names, separated by an underscore.

classEntityForeignName :: IsClassEntity a => Class -> a -> ExtName #

Computes the name under which a class entity is to be exposed in foreign languages. This is the concatenation of a class's entity prefix, and the external name of the entity.

classEntityForeignName' :: Class -> ExtName -> ExtName #

Computes the name under which a class entity is to be exposed in foreign languages, given a class and an entity's external name. The result is the concatenation of a class's entity prefix, and the external name of the entity.

makeClassVariable :: String -> Maybe ExtName -> Type -> Staticness -> Bool -> ClassEntity #

Creates a ClassVariable with full generality and manual name specification.

The result is wrapped in a CEVar. For an unwrapped value, use makeClassVariable_.

mkClassVariable :: String -> Type -> ClassEntity #

Creates a ClassVariable for a nonstatic class variable for class::varName whose external name is class_varName.

The result is wrapped in a CEVar. For an unwrapped value, use mkClassVariable_.

mkClassVariable_ :: String -> Type -> ClassVariable #

The unwrapped version of mkClassVariable.

mkStaticClassVariable :: String -> Type -> ClassEntity #

Same as mkClassVariable, but returns a static variable instead.

The result is wrapped in a CEVar. For an unwrapped value, use mkStaticClassVariable_.

classVarCName :: ClassVariable -> String #

The variable's C++ name.

classVarExtName :: ClassVariable -> ExtName #

The variable's external name.

classVarType :: ClassVariable -> Type #

The variable's type. This may be constT to indicate that the variable is read-only.

classVarStatic :: ClassVariable -> Staticness #

Whether the variable is static (i.e. whether it exists once in the class itself and not in each instance).

classVarGettable :: ClassVariable -> Bool #

Whether the variable should have an accompanying getter. Note this exists only for disabling getters on callback variables - as there is currently no functionality to pass callbacks out of c++

classVarGetterExtName :: Class -> ClassVariable -> ExtName #

Returns the external name of the getter function for the class variable.

classVarGetterForeignName :: Class -> ClassVariable -> ExtName #

Returns the foreign name of the getter function for the class variable.

classVarSetterExtName :: Class -> ClassVariable -> ExtName #

Returns the external name of the setter function for the class variable.

classVarSetterForeignName :: Class -> ClassVariable -> ExtName #

Returns the foreign name of the setter function for the class variable.

makeCtor #

Arguments

:: ExtName 
-> [Type]

Parameter types.

-> ClassEntity 

Creates a Ctor with full generality.

The result is wrapped in a CECtor. For an unwrapped value, use makeCtor_.

makeCtor_ :: ExtName -> [Type] -> Ctor #

The unwrapped version of makeCtor.

mkCtor #

Arguments

:: String 
-> [Type]

Parameter types.

-> ClassEntity 

mkCtor name creates a Ctor whose external name is className_name.

The result is wrapped in a CECtor. For an unwrapped value, use makeCtor_.

mkCtor_ :: String -> [Type] -> Ctor #

The unwrapped version of mkCtor.

ctorExtName :: Ctor -> ExtName #

The constructor's external name.

ctorParams :: Ctor -> [Type] #

The constructor's parameter types.

ctorExceptionHandlers :: Ctor -> ExceptionHandlers #

Exceptions that the constructor may throw.

data Method #

A C++ class method declaration.

Any operator function that can be written as a method may have its binding be written either as part of the associated class or as a separate entity, independently of how the function is declared in C++.

data MethodImpl #

The C++ code to which a Method is bound.

Constructors

RealMethod (FnName String)

The Method is bound to an actual class method.

FnMethod (FnName Identifier)

The Method is bound to a wrapper function. When wrapping a method with another function, this is preferrable to just using a Function binding because a method will still appear to be part of the class in foreign bindings.

constNegate :: Constness -> Constness #

Returns the opposite constness value.

makeMethod #

Arguments

:: IsFnName String name 
=> name

The C++ name of the method.

-> ExtName

The external name of the method.

-> MethodApplicability 
-> Purity 
-> [Type]

Parameter types.

-> Type

Return type.

-> ClassEntity 

Creates a Method with full generality and manual name specification.

The result is wrapped in a CEMethod. For an unwrapped value, use makeMethod_.

makeMethod_ :: IsFnName String name => name -> ExtName -> MethodApplicability -> Purity -> [Type] -> Type -> Method #

The unwrapped version of makeMethod.

makeFnMethod :: IsFnName Identifier name => name -> String -> MethodApplicability -> Purity -> [Type] -> Type -> ClassEntity #

Creates a Method that is in fact backed by a C++ non-member function (a la makeFn), but appears to be a regular method. This is useful for wrapping a method on the C++ side when its arguments aren't right for binding directly.

A this pointer parameter is not automatically added to the parameter list for non-static methods created with makeFnMethod.

The result is wrapped in a CEMethod. For an unwrapped value, use makeFnMethod_.

makeFnMethod_ :: IsFnName Identifier name => name -> String -> MethodApplicability -> Purity -> [Type] -> Type -> Method #

The unwrapped version of makeFnMethod.

mkMethod #

Arguments

:: IsFnName String name 
=> name

The C++ name of the method.

-> [Type]

Parameter types.

-> Type

Return type.

-> ClassEntity 

Creates a nonconst, nonstatic Method for class::methodName and whose external name is class_methodName. If the name is an operator, then the operatorPreferredExtName will be used in the external name.

For creating multiple bindings to a method, see mkMethod'.

The result is wrapped in a CEMethod. For an unwrapped value, use mkMethod_.

mkMethod_ :: IsFnName String name => name -> [Type] -> Type -> Method #

The unwrapped version of mkMethod.

mkMethod' #

Arguments

:: IsFnName String name 
=> name

The C++ name of the method.

-> String

A foreign name for the method.

-> [Type]

Parameter types.

-> Type

Return type.

-> ClassEntity 

Creates a nonconst, nonstatic Method for method class::methodName and whose external name is class_methodName. This enables multiple Methods with different foreign names (and hence different external names) to bind to the same method, e.g. to make use of optional arguments or overloading. See mkMethod for a simpler form.

The result is wrapped in a CEMethod. For an unwrapped value, use mkMethod'_.

mkMethod'_ :: IsFnName String name => name -> String -> [Type] -> Type -> Method #

The unwrapped version of mkMethod'.

mkConstMethod :: IsFnName String name => name -> [Type] -> Type -> ClassEntity #

Same as mkMethod, but returns an MConst method.

The result is wrapped in a CEMethod. For an unwrapped value, use mkConstMethod_.

mkConstMethod_ :: IsFnName String name => name -> [Type] -> Type -> Method #

The unwrapped version of mkConstMethod.

mkConstMethod' :: IsFnName String name => name -> String -> [Type] -> Type -> ClassEntity #

Same as mkMethod', but returns an MConst method.

The result is wrapped in a CEMethod. For an unwrapped value, use mkConstMethod'_.

mkConstMethod'_ :: IsFnName String name => name -> String -> [Type] -> Type -> Method #

The unwrapped version of mkConstMethod'.

mkStaticMethod :: IsFnName String name => name -> [Type] -> Type -> ClassEntity #

Same as mkMethod, but returns an MStatic method.

The result is wrapped in a CEMethod. For an unwrapped value, use mkStaticMethod_.

mkStaticMethod_ :: IsFnName String name => name -> [Type] -> Type -> Method #

The unwrapped version of mkStaticMethod.

mkStaticMethod' :: IsFnName String name => name -> String -> [Type] -> Type -> ClassEntity #

Same as mkMethod', but returns an MStatic method.

The result is wrapped in a CEMethod. For an unwrapped value, use mkStaticMethod'_.

mkStaticMethod'_ :: IsFnName String name => name -> String -> [Type] -> Type -> Method #

The unwrapped version of mkStaticMethod'.

data Prop #

A "property" getter/setter pair.

mkProp :: String -> Type -> ClassEntity #

Creates a getter/setter binding pair for methods:

T foo() const
void setFoo(T)

The result is wrapped in a CEProp. For an unwrapped value, use mkProp_.

mkProp_ :: String -> Type -> Prop #

The unwrapped version of mkProp.

mkStaticProp :: String -> Type -> ClassEntity #

Creates a getter/setter binding pair for static methods:

static T foo() const
static void setFoo(T)

mkStaticProp_ :: String -> Type -> Prop #

The unwrapped version of mkStaticProp.

mkBoolIsProp :: String -> ClassEntity #

Creates a getter/setter binding pair for boolean methods, where the getter is prefixed with is:

bool isFoo() const
void setFoo(bool)

The result is wrapped in a CEProp. For an unwrapped value, use mkBoolIsProp_.

mkBoolIsProp_ :: String -> Prop #

The unwrapped version of mkBoolIsProp.

mkBoolHasProp :: String -> ClassEntity #

Creates a getter/setter binding pair for boolean methods, where the getter is prefixed with has:

bool hasFoo() const
void setFoo(bool)

The result is wrapped in a CEProp. For an unwrapped value, use mkBoolHasProp_.

mkBoolHasProp_ :: String -> Prop #

The unwrapped version of mkBoolHasProp.

methodImpl :: Method -> MethodImpl #

The underlying code that the binding calls.

methodExtName :: Method -> ExtName #

The method's external name.

methodApplicability :: Method -> MethodApplicability #

How the method is associated to its class.

methodPurity :: Method -> Purity #

Whether the method is pure.

methodParams :: Method -> [Type] #

The method's parameter types.

methodReturn :: Method -> Type #

The method's return type.

methodExceptionHandlers :: Method -> ExceptionHandlers #

Exceptions that the method might throw.

methodConst :: Method -> Constness #

Returns the constness of a method, based on its methodApplicability.

methodStatic :: Method -> Staticness #

Returns the staticness of a method, based on its methodApplicability.

Conversion to and from foreign values

data ClassConversion #

Separately from passing object handles between C++ and foreign languages, objects can also be made to implicitly convert to native values in foreign languages. A single such type may be associated with any C++ class for each foreign language. The foreign type and the conversion process in each direction are specified using this object. Converting a C++ object to a foreign value is also called decoding, and vice versa is called encoding. A class may be convertible in one direction and not the other.

To use these implicit conversions, instead of specifying an object handle type such as ptrT . objT or refT . objT, use objT directly.

The subfields in this object specify how to do conversions between C++ and foreign languages.

Constructors

ClassConversion 

Fields

classConversionNone :: ClassConversion #

Conversion behaviour for a class that is not convertible.

classModifyConversion :: (ClassConversion -> ClassConversion) -> Class -> Class #

Modifies a class's ClassConversion structure with a given function.

classSetConversion :: ClassConversion -> Class -> Class #

Replaces a class's ClassConversion structure.

data ClassHaskellConversion #

Controls how conversions between C++ objects and Haskell values happen in Haskell bindings.

Constructors

ClassHaskellConversion 

Fields

classHaskellConversionNone :: ClassHaskellConversion #

Conversion behaviour for a class that is not convertible to or from Haskell.

Callbacks

data Callback #

A non-C++ function that can be invoked via a C++ functor or function pointer.

makeCallback #

Arguments

:: ExtName 
-> [Type]

Parameter types.

-> Type

Return type.

-> Callback 

Creates a binding for constructing callbacks into foreign code.

callbackExtName :: Callback -> ExtName #

The callback's external name.

callbackParams :: Callback -> [Type] #

The callback's parameter types.

callbackReturn :: Callback -> Type #

The callback's return type.

callbackThrows :: Callback -> Maybe Bool #

Whether the callback supports throwing C++ exceptions from Haskell into C++ during its execution. When absent, the value is inherited from moduleCallbacksThrow and interfaceCallbacksThrow.

callbackReqs :: Callback -> Reqs #

Requirements for the callback.

callbackSetThrows :: Bool -> Callback -> Callback #

Sets whether a callback supports handling thrown C++ exceptions and passing them into C++.

Exceptions

newtype ExceptionId #

Each exception class has a unique exception ID.

Constructors

ExceptionId 

Fields

exceptionCatchAllId :: ExceptionId #

The exception ID that represents the catch-all type.

data ExceptionHandler #

Indicates the ability to handle a certain type of C++ exception.

Constructors

CatchClass Class

Indicates that instances of the given class are handled (including derived types).

CatchAll

Indicates that all C++ exceptions are handled, i.e. catch (...).

data ExceptionHandlers #

Represents a list of exception handlers to be used for a body of code. Order is important; a CatchAll will prevent all subsequent handlers from being invoked.

Constructors

ExceptionHandlers 

Fields

handleExceptions :: HandlesExceptions a => [ExceptionHandler] -> a -> a #

Appends additional exception handlers to an object.

Addenda

data Addendum #

A literal piece of code that will be inserted into a generated source file after the regular binding glue. The Monoid instance concatenates code (actions).

Constructors

Addendum 

Fields

class HasAddendum a where #

A typeclass for types that have an addendum.

Minimal complete definition

getAddendum, (setAddendum | modifyAddendum)

Methods

getAddendum :: a -> Addendum #

Returns an object's addendum.

setAddendum :: Addendum -> a -> a #

Replaces and object's addendum with another.

modifyAddendum :: (Addendum -> Addendum) -> a -> a #

Modified an object's addendum.

addAddendumHaskell :: HasAddendum a => Generator () -> a -> a #

Adds a Haskell addendum to an object.

Haskell imports

type HsModuleName = String #

A Haskell module name.

data HsImportSet #

A collection of imports for a Haskell module. This is a monoid: import Statements are merged to give the union of imported bindings.

This structure supports two specific types of imports: - import Foo (...) - import qualified Foo as Bar Imports with as but without qualified, and qualified imports with a spec list, are not supported. This satisfies the needs of the code generator, and keeps the merging logic simple.

data HsImportKey #

References an occurrence of an import statement, under which bindings can be imported. Only imported specs under equal HsImportKeys may be merged.

data HsImportSpecs #

A specification of bindings to import from a module. If Nothing, then the entire module is imported. If Just empty, then only instances are imported.

type HsImportName = String #

An identifier that can be imported from a module. Symbols may be used here when surrounded by parentheses. Examples are "fmap" and "(++)".

data HsImportVal #

Specifies how a name is imported.

Constructors

HsImportVal

The name is imported, and nothing underneath it is.

HsImportValSome [HsImportName]

The name is imported, as are specific names underneath it. This is a X (a, b, c) import.

HsImportValAll

The name is imported, along with all names underneath it. This is a X (..) import.

hsWholeModuleImport :: HsModuleName -> HsImportSet #

An import for the entire contents of a Haskell module.

hsQualifiedImport :: HsModuleName -> HsModuleName -> HsImportSet #

A qualified import of a Haskell module.

hsImport1 :: HsModuleName -> HsImportName -> HsImportSet #

An import of a single name from a Haskell module.

hsImport1' :: HsModuleName -> HsImportName -> HsImportVal -> HsImportSet #

A detailed import of a single name from a Haskell module.

hsImports :: HsModuleName -> [HsImportName] -> HsImportSet #

An import of multiple names from a Haskell module.

hsImports' :: HsModuleName -> [(HsImportName, HsImportVal)] -> HsImportSet #

A detailed import of multiple names from a Haskell module.

hsImportSetMakeSource :: HsImportSet -> HsImportSet #

Sets all of the import specifications in an import set to be {--} imports.

Internal to Hoppy

interfaceAllExceptionClasses :: Interface -> [Class] #

Returns all of the exception classes in an interface.

classFindCopyCtor :: Class -> Maybe Ctor #

Searches a class for a copy constructor, returning it if found.

Haskell imports

makeHsImportSet :: Map HsImportKey HsImportSpecs -> HsImportSet #

Constructor for an import set.

getHsImportSet :: HsImportSet -> Map HsImportKey HsImportSpecs #

Returns the import set's internal map from module names to imported bindings.

hsImportForBits :: HsImportSet #

Imports Data.Bits qualified as HoppyDB.

hsImportForException :: HsImportSet #

Imports Control.Exception qualified as HoppyCE.

hsImportForInt :: HsImportSet #

Imports Data.Int qualified as HoppyDI.

hsImportForWord :: HsImportSet #

Imports Data.Word qualified as HoppyDW.

hsImportForForeign :: HsImportSet #

Imports Foreign qualified as HoppyF.

hsImportForForeignC :: HsImportSet #

Imports Foreign.C qualified as HoppyFC.

hsImportForMap :: HsImportSet #

Imports Data.Map qualified as HoppyDM.

hsImportForPrelude :: HsImportSet #

Imports Prelude qualified as HoppyP.

hsImportForRuntime :: HsImportSet #

Imports Foreign.Hoppy.Runtime qualified as HoppyFHR.

hsImportForTypeable :: HsImportSet #

Imports Data.Typeable qualified as HoppyDT.

hsImportForUnsafeIO :: HsImportSet #

Imports System.IO.Unsafe qualified as HoppySIU.

Error messages

objToHeapTWrongDirectionErrorMsg :: Maybe String -> Class -> String #

Returns an error message indicating that objToHeapT is used where data is going from a foreign language into C++.

tToGcInvalidFormErrorMessage :: Maybe String -> Type -> String #

Returns an error message indicating that objToHeapT is used where data is going from a foreign language into C++.

toGcTWrongDirectionErrorMsg :: Maybe String -> Type -> String #

Returns an error message indicating that toGcT is used where data is going from a foreign language into C++.

Advanced class conversions

classSetConversionToHeap :: Class -> Class #

Modifies a class's ClassConversion structure by setting all languages to use ClassConversionToHeap.

classSetConversionToGc :: Class -> Class #

Modifies a class's ClassConversion structure by setting all languages that support garbage collection to use ClassConversionToGc.