Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- __Breaking change__: Certain synthetic USRs have been modified to ensure they
cannot collide with real USRs. It's very unlikely that any user facing USRs
are affected.
- Enum struct members now have setters.

## 20.1.1

Expand Down
12 changes: 12 additions & 0 deletions pkgs/ffigen/example/libclang-example/generated_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7535,6 +7535,7 @@ final class CXTUResourceUsageEntry extends ffi.Struct {
external int kindAsInt;

CXTUResourceUsageKind get kind => CXTUResourceUsageKind.fromValue(kindAsInt);
set kind(CXTUResourceUsageKind value) => kindAsInt = value.value;

@ffi.UnsignedLong()
external int amount;
Expand Down Expand Up @@ -8667,6 +8668,7 @@ final class CXCursor extends ffi.Struct {
external int kindAsInt;

CXCursorKind get kind => CXCursorKind.fromValue(kindAsInt);
set kind(CXCursorKind value) => kindAsInt = value.value;

@ffi.Int()
external int xdata;
Expand Down Expand Up @@ -9259,6 +9261,7 @@ final class CXType extends ffi.Struct {
external int kindAsInt;

CXTypeKind get kind => CXTypeKind.fromValue(kindAsInt);
set kind(CXTypeKind value) => kindAsInt = value.value;

@ffi.Array.multi([2])
external ffi.Array<ffi.Pointer<ffi.Void>> data;
Expand Down Expand Up @@ -10109,6 +10112,7 @@ final class CXCompletionResult extends ffi.Struct {
external int CursorKindAsInt;

CXCursorKind get CursorKind => CXCursorKind.fromValue(CursorKindAsInt);
set CursorKind(CXCursorKind value) => CursorKindAsInt = value.value;

/// The code-completion string that describes how to insert this
/// code-completion result into the editing buffer.
Expand Down Expand Up @@ -10867,6 +10871,7 @@ final class CXIdxAttrInfo extends ffi.Struct {
external int kindAsInt;

CXIdxAttrKind get kind => CXIdxAttrKind.fromValue(kindAsInt);
set kind(CXIdxAttrKind value) => kindAsInt = value.value;

external CXCursor cursor;

Expand All @@ -10878,17 +10883,21 @@ final class CXIdxEntityInfo extends ffi.Struct {
external int kindAsInt;

CXIdxEntityKind get kind => CXIdxEntityKind.fromValue(kindAsInt);
set kind(CXIdxEntityKind value) => kindAsInt = value.value;

@ffi.UnsignedInt()
external int templateKindAsInt;

CXIdxEntityCXXTemplateKind get templateKind =>
CXIdxEntityCXXTemplateKind.fromValue(templateKindAsInt);
set templateKind(CXIdxEntityCXXTemplateKind value) =>
templateKindAsInt = value.value;

@ffi.UnsignedInt()
external int langAsInt;

CXIdxEntityLanguage get lang => CXIdxEntityLanguage.fromValue(langAsInt);
set lang(CXIdxEntityLanguage value) => langAsInt = value.value;

external ffi.Pointer<ffi.Char> name;

Expand Down Expand Up @@ -10980,6 +10989,7 @@ final class CXIdxObjCContainerDeclInfo extends ffi.Struct {

CXIdxObjCContainerKind get kind =>
CXIdxObjCContainerKind.fromValue(kindAsInt);
set kind(CXIdxObjCContainerKind value) => kindAsInt = value.value;
}

final class CXIdxBaseClassInfo extends ffi.Struct {
Expand Down Expand Up @@ -11104,6 +11114,7 @@ final class CXIdxEntityRefInfo extends ffi.Struct {
external int kindAsInt;

CXIdxEntityRefKind get kind => CXIdxEntityRefKind.fromValue(kindAsInt);
set kind(CXIdxEntityRefKind value) => kindAsInt = value.value;

/// Reference cursor.
external CXCursor cursor;
Expand Down Expand Up @@ -11132,6 +11143,7 @@ final class CXIdxEntityRefInfo extends ffi.Struct {
external int roleAsInt;

CXSymbolRole get role => CXSymbolRole.fromValue(roleAsInt);
set role(CXSymbolRole value) => roleAsInt = value.value;
}

/// A group of callbacks used by #clang_indexSourceFile and
Expand Down
6 changes: 5 additions & 1 deletion pkgs/ffigen/lib/src/code_generator/compound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ abstract class Compound extends BindingType with HasLocalScope {
final memberName = m.name;
s.write(
'$enumName get $memberName => '
'$enumName.fromValue(${memberName}AsInt);\n\n',
'$enumName.fromValue(${memberName}AsInt);\n',
);
s.write(
'set $memberName($enumName value) => '
'${memberName}AsInt = value.value;\n\n',
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ final class StructWithEnums extends ffi.Struct {
external int enum1AsInt;

Enum1 get enum1 => Enum1.fromValue(enum1AsInt);
set enum1(Enum1 value) => enum1AsInt = value.value;

@ffi.Int()
external int enum2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ final class Test extends ffi.Struct {
external int simpleAsInt;

Simple get simple => Simple.fromValue(simpleAsInt);
set simple(Simple value) => simpleAsInt = value.value;

external ffi.Pointer<ffi.Int> simpleWithNegative;

Expand All @@ -97,12 +98,16 @@ final class Test extends ffi.Struct {

PositiveIntOverflow get positiveIntOverflow =>
PositiveIntOverflow.fromValue(positiveIntOverflowAsInt);
set positiveIntOverflow(PositiveIntOverflow value) =>
positiveIntOverflowAsInt = value.value;

@ffi.Uint16()
external int explicitTypeWithOverflowAsInt;

ExplicitTypeWithOverflow get explicitTypeWithOverflow =>
ExplicitTypeWithOverflow.fromValue(explicitTypeWithOverflowAsInt);
set explicitTypeWithOverflow(ExplicitTypeWithOverflow value) =>
explicitTypeWithOverflowAsInt = value.value;
}

const int ANONYMOUS1 = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6076,6 +6076,7 @@ final class CXTUResourceUsageEntry extends ffi.Struct {
external int kindAsInt;

CXTUResourceUsageKind get kind => CXTUResourceUsageKind.fromValue(kindAsInt);
set kind(CXTUResourceUsageKind value) => kindAsInt = value.value;

@ffi.UnsignedLong()
external int amount;
Expand Down Expand Up @@ -7040,6 +7041,7 @@ final class CXCursor extends ffi.Struct {
external int kindAsInt;

CXCursorKind get kind => CXCursorKind.fromValue(kindAsInt);
set kind(CXCursorKind value) => kindAsInt = value.value;

@ffi.Int()
external int xdata;
Expand Down Expand Up @@ -7500,6 +7502,7 @@ final class CXType extends ffi.Struct {
external int kindAsInt;

CXTypeKind get kind => CXTypeKind.fromValue(kindAsInt);
set kind(CXTypeKind value) => kindAsInt = value.value;

@ffi.Array.multi([2])
external ffi.Array<ffi.Pointer<ffi.Void>> data;
Expand Down Expand Up @@ -7932,6 +7935,7 @@ final class CXCompletionResult extends ffi.Struct {
external int CursorKindAsInt;

CXCursorKind get CursorKind => CXCursorKind.fromValue(CursorKindAsInt);
set CursorKind(CXCursorKind value) => CursorKindAsInt = value.value;

/// The code-completion string that describes how to insert this
/// code-completion result into the editing buffer.
Expand Down Expand Up @@ -8500,6 +8504,7 @@ final class CXIdxAttrInfo extends ffi.Struct {
external int kindAsInt;

CXIdxAttrKind get kind => CXIdxAttrKind.fromValue(kindAsInt);
set kind(CXIdxAttrKind value) => kindAsInt = value.value;

external CXCursor cursor;

Expand All @@ -8511,17 +8516,21 @@ final class CXIdxEntityInfo extends ffi.Struct {
external int kindAsInt;

CXIdxEntityKind get kind => CXIdxEntityKind.fromValue(kindAsInt);
set kind(CXIdxEntityKind value) => kindAsInt = value.value;

@ffi.UnsignedInt()
external int templateKindAsInt;

CXIdxEntityCXXTemplateKind get templateKind =>
CXIdxEntityCXXTemplateKind.fromValue(templateKindAsInt);
set templateKind(CXIdxEntityCXXTemplateKind value) =>
templateKindAsInt = value.value;

@ffi.UnsignedInt()
external int langAsInt;

CXIdxEntityLanguage get lang => CXIdxEntityLanguage.fromValue(langAsInt);
set lang(CXIdxEntityLanguage value) => langAsInt = value.value;

external ffi.Pointer<ffi.Char> name;

Expand Down Expand Up @@ -8625,6 +8634,7 @@ final class CXIdxObjCContainerDeclInfo extends ffi.Struct {

CXIdxObjCContainerKind get kind =>
CXIdxObjCContainerKind.fromValue(kindAsInt);
set kind(CXIdxObjCContainerKind value) => kindAsInt = value.value;
}

final class CXIdxBaseClassInfo extends ffi.Struct {
Expand Down Expand Up @@ -8743,6 +8753,7 @@ final class CXIdxEntityRefInfo extends ffi.Struct {
external int kindAsInt;

CXIdxEntityRefKind get kind => CXIdxEntityRefKind.fromValue(kindAsInt);
set kind(CXIdxEntityRefKind value) => kindAsInt = value.value;

/// Reference cursor.
external CXCursor cursor;
Expand All @@ -8763,6 +8774,7 @@ final class CXIdxEntityRefInfo extends ffi.Struct {
external int roleAsInt;

CXSymbolRole get role => CXSymbolRole.fromValue(roleAsInt);
set role(CXSymbolRole value) => roleAsInt = value.value;
}

/// A group of callbacks used by #clang_indexSourceFile and
Expand Down