diff --git a/src/gen/generate/param_generate.js b/src/gen/generate/param_generate.js index 5ba6c1f1cdda589e44095dae4f6ec21408afec51..65c7d57db20069d1f43665f6cf49c595bde7436c 100644 --- a/src/gen/generate/param_generate.js +++ b/src/gen/generate/param_generate.js @@ -300,31 +300,64 @@ function paramGenerateMap(funcValue, param, p) { let name = funcValue.name let mapType = getMapType(type) let mapTypeString - if (mapType[1] != undefined && mapType[2] == undefined) { - if (mapType[1] == "string") { mapTypeString = "std::string" } - else if (mapType[1].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = mapType[1] } - else if (mapType[1] == "boolean") { mapTypeString = "bool" } - else { mapTypeString = mapType[1] } - } - else if (mapType[2] != undefined) { - if (mapType[2] == "string") { mapTypeString = "std::map" } - else if (mapType[2].substring(0, 12) == "NUMBER_TYPE_") { "std::map" } - else if (mapType[2] == "boolean") { mapTypeString = "std::map" } - } - else if (mapType[3] != undefined) { - if (mapType[3] == "string") { mapTypeString = "std::vector" } - else if (mapType[3].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = "std::vector<"+mapType[3]+">" } - else if (mapType[3] == "boolean") { mapTypeString = "std::vector" } + if(mapType[0].substring(0, 12) == "NUMBER_TYPE_") + { + let numbertepy = mapType[0] + if (mapType[1] != undefined && mapType[2] == undefined) { + if (mapType[1] == "string") { mapTypeString = "std::string" } + else if (mapType[1].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = mapType[1] } + else if (mapType[1] == "boolean") { mapTypeString = "bool" } + else { mapTypeString = mapType[1] } + } + else if (mapType[2] != undefined) { + if (mapType[2] == "string") { mapTypeString = "std::map" } + else if (mapType[2].substring(0, 12) == "NUMBER_TYPE_") { "std::map" } + else if (mapType[2] == "boolean") { mapTypeString = "std::map" } + } + else if (mapType[3] != undefined) { + if (mapType[3] == "string") { mapTypeString = "std::vector" } + else if (mapType[3].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = "std::vector<"+mapType[3]+">" } + else if (mapType[3] == "boolean") { mapTypeString = "std::vector" } + } + let inParamName = funcValue.optional ? "(*vio->in" + p + ")" : "vio->in" + p + let modifiers = funcValue.optional ? "*" : "&" + param.valueIn += funcValue.optional ? "\n std::map<%s,%s>* in%d = nullptr;".format(numbertepy,mapTypeString, p) + : "\n std::map<%s,%s> in%d;".format(numbertepy,mapTypeString, p) + param.valueCheckout += getValueCheckout(funcValue, param, inParamName, p, + "std::map<%s,%s>".format(numbertepy,mapTypeString)) + param.valueFill += "%svio->in%d".format(param.valueFill.length > 0 ? ", " : "", p) + param.valueDefine += "%sstd::map<%s,%s>%s %s" + .format(param.valueDefine.length > 0 ? ", " : "", numbertepy,mapTypeString, modifiers, name) + } + else + { + if (mapType[1] != undefined && mapType[2] == undefined) { + if (mapType[1] == "string") { mapTypeString = "std::string" } + else if (mapType[1].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = mapType[1] } + else if (mapType[1] == "boolean") { mapTypeString = "bool" } + else { mapTypeString = mapType[1] } + } + else if (mapType[2] != undefined) { + if (mapType[2] == "string") { mapTypeString = "std::map" } + else if (mapType[2].substring(0, 12) == "NUMBER_TYPE_") { "std::map" } + else if (mapType[2] == "boolean") { mapTypeString = "std::map" } + } + else if (mapType[3] != undefined) { + if (mapType[3] == "string") { mapTypeString = "std::vector" } + else if (mapType[3].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = "std::vector<"+mapType[3]+">" } + else if (mapType[3] == "boolean") { mapTypeString = "std::vector" } + } + let inParamName = funcValue.optional ? "(*vio->in" + p + ")" : "vio->in" + p + let modifiers = funcValue.optional ? "*" : "&" + param.valueIn += funcValue.optional ? "\n std::map* in%d = nullptr;".format(mapTypeString, p) + : "\n std::map in%d;".format(mapTypeString, p) + param.valueCheckout += getValueCheckout(funcValue, param, inParamName, p, + "std::map".format(mapTypeString)) + param.valueFill += "%svio->in%d".format(param.valueFill.length > 0 ? ", " : "", p) + param.valueDefine += "%sstd::map%s %s" + .format(param.valueDefine.length > 0 ? ", " : "", mapTypeString, modifiers, name) } - let inParamName = funcValue.optional ? "(*vio->in" + p + ")" : "vio->in" + p - let modifiers = funcValue.optional ? "*" : "&" - param.valueIn += funcValue.optional ? "\n std::map* in%d = nullptr;".format(mapTypeString, p) - : "\n std::map in%d;".format(mapTypeString, p) - param.valueCheckout += getValueCheckout(funcValue, param, inParamName, p, - "std::map".format(mapTypeString)) - param.valueFill += "%svio->in%d".format(param.valueFill.length > 0 ? ", " : "", p) - param.valueDefine += "%sstd::map%s %s" - .format(param.valueDefine.length > 0 ? ", " : "", mapTypeString, modifiers, name) + } function mapTempleteFunc(dest, napiVn, type) { @@ -351,7 +384,14 @@ for(uint32_t i[replace_lt]=0;i[replace_lt]GetMapLength(%s); +for(uint32_t i[replace_lt]=0;i[replace_lt]SwapJs2CUtf8(pxt->GetMapElementName(%s,i%d), tt%d); - pxt->SwapJs2CUtf8(pxt->GetMapElementValue(%s,tt%d.c_str()), tt%d);` - .format(napiVn, lt, lt, napiVn, lt, lt + 1)) - } - else if (mapTypeString.substring(0, 12) == "NUMBER_TYPE_") { - mapTemplete = mapTemplete.replaceAll("[replace_swap]", - `pxt->SwapJs2CUtf8(pxt->GetMapElementName(%s,i%d), tt%d); - NUMBER_JS_2_C(pxt->GetMapElementValue(%s,tt%d.c_str()),%s,tt%d);` - .format(napiVn, lt, lt, napiVn, lt, mapTypeString, lt + 1)) - } - else if (mapTypeString == "bool") { - mapTemplete = mapTemplete.replaceAll("[replace_swap]", - `pxt->SwapJs2CUtf8(pxt->GetMapElementName(%s,i%d), tt%d); - tt%d = pxt->SwapJs2CBool(pxt->GetMapElementValue(%s,tt%d.c_str()));` - .format(napiVn, lt, lt, lt + 1, napiVn, lt)) + let mapfirstType + let mapTemplete + if(mapType[0].substring(0, 12) == "NUMBER_TYPE_") + { + mapfirstType = mapType[0] + if (mapType[1] == "string") { mapTypeString = "std::string" } + else if (mapType[1].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = mapType[1] } + else if (mapType[1] == "boolean") { mapTypeString = "bool" } + else if (mapType[1] != null) { mapTypeString = mapType[1] } + mapTemplete = mapValueTempleteEx.format(napiVn,mapfirstType, mapTypeString, dest) + mapTemplete = mapTemplete.replaceAll("[replace_lt]", lt) + mapTemplete = mapTemplete.replaceAll("[replace_lt+1]", lt + 1) + if (mapTypeString == "std::string") { + mapTemplete = mapTemplete.replaceAll("[replace_swap]", + `pxt->SwapC2JsUint32(tt%d); + pxt->SwapJs2CUtf8(pxt->GetMapElementValue(%s,(const char*)(tt%d)), tt%d);` + .format(lt, napiVn, lt, lt + 1)) + } + else if (mapTypeString.substring(0, 12) == "NUMBER_TYPE_") { + mapTemplete = mapTemplete.replaceAll("[replace_swap]", + `pxt->SwapC2JsUint32(pxt->GetMapElementName(%s,i%d), tt%d); + NUMBER_JS_2_C(pxt->GetMapElementValue(%s,tt%d),%s,tt%d);` + .format(napiVn, lt, lt, napiVn, lt, mapTypeString, lt + 1)) + } + else if (mapTypeString == "bool") { + mapTemplete = mapTemplete.replaceAll("[replace_swap]", + `pxt->SwapC2JsUint32(pxt->GetMapElementName(%s,i%d), tt%d); + tt%d = pxt->SwapJs2CBool(pxt->GetMapElementValue(%s,tt%d));` + .format(napiVn, lt, lt, lt + 1, napiVn, lt)) + } + else if (InterfaceList.getValue(mapTypeString)) { + mapTemplete = mapInterface(mapTypeString, mapTemplete, napiVn, lt) + } } - else if (InterfaceList.getValue(mapTypeString)) { - mapTemplete = mapInterface(mapTypeString, mapTemplete, napiVn, lt) + else + { + if (mapType[1] == "string") { mapTypeString = "std::string" } + else if (mapType[1].substring(0, 12) == "NUMBER_TYPE_") { mapTypeString = mapType[1] } + else if (mapType[1] == "boolean") { mapTypeString = "bool" } + else if (mapType[1] != null) { mapTypeString = mapType[1] } + mapTemplete = mapValueTemplete.format(napiVn, mapTypeString, dest) + mapTemplete = mapTemplete.replaceAll("[replace_lt]", lt) + mapTemplete = mapTemplete.replaceAll("[replace_lt+1]", lt + 1) + if (mapTypeString == "std::string") { + mapTemplete = mapTemplete.replaceAll("[replace_swap]", + `pxt->SwapJs2CUtf8(pxt->GetMapElementName(%s,i%d), tt%d); + pxt->SwapJs2CUtf8(pxt->GetMapElementValue(%s,tt%d.c_str()), tt%d);` + .format(napiVn, lt, lt, napiVn, lt, lt + 1)) + } + else if (mapTypeString.substring(0, 12) == "NUMBER_TYPE_") { + mapTemplete = mapTemplete.replaceAll("[replace_swap]", + `pxt->SwapJs2CUtf8(pxt->GetMapElementName(%s,i%d), tt%d); + NUMBER_JS_2_C(pxt->GetMapElementValue(%s,tt%d.c_str()),%s,tt%d);` + .format(napiVn, lt, lt, napiVn, lt, mapTypeString, lt + 1)) + } + else if (mapTypeString == "bool") { + mapTemplete = mapTemplete.replaceAll("[replace_swap]", + `pxt->SwapJs2CUtf8(pxt->GetMapElementName(%s,i%d), tt%d); + tt%d = pxt->SwapJs2CBool(pxt->GetMapElementValue(%s,tt%d.c_str()));` + .format(napiVn, lt, lt, lt + 1, napiVn, lt)) + } + else if (InterfaceList.getValue(mapTypeString)) { + mapTemplete = mapInterface(mapTypeString, mapTemplete, napiVn, lt) + } } return mapTemplete } diff --git a/test/storytest/test_map/@ohos.test.d.ts b/test/storytest/test_map/@ohos.test.d.ts index d6f51195018d6500565617c8f77923864e0d1f65..834bedb4e51ff9f9436c5730db507c73bc2c5b8f 100644 --- a/test/storytest/test_map/@ohos.test.d.ts +++ b/test/storytest/test_map/@ohos.test.d.ts @@ -35,6 +35,7 @@ declare namespace napitest { fun8(v: Map>): number; fun9(v: {[key: string]: Human}): number; fun10(v: Map): number; + fun11(v: {[key: number]: string}): number; } } export default napitest; \ No newline at end of file diff --git a/test/storytest/test_map/test.js b/test/storytest/test_map/test.js index 52a195f5e2cbc69af1c9219de27dbeb53ed599ea..c45f4aa36e659113ad5016b39c2c27e07881f079 100644 --- a/test/storytest/test_map/test.js +++ b/test/storytest/test_map/test.js @@ -85,4 +85,9 @@ describe('Map', function () { ); assert.strictEqual(ret, 0); }); + it('test TestClass2 fun11', function () { + let tc2 = new TestClass2(); + let ret = tc2.fun11({"name":1234,"age":5678}); + assert.strictEqual(ret, 0); + }); }); \ No newline at end of file