Skip to content

Commit

Permalink
duplicate_definition for internal classes with throwing constructors
Browse files Browse the repository at this point in the history
Added ffi prefix to name of functions handling error and return type
retrival from throwing functions. This prevent duplicate_definition
error if more than one class has those function inside one file, for
example in case of multiple internall classes.

Relates-To:  heremaps#1547
Signed-off-by: Rafal Parzych <[email protected]>
  • Loading branch information
parzysty committed Aug 23, 2023
1 parent 1c36362 commit 1989ad8
Show file tree
Hide file tree
Showing 22 changed files with 1,004 additions and 214 deletions.
14 changes: 14 additions & 0 deletions functional-tests/functional/input/lime/StructsWithMethods.lime
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ class StructsWithMethodsInterface {
) throws ValidationUtils.Validation
}

struct Vector4 {
x: Double = 2.0
@Dart(Default)
constructor create(
) throws ValidationUtils.Validation
}

struct Vector5 {
y: Double = 7.0
@Dart(Default)
constructor create(
) throws ValidationUtils.Validation
}

struct StructWithStaticMethodsOnly {
static fun doStuff()
}
Expand Down
14 changes: 14 additions & 0 deletions functional-tests/functional/input/src/cpp/StructsWithMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ StructsWithMethodsInterface::Vector3::create( const StructsWithMethodsInterface:
);
}

lorem_ipsum::test::Return< StructsWithMethodsInterface::Vector4, std::error_code >
StructsWithMethodsInterface::Vector4::create( )
{
return lorem_ipsum::test::Return< StructsWithMethodsInterface::Vector4, std::error_code >(
StructsWithMethodsInterface::Vector4( ) );
}

lorem_ipsum::test::Return< StructsWithMethodsInterface::Vector5, std::error_code >
StructsWithMethodsInterface::Vector5::create( )
{
return lorem_ipsum::test::Return< StructsWithMethodsInterface::Vector5, std::error_code >(
StructsWithMethodsInterface::Vector5( ) );
}

