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

Add doc support of lambda parameters and return value for cpp,swift,dart #1545

Closed
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.here.gluecodium.model.lime.LimeExternalDescriptor.Companion.SETTER_NA
import com.here.gluecodium.model.lime.LimeField
import com.here.gluecodium.model.lime.LimeFunction
import com.here.gluecodium.model.lime.LimeGenericType
import com.here.gluecodium.model.lime.LimeLambdaParameter
import com.here.gluecodium.model.lime.LimeList
import com.here.gluecodium.model.lime.LimeMap
import com.here.gluecodium.model.lime.LimeNamedElement
Expand Down Expand Up @@ -84,6 +85,7 @@ internal class CppNameResolver(
is LimeType -> resolveTypeName(element, isFullName = false)
is LimeTypeRef -> resolveTypeRef(element)
is LimeReturnType -> resolveTypeRef(element.typeRef)
is LimeLambdaParameter -> resolveTypeRef(element.typeRef)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this addition, it would go to the throw statement.

is LimeNamedElement -> nameCache.getName(element)
else -> throw GluecodiumExecutionException("Unsupported element type ${element.javaClass.name}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.here.gluecodium.model.lime.LimeEnumerator
import com.here.gluecodium.model.lime.LimeExternalDescriptor.Companion.IMPORT_PATH_NAME
import com.here.gluecodium.model.lime.LimeFunction
import com.here.gluecodium.model.lime.LimeGenericType
import com.here.gluecodium.model.lime.LimeLambdaParameter
import com.here.gluecodium.model.lime.LimeList
import com.here.gluecodium.model.lime.LimeMap
import com.here.gluecodium.model.lime.LimeNamedElement
Expand Down Expand Up @@ -86,6 +87,7 @@ internal class DartNameResolver(
is LimeTypeAlias -> resolveName(element.typeRef)
is LimeType -> resolveTypeName(element)
is LimeNamedElement -> getPlatformName(element)
is LimeLambdaParameter -> resolveTypeRefName(element.typeRef)
else ->
throw GluecodiumExecutionException("Unsupported element type ${element.javaClass.name}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.here.gluecodium.model.lime.LimeFunction
import com.here.gluecodium.model.lime.LimeGenericType
import com.here.gluecodium.model.lime.LimeInterface
import com.here.gluecodium.model.lime.LimeLambda
import com.here.gluecodium.model.lime.LimeLambdaParameter
import com.here.gluecodium.model.lime.LimeList
import com.here.gluecodium.model.lime.LimeMap
import com.here.gluecodium.model.lime.LimeNamedElement
Expand Down Expand Up @@ -75,6 +76,7 @@ internal class SwiftNameResolver(
is LimeTypeRef -> resolveTypeRefName(element)
is LimeReturnType -> resolveTypeRefName(element.typeRef)
is LimeNamedElement -> nameRules.getName(element)
is LimeLambdaParameter -> resolveTypeRefName(element.typeRef)
else -> throw GluecodiumExecutionException("Unsupported element type ${element.javaClass.name}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
! License-Filename: LICENSE
!
!}}
{{>cpp/CppDocComment}}{{>cpp/CppAttributes}}
{{>cpp/CppFunctionDoc}}{{>cpp/CppAttributes}}
using {{resolveName}} = {{>cpp/CppLambdaType}};
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,8 @@
! License-Filename: LICENSE
!
!}}
{{#resolveName comment}}{{#unless this.isEmpty}}{{prefix this "/// "}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to split this the doc part and attribute part. Otherwise, the lambda gets some duplicated attributes here

///{{/unless}}{{/resolveName}}{{!!
}}{{#parameters}}{{#set self=this}}{{#resolveName comment}}{{#unless this.isEmpty}}
/// [{{resolveName self}}] {{prefix this "/// " skipFirstLine=true}}
///{{/unless}}{{/resolveName}}{{/set}}{{/parameters}}{{!!
}}{{#resolveName returnType.comment}}{{#unless this.isEmpty}}
/// Returns [{{resolveName returnType.typeRef}}]. {{prefix this "/// " skipFirstLine=true}}
///{{/unless}}{{/resolveName}}{{!!
}}{{#if thrownType}}{{#resolveName thrownType.comment}}{{#unless this.isEmpty}}
/// Throws [{{resolveName exception}}]. {{prefix this "/// " skipFirstLine=true}}
///{{/unless}}{{/resolveName}}{{/if}}{{!!
}}{{#ifPredicate "needsNoDoc"}}
/// @nodoc{{/ifPredicate}}{{!!
}}{{#if attributes.deprecated}}
@Deprecated("{{#resolveName attributes.deprecated.message}}{{escape this}}{{/resolveName}}")
{{/if}}{{!!
}}{{#if attributes.dart.attribute}}
{{>dart/DartLambdaDocs}}
{{#if attributes.dart.attribute}}

{{#attributes.dart.attribute}}
@{{this}}{{#if iter.hasNext}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
! License-Filename: LICENSE
!
!}}
{{>dart/DartDocumentation}}{{>dart/DartAttributes}}
{{>dart/DartLambdaDocs}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to leave a blank line here. Otherwise, the lambda declaration will be in the same line as the empty comment, which would hide the lambda declaration.

{{>dart/DartAttributes}}
typedef {{resolveName}} = {{>dart/DartLambdaType}};

// {{resolveName}} "private" section, not exported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
! License-Filename: LICENSE
!
!}}
{{>swift/SwiftComment}}{{>swift/SwiftAttributes}}
{{>swift/SwiftFunctionComment}}{{>swift/SwiftAttributes}}
{{#unless isInterface}}{{resolveName "visibility"}} {{/unless}}typealias {{resolveName}} = {{!!
}}({{#parameters}}{{#unless typeRef.isNullable}}{{#instanceOf typeRef.type.actualType "LimeLambda"}}@escaping {{/instanceOf}}{{/unless}}{{!!
}}{{resolveName typeRef}}{{#if iter.hasNext}}, {{/if}}{{/parameters}}) -> {{resolveName returnType}}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class _GLUECODIUM_CPP_EXPORT Comments {
};
/**
* This is some very useful lambda that does it.
* \param[in] ::std::string Very useful input parameter
* \param[in] int32_t Slightly less useful input parameter
* \return Usefulness of the input
*/
using SomeLambda = ::std::function<double(const ::std::string&, const int32_t)>;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class _GLUECODIUM_CPP_EXPORT ExcludedComments {
/**
* This is some very useful lambda that does it.
* \private
* \param[in] ::std::string Very useful input parameter
* \param[in] int32_t Slightly less useful input parameter
* \return Usefulness of the input
*/
using SomeLambda = ::std::function<double(const ::std::string&, const int32_t)>;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class _GLUECODIUM_CPP_EXPORT ExcludedCommentsOnly {
USELESS
};
/**
*
* \private
* \param[in] ::std::string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one lost the const&. Would need some fix.

* \param[in] int32_t
* \return
*/
using SomeLambda = ::std::function<double(const ::std::string&, const int32_t)>;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ void smokeCommentsSomestructReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeCommentsSomestructReleaseHandleNullable(handle);
// End of Comments_SomeStruct "private" section.
/// This is some very useful lambda that does it.
///
/// [String] Very useful input parameter
///
/// [int] Slightly less useful input parameter
///
/// Returns [double]. Usefulness of the input
///
typedef Comments_SomeLambda = double Function(String, int);
// Comments_SomeLambda "private" section, not exported.
final _smokeCommentsSomelambdaRegisterFinalizer = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ void smokeExcludedcommentsSomestructReleaseFfiHandleNullable(Pointer<Void> handl
_smokeExcludedcommentsSomestructReleaseHandleNullable(handle);
// End of ExcludedComments_SomeStruct "private" section.
/// This is some very useful lambda that does it.
///
/// [String] Very useful input parameter
///
/// [int] Slightly less useful input parameter
///
/// Returns [double]. Usefulness of the input
///
/// @nodoc
typedef ExcludedComments_SomeLambda = double Function(String, int);
// ExcludedComments_SomeLambda "private" section, not exported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class Comments {
/// This is some very useful exception.
public typealias SomethingWrongError = Comments.SomeEnum
/// This is some very useful lambda that does it.
/// - Parameters:
/// - String: Very useful input parameter
/// - Int32: Slightly less useful input parameter
/// - Returns: Usefulness of the input
public typealias SomeLambda = (String, Int32) -> Double
/// This is some very useful constant.
public static let veryUseful: Comments.Usefulness = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class ExcludedComments {
/// :nodoc:
public typealias SomethingWrongError = ExcludedComments.SomeEnum
/// This is some very useful lambda that does it.
/// - Parameters:
/// - String: Very useful input parameter
/// - Int32: Slightly less useful input parameter
/// - Returns: Usefulness of the input
/// :nodoc:
public typealias SomeLambda = (String, Int32) -> Double
/// This is some very useful constant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public class ExcludedCommentsOnly {
public typealias Usefulness = Bool
/// :nodoc:
public typealias SomethingWrongError = ExcludedCommentsOnly.SomeEnum
///
/// - Parameters:
/// - String:
/// - Int32:
/// - Returns:
/// :nodoc:
public typealias SomeLambda = (String, Int32) -> Double
/// :nodoc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class _GLUECODIUM_CPP_EXPORT Lambdas {
using Producer = ::std::function<::std::string()>;
/**
* Should confuse everyone thoroughly
* \param[in] ::std::string
* \return
*/
using Confuser = ::std::function<::smoke::Lambdas::Producer(const ::std::string&)>;
using Consumer = ::std::function<void(const ::std::string&)>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void smokeLambdasProducerReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeLambdasProducerReleaseHandleNullable(handle);
// End of Lambdas_Producer "private" section.
/// Should confuse everyone thoroughly
///
typedef Lambdas_Confuser = Lambdas_Producer Function(String);
// Lambdas_Confuser "private" section, not exported.
final _smokeLambdasConfuserRegisterFinalizer = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Foundation
public class Lambdas {
public typealias Producer = () -> String
/// Should confuse everyone thoroughly
/// - Parameter String:
/// - Returns:
public typealias Convoluter = (String) -> Lambdas.Producer
public typealias Consumer = (String) -> Void
public typealias Indexer = (String, Float) -> Int32
Expand Down
6 changes: 3 additions & 3 deletions lime-loader/src/main/antlr/LimeParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ parentTypes
function
: docComment* annotation* ('static' NewLine*)? 'fun' NewLine* simpleId NewLine*
'(' NewLine* (parameter (',' NewLine* parameter)*)? ')' NewLine*
returnType? throwsClause? NewLine*
(':' returnType)? throwsClause? NewLine*
;

constructor
Expand All @@ -74,7 +74,7 @@ parameter
;

returnType
: ':' NewLine* docComment* typeRef NewLine*
: NewLine* docComment* typeRef NewLine*
;

throwsClause
Expand Down Expand Up @@ -133,7 +133,7 @@ exception
lambda
: docComment* annotation* 'lambda' NewLine* simpleId NewLine* '=' NewLine*
'(' NewLine* (lambdaParameter (',' NewLine* lambdaParameter)*)? ')' NewLine*
'->' NewLine* typeRef NewLine+
'->' returnType
;

lambdaParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,19 @@ internal class AntlrLimeModelBuilder(
)
)
}
val returnType = ctx.returnType()
?.let {
LimeReturnType(
typeMapper.mapTypeRef(currentPath, it.typeRef()),
getComment("return", it.docComment(), it)
)
} ?: LimeReturnType.VOID
val limeElement = LimeLambda(
path = currentPath,
comment = parseStructuredComment(ctx.docComment(), ctx).description,
attributes = AntlrLimeConverter.convertAnnotations(currentPath, ctx.annotation()),
parameters = parameters,
returnType = LimeReturnType(
typeMapper.mapTypeRef(currentPath, ctx.typeRef()),
getComment("return", null, ctx)
)
returnType = returnType
)

storeResultAndPopStacks(limeElement)
Expand Down
Loading