Annotation Interface CField


@Retention(RUNTIME) @Target(METHOD) public @interface CField
Denotes a method as a field access of a C struct.

If the method has a non-void return type, it is a get-method of the field. Calls of the method are replaced with a memory read. The possible signatures are FieldType getFieldName([IntType index], [LocationIdentity locationIdentity]);

If the method has the return type void, it is a set-method of the field. Calls of the method are replaced with a memory write. The possible signatures are void setFieldName([IntType index], FieldType value, [LocationIdentity locationIdentity]);

The receiver is the pointer to the struct that is accessed, i.e., the base address of the memory access.

The FieldType must be the Java-equivalent of the C type used in the C struct. The additional annotations AllowNarrowingCast or AllowWideningCast can be used to relax the strict type requirements.

The optional parameter index (always the first parameter when it is present) denotes an index, i.e., the receiver is treated as an array of the struct. The type must be a primitive integer type or a word type. Address arithmetic is used to scale the index with the size of the struct.

The optional parameter locationIdentity specifies the LocationIdentity to be used for the memory access. Two memory accesses with two different location identities are guaranteed to not alias. The parameter cannot be used together with the UniqueLocationIdentity annotation, which is another way of providing a location identity for the memory access.

Multiple accessor methods, with different signatures according to the rules of allowed signatures, are allowed for a single field.

Since:
19.0
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies the field name inside the C struct.
  • Element Details

    • value

      String value
      Specifies the field name inside the C struct. If no name is provided, the method name is used as the field name. A possible "get" or "set" prefix of the method name is removed.
      Since:
      19.0
      Default:
      ""