add SOLUTION.md

Signed-off-by: gou-jingjing <goujingjing@kaihong.com>
This commit is contained in:
gou-jingjing 2023-11-24 09:14:06 +08:00
parent b172a994e0
commit 6e9bb2c6a9
10 changed files with 146 additions and 53 deletions

72
docs/SOLUTION.md Normal file
View File

@ -0,0 +1,72 @@
# 当前已知不支持推荐方案
1.注册的object回调不支持箭头函数写法, 注册回调格式为addXXX注销回调格式为removeXXX且回调方法命名格式为onXXX, 例如:
```
export interface InterfaceB {
byClass: (listener: InterfaceA) => void;
}
export interface InterfaceA {
callFunction: (res: number) => void;
}
```
修改为:
```
export interface InterfaceB {
// object注册回调, 关键字add
addByClass(listener: InterfaceA);
// object注销回调, 关键字remove
removeByClass(listener: InterfaceA);
}
export interface InterfaceA {
onCallFunction(res: number): void;
}
```
2.注册回调只能支持单个参数, 且注册单个参数的注册回调方法命名格式为registerXXX, 例如:
```
export interface TestA {
bGyClass: (a: number, callback: (result: number) => void) => number;
}
```
修改为:
```
export interface TestA {
// 原bGyClass的参数 callback: (res: number) => void 改为registerXXX/unRegisterXXX形式
// register形式注册回调 关键字register
registerTestACallback(callback: (dd: number) => void);
// unRegister形式注销回调, 关键字unRegister
unRegisterTestACallback(callback: (dd: number) => void);
// gByClass用于调用回调
bGyClass: (a: number) => number;
}
```
3.生成报错The current version does not support generating parameter。
```
genError:at paramGenerate [C:\snapshot\napi_generator\src\gen\generate\param_generate.js(899:17)] The current version does not support generating parameter [elementName] with type [ElementName]
```
ts文件为
```
import { ElementName } from './bundleManager/ElementName';
declare namespace cardEmulation {
export class HceService {
start(elementName: ElementName, aidList: string[]): void;
stop(elementName: ElementName): void;
}
}
export default cardEmulation;
```
修改:
文件中引用了 ElementName 类型, 需要把被引用的文件( import { ElementName } from './bundleManager/ElementName'; )放到转换路径下工具才可进行转换

View File

