Skip to content

Commit

Permalink
Make <NSObject> protocol optional via command line switch
Browse files Browse the repository at this point in the history
  • Loading branch information
li-feng-sc committed Jul 7, 2022
1 parent 61a38ee commit ca15c6c
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/generated-src/objc/TXSTextboxListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <Foundation/Foundation.h>


@protocol TXSTextboxListener
@protocol TXSTextboxListener <NSObject>

- (void)update:(nonnull TXSItemList *)items;

Expand Down
2 changes: 1 addition & 1 deletion perftest/generated-src/objc/TXSObjectPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


/** interfaces for platform Java or Objective-C objects, to be passed to C++ */
@protocol TXSObjectPlatform
@protocol TXSObjectPlatform <NSObject>

- (void)onDone;

Expand Down
5 changes: 5 additions & 0 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ object Main {
var objcppFunctionPrologueFile: Option[String] = None
var objcppDisableExceptionTranslation: Boolean = false
var objcFileIdentStyleOptional: Option[IdentConverter] = None
var objcStrictProtocol: Boolean = true
var objcppNamespace: String = "djinni_generated"
var objcBaseLibIncludePrefix: String = ""
var wasmOutFolder: Option[File] = None
Expand Down Expand Up @@ -202,6 +203,9 @@ object Main {
.text("Disable generating Objective-C class init helper method.")
opt[Boolean]("objc-closed-enums").valueName("<true/false>").foreach(x => objcClosedEnums = x)
.text("All generated Objective-C enums will be NS_CLOSED_ENUM (default: false). ")
opt[Boolean]("objc-strict-protocols")
.valueName("<true/false>").foreach(x => objcStrictProtocol = x)
.text("All generated @protocol will implement <NSObject> (default: true). ")
note("")
opt[File]("objcpp-out").valueName("<out-folder>").foreach(x => objcppOutFolder = Some(x))
.text("The output folder for private Objective-C++ files (Generator disabled if unspecified).")
Expand Down Expand Up @@ -416,6 +420,7 @@ object Main {
objcGenProtocol,
objcDisableClassCtor,
objcClosedEnums,
objcStrictProtocol,
wasmOutFolder,
wasmIncludePrefix,
wasmIncludeCppPrefix,
Expand Down
7 changes: 6 additions & 1 deletion src/source/ObjcGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) {

w.wl
writeDoc(w, doc)
if (useProtocol(i.ext, spec)) w.wl(s"@protocol $self") else w.wl(s"@interface $self : NSObject")
if (useProtocol(i.ext, spec)) {
val baseProtocol = if (spec.objcStrictProtocol) " <NSObject>" else ""
w.wl(s"@protocol $self$baseProtocol")
} else {
w.wl(s"@interface $self : NSObject")
}

for (m <- i.methods) {
if (!m.static || (!spec.objcGenProtocol && m.lang.objc)) {
Expand Down
1 change: 1 addition & 0 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ package object generatorTools {
objcGenProtocol: Boolean,
objcDisableClassCtor: Boolean,
objcClosedEnums: Boolean,
objcStrictProtocol: Boolean,
wasmOutFolder: Option[File],
wasmIncludePrefix: String,
wasmIncludeCppPrefix: String,
Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBAsyncInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <Foundation/Foundation.h>


@protocol DBAsyncInterface
@protocol DBAsyncInterface <NSObject>

- (nonnull DJFuture<NSString *> *)futureRoundtrip:(nonnull DJFuture<NSNumber *> *)f;

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBClientInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


/** Client interface */
@protocol DBClientInterface
@protocol DBClientInterface <NSObject>

/** Returns record of given string */
- (nonnull DBClientReturnedRecord *)getRecord:(int64_t)recordId
Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBEnumUsageInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <Foundation/Foundation.h>


@protocol DBEnumUsageInterface
@protocol DBEnumUsageInterface <NSObject>

- (DBColor)e:(DBColor)e;

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBExternInterface2.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#import <Foundation/Foundation.h>


@protocol DBExternInterface2
@protocol DBExternInterface2 <NSObject>

- (nonnull DBExternRecordWithDerivings *)foo:(nullable DBTestHelpers *)i;

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBFirstListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


/** Used for ObjC multiple inheritance tests */
@protocol DBFirstListener
@protocol DBFirstListener <NSObject>

- (void)first;

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBObjcOnlyListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#import <Foundation/Foundation.h>


@protocol DBObjcOnlyListener
@protocol DBObjcOnlyListener <NSObject>

@end
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBSecondListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


/** Used for ObjC multiple inheritance tests */
@protocol DBSecondListener
@protocol DBSecondListener <NSObject>

- (void)second;

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/objc/DBUserToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import <Foundation/Foundation.h>


@protocol DBUserToken
@protocol DBUserToken <NSObject>

- (nonnull NSString *)whoami;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Generating and compiling this makes sure other languages don't break
* on references to interfaces they don't need.
*/
@protocol DBUsesSingleLanguageListeners
@protocol DBUsesSingleLanguageListeners <NSObject>

- (void)callForObjC:(nullable id<DBObjcOnlyListener>)l;

Expand Down

0 comments on commit ca15c6c

Please sign in to comment.