Note

You are not reading the most recent version of this documentation. 1.4.7 is the latest version available.

Attributes

enum Header

This enum is used by several of the other attributes to specify includes in the generated code.

case System(header : String)

header specifies the name of a system file to be included. The generated code for each system file included is #include <header.h>.

case User(header : String)

header specifies the name of a user file to be included. The generated code for each user file included is #include "header.h".

enum ParameterStyle

This enum specifies the way in which an external type is passed in a call to an external function.

case ConstReference

The parameter should be of type const T&.

case Pointer

The parameter should be of type T*.

case RValueReference

The parameter should be of type T&&.

case Value

The parameter should be of type T.

attribute @mapToMember(name : String)
Applies to:External functions with at least one argument

This attribute specifies that a function should be mapped to a member function of the first argument instead of to a top-level function. For example, given:

@CPP.mapToMember("f")
external function f(x : T, y : Bool) : Nil = {}

then an expression like f(a, b) will be mapped to a.f(b) in the generated C++ code.

attribute @mapToType(name : String, parameterStyle : ParameterStyle, header : List<Header>)
Applies to:External types

This attribute specifies how an external type should be mapped into the generated C++. The following example defines how the external datatype ChronoDuration is mapped to std::chrono::duration in the generated C++ code:

@CPP.mapToType("std::chrono::duration", CPP.ParameterStyle.Value, [CPP.Header.System("chrono")])
external type ChronoDuration
attribute @mapToValue(name : String, header : List<Header>)
Applies to:External functions

This attribute specifies how external functions are to be mapped into the generated C++. The following example defines how a reference to the standard library std::this_thread::sleep_for function can be accessed:

@CPP.mapToValue("std::this_thread::sleep_for", [CPP.Header.System("thread"), CPP.Header.System("chrono")])
external function chronoSleep(t : Duration) : Nil = {}

Advanced Attributes

attribute @binaryOperator(operator : BinaryOperator)

Used to specify that the given Coco function, which must be a function with exactly two arguments, should be mapped to the given operator in C++.

enum BinaryOperator
case Divide
case Equals
case GreaterThan
case GreaterThanEquals
case LessThan
case LessThanEquals
case LogicalAnd
case LogicalOr
case Modulus
case Minus
case NotEquals
case Plus
case Times
attribute @include(header : List<Header>)

When applied to a Coco declaration, will cause any usage of this declaration to contain the given includes. For example:

@CPP.include([CPP.Header.User("hdr")])
port P { ... }

will include #include "hdr" in the generated C++ file that includes P.

attribute @implicitCast
Applies to:External functions with exactly one argument

This attribute can be used to specify that an external function represents an implicit cast in C++ and therefored does not need to be represented in the generated code. For example, given:

@CPP.implicitCast
external function f(x : Int) : IntLike = _

f(y) will appear in the generated code as y.

attribute @unaryOperator(operator : UnaryOperator)

Used to specify that the given Coco function, which must be a function with exactly one argument, should be mapped to the given operator in C++.

enum UnaryOperator
case LogicalNot
case Negate
case PreDecrement
case PreIncrement
case PostDecrement
case PostIncrement