Fix ObjC++ structs and method mapping

Summary:
Adjust generated ObjC++ code to resolve a few build time and run time errors:

* Suppress CONSTANTS struct implementations
* Use type alias name as struct name when serializing arguments that involve a type alias
* Use actual number of arguments for a method when generating method map.

With these changes in place, RNTester can be built and run using the code that is generated by the new codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23926500

fbshipit-source-id: 88fcbb795fd71dc8155eb26348db943975e13e84
This commit is contained in:
Ramanpreet Nara
2020-09-29 14:39:41 -07:00
committed by Facebook GitHub Bot
parent 97d3e85c29
commit 6d6e04619f
4 changed files with 61 additions and 161 deletions
@@ -46,11 +46,12 @@ namespace facebook {
Native${moduleName}SpecJSI::Native${moduleName}SpecJSI(const ObjCTurboModule::InitParams &params)
: ObjCTurboModule(params) {
${methodSerializationOutputs
.map(({methodName, structParamRecords}) =>
.map(({methodName, structParamRecords, argCount}) =>
MethodMapEntryTemplate({
moduleName,
methodName,
structParamRecords,
argCount,
}),
)
.join('\n' + ' '.repeat(8))}
@@ -94,12 +95,14 @@ const MethodMapEntryTemplate = ({
moduleName,
methodName,
structParamRecords,
argCount,
}: $ReadOnly<{|
moduleName: string,
methodName: string,
structParamRecords: $ReadOnlyArray<StructParameterRecord>,
argCount: number,
|}>) => `
methodMap_["${methodName}"] = MethodMetadata {1, __hostFunction_Native${moduleName}SpecJSI_${methodName}};
methodMap_["${methodName}"] = MethodMetadata {${argCount}, __hostFunction_Native${moduleName}SpecJSI_${methodName}};
${structParamRecords
.map(({paramIndex, structName}) => {
return `setMethodArgConversionSelector(@"${methodName}", ${paramIndex}, @"JS_Native${moduleName}_${structName}:");`;
@@ -114,7 +117,7 @@ function serializeModuleSource(
): string {
return ModuleTemplate({
moduleName,
structs,
structs: structs.filter(({context}) => context !== 'CONSTANTS'),
methodSerializationOutputs,
});
}