diff --git a/src/gen/generate/param_generate.js b/src/gen/generate/param_generate.js index fd5865e4b988afb2c92a7434af2f3d70c8ea5d7a..5ba6c1f1cdda589e44095dae4f6ec21408afec51 100644 --- a/src/gen/generate/param_generate.js +++ b/src/gen/generate/param_generate.js @@ -103,14 +103,21 @@ function getArrayTypeTemplete(type) { arrayType = "std::string" } else if (arrayType == "boolean") { arrayType = "bool" - } else if (arrayType == "[key:string]:string") { + } else if (arrayType == "[key:string]:string" || arrayType == "Map") { arrayType = "std::map" - } else if (arrayType.substring(0, arrayType.length-1) == "[key:string]:NUMBER_TYPE_") { + } else if (arrayType.substring(0, arrayType.length-1) == "[key:string]:NUMBER_TYPE_" || + arrayType.substring(0, arrayType.length-1) == "Map") { let len = arrayType.length let num = arrayType.substring(len-1, len) arrayType = "std::map".format(num) - } else if (arrayType == "[key:string]:boolean") { + } else if (arrayType == "[key:string]:boolean" || arrayType == "Map") { arrayType = "std::map" + } else if (arrayType.substring(0, 14) == "[key:string]:") { + let valueType = arrayType.substring(14, arrayType.length) + arrayType = "std::map".format(valueType) + } else if (arrayType.substring(0, 11) == "Map 0 ? ", " : "", p) param.valueDefine += "%sstd::vector<%s> %s%s".format(param.valueDefine.length > 0 ? ", " : "", arrayType, modifiers, name) - } else if (type.substring(0, 6) == "Array<") { - let str = "[key:string]:" - let strLen = str.length + } else if (type.substring(0, 6) == "Array<") { let arrayType = getArrayType(type) - if (arrayType == "string") arrayType = "std::string" - if (arrayType == "boolean") arrayType = "bool" - if (arrayType.substring(0, strLen) == "[key:string]:") { - let valueTypeIn = arrayType.substring(strLen, arrayType.length) - let valueTypeOut - if (valueTypeIn == "string") { - valueTypeOut = "std::string" - } else if (valueTypeIn == "boolean") { - valueTypeOut = "bool" - } else { - valueTypeOut = valueTypeIn - } - arrayType = "std::map".format(valueTypeOut) + let strLen = getMapKeyLen(arrayType) + let keyType = arrayType.substring(0, strLen) + + if (arrayType == "string") { + arrayType = "std::string" + } else if (arrayType == "boolean") { + arrayType = "bool" + } else if (keyType == "[key:string]:"|| keyType == "Map* in%d = nullptr;".format(arrayType, p) : "\n std::vector<%s> in%d;".format(arrayType, p) diff --git a/src/gen/tools/common.js b/src/gen/tools/common.js index 5a160741f840c7d274635c80f06838913bed8a20..e555c51b7544840775003da138f1be7e2754d2ad 100644 --- a/src/gen/tools/common.js +++ b/src/gen/tools/common.js @@ -102,18 +102,34 @@ function getArrayType(type) { let tt = re.match("Array<([a-zA-Z_0-9]+)>", type) if (tt != null) { return re.getReg(type, tt.regs[1]) - } else { - tt = re.match("Array<{([[a-z:]+)([a-z:]]+)([a-zA-Z_1-9:]+)", type) - if (tt != null) { - let res = '' - let len = tt.regs.length - for (let i=1; i>; -- 待实现 } + + function fun7(v: Array<{[key: string]:testInerface}>): number; -- 待实现 + function fun10(v: Array>): number; -- 待实现 + function fun11(v: Array>): number; -- 待实现 + function fun17(v: Array>>): number; -- 待实现 + + --not support-- + function fun4(v: Array<{[key: string]:Object}>): number; -- 参数、返回值暂时不支持 + function fun5(v: Array<{[key: string]:[]}>): number; -- ohos中无此类用法,暂不实现 + function fun6(v: Array<{[key: string]:any}>): number; -- 依赖于参数、返回值any类型 + + function fun13(v: {[key: string]:any}[]): number; --ohos中无此类用法,暂不实现 + function fun14(v: {[key: string]:any}[]): number; --ohos中无此类用法,暂不实现 + function fun15(v: map[]): number; --ohos中无此类用法,暂不实现 + function fun15(v: string): map[]; --ohos中返回值类型为 map数组,无此类用法,暂不实现 + */ + function fun1(v: Array<{[key: string]:string}>): number; function fun2(v: Array<{[key: string]:number}>): number; function fun3(v: Array<{[key: string]:boolean}>): number; + + function fun8(v: Array>): number; + function fun9(v: Array>): number; + function fun10(v: Array>): number; } export default napitest; \ No newline at end of file diff --git a/test/storytest/test_array_map/test.js b/test/storytest/test_array_map/test.js index d78cbfaf9107c037aec51bef598bbf8328db06e0..cd1b2258d403786fb7f1eb2c4db8cb5e3b81ec3f 100644 --- a/test/storytest/test_array_map/test.js +++ b/test/storytest/test_array_map/test.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1, fun2, fun3 } = require("./out/build/Release/napitest") +const { fun1, fun2, fun3, fun8, fun9, fun10} = require("./out/build/Release/napitest") var assert = require("assert"); describe('array_map', function () { @@ -30,4 +30,37 @@ describe('array_map', function () { let ret = fun3([{"age":true}, {"name":false}]); assert.strictEqual(ret, 0); }); -}); \ No newline at end of file + + it('test fun8', function () { + let ret = fun8([{"age":"a"}, {"name":"b"}]); + assert.strictEqual(ret, 0); + }); + + it('test fun9', function () { + let ret = fun9([{"age":1}, {"name":2}]); + assert.strictEqual(ret, 0); + }); + + it('test fun10', function () { + let ret = fun10([{"age":true}, {"name":false}]); + assert.strictEqual(ret, 0); + }); + + /* + it('test fun7', function () { + let ret = fun7([{"key":'{"code":0,"data":"code0"}'}, {"name":'{"code":1,"data":"code1"}'}]); + assert.strictEqual(ret, 0); + }); + */ + + /*it('test fun12', function () { + let ret = fun12([{"key1":'code1'}, {"key2":'code2'}]); + assert.strictEqual(ret, 0); + }); + + it('test fun10', function () { + let ret = fun12([{"key1":'{"code":0,"data":"code0"}'}, {"key2":'{"code":1,"data":"code1"}'}]); + assert.strictEqual(ret, 0); + }); + */ +});