void
StructsWithMethodsInterface::StructWithStaticMethodsOnly::do_stuff( )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
{{#resolveName}}{{#setJoin "varName" "_" this "Handle" delimiter=""}}{{>dart/DartFfiReleaseHandle}}{{/setJoin}}{{/resolveName}}
{{/parameters}}
{{#if this.thrownType}}
if (_{{resolveName}}ReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _{{resolveName}}ReturnGetError(__callResultHandle);
_{{resolveName}}ReturnReleaseHandle(__callResultHandle);
if (_{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnGetError(__callResultHandle);
_{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnReleaseHandle(__callResultHandle);
try {
throw {{resolveName exception}}({{#set call="FromFfi" typeRef=exception.errorType}}{{>dart/DartFfiConversionCall}}{{/set}}(__errorHandle));
} finally {
{{#set typeRef=exception.errorType varName="__errorHandle"}}{{>dart/DartFfiReleaseHandle}}{{/set}}
}
}
{{#unless returnType.isVoid}}
final __resultHandle = _{{resolveName}}ReturnGetResult(__callResultHandle);
final __resultHandle = _{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnGetResult(__callResultHandle);
{{/unless}}
_{{resolveName}}ReturnReleaseHandle(__callResultHandle);
_{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnReleaseHandle(__callResultHandle);
{{/if}}
{{#if isConstructor}}{{#if isStruct}}{{>ffiReturnConversion}}{{/if}}{{!!
}}{{#unless isStruct}} return __resultHandle;{{/unless}}{{/if}}{{!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
!
!}}
{{#if thrownType}}{{#unless attributes.async}}
final _{{resolveName}}ReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('{{>dart/DartFunctionFfiName}}_return_release_handle'));
{{#unless returnType.isVoid}}
final _{{resolveName}}ReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
{{resolveName returnType.typeRef "FfiApiTypes"}} Function(Pointer<Void>),
{{resolveName returnType.typeRef "FfiDartTypes"}} Function(Pointer<Void>)
>('{{>dart/DartFunctionFfiName}}_return_get_result'));
{{/unless}}
final _{{resolveName}}ReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
{{resolveName exception.errorType "FfiApiTypes"}} Function(Pointer<Void>),
{{resolveName exception.errorType "FfiDartTypes"}} Function(Pointer<Void>)
>('{{>dart/DartFunctionFfiName}}_return_get_error'));
final _{{resolveName}}ReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _{{resolveName "FfiSnakeCase"}}_{{resolveName}}ReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint8 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('{{>dart/DartFunctionFfiName}}_return_has_error'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,19 @@ final _smokeCommentsReleaseHandle = __lib.catchArgumentError(() => __lib.nativeL
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_Comments_release_handle'));
final _someMethodWithAllCommentsReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_Comments_someMethodWithAllComments__String_return_release_handle'));
final _someMethodWithAllCommentsReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint8 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_Comments_someMethodWithAllComments__String_return_get_result'));
final _someMethodWithAllCommentsReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_Comments_someMethodWithAllComments__String_return_get_error'));
final _someMethodWithAllCommentsReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint8 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_Comments_someMethodWithAllComments__String_return_has_error'));
Expand All @@ -360,17 +360,17 @@ class Comments$Impl extends __lib.NativeBase implements Comments {
final _handle = this.handle;
final __callResultHandle = _someMethodWithAllCommentsFfi(_handle, __lib.LibraryContext.isolateId, _inputParameterHandle);
stringReleaseFfiHandle(_inputParameterHandle);
if (_someMethodWithAllCommentsReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _someMethodWithAllCommentsReturnGetError(__callResultHandle);
_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
if (_smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetError(__callResultHandle);
_smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
try {
throw Comments_SomethingWrongException(smokeCommentsSomeenumFromFfi(__errorHandle));
} finally {
smokeCommentsSomeenumReleaseFfiHandle(__errorHandle);
}
}
final __resultHandle = _someMethodWithAllCommentsReturnGetResult(__callResultHandle);
_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
final __resultHandle = _smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetResult(__callResultHandle);
_smoke_Comments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
try {
return booleanFromFfi(__resultHandle);
} finally {
Expand Down Expand Up @@ -534,4 +534,4 @@ Comments? smokeCommentsFromFfiNullable(Pointer<Void> handle) =>
handle.address != 0 ? smokeCommentsFromFfi(handle) : null;
void smokeCommentsReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeCommentsReleaseHandle(handle);
// End of Comments "private" section.
// End of Comments "private" section.
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@ final _smokeCommentslinksReleaseHandle = __lib.catchArgumentError(() => __lib.na
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_CommentsLinks_release_handle'));
final _randomMethodReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_CommentsLinks_randomMethod__SomeEnum_return_release_handle'));
final _randomMethodReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_CommentsLinks_randomMethod__SomeEnum_return_get_result'));
final _randomMethodReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_CommentsLinks_randomMethod__SomeEnum_return_get_error'));
final _randomMethodReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint8 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_CommentsLinks_randomMethod__SomeEnum_return_has_error'));
Expand All @@ -164,17 +164,17 @@ class CommentsLinks$Impl extends __lib.NativeBase implements CommentsLinks {
final _handle = this.handle;
final __callResultHandle = _randomMethodFfi(_handle, __lib.LibraryContext.isolateId, _inputParameterHandle);
smokeCommentsSomeenumReleaseFfiHandle(_inputParameterHandle);
if (_randomMethodReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _randomMethodReturnGetError(__callResultHandle);
_randomMethodReturnReleaseHandle(__callResultHandle);
if (_smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnGetError(__callResultHandle);
_smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnReleaseHandle(__callResultHandle);
try {
throw Comments_SomethingWrongException(smokeCommentsSomeenumFromFfi(__errorHandle));
} finally {
smokeCommentsSomeenumReleaseFfiHandle(__errorHandle);
}
}
final __resultHandle = _randomMethodReturnGetResult(__callResultHandle);
_randomMethodReturnReleaseHandle(__callResultHandle);
final __resultHandle = _smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnGetResult(__callResultHandle);
_smoke_CommentsLinks_randomMethod__SomeEnum_randomMethodReturnReleaseHandle(__callResultHandle);
try {
return smokeCommentsSomeenumFromFfi(__resultHandle);
} finally {
Expand Down Expand Up @@ -212,4 +212,4 @@ CommentsLinks? smokeCommentslinksFromFfiNullable(Pointer<Void> handle) =>
handle.address != 0 ? smokeCommentslinksFromFfi(handle) : null;
void smokeCommentslinksReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeCommentslinksReleaseHandle(handle);
// End of CommentsLinks "private" section.
// End of CommentsLinks "private" section.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:library/src/builtin_types__conversion.dart';
/// This is some very useful class.
/// @nodoc
abstract class ExcludedComments {

/// This is some very useful constant.
/// @nodoc
static final bool veryUseful = true;
Expand Down Expand Up @@ -268,43 +267,42 @@ final _smokeExcludedcommentsReleaseHandle = __lib.catchArgumentError(() => __lib
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_ExcludedComments_release_handle'));
final _someMethodWithAllCommentsReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_ExcludedComments_someMethodWithAllComments__String_return_release_handle'));
final _someMethodWithAllCommentsReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetResult = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint8 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_ExcludedComments_someMethodWithAllComments__String_return_get_result'));
final _someMethodWithAllCommentsReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_ExcludedComments_someMethodWithAllComments__String_return_get_error'));
final _someMethodWithAllCommentsReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
final _smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnHasError = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint8 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_ExcludedComments_someMethodWithAllComments__String_return_has_error'));
class ExcludedComments$Impl extends __lib.NativeBase implements ExcludedComments {
ExcludedComments$Impl(Pointer<Void> handle) : super(handle);

@override
bool someMethodWithAllComments(String inputParameter) {
final _someMethodWithAllCommentsFfi = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<Pointer<Void> Function(Pointer<Void>, Int32, Pointer<Void>), Pointer<Void> Function(Pointer<Void>, int, Pointer<Void>)>('library_smoke_ExcludedComments_someMethodWithAllComments__String'));
final _inputParameterHandle = stringToFfi(inputParameter);
final _handle = this.handle;
final __callResultHandle = _someMethodWithAllCommentsFfi(_handle, __lib.LibraryContext.isolateId, _inputParameterHandle);
stringReleaseFfiHandle(_inputParameterHandle);
if (_someMethodWithAllCommentsReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _someMethodWithAllCommentsReturnGetError(__callResultHandle);
_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
if (_smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnHasError(__callResultHandle) != 0) {
final __errorHandle = _smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetError(__callResultHandle);
_smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
try {
throw ExcludedComments_SomethingWrongException(smokeExcludedcommentsSomeenumFromFfi(__errorHandle));
} finally {
smokeExcludedcommentsSomeenumReleaseFfiHandle(__errorHandle);
}
}
final __resultHandle = _someMethodWithAllCommentsReturnGetResult(__callResultHandle);
_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
final __resultHandle = _smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnGetResult(__callResultHandle);
_smoke_ExcludedComments_someMethodWithAllComments__String_someMethodWithAllCommentsReturnReleaseHandle(__callResultHandle);
try {
return booleanFromFfi(__resultHandle);
} finally {
Expand Down Expand Up @@ -357,4 +355,4 @@ ExcludedComments? smokeExcludedcommentsFromFfiNullable(Pointer<Void> handle) =>
handle.address != 0 ? smokeExcludedcommentsFromFfi(handle) : null;
void smokeExcludedcommentsReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeExcludedcommentsReleaseHandle(handle);
// End of ExcludedComments "private" section.
// End of ExcludedComments "private" section.
Loading

0 comments on commit 1989ad8

Please sign in to comment.