Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart: do not generate default clause for enumerations #1641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Gluecodium project Release Notes

## Unreleased
### Bug fixes:
* Dart: removed generation of redundant `default` clause in exhaustive switch-cases for enumerations. The redundant `default` caused linter warnings.

## 13.10.1
Release date 2024-12-12
### Bug fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ int {{resolveName "Ffi"}}ToFfi({{resolveName this "" "ref"}} value{{#if external
{{#set parent=this}}{{#uniqueEnumerators}}
case {{resolveName parent "" "ref"}}{{#if external.dart.converter}}Internal{{/if}}.{{resolveName}}:
return {{value}};
{{/uniqueEnumerators}}{{/set}}
{{/uniqueEnumerators}}{{/set}}{{!!
}}{{#if aliasEnumerators}}
default:
throw StateError("Invalid enum value $value for {{resolveName}} enum.");
{{/if}}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@


import 'dart:ffi';
import 'package:library/src/_library_context.dart' as __lib;

@OnEnumeration
enum AttributesEnum {
@OnEnumerator
nope
}

// AttributesEnum "private" section, not exported.

int smokeAttributesenumToFfi(AttributesEnum value) {
switch (value) {
case AttributesEnum.nope:
return 0;
default:
throw StateError("Invalid enum value $value for AttributesEnum enum.");
}
}

AttributesEnum smokeAttributesenumFromFfi(int handle) {
switch (handle) {
case 0:
Expand All @@ -22,7 +26,9 @@ AttributesEnum smokeAttributesenumFromFfi(int handle) {
throw StateError("Invalid numeric value $handle for AttributesEnum enum.");
}
}

void smokeAttributesenumReleaseFfiHandle(int handle) {}

final _smokeAttributesenumCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Uint32),
Pointer<Void> Function(int)
Expand All @@ -35,20 +41,26 @@ final _smokeAttributesenumGetValueNullable = __lib.catchArgumentError(() => __li
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_AttributesEnum_get_value_nullable'));

Pointer<Void> smokeAttributesenumToFfiNullable(AttributesEnum? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeAttributesenumToFfi(value);
final result = _smokeAttributesenumCreateHandleNullable(_handle);
smokeAttributesenumReleaseFfiHandle(_handle);
return result;
}

AttributesEnum? smokeAttributesenumFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeAttributesenumGetValueNullable(handle);
final result = smokeAttributesenumFromFfi(_handle);
smokeAttributesenumReleaseFfiHandle(_handle);
return result;
}

void smokeAttributesenumReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeAttributesenumReleaseHandleNullable(handle);

// End of AttributesEnum "private" section.


Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ int smokeCommentsSomeenumToFfi(Comments_SomeEnum value) {
return 0;
case Comments_SomeEnum.useful:
return 1;
default:
throw StateError("Invalid enum value $value for Comments_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ int smokeCommentsinterfaceSomeenumToFfi(CommentsInterface_SomeEnum value) {
return 0;
case CommentsInterface_SomeEnum.useful:
return 1;
default:
throw StateError("Invalid enum value $value for CommentsInterface_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ int smokeDeprecationcommentsSomeenumToFfi(DeprecationComments_SomeEnum value) {
switch (value) {
case DeprecationComments_SomeEnum.useless:
return 0;
default:
throw StateError("Invalid enum value $value for DeprecationComments_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ int smokeDeprecationcommentsonlySomeenumToFfi(DeprecationCommentsOnly_SomeEnum v
switch (value) {
case DeprecationCommentsOnly_SomeEnum.useless:
return 0;
default:
throw StateError("Invalid enum value $value for DeprecationCommentsOnly_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ int smokeExcludedcommentsSomeenumToFfi(ExcludedComments_SomeEnum value) {
switch (value) {
case ExcludedComments_SomeEnum.useless:
return 0;
default:
throw StateError("Invalid enum value $value for ExcludedComments_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ int smokeExcludedcommentsonlySomeenumToFfi(ExcludedCommentsOnly_SomeEnum value)
switch (value) {
case ExcludedCommentsOnly_SomeEnum.useless:
return 0;
default:
throw StateError("Invalid enum value $value for ExcludedCommentsOnly_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ int smokePlatformcommentsSomeenumToFfi(PlatformComments_SomeEnum value) {
return 0;
case PlatformComments_SomeEnum.useful:
return 1;
default:
throw StateError("Invalid enum value $value for PlatformComments_SomeEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@


import 'dart:ffi';
import 'package:library/src/_library_context.dart' as __lib;


class Constants {
static final bool boolConstant = true;

static final int intConstant = -11;

static final int uintConstant = 4294967295;

static final double floatConstant = 2.71;

static final double doubleConstant = -3.14;

static final String stringConstant = "Foo bar";

static final Constants_StateEnum enumConstant = Constants_StateEnum.on;

}

enum Constants_StateEnum {
off,
on
}

// Constants_StateEnum "private" section, not exported.

int smokeConstantsStateenumToFfi(Constants_StateEnum value) {
switch (value) {
case Constants_StateEnum.off:
return 0;
case Constants_StateEnum.on:
return 1;
default:
throw StateError("Invalid enum value $value for Constants_StateEnum enum.");
}
}

Constants_StateEnum smokeConstantsStateenumFromFfi(int handle) {
switch (handle) {
case 0:
Expand All @@ -34,7 +47,9 @@ Constants_StateEnum smokeConstantsStateenumFromFfi(int handle) {
throw StateError("Invalid numeric value $handle for Constants_StateEnum enum.");
}
}

void smokeConstantsStateenumReleaseFfiHandle(int handle) {}

final _smokeConstantsStateenumCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Uint32),
Pointer<Void> Function(int)
Expand All @@ -47,24 +62,30 @@ final _smokeConstantsStateenumGetValueNullable = __lib.catchArgumentError(() =>
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_Constants_StateEnum_get_value_nullable'));

Pointer<Void> smokeConstantsStateenumToFfiNullable(Constants_StateEnum? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeConstantsStateenumToFfi(value);
final result = _smokeConstantsStateenumCreateHandleNullable(_handle);
smokeConstantsStateenumReleaseFfiHandle(_handle);
return result;
}

Constants_StateEnum? smokeConstantsStateenumFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeConstantsStateenumGetValueNullable(handle);
final result = smokeConstantsStateenumFromFfi(_handle);
smokeConstantsStateenumReleaseFfiHandle(_handle);
return result;
}

void smokeConstantsStateenumReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeConstantsStateenumReleaseHandleNullable(handle);

// End of Constants_StateEnum "private" section.

// Constants "private" section, not exported.

final _smokeConstantsCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(),
Pointer<Void> Function()
Expand All @@ -73,19 +94,26 @@ final _smokeConstantsReleaseHandle = __lib.catchArgumentError(() => __lib.native
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_Constants_release_handle'));



Pointer<Void> smokeConstantsToFfi(Constants value) {
final _result = _smokeConstantsCreateHandle();
return _result;
}

Constants smokeConstantsFromFfi(Pointer<Void> handle) {
try {
return Constants(
);
} finally {
}
}

void smokeConstantsReleaseFfiHandle(Pointer<Void> handle) => _smokeConstantsReleaseHandle(handle);

// Nullable Constants

final _smokeConstantsCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
Expand All @@ -98,20 +126,26 @@ final _smokeConstantsGetValueNullable = __lib.catchArgumentError(() => __lib.nat
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_Constants_get_value_nullable'));

Pointer<Void> smokeConstantsToFfiNullable(Constants? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeConstantsToFfi(value);
final result = _smokeConstantsCreateHandleNullable(_handle);
smokeConstantsReleaseFfiHandle(_handle);
return result;
}

Constants? smokeConstantsFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeConstantsGetValueNullable(handle);
final result = smokeConstantsFromFfi(_handle);
smokeConstantsReleaseFfiHandle(_handle);
return result;
}

void smokeConstantsReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeConstantsReleaseHandleNullable(handle);

// End of Constants "private" section.


Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ int smokeConstantsinterfaceStateenumToFfi(ConstantsInterface_StateEnum value) {
return 0;
case ConstantsInterface_StateEnum.on:
return 1;
default:
throw StateError("Invalid enum value $value for ConstantsInterface_StateEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ int smokeConstructorsErrorenumToFfi(Constructors_ErrorEnum value) {
return 0;
case Constructors_ErrorEnum.crashed:
return 1;
default:
throw StateError("Invalid enum value $value for Constructors_ErrorEnum enum.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@


import 'dart:ffi';
import 'package:library/src/_library_context.dart' as __lib;

enum Alphabet {
a,
b,
c
}

// Alphabet "private" section, not exported.

int smokeAlphabetToFfi(Alphabet value) {
switch (value) {
case Alphabet.a:
Expand All @@ -14,10 +19,9 @@ int smokeAlphabetToFfi(Alphabet value) {
return 1;
case Alphabet.c:
return 2;
default:
throw StateError("Invalid enum value $value for Alphabet enum.");
}
}

Alphabet smokeAlphabetFromFfi(int handle) {
switch (handle) {
case 0:
Expand All @@ -30,7 +34,9 @@ Alphabet smokeAlphabetFromFfi(int handle) {
throw StateError("Invalid numeric value $handle for Alphabet enum.");
}
}

void smokeAlphabetReleaseFfiHandle(int handle) {}

final _smokeAlphabetCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Uint32),
Pointer<Void> Function(int)
Expand All @@ -43,20 +49,26 @@ final _smokeAlphabetGetValueNullable = __lib.catchArgumentError(() => __lib.nati
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_Alphabet_get_value_nullable'));

Pointer<Void> smokeAlphabetToFfiNullable(Alphabet? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeAlphabetToFfi(value);
final result = _smokeAlphabetCreateHandleNullable(_handle);
smokeAlphabetReleaseFfiHandle(_handle);
return result;
}

Alphabet? smokeAlphabetFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeAlphabetGetValueNullable(handle);
final result = smokeAlphabetFromFfi(_handle);
smokeAlphabetReleaseFfiHandle(_handle);
return result;
}

void smokeAlphabetReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeAlphabetReleaseHandleNullable(handle);

// End of Alphabet "private" section.


Loading
Loading