@ -7,6 +7,10 @@
## 版本特性<a name="section249611124917"></a>
**表 1** 已支持特性
当前已知不支持写法的适配工具的推荐方案:
[当前已知不支持的推荐方案](https://gitee.com/openharmony/napi_generator/blob/master/docs/SOLUTION.md)
<a name="table143385853320"></a>
<table><thead align="left"><tr id="row53375863312"><th class="cellrowborder" valign="top" width="18%" id="mcps1.2.3.1.1"><p id="p20331858193317"><a name="p20331858193317"></a><a name="p20331858193317"></a><ul>类别</ul></p>

View File

@ -7,6 +7,10 @@
## 版本特性<a name="section249611124917"></a>
**表 1** 已支持特性
当前已知不支持写法的适配工具的推荐方案:
[当前已知不支持的推荐方案](https://gitee.com/openharmony/napi_generator/blob/master/docs/SOLUTION.md)
<a name="table143385853320"></a>
<table><thead align="left"><tr id="row53375863312"><th class="cellrowborder" valign="top" width="18%" id="mcps1.2.3.1.1"><p id="p20331858193317"><a name="p20331858193317"></a><a name="p20331858193317"></a><ul>类别</ul></p>
@ -30,7 +34,7 @@ interface Test {
</tr>
<tr id="row334175803317"><td class="cellrowborder" valign="top" width="18%" headers="mcps1.2.3.1.1 "><p id="p382391145710"><a name="p382391145710"></a><a name="p382391145710"></a><ul>函数类型</ul></p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.2.3.1.2 "><a name="ul334485413318"></a><a name="ul334485413318"></a><ul id="ul334485413318"><li>支持ts接口文件中namespace域中的registerXXX注册、unRegisterXXX去注册函数</li><li>支持ts语言中callback、promise类型的异步函数自动转换为C++类型</li><li>支持ts接口文件中namespace域中的addXXX注册、removeXXX去注册、onXXX定义回调的函数</li><li>支持on注册类型为固定值,注册回调为箭头函数如function on(type: 'onEvents', callback: (wid: number) => void): void; </li><li>支持文件中定义多个on注册函数</li><li>支持callback方法为箭头函数如function fun1(cb: (wid: boolean) => string): string;</li><li>支持callback方法为Function关键字如function fun2(tt: Function): void;</li><li>支持Promise类型是匿名interface的函数</li></ul>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.2.3.1.2 "><a name="ul334485413318"></a><a name="ul334485413318"></a><ul id="ul334485413318"><li>支持ts接口文件中namespace域中的registerXXX注册、unRegisterXXX去注册函数当前注册回调支持单个参数不支持多个参数。如registerCallbackfunc(cb : (wid: number) => string);或者fun11(cb: Callback<number>): void;或者fun17(tt: Function): string;</li><li>支持ts语言中callback、promise类型的异步函数自动转换为C++类型</li><li>支持ts接口文件中namespace域中的addXXX注册、removeXXX去注册、onXXX定义回调的函数1当前注册回调支持单个参数不支持多个参数支持类型写法addSayHelloListener(listener: NodeISayHelloListener);2注册的object回调函数写法不支持箭头函数写法, 只支持onSayHelloStart(info1: SayInfo, info2: string);这样的写法)</li><li>支持on注册类型为固定值,注册回调为箭头函数如function on(type: 'onEvents', callback: (wid: number) => void): void; </li><li>支持文件中定义多个on注册函数</li><li>支持callback方法为箭头函数如function fun1(cb: (wid: boolean) => string): string;</li><li>支持callback方法为Function关键字如function fun2(tt: Function): void;</li><li>支持Promise类型是匿名interface的函数。如sayHelloWithResponse(from: string, to: string, sayType: SayType): Promise<{result: number, errMsg: string, response: string}>; </li></ul>
</td>
<td class="cellrowborder" valign="top" width="12%" headers="mcps1.2.3.1.3 "><p id="p2142111345716"><a name="p2142111345716"></a><a name="p2142111345716"></a><ul>V1.4</ul></p>
</td>
@ -61,7 +65,11 @@ interface Test {
**表 2**
[待开发特性](https://gitee.com/openharmony/napi_generator/blob/master/docs/ROADMAP_ZH.md)

View File

@ -14,7 +14,7 @@
*/
const re = require("../tools/re");
const { FuncType, NumberIncrease, isEnum, EnumValueType, enumIndex, isType, typeIndex, isOnObjCallback,
getOnObjCallbackType } = require("../tools/common");
getOnObjCallbackType, getLogErrInfo } = require("../tools/common");
const { analyzeParams } = require("./params");
const { analyzeReturn } = require("./return");
const { NapiLog } = require("../tools/NapiLog");
@ -69,8 +69,8 @@ function getFuncParaType(v, interfaceName, data, results) {
} else if (data.enum[index].body.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
v["type"] = v["type"].replace(parameter, "string")
} else {
NapiLog.logError("analyzeFunction getFuncParaType is not support this type %s"
.format(data.enum[index].body.enumValueType));
NapiLog.logError("analyzeFunction getFuncParaType is not support this type %s."
.format(data.enum[index].body.enumValueType), getLogErrInfo);
return null
}
}
@ -82,8 +82,8 @@ function getFuncParaType(v, interfaceName, data, results) {
} else if (results.enum[index].body.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
v["type"] = v["type"].replace(parameter, "string")
} else {
NapiLog.logError("analyzeFunction getFuncParaType is not support this type %s"
.format(results.enum[index].body.enumValueType));
NapiLog.logError("analyzeFunction getFuncParaType is not support this type %s."
.format(results.enum[index].body.enumValueType), getLogErrInfo());
return null
}
}
@ -256,7 +256,7 @@ function analyzeFunction(data, isStatic, name, values, ret, results, interfaceNa
let v = values[j]
v = getFuncParaType(v, res.interfaceName, data, results)
if (v == null) {
NapiLog.logError("analyzeFunction is not support this type %s".format(v));
NapiLog.logError("analyzeFunction is not support this type %s.".format(v), getLogErrInfo());
}
}
ret = analyseSubReturn(ret, data, results)

View File

@ -19,7 +19,7 @@ const { analyzeInterface, parseNotes } = require("./interface");
const { analyzeEnum } = require("./enum");
const { NapiLog } = require("../tools/NapiLog");
const { analyzeType, analyzeType2, analyzeType2Result } = require("./type");
const { NumberIncrease, EnumValueType } = require("../tools/common");
const { NumberIncrease, EnumValueType, getLogErrInfo } = require("../tools/common");
function preProcessData(data) {
data = data.indexOf("//") < 0 ? data : parseNotes(data);
@ -123,8 +123,8 @@ function parseEnumType(result) {
} else if (enumm.body.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
v.type = "string";
} else {
NapiLog.logError("parseEnumType for interface function value is not support this type %s"
.format(enumm.body.enumValueType));
NapiLog.logError("parseEnumType for interface function value is not support this type %s."
.format(enumm.body.enumValueType), getLogErrInfo());
return null;
}
result.interface[i].body.function[j].value[k].type = v.type;

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
const re = require("../tools/re");
const { EnumValueType } = require("../tools/common");
const { EnumValueType, getLogErrInfo } = require("../tools/common");
const { NapiLog } = require("../tools/NapiLog");
function generateEnum(name, data) {
let implH = ""
@ -25,7 +25,7 @@ function generateEnum(name, data) {
} else if (data.enumValueType == EnumValueType.ENUM_VALUE_TYPE_NUMBER){
implH = `\nenum class %s {\n`.format(name, implH)
} else {
NapiLog.logError(`The enum type[%s] is not support`.format(data.enumValueType));
NapiLog.logError(`The enum type[%s] is not support.`.format(data.enumValueType), getLogErrInfo());
return {implH: "", implCpp: ""}
}
for (let i in data.element) {

View File

@ -16,7 +16,7 @@ const { replaceAll, getPrefix, getConstNum } = require("../tools/tool");
const { paramGenerate } = require("./param_generate");
const { returnGenerate } = require("./return_generate");
const { NapiLog } = require("../tools/NapiLog");
const { NumberIncrease, jsonCfgList }= require("../tools/common");
const { NumberIncrease, jsonCfgList, getLogErrInfo }= require("../tools/common");
/**
* 结果通过同步回调(CallBack)返回
@ -130,7 +130,8 @@ function callBackReturnValJs2C(className, funcName, callbackRetType, funcRetType
cbRetJs2CTrans = 'NUMBER_JS_2_C(retVal, NUMBER_TYPE_1, vio->cbOut);\n' +
'%s%sReturn(vio->cbOut%s);\n'.format(className == null ? "" : "pInstance->", funcName, retOutFill);
} else {
NapiLog.logError("callBackReturnValJs2C not surpport callbackRetType:%s".format(callbackRetType));
NapiLog.logError("callBackReturnValJs2C not surpport callbackRetType:%s."
.format(callbackRetType), getLogErrInfo());
}
return cbRetJs2CTrans;
}
@ -170,7 +171,8 @@ function fillCbRetValueStruct(type, param, outName) {
type, outName)
}
else {
NapiLog.logError("[fillCbRetValueStruct] The current type:%s don't support".format(type));
NapiLog.logError("[fillCbRetValueStruct] The current type:%s don't support."
.format(type), getLogErrInfo());
}
}
@ -204,7 +206,8 @@ function fillValueStruct(type, param, outName) {
}
}
else {
NapiLog.logError("[fillValueStruct] The current type:%s don't support".format(type));
NapiLog.logError("[fillValueStruct] The current type:%s don't support."
.format(type), getLogErrInfo());
}
}
@ -220,7 +223,8 @@ function callbackReturnProc(param, func) {
} else if (func.ret == "void") {
NapiLog.logInfo("The current void type don't need generate");
} else{
NapiLog.logError("not support func.ret:%s!".format(func.ret))
NapiLog.logError("not support returnType:%s!".format(param.callback.returnType),
getLogErrInfo())
}
} else {
// param.cbRetvalueDefine赋值传递给funcnameReturn函数

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
const { InterfaceList, getArrayType, getArrayTypeTwo, NumberIncrease,
enumIndex, isEnum, EnumValueType, getMapType,
enumIndex, isEnum, EnumValueType, getMapType, getLogErrInfo,
EnumList, getUnionType, TypeList, CallFunctionList, isFuncType, isArrowFunc } = require("../tools/common");
const re = require("../tools/re");
const { NapiLog } = require("../tools/NapiLog");
@ -104,7 +104,8 @@ function jsToC(dest, napiVn, type, enumType = 0, optional) {
} else if (type == "Object" || type == "object") {
return objectTempleteFunc(dest, napiVn);
}else {
NapiLog.logError(`do not support to generate jsToC %s,%s,%s`.format(dest, napiVn, type));
NapiLog.logError(`do not support to generate jsToC %s,%s,%s`
.format(dest, napiVn, type), getLogErrInfo());
}
}
@ -402,7 +403,6 @@ function paramGenerateArray(p, funcValue, param) {
let arrayType = getArrayType(type)
let strLen = getMapKeyLen(arrayType)
let keyType = arrayType.substring(0, strLen)
let suType = arrayType.substring(0,12)
if (arrayType == "string") {
arrayType = "std::string"
} else if (arrayType == "boolean") {
@ -427,7 +427,8 @@ function paramGenerateArray(p, funcValue, param) {
param.valueDefine += "%sstd::vector<%s>%s%s".format(param.valueDefine.length > 0 ? ", "
: "", arrayType, modifiers, name)
} else {
NapiLog.logError("The current version do not support to this param to generate :", name, "type :", type);
NapiLog.logError("The current version do not support to this param to generate :", name,
"type :", type, getLogErrInfo());
}
}
@ -454,7 +455,7 @@ function paramGenerateEnum(data, funcValue, param, p) {
} else if (data.enum[index].body.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
funcValue.type = "string"
} else {
NapiLog.logError(`paramGenerate is not support`);
NapiLog.logError(`paramGenerate is not support`, getLogErrInfo());
return
}
paramGenerate(p, funcValue, param, data)
@ -819,7 +820,7 @@ function paramGenerateCallBack(data, funcValue, param, p) {
} else if (data.enum[index].body.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
cbParamType = "string"
} else {
NapiLog.logError(`paramGenerate is not support`);
NapiLog.logError(`paramGenerate is not support`, getLogErrInfo());
return
}
}
@ -1060,32 +1061,23 @@ function paramGenerate(p, funcValue, param, data) {
let modifiers = funcValue.optional ? "*" : "&"
if (type.indexOf("|") >= 0) {
return paramGenerateUnion(type, param, p, name)
}
else if (type == "string") {
} else if (type == "string") {
paramGenerateCommon(p, "std::string", funcValue, param, modifiers, inParamName)
}
else if (type.substring(0, 12) == "NUMBER_TYPE_" && type.indexOf("[]") < 0) {
} else if (type.substring(0, 12) == "NUMBER_TYPE_" && type.indexOf("[]") < 0) {
paramGenerateCommon(p, funcValue.type, funcValue, param, modifiers, inParamName)
}
else if (InterfaceList.getValue(type)) {
} else if (InterfaceList.getValue(type)) {
paramGenerateCommon(p, funcValue.type, funcValue, param, modifiers, inParamName)
}
else if (TypeList.getValue(type)) {
} else if (TypeList.getValue(type)) {
paramGenerateCommon(p, funcValue.type, funcValue, param, modifiers, inParamName)
}
else if (isCallbackFunc(type)) {
} else if (isCallbackFunc(type)) {
paramGenerateCallBack(data, funcValue, param, p)
}
else if (CallFunctionList.getValue(type)) {
} else if (CallFunctionList.getValue(type)) {
paramGenerateArrowCallBack(funcValue, param, p)
}
else if (type == "boolean") {
} else if (type == "boolean") {
paramGenerateCommon(p, "bool", funcValue, param, modifiers, inParamName)
}
else if (isEnum(type, data)) {
} else if (isEnum(type, data)) {
paramGenerateEnum(data, funcValue, param, p)
}
else if (type.substring(0, 4) == "Map<" || type.substring(0, 6) == "{[key:") {
} else if (type.substring(0, 4) == "Map<" || type.substring(0, 6) == "{[key:") {
paramGenerateMap(funcValue, param, p)
} else if (isArrayType(type)) {
paramGenerateArray(p, funcValue, param);
@ -1094,8 +1086,8 @@ function paramGenerate(p, funcValue, param, data) {
} else if (type == "object" || type == "Object") {
paramGenerateObject(p, funcValue, param);
} else {
NapiLog.logError(
"The current version does not support generating parameter [%s] with type [%s]".format(name, type));
NapiLog.logError("The current version does not support generating parameter [%s] with type [%s]."
.format(name, type), getLogErrInfo());
}
}
@ -1133,8 +1125,8 @@ function eventParamGenerate(p, funcValue, param, data) {
}
param.valueDefine += "%sstd::string &%s".format(param.valueDefine.length > 0 ? ", " : "", name)
} else {
NapiLog.logError("function eventParamGenerate:The current version do not support to this param to generate :"
, name, "type :", type);
NapiLog.logError("function eventParamGenerate:The current version do not support to this param to generate :",
name, "type :", type, getLogErrInfo());
}
}

View File

@ -15,7 +15,7 @@
const { isMappedTypeNode } = require("typescript");
const { InterfaceList, getArrayType, NumberIncrease, enumIndex,
isEnum, EnumValueType, getArrayTypeTwo, getMapType, EnumList,
jsType2CType, getUnionType, TypeList, isArrowFunc } = require("../tools/common");
jsType2CType, getUnionType, TypeList, isArrowFunc, getLogErrInfo } = require("../tools/common");
const { NapiLog } = require("../tools/NapiLog");
const { print } = require("../tools/tool");
@ -153,7 +153,8 @@ function cToJs(value, type, dest, deep = 1, optional) {
return objectTempleteFuncReturn(value)
}
else {
NapiLog.logError(`\n---- This type do not generate cToJs %s,%s,%s ----\n`.format(value, type, dest));
NapiLog.logError(`\n---- This type do not generate cToJs %s,%s,%s ----\n. `
.format(value, type, dest), getLogErrInfo());
}
}
@ -354,7 +355,8 @@ function mapTempleteValue(mapType, tnvdef, lt, value, tnv) {
ret = mapInterface(value, lt, tnv, mapType)
}
else
NapiLog.logError(`This type do not generate cToJs %s,%s,%s`.format(value, type, dest));
NapiLog.logError(`This type do not generate cToJs %s,%s,%s`
.format(value, type, dest), getLogErrInfo());
return ret
}
@ -569,7 +571,8 @@ function returnGenerateForArrowCbMultiPara(paramInfo, param, data, i) {
paramInfo.name)
}
else {
NapiLog.logError("Do not support returning the type [%s].".format(type));
NapiLog.logError("Do not support returning the type [%s]."
.format(type), getLogErrInfo());
}
}
@ -615,7 +618,8 @@ function returnGenerateForOnOffMultiPara(paramInfo, param, data) {
param.params += "%s%s%s %s".format(param.params.length > 0 ? ", " : "", type, modifiers, paramInfo.name)
}
else {
NapiLog.logError("Do not support returning the type [%s].".format(type));
NapiLog.logError("Do not support returning the type [%s]."
.format(type), getLogErrInfo());
}
}
@ -659,7 +663,8 @@ function returnGenerate(returnInfo, param, data, isOnFuncFlag = false) {
} else if (isArrowFunc(type)) {
genArrowFuncParam(param, returnInfo, data);
} else {
NapiLog.logError("Do not support returning the type [%s].".format(type));
NapiLog.logError("Do not support returning the type [%s]."
.format(type), getLogErrInfo());
}
}
@ -779,7 +784,8 @@ function returnGenerateEnum(data, returnInfo, param) {
} else if (data.enum[index].body.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
type = "string"
} else {
NapiLog.logError(`function returnGenerateEnum:this type is not support %s`.format(type));
NapiLog.logError(`function returnGenerateEnum:this type is not support %s`
.format(type), getLogErrInfo());
return
}
param.valuePackage = cToJs("vio->out", type, "result")

View File

@ -421,6 +421,12 @@ jsonCfgList.getValue = function (className, inter) {
return null;
}
function getLogErrInfo() {
let errInfo = " Please refer to for support capacity:"
+ "https://gitee.com/openharmony/napi_generator/tree/master/release-notes"
return errInfo
}
module.exports = {
FuncType,
EnumValueType,
@ -446,5 +452,6 @@ module.exports = {
isUnRegisterFunc,
isOnObjCallback,
isOnOffRegisterFunc,
getOnObjCallbackType
getOnObjCallbackType,
getLogErrInfo
}