Skip to content

Commit

Permalink
Fix missing documentation
Browse files Browse the repository at this point in the history
Fix an issue where generated code would sometimes be missing
documentation. This was causing missing enum class comments
in C++, missing enum comments in Swift, and missing static
method comments in Swift.
  • Loading branch information
trblunt committed Oct 3, 2024
1 parent 3fe25d8 commit 51a7f7b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/generated-src/swift/SortItems+Private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SortItems_statics {
try handleCppErrors(&ret)
return SortItemsMarshaller.fromCpp(ret)
}
/** For the localhost / command-line demo */
public static func runSort(_ items: TextSort.ItemList) throws -> TextSort.ItemList {
var _params = djinni.swift.ParameterList()
_params.addValue(ItemListMarshaller.toCpp(items))
Expand Down
9 changes: 5 additions & 4 deletions src/source/CppGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* This file has been modified by Snap, Inc.
*/

Expand Down Expand Up @@ -72,6 +72,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
val underlyingType = if(e.flags) flagsType else enumType

writeHppFile(ident, origin, refs.hpp, refs.hppFwds, w => {
writeDoc(w, doc)
w.w(s"enum class $self : $underlyingType").bracedSemi {
writeEnumOptionNone(w, e, idCpp.enum)
writeEnumOptions(w, e, idCpp.enum)
Expand Down Expand Up @@ -264,9 +265,9 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
writeAlignedCall(w, ": " + actualSelf + "(", r.fields, ")", f => {
var param = "std::move(" + idCpp.local(f.ident) + "_)"
if (isOptional(f.ty.resolved))
if (isInterface(f.ty.resolved.args.head))
param = s"nullptr"
else
if (isInterface(f.ty.resolved.args.head))
param = s"nullptr"
else
param = s"${spec.cppNulloptValue}"

param
Expand Down
3 changes: 3 additions & 0 deletions src/source/SwiftGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
writeSwiftFile(ident, origin, List[String](), w => {
val t = marshal.typename(ident, e)
if (e.flags) {
writeDoc(w, doc)
w.w(s"public struct $t: OptionSet").braced {
w.wl("public let rawValue: Int32")
w.wl("public init(rawValue: Int32) { self.rawValue = rawValue }")
Expand All @@ -95,6 +96,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
writeFlagAll(w, e, idSwift.enum, t)
}
} else {
writeDoc(w, doc)
w.w(s"public enum ${marshal.typename(ident, e)}: Int32").braced {
writeEnumOptions(w, e, idSwift.enum, "=", "case ", "")
}
Expand Down Expand Up @@ -326,6 +328,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
if (!staticMethods.isEmpty) {
w.w(s"public class ${marshal.typename(ident, i)}_statics").braced {
for (m <- staticMethods) {
writeMethodDoc(w, m, idSwift.local)
w.w(s"public static func ${swiftMethodName(m.ident)}(")
if (m.params.nonEmpty) { w.w("_ ") }
w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", "))
Expand Down
1 change: 1 addition & 0 deletions test-suite/generated-src/cpp/constant_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace testsuite {

/** enum for use in constants */
enum class constant_enum : int {
SOME_VALUE = 0,
SOME_OTHER_VALUE = 1,
Expand Down
1 change: 1 addition & 0 deletions test-suite/generated-src/swift/ConstantEnum.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file was generated by Djinni from constant_enum.djinni

/** enum for use in constants */
public enum ConstantEnum: Int32 {
case someValue = 0
case someOtherValue = 1
Expand Down
12 changes: 12 additions & 0 deletions test-suite/generated-src/swift/TestHelpers+Private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ public enum TestHelpersMarshaller: DjinniSupport.Marshaller {
}
}
public class TestHelpers_statics {
/** Method with documentation */
public static func getSetRecord() throws -> TestSuite.SetRecord {
var _params = djinni.swift.ParameterList()
var ret = djinni_generated.TestHelpers_getSetRecord(&_params)
try handleCppErrors(&ret)
return SetRecordMarshaller.fromCpp(ret)
}
/**
* Method with long documentation
* (Second line of multi-line documentation.
* Indented third line of multi-line documentation.)
*/
public static func checkSetRecord(_ rec: TestSuite.SetRecord) throws -> Bool {
var _params = djinni.swift.ParameterList()
_params.addValue(SetRecordMarshaller.toCpp(rec))
Expand Down Expand Up @@ -172,6 +178,7 @@ public class TestHelpers_statics {
try handleCppErrors(&ret)
return OptionalMarshaller<I32Marshaller>.fromCpp(ret)
}
/** Ensures that we generate integer translation code */
public static func assortedPrimitivesId(_ i: TestSuite.AssortedPrimitives) throws -> TestSuite.AssortedPrimitives {
var _params = djinni.swift.ParameterList()
_params.addValue(AssortedPrimitivesMarshaller.toCpp(i))
Expand Down Expand Up @@ -212,13 +219,18 @@ public class TestHelpers_statics {
try handleCppErrors(&ret)
return DjinniSupport.FutureMarshaller<Void_Marshaller>.fromCpp(ret)
}
/**
* If the input is empty, returns back an empty future.
* If the input is non-empty, returns back the value plus one.
*/
public static func addOneIfPresent(_ f: DjinniSupport.DJFuture<Optional<Int32>>) throws -> DjinniSupport.DJFuture<Optional<Int32>> {
var _params = djinni.swift.ParameterList()
_params.addValue(DjinniSupport.FutureMarshaller<OptionalMarshaller<I32Marshaller>>.toCpp(f))
var ret = djinni_generated.TestHelpers_addOneIfPresent(&_params)
try handleCppErrors(&ret)
return DjinniSupport.FutureMarshaller<OptionalMarshaller<I32Marshaller>>.fromCpp(ret)
}
/** try-catches the future f, and accesses the error message, and returns as a string. */
public static func returnExceptionString(_ f: DjinniSupport.DJFuture<Int32>) throws -> DjinniSupport.DJFuture<String> {
var _params = djinni.swift.ParameterList()
_params.addValue(DjinniSupport.FutureMarshaller<I32Marshaller>.toCpp(f))
Expand Down

0 comments on commit 51a7f7b

Please sign in to comment.