From dec59a4fea71eb9312bc713c8bbd22bfaf0b56f9 Mon Sep 17 00:00:00 2001 From: grebelnik Date: Fri, 23 Aug 2024 13:47:07 +0500 Subject: [PATCH 1/9] CALL_LOG: add memory allocation for arrays --- package.json | 3 +- peer_lib/call_log/meson.build | 4 +- peer_lib/sig/arkoala/arkui/src/main.ts | 1 + peer_lib/sig/arkoala/arkui/src/test_utils.ts | 4 +- src/peer-generation/DeclarationTable.ts | 92 ++++++++++--------- .../printers/BridgeCcPrinter.ts | 12 ++- .../printers/ModifierPrinter.ts | 3 +- templates/dummy_impl_prologue.cc | 68 ++++++++------ 8 files changed, 108 insertions(+), 79 deletions(-) diff --git a/package.json b/package.json index 8ea4596d4..195e030f0 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "rollup:host:full": "npm run check:peers && cd out/ts-peers && rollup -c", "configure:cj:native": "cd ./native && meson setup -Dsource_set=cangjie-subset -Devents_test=false -Dcallbacks_test=false build-cangjie-native-dummy", "compile:cj:native": "npm run configure:cj:native && cd native && meson compile --verbose -C build-cangjie-native-dummy", - "run:cj": "npm run compile && node . --api-version 99 --dts2peer --need-interfaces --input-dir ./tests/cangjie-subset/ --output-dir ./out/cangjie-subset/generated --language cangjie && npm run compile:cj:native && LD_LIBRARY_PATH=./native/build-cangjie-native-dummy:$LD_LIBRARY_PATH && cjpm run" + "run:cj": "npm run compile && node . --api-version 99 --dts2peer --need-interfaces --input-dir ./tests/cangjie-subset/ --output-dir ./out/cangjie-subset/generated --language cangjie && npm run compile:cj:native && LD_LIBRARY_PATH=./native/build-cangjie-native-dummy:$LD_LIBRARY_PATH && cjpm run", + "run:peers:call_log": "npm run check:peers:run && cd ./peer_lib/call_log && meson setup build && cd ./build && meson compile && ./run_call_log" } } diff --git a/peer_lib/call_log/meson.build b/peer_lib/call_log/meson.build index 2aee2dee7..be92493f1 100644 --- a/peer_lib/call_log/meson.build +++ b/peer_lib/call_log/meson.build @@ -10,9 +10,9 @@ deps = CXX.find_library( dirs : [meson.current_source_dir() + '/../../native/'] ) # for subset: -# inc_dir = include_directories('../../generated/subset/libace/generated/interface') +# inc_dir = include_directories('../../out/ts-subset/generated/libace/generated/interface') # for peers: -inc_dir = include_directories('../../generated/peers/koalaui/arkoala/native/src/generated') +inc_dir = include_directories('../../out/ts-peers/generated/libace/generated/interface') executable( 'run_call_log', sources, diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index 05117f1c6..4f780f637 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -607,6 +607,7 @@ function main() { #include #include +#include namespace OHOS::Ace::NG::GeneratedModifier { EXTERN_C IDLIZE_API_EXPORT const GENERATED_ArkUIAnyAPI* GENERATED_GetArkAnyAPI(GENERATED_Ark_APIVariantKind kind, int version); diff --git a/peer_lib/sig/arkoala/arkui/src/test_utils.ts b/peer_lib/sig/arkoala/arkui/src/test_utils.ts index c3413a71c..6679097b8 100644 --- a/peer_lib/sig/arkoala/arkui/src/test_utils.ts +++ b/peer_lib/sig/arkoala/arkui/src/test_utils.ts @@ -27,7 +27,7 @@ export function stopNativeLog(group: number) { nativeModule()._StopGroupedLog(group) } -export function getNativeLog(group: number = TEST_GROUP_LOG): string { +export function getNativeLog(group: number): string { return withStringResult(nativeModule()._GetGroupedLog(group))! } @@ -35,7 +35,7 @@ export function checkResult(name: string, test: () => void, expected: string) { startNativeLog(TEST_GROUP_LOG) test() stopNativeLog(TEST_GROUP_LOG) - const out = getNativeLog() + const out = getNativeLog(TEST_GROUP_LOG) // remove out comments like /* some text */ const actual = out.replace(/\s?\/\*.*?\*\//g, ""); if (reportTestFailures) { diff --git a/src/peer-generation/DeclarationTable.ts b/src/peer-generation/DeclarationTable.ts index 0dc591494..5906ebc0b 100644 --- a/src/peer-generation/DeclarationTable.ts +++ b/src/peer-generation/DeclarationTable.ts @@ -1057,19 +1057,19 @@ export class DeclarationTable { writeOptional(nameOptional: string, printer: LanguageWriter, isPointer: boolean) { printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${nameOptional}* value) {`) + printer.print(`inline void WriteToString(string* result, const ${nameOptional}* value, string* prereq) {`) printer.print(`result->append("{.tag=");`) printer.print(`result->append(tagNameExact((${PrimitiveType.Tag.getText()})(value->tag)));`) printer.print(`result->append(", .value=");`) printer.pushIndent() printer.print(`if (value->tag != ${PrimitiveType.UndefinedTag}) {`) printer.pushIndent() - printer.print(`WriteToString(result, ${isPointer ? "&" : ""}value->value);`) + printer.print(`WriteToString(result, ${isPointer ? "&" : ""}value->value, prereq);`) printer.popIndent() printer.print(`} else {`) printer.pushIndent() printer.print(`${PrimitiveType.Undefined.getText()} undefined = { 0 };`) - printer.print(`WriteToString(result, undefined);`) + printer.print(`WriteToString(result, undefined, prereq);`) printer.popIndent() printer.print(`}`) printer.popIndent() @@ -1131,32 +1131,40 @@ export class DeclarationTable { let elementNativeType = convertor.nativeType(false) let constCast = isPointerField ? `(const ${elementNativeType}*)` : `` - printer.print(`inline void WriteToString(string* result, const ${name}* value, const std::string& ptrName = std::string()) {`) - printer.pushIndent() - printer.print(`result->append("{");`) - printer.print(`if (ptrName.empty()) {`) - printer.pushIndent() - printer.print(`int32_t count = value->length;`) - printer.print(`if (count > 0) result->append("{");`) - printer.print(`for (int i = 0; i < count; i++) {`) - printer.pushIndent() - printer.print(`if (i > 0) result->append(", ");`) - printer.print(`WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i]);`) - printer.popIndent() - printer.print(`}`) - printer.print(`if (count == 0) result->append("{}");`) - printer.print(`if (count > 0) result->append("}");`) - printer.popIndent() - printer.print(`} else {`) - printer.pushIndent() - printer.print(`result->append(ptrName + ".data()");`) - printer.popIndent() - printer.print(`}`) - printer.print(`result->append(", .length=");`) - printer.print(`result->append(std::to_string(value->length));`) - printer.print(`result->append("}");`) - printer.popIndent() - printer.print(`}`) + printer.print( +` +inline void WriteToString(string* result, const ${name}* value, string* prereq = nullptr, const std::string& ptrName = std::string()) { + int32_t count = value->length; + result->append("{"); + if (ptrName.empty()) { + if (count > 0) result->append(".array={"); + if (prereq != nullptr) { + result->append("prereq_" + std::to_string(prereq_num) + "[0]"); + } else { + for (int i = 0; i < count; i++) { + if (i > 0) result->append(", "); + WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i], prereq); + } + } + if (count == 0) result->append("{}"); + if (count > 0) result->append("}"); + } else { + result->append(ptrName + ".data()"); + } + result->append(", .length="); + result->append(std::to_string(value->length)); + result->append("}"); + if (prereq != nullptr) { + prereq->append(" std::vector<${elementNativeType}*> prereq_" + std::to_string(prereq_num) + "(" + std::to_string(count) + ");\\n"); + for (int i = 0; i < count; i++) { + std::string initializer; + WriteToString(&initializer, ${constCast}${isPointerField ? "&" : ""}value->array[i], nullptr); + prereq->append(" prereq_" + std::to_string(prereq_num) + "[" + std::to_string(i) + "] = new ${elementNativeType}" + initializer + ";\\n"); + } + ++prereq_num; + } +} +`) } private generateStdArrayDefinition(name: string, target: DeclarationTarget, printer: LanguageWriter) { @@ -1175,17 +1183,17 @@ export class DeclarationTable { // Provide prototype of element printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${elementNativeType}${isPointerField ? "*" : ""} value);`) + printer.print(`inline void WriteToString(string* result, const ${elementNativeType}${isPointerField ? "*" : ""} value, string* prereq);`) // Printer. - printer.print(`inline void generateStdArrayDefinition(string* result, const ${name}* value) {`) + printer.print(`inline void generateStdArrayDefinition(string* result, const ${name}* value, string* prereq) {`) printer.pushIndent() printer.print(`int32_t count = value->length;`) printer.print(`result->append("std::array<${elementNativeType}, " + std::to_string(count) + ">{{");`) printer.print(`for (int i = 0; i < count; i++) {`); printer.pushIndent() printer.print(`std::string tmp;`) - printer.print(`WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i]);`) + printer.print(`WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i], prereq);`) printer.print(`result->append(tmp);`); printer.print(`result->append(", ");`) printer.popIndent() @@ -1214,23 +1222,23 @@ export class DeclarationTable { // Provide prototype of keys printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${keyNativeType}${isPointerKeyField ? "*" : ""} value);`) + printer.print(`inline void WriteToString(string* result, const ${keyNativeType}${isPointerKeyField ? "*" : ""} value, string* prereq);`) // Provide prototype of values printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${valueNativeType}${isPointerValueField ? "*" : ""} value);`) + printer.print(`inline void WriteToString(string* result, const ${valueNativeType}${isPointerValueField ? "*" : ""} value, string* prereq);`) // Printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${name}* value) {`) + printer.print(`inline void WriteToString(string* result, const ${name}* value, string* prereq) {`) printer.pushIndent() printer.print(`result->append("{");`) printer.print(`int32_t count = value->size;`) printer.print(`for (int i = 0; i < count; i++) {`) printer.pushIndent() printer.print(`if (i > 0) result->append(", ");`) - printer.print(`WriteToString(result, ${keyConstCast}${isPointerKeyField ? "&" : ""}value->keys[i]);`) + printer.print(`WriteToString(result, ${keyConstCast}${isPointerKeyField ? "&" : ""}value->keys[i], prereq);`) printer.print(`result->append(": ");`) - printer.print(`WriteToString(result, ${valueConstCast}${isPointerValueField ? "&" : ""}value->values[i]);`) + printer.print(`WriteToString(result, ${valueConstCast}${isPointerValueField ? "&" : ""}value->values[i], prereq);`) printer.popIndent() printer.print(`}`) printer.print(`result->append("}");`) @@ -1260,7 +1268,7 @@ export class DeclarationTable { this.generateMapWriteToString(name, target, printer) } else { printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${name}${isPointer ? "*" : ""} value) {`) + printer.print(`inline void WriteToString(string* result, const ${name}${isPointer ? "*" : ""} value, string* prereq) {`) printer.pushIndent() if (isUnion) { @@ -1274,7 +1282,7 @@ export class DeclarationTable { printer.print(`if (value${access}selector == ${index - 1}) {`) printer.pushIndent() printer.print(`result->append(".${field.name}=");`); - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) printer.popIndent() printer.print(`}`) }) @@ -1292,7 +1300,7 @@ export class DeclarationTable { let isPointerField = this.isPointerDeclaration(field.declaration, field.optional) if (index > 0) printer.print(`result->append(", ");`) printer.print(`result->append(".${field.name}=");`) - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) }) printer.print(`result->append("}");`) } else if (isOptional) { @@ -1303,7 +1311,7 @@ export class DeclarationTable { if (index > 0) printer.print(`result->append(", ");`) printer.print(`result->append("${field.name}: ");`) let isPointerField = this.isPointerDeclaration(field.declaration, field.optional) - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) if (index == 0) { printer.print(`if (value${access}${field.name} != ${PrimitiveType.UndefinedTag}) {`) printer.pushIndent() @@ -1321,7 +1329,7 @@ export class DeclarationTable { if (index > 0) printer.print(`result->append(", ");`) printer.print(`result->append(".${field.name}=");`) let isPointerField = this.isPointerDeclaration(field.declaration, field.optional) - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) }) printer.print(`result->append("}");`) } diff --git a/src/peer-generation/printers/BridgeCcPrinter.ts b/src/peer-generation/printers/BridgeCcPrinter.ts index f148c564e..8a62159f3 100644 --- a/src/peer-generation/printers/BridgeCcPrinter.ts +++ b/src/peer-generation/printers/BridgeCcPrinter.ts @@ -92,23 +92,27 @@ class BridgeCcVisitor { this.generatedApi.pushIndent() this.generatedApi.print('std::string _logData;') this.generatedApi.print('std::string _tmp;') + this.generatedApi.print('std::string _prereq;') this.generatedApi.print('static int _num = 0;') - this.generatedApi.print(`static int _array_num = 0;`); + if (method.argConvertors.some(it => it instanceof ArrayConvertor)) { + this.generatedApi.print(`static int _array_num = 0;`); + } let varNames : string[] = new Array() for (let i = 0; i < method.argConvertors.length; ++i) { let it = method.argConvertors[i] let name = this.generateApiArgument(it) // it.param + '_value' if (it instanceof ArrayConvertor) { - this.generatedApi.print(`_tmp = "", generateStdArrayDefinition(&_tmp, ${name});`); + this.generatedApi.print(`_tmp = "", generateStdArrayDefinition(&_tmp, ${name}, &_prereq);`); this.generatedApi.print(`_logData.append(" auto array" + std::to_string(_array_num) + " = " + _tmp + ";");`); this.generatedApi.print(`_logData.append("\\n");`); - this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name}, "array" + std::to_string(_array_num));`) + this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name}, &_prereq, "array" + std::to_string(_array_num));`) this.generatedApi.print("_array_num += 1;") } else { - this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name});`) + this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name}, &_prereq);`) } varNames.push(`var${BridgeCcVisitor.varCnt}`) let ptrType = `const ${it.nativeType(false)}` + this.generatedApi.print(`_logData.append( _prereq);`) this.generatedApi.print(`_logData.append(" ${ptrType} ${varNames[i]}_" + std::to_string(_num) + " = " + _tmp + ";\\n");`) BridgeCcVisitor.varCnt += 1 } diff --git a/src/peer-generation/printers/ModifierPrinter.ts b/src/peer-generation/printers/ModifierPrinter.ts index 1da11e51c..1df1a33d7 100644 --- a/src/peer-generation/printers/ModifierPrinter.ts +++ b/src/peer-generation/printers/ModifierPrinter.ts @@ -163,9 +163,10 @@ export class ModifierVisitor { _.makeReturn( method.retConvertor.isVoid ? undefined : _.makeString(method.dummyReturnValue ?? "0")))) _.print(`string out("${method.toStringName}(");`) + _.print(`string _prereq;`) method.argConvertors.forEach((argConvertor, index) => { if (index > 0) this.dummy.print(`out.append(", ");`) - _.print(`WriteToString(&out, ${argConvertor.param});`) + _.print(`WriteToString(&out, ${argConvertor.param}, &_prereq);`) }) _.print(`out.append(")");`) const retVal = method.dummyReturnValue diff --git a/templates/dummy_impl_prologue.cc b/templates/dummy_impl_prologue.cc index 0f4a65153..64c423ee1 100644 --- a/templates/dummy_impl_prologue.cc +++ b/templates/dummy_impl_prologue.cc @@ -350,12 +350,13 @@ Ark_NodeHandle CreateNode(GENERATED_Ark_NodeType type, Ark_Int32 id, Ark_Int32 f if (!needGroupedLog(1)) { return result; } + string prereq; string out("createNode("); - WriteToString(&out, (Ark_Int32)type); + WriteToString(&out, (Ark_Int32)type, &prereq); out.append(", "); - WriteToString(&out, id); + WriteToString(&out, id, &prereq); out.append(", "); - WriteToString(&out, flags); + WriteToString(&out, flags, &prereq); out.append(")"); appendGroupedLog(1, out); return result; @@ -374,7 +375,8 @@ Ark_Float32 GetDensity(Ark_Int32 deviceId) { } string out("getDensity("); - WriteToString(&out, deviceId); + string prereq; + WriteToString(&out, deviceId, &prereq); out.append(")"); appendGroupedLog(1, out); @@ -389,7 +391,8 @@ Ark_Float32 GetFontScale(Ark_Int32 deviceId) { } string out("getFontScale("); - WriteToString(&out, deviceId); + string prereq; + WriteToString(&out, deviceId, &prereq); out.append(")"); appendGroupedLog(1, out); @@ -404,7 +407,8 @@ Ark_Float32 GetDesignWidthScale(Ark_Int32 deviceId) { } string out("getDesignWidthScale("); - WriteToString(&out, deviceId); + string prereq; + WriteToString(&out, deviceId, &prereq); out.append(")"); appendGroupedLog(1, out); @@ -431,7 +435,8 @@ void DisposeNode(Ark_NodeHandle node) { } string out("disposeNode("); - WriteToString(&out, node); + string prereq; + WriteToString(&out, node, &prereq); out.append(")"); appendGroupedLog(1, out); } @@ -457,9 +462,10 @@ Ark_Int32 AddChild(Ark_NodeHandle parent, Ark_NodeHandle child) { } string out("addChild("); - WriteToString(&out, parent); + string prereq; + WriteToString(&out, parent, &prereq); out.append(", "); - WriteToString(&out, child); + WriteToString(&out, child, &prereq); out.append(")"); appendGroupedLog(1, out); @@ -477,9 +483,10 @@ void RemoveChild(Ark_NodeHandle parent, Ark_NodeHandle child) { } string out("removeChild("); - WriteToString(&out, parent); + string prereq; + WriteToString(&out, parent, &prereq); out.append(", "); - WriteToString(&out, child); + WriteToString(&out, child, &prereq); out.append(")"); appendGroupedLog(1, out); } @@ -492,11 +499,12 @@ Ark_Int32 InsertChildAfter(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Node } string out("insertChildAfter("); - WriteToString(&out, parent); + string prereq; + WriteToString(&out, parent, &prereq); out.append(", "); - WriteToString(&out, child); + WriteToString(&out, child, &prereq); out.append(", "); - WriteToString(&out, sibling); + WriteToString(&out, sibling, &prereq); out.append(")"); appendGroupedLog(1, out); return result; @@ -510,11 +518,12 @@ Ark_Int32 InsertChildBefore(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Nod } string out("insertChildBefore("); - WriteToString(&out, parent); + string prereq; + WriteToString(&out, parent, &prereq); out.append(", "); - WriteToString(&out, child); + WriteToString(&out, child, &prereq); out.append(", "); - WriteToString(&out, sibling); + WriteToString(&out, sibling, &prereq); out.append(")"); appendGroupedLog(1, out); return result; @@ -528,11 +537,12 @@ Ark_Int32 InsertChildAt(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Int32 p } string out("insertChildAt("); - WriteToString(&out, parent); + string prereq; + WriteToString(&out, parent, &prereq); out.append(", "); - WriteToString(&out, child); + WriteToString(&out, child, &prereq); out.append(", "); - WriteToString(&out, position); + WriteToString(&out, position, &prereq); out.append(")"); appendGroupedLog(1, out); return result; @@ -543,7 +553,8 @@ void ApplyModifierFinish(Ark_NodeHandle node) { return; } string out("applyModifierFinish("); - WriteToString(&out, node); + string prereq; + WriteToString(&out, node, &prereq); out.append(")"); appendGroupedLog(1, out); } @@ -553,9 +564,10 @@ void MarkDirty(Ark_NodeHandle node, Ark_UInt32 flag) { return; } string out("markDirty("); - WriteToString(&out, node); + string prereq; + WriteToString(&out, node, &prereq); out.append(", "); - WriteToString(&out, flag); + WriteToString(&out, flag, &prereq); out.append(")"); appendGroupedLog(1, out); } @@ -566,7 +578,8 @@ Ark_Boolean IsBuilderNode(Ark_NodeHandle node) { return result; } string out("isBuilderNode("); - WriteToString(&out, node); + string prereq; + WriteToString(&out, node, &prereq); out.append(")"); appendGroupedLog(1, out); return result; @@ -579,11 +592,12 @@ Ark_Float32 ConvertLengthMetricsUnit(Ark_Float32 value, Ark_Int32 originUnit, Ar } string out("convertLengthMetricsUnit("); - WriteToString(&out, value); + string prereq; + WriteToString(&out, value, &prereq); out.append(", "); - WriteToString(&out, originUnit); + WriteToString(&out, originUnit, &prereq); out.append(", "); - WriteToString(&out, targetUnit); + WriteToString(&out, targetUnit, &prereq); out.append(")"); appendGroupedLog(1, out); return result; -- Gitee From a2476bec28d50a2b45a8555a79af1eac871952e2 Mon Sep 17 00:00:00 2001 From: grebelnik Date: Mon, 19 Aug 2024 15:33:57 +0300 Subject: [PATCH 2/9] call_log: fix dummy_impl_prologue --- templates/dummy_impl_prologue.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/dummy_impl_prologue.cc b/templates/dummy_impl_prologue.cc index 64c423ee1..b1f111407 100644 --- a/templates/dummy_impl_prologue.cc +++ b/templates/dummy_impl_prologue.cc @@ -449,7 +449,8 @@ void DumpTreeNode(Ark_NodeHandle node) { } string out("dumpTreeNode("); - WriteToString(&out, node); + std::string prereq; + WriteToString(&out, node, &prereq); out.append(")"); appendGroupedLog(1, out); } @@ -634,7 +635,8 @@ Ark_Int32 MeasureLayoutAndDraw(Ark_VMContext vmContext, Ark_NodeHandle root) { return result; } string out("measureLayoutAndDraw("); - WriteToString(&out, root); + std::string prereq; + WriteToString(&out, root, &prereq); out.append(")"); appendGroupedLog(1, out); return result; -- Gitee From d9b0916d7150e95f0536e8f70fb31fc8547ec5b4 Mon Sep 17 00:00:00 2001 From: grebelnik Date: Fri, 23 Aug 2024 13:50:45 +0500 Subject: [PATCH 3/9] CALL_LOG: add memory allocation for arrays --- peer_lib/sig/arkoala/arkui/src/main.ts | 6 +++--- tests/arkts-subset/common.d.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index 4f780f637..7167dd2e8 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -60,7 +60,7 @@ if (!reportTestFailures) { console.log("WARNING: ignore test result") } -const recordCallLog = false +const recordCallLog = true function checkSerdeResult(name: string, value: any, expected: any) { if (value !== expected) { @@ -568,7 +568,7 @@ function main() { checkPerf3(5 * 1000 * 1000) startPerformanceTest() - if (recordCallLog) startNativeLog(CALL_GROUP_LOG) + startNativeLog(CALL_GROUP_LOG) checkNodeAPI() checkCallback() checkWriteFunction() @@ -584,7 +584,7 @@ function main() { checkEvent_Interface_Optional() checkEvent_Array_Class() checkNativeCallback() - if (recordCallLog) stopNativeLog(CALL_GROUP_LOG) + stopNativeLog(CALL_GROUP_LOG) const callGroupLog = getNativeLog(CALL_GROUP_LOG) const callLogCppCode = ` diff --git a/tests/arkts-subset/common.d.ts b/tests/arkts-subset/common.d.ts index 445f46048..1d7e4c51f 100644 --- a/tests/arkts-subset/common.d.ts +++ b/tests/arkts-subset/common.d.ts @@ -69,7 +69,8 @@ declare enum ThemeColorMode { } declare enum AdaptiveColor { - DEFAULT = 0, + DEFAULT = 0, + AVERAGE = 1, } declare interface BlurOptions { -- Gitee From 74d8479a59c778a99cd10378ab85fadb21a0605b Mon Sep 17 00:00:00 2001 From: grebelnik Date: Wed, 21 Aug 2024 16:33:04 +0500 Subject: [PATCH 4/9] Revert main.ts --- peer_lib/sig/arkoala/arkui/src/main.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index 7167dd2e8..5d5ea41d1 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -60,7 +60,7 @@ if (!reportTestFailures) { console.log("WARNING: ignore test result") } -const recordCallLog = true +const recordCallLog = false function checkSerdeResult(name: string, value: any, expected: any) { if (value !== expected) { @@ -568,7 +568,7 @@ function main() { checkPerf3(5 * 1000 * 1000) startPerformanceTest() - startNativeLog(CALL_GROUP_LOG) + if (recordCallLog) startNativeLog(CALL_GROUP_LOG) checkNodeAPI() checkCallback() checkWriteFunction() @@ -584,7 +584,7 @@ function main() { checkEvent_Interface_Optional() checkEvent_Array_Class() checkNativeCallback() - stopNativeLog(CALL_GROUP_LOG) + if (recordCallLog) stopNativeLog(CALL_GROUP_LOG) const callGroupLog = getNativeLog(CALL_GROUP_LOG) const callLogCppCode = ` @@ -639,4 +639,4 @@ ${callGroupLog} checkTestFailures() } -main() \ No newline at end of file +main() -- Gitee From 59e4b31b323f00741e1b2ee6f3ae62c980d09abf Mon Sep 17 00:00:00 2001 From: grebelnik Date: Mon, 2 Sep 2024 17:57:31 +0500 Subject: [PATCH 5/9] Add more logging + call-log library --- insert-call-log.sh | 2 + peer_lib/call_log/meson.build | 6 +- peer_lib/sig/arkoala/arkui/src/main.ts | 88 +++++++++++++++----- peer_lib/sig/arkoala/arkui/src/test_utils.ts | 8 ++ remove-call-log.sh | 2 + templates/NativeModuleEmpty_template.ts | 6 ++ templates/arkts/NativeModule_template.ts | 2 + templates/dummy_impl_prologue.cc | 87 +++++++++++++++++++ templates/ts/NativeModule_template.ts | 2 + 9 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 insert-call-log.sh create mode 100644 remove-call-log.sh diff --git a/insert-call-log.sh b/insert-call-log.sh new file mode 100644 index 000000000..ef0cdc685 --- /dev/null +++ b/insert-call-log.sh @@ -0,0 +1,2 @@ +#! bin/bash +sed -i 's/--dts2peer/--dts2peer --call-log/g' package.json diff --git a/peer_lib/call_log/meson.build b/peer_lib/call_log/meson.build index be92493f1..d4f5616b6 100644 --- a/peer_lib/call_log/meson.build +++ b/peer_lib/call_log/meson.build @@ -10,10 +10,10 @@ deps = CXX.find_library( dirs : [meson.current_source_dir() + '/../../native/'] ) # for subset: -# inc_dir = include_directories('../../out/ts-subset/generated/libace/generated/interface') +inc_dir = include_directories('../../out/ts-subset/generated/libace/generated/interface') # for peers: -inc_dir = include_directories('../../out/ts-peers/generated/libace/generated/interface') -executable( +# inc_dir = include_directories('../../out/ts-peers/generated/libace/generated/interface') +library( 'run_call_log', sources, dependencies: deps, diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index 5d5ea41d1..12354efe9 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -50,6 +50,8 @@ import { assertEquals, assertTrue, assertThrows, + startNativeTest, + stopNativeTest, } from "./test_utils" import { nativeModule } from "@koalaui/arkoala" import { mkdirSync, writeFileSync } from "fs" @@ -60,7 +62,7 @@ if (!reportTestFailures) { console.log("WARNING: ignore test result") } -const recordCallLog = false +const recordCallLog = true function checkSerdeResult(name: string, value: any, expected: any) { if (value !== expected) { @@ -118,6 +120,8 @@ function checkSerdeBaseCustomObject() { } function checkNodeAPI() { + startNativeTest(checkNodeAPI.name, CALL_GROUP_LOG) + const ARKUI_TEXT = 1 const id = 12 const flags = 7 @@ -188,10 +192,11 @@ function checkNodeAPI() { `convertLengthMetricsUnit(1.230000, 10, 0)` ) assertTrue("BasicNodeAPI convertLengthMetricsUnit result", Math.abs(12.3 - length) < 0.00001) + + stopNativeTest(CALL_GROUP_LOG) } function checkCallback() { - const id1 = wrapCallback((args, length) => 1001) const id2 = wrapCallback((args, length) => 1002) assertTrue("Register callback 1", id1 != -1) @@ -218,6 +223,8 @@ function checkWriteFunction() { } function checkButton() { + startNativeTest(checkButton.name, CALL_GROUP_LOG) + let peer = ArkButtonPeer.create(ArkUINodeType.Button) checkResult("width", () => peer.widthAttribute("42%"), @@ -239,17 +246,25 @@ function checkButton() { "labelStyle({.overflow={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxLines={.tag=ARK_TAG_UNDEFINED, .value={}}, .minFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .heightAdaptivePolicy={.tag=ARK_TAG_UNDEFINED, .value={}}, .font={.tag=ARK_TAG_UNDEFINED, .value={}}})") //nativeModule()._MeausureLayoutAndDraw(peer.peer.ptr) assertTrue("ButtonPeer finalizer", peer!.peer!.finalizer != nullptr) + + stopNativeTest(CALL_GROUP_LOG) } function checkCalendar() { + startNativeTest(checkCalendar.name, CALL_GROUP_LOG) + let peer = ArkCalendarPickerPeer.create(ArkUINodeType.CalendarPicker) checkResult("edgeAlign1", () => peer.edgeAlignAttribute(2, { dx: 5, dy: 6 }), `edgeAlign(2, {.tag=ARK_TAG_OBJECT, .value={.dx={.type=1, .value=5.000000, .unit=1, .resource=0}, .dy={.type=1, .value=6.000000, .unit=1, .resource=0}}})`) checkResult("edgeAlign2", () => peer.edgeAlignAttribute(2), `edgeAlign(2, {.tag=ARK_TAG_UNDEFINED, .value={}})`) + + stopNativeTest(CALL_GROUP_LOG) } function checkFormComponent() { + startNativeTest(checkFormComponent.name, CALL_GROUP_LOG) + let peer = ArkFormComponentPeer.create(ArkUINodeType.FormComponent) checkResult("size int", () => peer.sizeAttribute({ width: 5, height: 6 }), `size({.width={.tag=102, .i32=5}, .height={.tag=102, .i32=6}})`) @@ -257,9 +272,13 @@ function checkFormComponent() { `size({.width={.tag=103, .f32=5.50}, .height={.tag=103, .f32=6.78}})`) checkResult("size zero", () => peer.sizeAttribute({ width: 0.0, height: 0.0 }), `size({.width={.tag=102, .i32=0}, .height={.tag=102, .i32=0}})`) + + stopNativeTest(CALL_GROUP_LOG) } function checkCommon() { + startNativeTest(checkCommon.name, CALL_GROUP_LOG) + let peer = ArkCommonPeer.create(ArkUINodeType.Common) // check backgroundBlurStyle and check the heritance by the way let backgroundBlurStyle: BackgroundBlurStyleOptions = { @@ -284,20 +303,24 @@ function checkCommon() { () => peer.dragPreviewOptionsAttribute({ numberBadge: true }, { defaultAnimationBeforeLifting: false }), `dragPreviewOptions({.mode={.tag=ARK_TAG_UNDEFINED, .value={}}, .modifier={.tag=ARK_TAG_UNDEFINED, .value={}}, .numberBadge={.tag=ARK_TAG_OBJECT, .value={.selector=0, .value0=true}}}, {.tag=ARK_TAG_OBJECT, .value={.isMultiSelectionEnabled={.tag=ARK_TAG_UNDEFINED, .value={}}, .defaultAnimationBeforeLifting={.tag=ARK_TAG_OBJECT, .value=false}}})` ) -} - -class ArkSideBarContainerComponentTest extends ArkSideBarContainerComponent { - constructor(peer: ArkSideBarContainerPeer) { - super() - this.peer = peer - } - override checkPriority(name: string) { - return true - } + stopNativeTest(CALL_GROUP_LOG) } function checkOverloads() { + startNativeTest(checkOverloads.name, CALL_GROUP_LOG) + + class ArkSideBarContainerComponentTest extends ArkSideBarContainerComponent { + constructor(peer: ArkSideBarContainerPeer) { + super() + this.peer = peer + } + + override checkPriority(name: string) { + return true + } + } + const peer = ArkSideBarContainerPeer.create(ArkUINodeType.SideBarContainer) const component = new ArkSideBarContainerComponentTest(peer) checkResult("Test number implementation for SideBarContainer.minSideBarWidth", @@ -308,15 +331,21 @@ function checkOverloads() { () => component.minSideBarWidth("42%"), `minSideBarWidth({.type=1, .value=42.000000, .unit=3, .resource=0})` ) + + stopNativeTest(CALL_GROUP_LOG) } function checkNavigation() { + startNativeTest(checkNavigation.name, CALL_GROUP_LOG) let peer = ArkNavigationPeer.create(ArkUINodeType.Navigation) checkResult("backButtonIcon", () => peer.backButtonIconAttribute("attr"), `backButtonIcon({.selector=0, .value0={.chars="attr", .length=4}})`) + stopNativeTest(CALL_GROUP_LOG) } function checkTabContent() { + startNativeTest(checkTabContent.name, CALL_GROUP_LOG) + let peer = ArkTabContentPeer.create(ArkUINodeType.TabContent) let subTabBarStyle: SubTabBarStyle = new SubTabBarStyle("Resource").id("testID") assertEquals("SubTabBarStyle id", "testID", subTabBarStyle._id) @@ -329,9 +358,12 @@ function checkTabContent() { // TBD: check SubTabBarStyle is created from static method // subTabBarStyle = SubTabBarStyle.of("Resource2") + + stopNativeTest(CALL_GROUP_LOG) } function checkCanvasRenderingContext2D() { + startNativeTest(checkCanvasRenderingContext2D.name, CALL_GROUP_LOG) let canvasRenderingContext2D: CanvasRenderingContext2D | undefined = undefined @@ -355,6 +387,8 @@ function checkCanvasRenderingContext2D() { checkResult("CanvasRenderingContext2D peer close()", () => canvasRenderingContext2D!.peer!.close(), `dummyClassFinalizer(0x64)`) + + stopNativeTest(CALL_GROUP_LOG) } function checkPerf1(count: number) { @@ -501,6 +535,8 @@ function checkEvent_Array_Class() { } function checkNativeCallback() { + startNativeTest(checkNativeCallback.name, CALL_GROUP_LOG) + const id1 = wrapCallback((args: Uint8Array, length: number): number => { return 123456 }) @@ -556,6 +592,8 @@ function checkNativeCallback() { return args.reduce((acc, val) => acc + val, 0) }, false) nativeModule()._TestCallIntMemory(id5, 1000) + + stopNativeTest(CALL_GROUP_LOG) } function main() { @@ -568,7 +606,9 @@ function main() { checkPerf3(5 * 1000 * 1000) startPerformanceTest() - if (recordCallLog) startNativeLog(CALL_GROUP_LOG) + if (recordCallLog) + startNativeLog(CALL_GROUP_LOG) + checkNodeAPI() checkCallback() checkWriteFunction() @@ -584,7 +624,12 @@ function main() { checkEvent_Interface_Optional() checkEvent_Array_Class() checkNativeCallback() - if (recordCallLog) stopNativeLog(CALL_GROUP_LOG) + + checkTabContent() + checkCanvasRenderingContext2D() + + if (recordCallLog) + stopNativeLog(CALL_GROUP_LOG) const callGroupLog = getNativeLog(CALL_GROUP_LOG) const callLogCppCode = ` @@ -613,27 +658,32 @@ namespace OHOS::Ace::NG::GeneratedModifier { EXTERN_C IDLIZE_API_EXPORT const GENERATED_ArkUIAnyAPI* GENERATED_GetArkAnyAPI(GENERATED_Ark_APIVariantKind kind, int version); } +__attribute__((visibility("hidden"))) const GENERATED_ArkUINodeModifiers* GetNodeModifiers() { static const auto val = (const GENERATED_ArkUIFullNodeAPI*)(OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_FULL,GENERATED_ARKUI_FULL_API_VERSION)); return val->getNodeModifiers(); } +__attribute__((visibility("hidden"))) +const GENERATED_ArkUIAccessors* GetAccessors() { + static const auto val = (const GENERATED_ArkUIFullNodeAPI*)(OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_FULL,GENERATED_ARKUI_FULL_API_VERSION)); + return val->getAccessors(); +} + +__attribute__((visibility("hidden"))) const GENERATED_ArkUIBasicNodeAPI* GetBasicNodeApi() { static const auto val = (const GENERATED_ArkUIBasicNodeAPI*)OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_BASIC, GENERATED_ARKUI_BASIC_NODE_API_VERSION); return val; } -int main(int argc, const char** argv) { ${callGroupLog} - return 0; -}` +` + if (callGroupLog.length > 0) { console.log(callLogCppCode) mkdirSync('./generated/call_log', { recursive: true }) writeFileSync('./generated/call_log/main.cpp', callLogCppCode) } - checkTabContent() - checkCanvasRenderingContext2D() // Report in error code. checkTestFailures() diff --git a/peer_lib/sig/arkoala/arkui/src/test_utils.ts b/peer_lib/sig/arkoala/arkui/src/test_utils.ts index 6679097b8..6c1d7b119 100644 --- a/peer_lib/sig/arkoala/arkui/src/test_utils.ts +++ b/peer_lib/sig/arkoala/arkui/src/test_utils.ts @@ -19,6 +19,14 @@ export function checkTestFailures() { } } +export function startNativeTest(testName: string, group: number) { + nativeModule()._StartNativeTest(testName, group) +} + +export function stopNativeTest(group: number) { + nativeModule()._StopNativeTest(group) +} + export function startNativeLog(group: number) { nativeModule()._StartGroupedLog(group) } diff --git a/remove-call-log.sh b/remove-call-log.sh new file mode 100644 index 000000000..f5fd1bc59 --- /dev/null +++ b/remove-call-log.sh @@ -0,0 +1,2 @@ +#! bin/bash +sed -i 's/--dts2peer --call-log/--dts2peer/g' package.json diff --git a/templates/NativeModuleEmpty_template.ts b/templates/NativeModuleEmpty_template.ts index 0e79de59f..18bf29027 100644 --- a/templates/NativeModuleEmpty_template.ts +++ b/templates/NativeModuleEmpty_template.ts @@ -6,6 +6,12 @@ export class NativeModuleEmptyIntegrated implements NativeModuleIntegrated { _CleanCallbackDispatcher(): void { throw new Error("_CleanCallbackDispatcher") } + _StartNativeTest(testName: KStringPtr, index: KInt): void { + throw new Error("_StartNativeTest") + } + _StopNativeTest(index: KInt): void { + throw new Error("_StopNativeTest") + } _GetGroupedLog(index: KInt): KPointer { throw new Error("_GetResultString") } diff --git a/templates/arkts/NativeModule_template.ts b/templates/arkts/NativeModule_template.ts index 8cdea343f..97be85eac 100644 --- a/templates/arkts/NativeModule_template.ts +++ b/templates/arkts/NativeModule_template.ts @@ -53,6 +53,8 @@ export class NativeModule { static native _GetNodeFinalizer(): long; static native _GetPtrVectorSize(arg1: long): KInt; static native _GetPtrVectorElement(arg1: long, arg2: KInt): long; + static native _StartNativeTest(arg1: String, arg2: KInt): void; + static native _StopNativeTest(arg1: KInt): void; static native _GetGroupedLog(arg1: KInt): long; static native _StartGroupedLog(arg1: KInt): void; static native _StopGroupedLog(arg1: KInt): void; diff --git a/templates/dummy_impl_prologue.cc b/templates/dummy_impl_prologue.cc index b1f111407..48eec5479 100644 --- a/templates/dummy_impl_prologue.cc +++ b/templates/dummy_impl_prologue.cc @@ -417,8 +417,15 @@ Ark_Float32 GetDesignWidthScale(Ark_Int32 deviceId) { namespace ApiImpl { +static int res_num = 0; + Ark_NodeHandle GetNodeByViewStack() { Ark_NodeHandle result = (Ark_NodeHandle) 234; + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_NodeHandle peer" + std::to_string((uintptr_t)result) + " = GetBasicNodeApi()->getNodeByViewStack();\n"); + appendGroupedLog(2, _logData); + } if (!needGroupedLog(1)) { return result; } @@ -430,6 +437,12 @@ Ark_NodeHandle GetNodeByViewStack() { void DisposeNode(Ark_NodeHandle node) { AsNode(node)->dispose(); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" GetBasicNodeApi()->disposeNode(peer" + std::to_string((uintptr_t)node) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return; } @@ -444,6 +457,12 @@ void DisposeNode(Ark_NodeHandle node) { void DumpTreeNode(Ark_NodeHandle node) { DumpTree(AsNode(node), 0); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" GetBasicNodeApi()->dumpTreeNode(peer" + std::to_string((uintptr_t)node) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return; } @@ -458,6 +477,13 @@ void DumpTreeNode(Ark_NodeHandle node) { Ark_Int32 AddChild(Ark_NodeHandle parent, Ark_NodeHandle child) { int result = AsNode(parent)->addChild(AsNode(child)); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_Int32 res" + std::to_string(res_num++) + " = GetBasicNodeApi()->addChild(peer" + + std::to_string((uintptr_t)parent) + ", peer" + std::to_string((uintptr_t)child) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return result; } @@ -479,6 +505,13 @@ void RemoveChild(Ark_NodeHandle parent, Ark_NodeHandle child) { TreeNode *childPtr = reinterpret_cast(child); parentPtr->removeChild(childPtr); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" GetBasicNodeApi()->removeChild(peer" + + std::to_string((uintptr_t)parent) + ", peer" + std::to_string((uintptr_t)child) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return; } @@ -495,6 +528,14 @@ void RemoveChild(Ark_NodeHandle parent, Ark_NodeHandle child) { Ark_Int32 InsertChildAfter(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_NodeHandle sibling) { int result = AsNode(parent)->insertChildAfter(AsNode(child), AsNode(sibling)); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_Int32 res" + std::to_string(res_num++) + " = GetBasicNodeApi()->insertChildAfter(peer" + + std::to_string((uintptr_t)parent) + ", peer" + std::to_string((uintptr_t)child) + + ", peer" + std::to_string((uintptr_t)sibling) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return result; } @@ -514,6 +555,14 @@ Ark_Int32 InsertChildAfter(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Node Ark_Int32 InsertChildBefore(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_NodeHandle sibling) { int result = AsNode(parent)->insertChildBefore(AsNode(child), AsNode(sibling)); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_Int32 res" + std::to_string(res_num++) + " = GetBasicNodeApi()->insertChildBefore(peer" + + std::to_string((uintptr_t)parent) + ", peer" + std::to_string((uintptr_t)child) + + ", peer" + std::to_string((uintptr_t)sibling) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return result; } @@ -533,6 +582,14 @@ Ark_Int32 InsertChildBefore(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Nod Ark_Int32 InsertChildAt(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Int32 position) { int result = AsNode(parent)->insertChildAt(AsNode(child), position); + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_Int32 res" + std::to_string(res_num++) + " = GetBasicNodeApi()->insertChildAt(peer" + + std::to_string((uintptr_t)parent) + ", peer" + std::to_string((uintptr_t)child) + + ", " + std::to_string(position) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return result; } @@ -550,6 +607,13 @@ Ark_Int32 InsertChildAt(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Int32 p } void ApplyModifierFinish(Ark_NodeHandle node) { + + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" GetBasicNodeApi()->applyModifierFinish(peer" + std::to_string((uintptr_t)node) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return; } @@ -561,6 +625,13 @@ void ApplyModifierFinish(Ark_NodeHandle node) { } void MarkDirty(Ark_NodeHandle node, Ark_UInt32 flag) { + + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" GetBasicNodeApi()->markDirty(peer" + std::to_string((uintptr_t)node) + ", " + std::to_string(flag) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return; } @@ -575,6 +646,14 @@ void MarkDirty(Ark_NodeHandle node, Ark_UInt32 flag) { Ark_Boolean IsBuilderNode(Ark_NodeHandle node) { Ark_Boolean result = true; + + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_Boolean res" + std::to_string(res_num++) + " = GetBasicNodeApi()->isBuilderNode(peer" + + std::to_string((uintptr_t)node) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return result; } @@ -588,6 +667,14 @@ Ark_Boolean IsBuilderNode(Ark_NodeHandle node) { Ark_Float32 ConvertLengthMetricsUnit(Ark_Float32 value, Ark_Int32 originUnit, Ark_Int32 targetUnit) { Ark_Float32 result = value * originUnit; + + if (needGroupedLog(2)) { + std::string _logData; + _logData.append(" Ark_Float32 res" + std::to_string(res_num++) + " = GetBasicNodeApi()->convertLengthMetricsUnit(" + + std::to_string(value) + ", " + std::to_string(originUnit) + ", " + std::to_string(targetUnit) + ");\n"); + appendGroupedLog(2, _logData); + } + if (!needGroupedLog(1)) { return result; } diff --git a/templates/ts/NativeModule_template.ts b/templates/ts/NativeModule_template.ts index d1e651fd0..b0b558133 100644 --- a/templates/ts/NativeModule_template.ts +++ b/templates/ts/NativeModule_template.ts @@ -57,6 +57,8 @@ export interface InteropOps { _SetCallbackDispatcher(dispatcher: (id: int32, args: Uint8Array, length: int32) => int32): void _CleanCallbackDispatcher(): void + _StartNativeTest(testName: KStringPtr, index: KInt): void + _StopNativeTest(index: KInt): void _GetGroupedLog(index: KInt): KPointer _StartGroupedLog(index: KInt): void _StopGroupedLog(index: KInt): void -- Gitee From 5e9bccfebfe5cab359bc726846579f9b3cd832c2 Mon Sep 17 00:00:00 2001 From: grebelnik Date: Mon, 2 Sep 2024 18:13:51 +0500 Subject: [PATCH 6/9] turn off recordCallLog --- peer_lib/sig/arkoala/arkui/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index 12354efe9..8982b0bd9 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -62,7 +62,7 @@ if (!reportTestFailures) { console.log("WARNING: ignore test result") } -const recordCallLog = true +const recordCallLog = false function checkSerdeResult(name: string, value: any, expected: any) { if (value !== expected) { -- Gitee From 4163a30cec47729d66c3ea1ba3242345aa7310de Mon Sep 17 00:00:00 2001 From: grebelnik Date: Fri, 13 Sep 2024 18:18:55 +0500 Subject: [PATCH 7/9] New array allocation in call-log --- peer_lib/call_log/meson.build | 3 +- peer_lib/sig/arkoala/arkui/src/main.ts | 33 ++++-- src/peer-generation/DeclarationTable.ts | 104 +++++------------- .../printers/BridgeCcPrinter.ts | 19 +--- .../printers/ModifierPrinter.ts | 3 +- templates/dummy_impl_prologue.cc | 74 +++++-------- 6 files changed, 89 insertions(+), 147 deletions(-) diff --git a/peer_lib/call_log/meson.build b/peer_lib/call_log/meson.build index d4f5616b6..9d6019a40 100644 --- a/peer_lib/call_log/meson.build +++ b/peer_lib/call_log/meson.build @@ -1,5 +1,6 @@ project('call_log', 'cpp', - version: '0.1' + version: '0.1', + default_options: ['cpp_std=c++17', ] ) sources = [ '../../generated/call_log/main.cpp' diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index 8982b0bd9..afd74a7eb 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -237,9 +237,9 @@ function checkButton() { title: { id: 43, type: 2000, bundleName: "MyApp", moduleName: "MyApp", params: ["param1", "param2"] } } }), - `bindSheet({.tag=ARK_TAG_OBJECT, .value=false}, {.selector=0, .value0={.id=4}}, {.tag=ARK_TAG_OBJECT, .value={.backgroundColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .onAppear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onDisappear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillAppear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillDisappear={.tag=ARK_TAG_UNDEFINED, .value={}}, .height={.tag=ARK_TAG_UNDEFINED, .value={}}, .dragBar={.tag=ARK_TAG_UNDEFINED, .value={}}, .maskColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .detents={.tag=ARK_TAG_UNDEFINED, .value={}}, .blurStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, .showClose={.tag=ARK_TAG_UNDEFINED, .value={}}, .preferType={.tag=ARK_TAG_UNDEFINED, .value={}}, .title={.tag=ARK_TAG_OBJECT, .value={.selector=0, .value0={.title={.selector=1, .value1={.id={.tag=102, .i32=43}, .type={.tag=102, .i32=2000}, .moduleName={.chars="MyApp", .length=5}, .bundleName={.chars="MyApp", .length=5}, .params={.tag=ARK_TAG_OBJECT, .value={{{.chars="param1", .length=6}, {.chars="param2", .length=6}}, .length=2}}}}, .subtitle={.tag=ARK_TAG_UNDEFINED, .value={}}}}}, .shouldDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillSpringBackWhenDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .enableOutsideInteractive={.tag=ARK_TAG_UNDEFINED, .value={}}, .width={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderWidth={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, .shadow={.tag=ARK_TAG_UNDEFINED, .value={}}, .onHeightDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .mode={.tag=ARK_TAG_UNDEFINED, .value={}}, .scrollSizeMode={.tag=ARK_TAG_UNDEFINED, .value={}}, .onDetentsDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWidthDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .onTypeDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .expandSafeAreaInEmbeddedMode={.tag=ARK_TAG_UNDEFINED, .value={}}, .uiContext={.tag=ARK_TAG_UNDEFINED, .value={}}, .keyboardAvoidMode={.tag=ARK_TAG_UNDEFINED, .value={}}}})` + `bindSheet({.tag=ARK_TAG_OBJECT, .value=false}, {.selector=0, .value0={.id=4}}, {.tag=ARK_TAG_OBJECT, .value={.backgroundColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .onAppear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onDisappear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillAppear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillDisappear={.tag=ARK_TAG_UNDEFINED, .value={}}, .height={.tag=ARK_TAG_UNDEFINED, .value={}}, .dragBar={.tag=ARK_TAG_UNDEFINED, .value={}}, .maskColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .detents={.tag=ARK_TAG_UNDEFINED, .value={}}, .blurStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, .showClose={.tag=ARK_TAG_UNDEFINED, .value={}}, .preferType={.tag=ARK_TAG_UNDEFINED, .value={}}, .title={.tag=ARK_TAG_OBJECT, .value={.selector=0, .value0={.title={.selector=1, .value1={.id={.tag=102, .i32=43}, .type={.tag=102, .i32=2000}, .moduleName={.chars="MyApp", .length=5}, .bundleName={.chars="MyApp", .length=5}, .params={.tag=ARK_TAG_OBJECT, .value={.array=allocArray({{{.chars="param1", .length=6}, {.chars="param2", .length=6}}}), .length=2}}}}, .subtitle={.tag=ARK_TAG_UNDEFINED, .value={}}}}}, .shouldDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillSpringBackWhenDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .enableOutsideInteractive={.tag=ARK_TAG_UNDEFINED, .value={}}, .width={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderWidth={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, .shadow={.tag=ARK_TAG_UNDEFINED, .value={}}, .onHeightDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .mode={.tag=ARK_TAG_UNDEFINED, .value={}}, .scrollSizeMode={.tag=ARK_TAG_UNDEFINED, .value={}}, .onDetentsDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWidthDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .onTypeDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .expandSafeAreaInEmbeddedMode={.tag=ARK_TAG_UNDEFINED, .value={}}, .uiContext={.tag=ARK_TAG_UNDEFINED, .value={}}}})` ) - checkResult("type", () => peer.typeAttribute(1), "type(1)") + checkResult("type", () => peer.typeAttribute(1), "type(Ark_ButtonType(1))") checkResult("labelStyle", () => peer.labelStyleAttribute({ maxLines: 3 }), "labelStyle({.overflow={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxLines={.tag=ARK_TAG_OBJECT, .value={.tag=102, .i32=3}}, .minFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .heightAdaptivePolicy={.tag=ARK_TAG_UNDEFINED, .value={}}, .font={.tag=ARK_TAG_UNDEFINED, .value={}}})") checkResult("labelStyle2", () => peer.labelStyleAttribute({}), @@ -255,9 +255,9 @@ function checkCalendar() { let peer = ArkCalendarPickerPeer.create(ArkUINodeType.CalendarPicker) checkResult("edgeAlign1", () => peer.edgeAlignAttribute(2, { dx: 5, dy: 6 }), - `edgeAlign(2, {.tag=ARK_TAG_OBJECT, .value={.dx={.type=1, .value=5.000000, .unit=1, .resource=0}, .dy={.type=1, .value=6.000000, .unit=1, .resource=0}}})`) + `edgeAlign(Ark_CalendarAlign(2), {.tag=ARK_TAG_OBJECT, .value={.dx={.type=1, .value=5.000000, .unit=1, .resource=0}, .dy={.type=1, .value=6.000000, .unit=1, .resource=0}}})`) checkResult("edgeAlign2", () => peer.edgeAlignAttribute(2), - `edgeAlign(2, {.tag=ARK_TAG_UNDEFINED, .value={}})`) + `edgeAlign(Ark_CalendarAlign(2), {.tag=ARK_TAG_UNDEFINED, .value={}})`) stopNativeTest(CALL_GROUP_LOG) } @@ -291,7 +291,7 @@ function checkCommon() { } checkResult("Test backgroundBlurStyle for BackgroundBlurStyleOptions", () => peer.backgroundBlurStyleAttribute(0, backgroundBlurStyle), - `backgroundBlurStyle(0, {.tag=ARK_TAG_OBJECT, .value={.colorMode={.tag=ARK_TAG_OBJECT, .value=0}, .adaptiveColor={.tag=ARK_TAG_OBJECT, .value=0}, .scale={.tag=ARK_TAG_OBJECT, .value={.tag=102, .i32=1}}, .blurOptions={.tag=ARK_TAG_OBJECT, .value={.grayscale={.value0={.tag=102, .i32=1}, .value1={.tag=102, .i32=1}}}}, .policy={.tag=ARK_TAG_UNDEFINED, .value={}}, .inactiveColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .type={.tag=ARK_TAG_UNDEFINED, .value={}}}})` + `backgroundBlurStyle(Ark_BlurStyle(0), {.tag=ARK_TAG_OBJECT, .value={.colorMode={.tag=ARK_TAG_OBJECT, .value=Ark_ThemeColorMode(0)}, .adaptiveColor={.tag=ARK_TAG_OBJECT, .value=Ark_AdaptiveColor(0)}, .scale={.tag=ARK_TAG_OBJECT, .value={.tag=102, .i32=1}}, .blurOptions={.tag=ARK_TAG_OBJECT, .value={.grayscale={.value0={.tag=102, .i32=1}, .value1={.tag=102, .i32=1}}}}, .policy={.tag=ARK_TAG_UNDEFINED, .value={}}, .inactiveColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .type={.tag=ARK_TAG_UNDEFINED, .value={}}}})` ) checkResult("Test dragPreviewOptions numberBadge with number", @@ -650,9 +650,10 @@ function main() { #include "arkoala_api_generated.h" #include "arkoala-macros.h" -#include #include -#include +#include +#include +#include namespace OHOS::Ace::NG::GeneratedModifier { EXTERN_C IDLIZE_API_EXPORT const GENERATED_ArkUIAnyAPI* GENERATED_GetArkAnyAPI(GENERATED_Ark_APIVariantKind kind, int version); @@ -676,6 +677,24 @@ const GENERATED_ArkUIBasicNodeAPI* GetBasicNodeApi() { return val; } +static const std::size_t buffer_size = 1024 * 1024; // 1 MB +static std::size_t offset = 0; +alignas(std::max_align_t) static char buffer[buffer_size]; + +template +T* allocArray(const std::array& ref) { + std::size_t space = sizeof(buffer) - offset; + void* ptr = buffer + offset; + void* aligned_ptr = std::align(alignof(T), sizeof(T) * size, ptr, space); + assert(aligned_ptr != nullptr && "Insufficient space or alignment failed!"); + offset = (char*)aligned_ptr + sizeof(T) * size - buffer; + T* array = reinterpret_cast(aligned_ptr); + for (size_t i = 0; i < size; ++i) { + new (&array[i]) T(ref[i]); + } + return array; +} + ${callGroupLog} ` diff --git a/src/peer-generation/DeclarationTable.ts b/src/peer-generation/DeclarationTable.ts index 5906ebc0b..2a9302ca8 100644 --- a/src/peer-generation/DeclarationTable.ts +++ b/src/peer-generation/DeclarationTable.ts @@ -860,7 +860,9 @@ export class DeclarationTable { writeToString.print(`inline void WriteToString(string* result, enum ${enumName} value) {`) writeToString.pushIndent() + writeToString.print(`result->append("${enumName}(");`) writeToString.print(`WriteToString(result, (${PrimitiveType.Int32.getText()}) value);`) + writeToString.print(`result->append(")");`) writeToString.popIndent() writeToString.print(`}`) @@ -1057,19 +1059,19 @@ export class DeclarationTable { writeOptional(nameOptional: string, printer: LanguageWriter, isPointer: boolean) { printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${nameOptional}* value, string* prereq) {`) + printer.print(`inline void WriteToString(string* result, const ${nameOptional}* value) {`) printer.print(`result->append("{.tag=");`) printer.print(`result->append(tagNameExact((${PrimitiveType.Tag.getText()})(value->tag)));`) printer.print(`result->append(", .value=");`) printer.pushIndent() printer.print(`if (value->tag != ${PrimitiveType.UndefinedTag}) {`) printer.pushIndent() - printer.print(`WriteToString(result, ${isPointer ? "&" : ""}value->value, prereq);`) + printer.print(`WriteToString(result, ${isPointer ? "&" : ""}value->value);`) printer.popIndent() printer.print(`} else {`) printer.pushIndent() printer.print(`${PrimitiveType.Undefined.getText()} undefined = { 0 };`) - printer.print(`WriteToString(result, undefined, prereq);`) + printer.print(`WriteToString(result, undefined);`) printer.popIndent() printer.print(`}`) printer.popIndent() @@ -1133,76 +1135,27 @@ export class DeclarationTable { printer.print( ` -inline void WriteToString(string* result, const ${name}* value, string* prereq = nullptr, const std::string& ptrName = std::string()) { +template <> +inline void WriteToString(string* result, const ${elementNativeType}${isPointerField ? "*" : ""} value); + +inline void WriteToString(string* result, const ${name}* value) { int32_t count = value->length; - result->append("{"); - if (ptrName.empty()) { - if (count > 0) result->append(".array={"); - if (prereq != nullptr) { - result->append("prereq_" + std::to_string(prereq_num) + "[0]"); - } else { - for (int i = 0; i < count; i++) { - if (i > 0) result->append(", "); - WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i], prereq); - } - } - if (count == 0) result->append("{}"); - if (count > 0) result->append("}"); - } else { - result->append(ptrName + ".data()"); - } + + result->append("{.array=allocArray<${elementNativeType}, " + std::to_string(count) + ">({{"); + for (int i = 0; i < count; i++) { + if (i > 0) result->append(", "); + WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i]); + } + result->append("}})"); + result->append(", .length="); result->append(std::to_string(value->length)); + result->append("}"); - if (prereq != nullptr) { - prereq->append(" std::vector<${elementNativeType}*> prereq_" + std::to_string(prereq_num) + "(" + std::to_string(count) + ");\\n"); - for (int i = 0; i < count; i++) { - std::string initializer; - WriteToString(&initializer, ${constCast}${isPointerField ? "&" : ""}value->array[i], nullptr); - prereq->append(" prereq_" + std::to_string(prereq_num) + "[" + std::to_string(i) + "] = new ${elementNativeType}" + initializer + ";\\n"); - } - ++prereq_num; - } } `) } - private generateStdArrayDefinition(name: string, target: DeclarationTarget, printer: LanguageWriter) { - if (target instanceof PrimitiveType) throw new Error("Impossible") - let elementType = ts.isArrayTypeNode(target) - ? target.elementType - : ts.isTypeReferenceNode(target) && target.typeArguments - ? target.typeArguments[0] - : undefined - - if (!elementType) throw new Error("Impossible") - let convertor = this.typeConvertor("param", elementType) - let isPointerField = convertor.isPointerType() - let elementNativeType = convertor.nativeType(false) - let constCast = isPointerField ? `(const ${elementNativeType}*)` : `` - - // Provide prototype of element printer. - printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${elementNativeType}${isPointerField ? "*" : ""} value, string* prereq);`) - - // Printer. - printer.print(`inline void generateStdArrayDefinition(string* result, const ${name}* value, string* prereq) {`) - printer.pushIndent() - printer.print(`int32_t count = value->length;`) - printer.print(`result->append("std::array<${elementNativeType}, " + std::to_string(count) + ">{{");`) - printer.print(`for (int i = 0; i < count; i++) {`); - printer.pushIndent() - printer.print(`std::string tmp;`) - printer.print(`WriteToString(result, ${constCast}${isPointerField ? "&" : ""}value->array[i], prereq);`) - printer.print(`result->append(tmp);`); - printer.print(`result->append(", ");`) - printer.popIndent() - printer.print(`}`) - printer.print(`result->append("}}");`) - printer.popIndent() - printer.print(`}`) - } - private generateMapWriteToString(name: string, target: DeclarationTarget, printer: LanguageWriter) { if (target instanceof PrimitiveType) throw new Error("Impossible") @@ -1222,23 +1175,23 @@ inline void WriteToString(string* result, const ${name}* value, string* prereq = // Provide prototype of keys printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${keyNativeType}${isPointerKeyField ? "*" : ""} value, string* prereq);`) + printer.print(`inline void WriteToString(string* result, const ${keyNativeType}${isPointerKeyField ? "*" : ""} value);`) // Provide prototype of values printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${valueNativeType}${isPointerValueField ? "*" : ""} value, string* prereq);`) + printer.print(`inline void WriteToString(string* result, const ${valueNativeType}${isPointerValueField ? "*" : ""} value);`) // Printer. printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${name}* value, string* prereq) {`) + printer.print(`inline void WriteToString(string* result, const ${name}* value) {`) printer.pushIndent() printer.print(`result->append("{");`) printer.print(`int32_t count = value->size;`) printer.print(`for (int i = 0; i < count; i++) {`) printer.pushIndent() printer.print(`if (i > 0) result->append(", ");`) - printer.print(`WriteToString(result, ${keyConstCast}${isPointerKeyField ? "&" : ""}value->keys[i], prereq);`) + printer.print(`WriteToString(result, ${keyConstCast}${isPointerKeyField ? "&" : ""}value->keys[i]);`) printer.print(`result->append(": ");`) - printer.print(`WriteToString(result, ${valueConstCast}${isPointerValueField ? "&" : ""}value->values[i], prereq);`) + printer.print(`WriteToString(result, ${valueConstCast}${isPointerValueField ? "&" : ""}value->values[i]);`) printer.popIndent() printer.print(`}`) printer.print(`result->append("}");`) @@ -1262,13 +1215,12 @@ inline void WriteToString(string* result, const ${name}* value, string* prereq = isArray = identName(target.typeName) === "Array" } if (isArray) { - this.generateStdArrayDefinition(name, target, printer) this.generateArrayWriteToString(name, target, printer) } else if (isMap) { this.generateMapWriteToString(name, target, printer) } else { printer.print(`template <>`) - printer.print(`inline void WriteToString(string* result, const ${name}${isPointer ? "*" : ""} value, string* prereq) {`) + printer.print(`inline void WriteToString(string* result, const ${name}${isPointer ? "*" : ""} value) {`) printer.pushIndent() if (isUnion) { @@ -1282,7 +1234,7 @@ inline void WriteToString(string* result, const ${name}* value, string* prereq = printer.print(`if (value${access}selector == ${index - 1}) {`) printer.pushIndent() printer.print(`result->append(".${field.name}=");`); - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) printer.popIndent() printer.print(`}`) }) @@ -1300,7 +1252,7 @@ inline void WriteToString(string* result, const ${name}* value, string* prereq = let isPointerField = this.isPointerDeclaration(field.declaration, field.optional) if (index > 0) printer.print(`result->append(", ");`) printer.print(`result->append(".${field.name}=");`) - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) }) printer.print(`result->append("}");`) } else if (isOptional) { @@ -1311,7 +1263,7 @@ inline void WriteToString(string* result, const ${name}* value, string* prereq = if (index > 0) printer.print(`result->append(", ");`) printer.print(`result->append("${field.name}: ");`) let isPointerField = this.isPointerDeclaration(field.declaration, field.optional) - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) if (index == 0) { printer.print(`if (value${access}${field.name} != ${PrimitiveType.UndefinedTag}) {`) printer.pushIndent() @@ -1329,7 +1281,7 @@ inline void WriteToString(string* result, const ${name}* value, string* prereq = if (index > 0) printer.print(`result->append(", ");`) printer.print(`result->append(".${field.name}=");`) let isPointerField = this.isPointerDeclaration(field.declaration, field.optional) - printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name}, prereq);`) + printer.print(`WriteToString(result, ${isPointerField ? "&" : ""}value${access}${field.name});`) }) printer.print(`result->append("}");`) } diff --git a/src/peer-generation/printers/BridgeCcPrinter.ts b/src/peer-generation/printers/BridgeCcPrinter.ts index 8a62159f3..b34940821 100644 --- a/src/peer-generation/printers/BridgeCcPrinter.ts +++ b/src/peer-generation/printers/BridgeCcPrinter.ts @@ -15,7 +15,7 @@ import { IndentedPrinter } from "../../IndentedPrinter"; import { Language, capitalize, dropSuffix, isDefined } from "../../util"; -import { ArgConvertor, ArrayConvertor } from "../Convertors"; +import {ArgConvertor, EnumConvertor} from "../Convertors"; import { PrimitiveType } from "../DeclarationTable"; import { bridgeCcCustomDeclaration, bridgeCcGeneratedDeclaration } from "../FileGenerators"; import { createLanguageWriter, Method, NamedMethodSignature, Type } from "../LanguageWriters"; @@ -92,27 +92,14 @@ class BridgeCcVisitor { this.generatedApi.pushIndent() this.generatedApi.print('std::string _logData;') this.generatedApi.print('std::string _tmp;') - this.generatedApi.print('std::string _prereq;') this.generatedApi.print('static int _num = 0;') - if (method.argConvertors.some(it => it instanceof ArrayConvertor)) { - this.generatedApi.print(`static int _array_num = 0;`); - } let varNames : string[] = new Array() for (let i = 0; i < method.argConvertors.length; ++i) { let it = method.argConvertors[i] let name = this.generateApiArgument(it) // it.param + '_value' - if (it instanceof ArrayConvertor) { - this.generatedApi.print(`_tmp = "", generateStdArrayDefinition(&_tmp, ${name}, &_prereq);`); - this.generatedApi.print(`_logData.append(" auto array" + std::to_string(_array_num) + " = " + _tmp + ";");`); - this.generatedApi.print(`_logData.append("\\n");`); - this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name}, &_prereq, "array" + std::to_string(_array_num));`) - this.generatedApi.print("_array_num += 1;") - } else { - this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name}, &_prereq);`) - } + this.generatedApi.print(`_tmp = "", WriteToString(&_tmp, ${name});`) varNames.push(`var${BridgeCcVisitor.varCnt}`) - let ptrType = `const ${it.nativeType(false)}` - this.generatedApi.print(`_logData.append( _prereq);`) + let ptrType = it instanceof EnumConvertor ? `const ${it.nativeType(false).replace("enum ", "")}` : `const ${it.nativeType(false)}` this.generatedApi.print(`_logData.append(" ${ptrType} ${varNames[i]}_" + std::to_string(_num) + " = " + _tmp + ";\\n");`) BridgeCcVisitor.varCnt += 1 } diff --git a/src/peer-generation/printers/ModifierPrinter.ts b/src/peer-generation/printers/ModifierPrinter.ts index 1df1a33d7..1da11e51c 100644 --- a/src/peer-generation/printers/ModifierPrinter.ts +++ b/src/peer-generation/printers/ModifierPrinter.ts @@ -163,10 +163,9 @@ export class ModifierVisitor { _.makeReturn( method.retConvertor.isVoid ? undefined : _.makeString(method.dummyReturnValue ?? "0")))) _.print(`string out("${method.toStringName}(");`) - _.print(`string _prereq;`) method.argConvertors.forEach((argConvertor, index) => { if (index > 0) this.dummy.print(`out.append(", ");`) - _.print(`WriteToString(&out, ${argConvertor.param}, &_prereq);`) + _.print(`WriteToString(&out, ${argConvertor.param});`) }) _.print(`out.append(")");`) const retVal = method.dummyReturnValue diff --git a/templates/dummy_impl_prologue.cc b/templates/dummy_impl_prologue.cc index 48eec5479..2c1397cf6 100644 --- a/templates/dummy_impl_prologue.cc +++ b/templates/dummy_impl_prologue.cc @@ -350,13 +350,12 @@ Ark_NodeHandle CreateNode(GENERATED_Ark_NodeType type, Ark_Int32 id, Ark_Int32 f if (!needGroupedLog(1)) { return result; } - string prereq; string out("createNode("); - WriteToString(&out, (Ark_Int32)type, &prereq); + WriteToString(&out, (Ark_Int32)type); out.append(", "); - WriteToString(&out, id, &prereq); + WriteToString(&out, id); out.append(", "); - WriteToString(&out, flags, &prereq); + WriteToString(&out, flags); out.append(")"); appendGroupedLog(1, out); return result; @@ -375,8 +374,7 @@ Ark_Float32 GetDensity(Ark_Int32 deviceId) { } string out("getDensity("); - string prereq; - WriteToString(&out, deviceId, &prereq); + WriteToString(&out, deviceId); out.append(")"); appendGroupedLog(1, out); @@ -391,8 +389,7 @@ Ark_Float32 GetFontScale(Ark_Int32 deviceId) { } string out("getFontScale("); - string prereq; - WriteToString(&out, deviceId, &prereq); + WriteToString(&out, deviceId); out.append(")"); appendGroupedLog(1, out); @@ -407,8 +404,7 @@ Ark_Float32 GetDesignWidthScale(Ark_Int32 deviceId) { } string out("getDesignWidthScale("); - string prereq; - WriteToString(&out, deviceId, &prereq); + WriteToString(&out, deviceId); out.append(")"); appendGroupedLog(1, out); @@ -448,8 +444,7 @@ void DisposeNode(Ark_NodeHandle node) { } string out("disposeNode("); - string prereq; - WriteToString(&out, node, &prereq); + WriteToString(&out, node); out.append(")"); appendGroupedLog(1, out); } @@ -468,8 +463,7 @@ void DumpTreeNode(Ark_NodeHandle node) { } string out("dumpTreeNode("); - std::string prereq; - WriteToString(&out, node, &prereq); + WriteToString(&out, node); out.append(")"); appendGroupedLog(1, out); } @@ -489,10 +483,9 @@ Ark_Int32 AddChild(Ark_NodeHandle parent, Ark_NodeHandle child) { } string out("addChild("); - string prereq; - WriteToString(&out, parent, &prereq); + WriteToString(&out, parent); out.append(", "); - WriteToString(&out, child, &prereq); + WriteToString(&out, child); out.append(")"); appendGroupedLog(1, out); @@ -517,10 +510,9 @@ void RemoveChild(Ark_NodeHandle parent, Ark_NodeHandle child) { } string out("removeChild("); - string prereq; - WriteToString(&out, parent, &prereq); + WriteToString(&out, parent); out.append(", "); - WriteToString(&out, child, &prereq); + WriteToString(&out, child); out.append(")"); appendGroupedLog(1, out); } @@ -541,12 +533,11 @@ Ark_Int32 InsertChildAfter(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Node } string out("insertChildAfter("); - string prereq; - WriteToString(&out, parent, &prereq); + WriteToString(&out, parent); out.append(", "); - WriteToString(&out, child, &prereq); + WriteToString(&out, child); out.append(", "); - WriteToString(&out, sibling, &prereq); + WriteToString(&out, sibling); out.append(")"); appendGroupedLog(1, out); return result; @@ -568,12 +559,11 @@ Ark_Int32 InsertChildBefore(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Nod } string out("insertChildBefore("); - string prereq; - WriteToString(&out, parent, &prereq); + WriteToString(&out, parent); out.append(", "); - WriteToString(&out, child, &prereq); + WriteToString(&out, child); out.append(", "); - WriteToString(&out, sibling, &prereq); + WriteToString(&out, sibling); out.append(")"); appendGroupedLog(1, out); return result; @@ -595,12 +585,11 @@ Ark_Int32 InsertChildAt(Ark_NodeHandle parent, Ark_NodeHandle child, Ark_Int32 p } string out("insertChildAt("); - string prereq; - WriteToString(&out, parent, &prereq); + WriteToString(&out, parent); out.append(", "); - WriteToString(&out, child, &prereq); + WriteToString(&out, child); out.append(", "); - WriteToString(&out, position, &prereq); + WriteToString(&out, position); out.append(")"); appendGroupedLog(1, out); return result; @@ -618,8 +607,7 @@ void ApplyModifierFinish(Ark_NodeHandle node) { return; } string out("applyModifierFinish("); - string prereq; - WriteToString(&out, node, &prereq); + WriteToString(&out, node); out.append(")"); appendGroupedLog(1, out); } @@ -636,10 +624,9 @@ void MarkDirty(Ark_NodeHandle node, Ark_UInt32 flag) { return; } string out("markDirty("); - string prereq; - WriteToString(&out, node, &prereq); + WriteToString(&out, node); out.append(", "); - WriteToString(&out, flag, &prereq); + WriteToString(&out, flag); out.append(")"); appendGroupedLog(1, out); } @@ -658,8 +645,7 @@ Ark_Boolean IsBuilderNode(Ark_NodeHandle node) { return result; } string out("isBuilderNode("); - string prereq; - WriteToString(&out, node, &prereq); + WriteToString(&out, node); out.append(")"); appendGroupedLog(1, out); return result; @@ -680,12 +666,11 @@ Ark_Float32 ConvertLengthMetricsUnit(Ark_Float32 value, Ark_Int32 originUnit, Ar } string out("convertLengthMetricsUnit("); - string prereq; - WriteToString(&out, value, &prereq); + WriteToString(&out, value); out.append(", "); - WriteToString(&out, originUnit, &prereq); + WriteToString(&out, originUnit); out.append(", "); - WriteToString(&out, targetUnit, &prereq); + WriteToString(&out, targetUnit); out.append(")"); appendGroupedLog(1, out); return result; @@ -722,8 +707,7 @@ Ark_Int32 MeasureLayoutAndDraw(Ark_VMContext vmContext, Ark_NodeHandle root) { return result; } string out("measureLayoutAndDraw("); - std::string prereq; - WriteToString(&out, root, &prereq); + WriteToString(&out, root); out.append(")"); appendGroupedLog(1, out); return result; -- Gitee From 4ebab0a3f090251507e1e7524b9c0dcf4b9f6508 Mon Sep 17 00:00:00 2001 From: grebelnik Date: Fri, 13 Sep 2024 18:40:45 +0500 Subject: [PATCH 8/9] Remove attributes --- peer_lib/sig/arkoala/arkui/src/main.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/peer_lib/sig/arkoala/arkui/src/main.ts b/peer_lib/sig/arkoala/arkui/src/main.ts index afd74a7eb..299dc57a7 100644 --- a/peer_lib/sig/arkoala/arkui/src/main.ts +++ b/peer_lib/sig/arkoala/arkui/src/main.ts @@ -659,19 +659,16 @@ namespace OHOS::Ace::NG::GeneratedModifier { EXTERN_C IDLIZE_API_EXPORT const GENERATED_ArkUIAnyAPI* GENERATED_GetArkAnyAPI(GENERATED_Ark_APIVariantKind kind, int version); } -__attribute__((visibility("hidden"))) const GENERATED_ArkUINodeModifiers* GetNodeModifiers() { static const auto val = (const GENERATED_ArkUIFullNodeAPI*)(OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_FULL,GENERATED_ARKUI_FULL_API_VERSION)); return val->getNodeModifiers(); } -__attribute__((visibility("hidden"))) const GENERATED_ArkUIAccessors* GetAccessors() { static const auto val = (const GENERATED_ArkUIFullNodeAPI*)(OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_FULL,GENERATED_ARKUI_FULL_API_VERSION)); return val->getAccessors(); } -__attribute__((visibility("hidden"))) const GENERATED_ArkUIBasicNodeAPI* GetBasicNodeApi() { static const auto val = (const GENERATED_ArkUIBasicNodeAPI*)OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_BASIC, GENERATED_ARKUI_BASIC_NODE_API_VERSION); return val; -- Gitee From 166a9481270382ee33b3aaafcb21f4ff613ea1ee Mon Sep 17 00:00:00 2001 From: grebelnik Date: Mon, 16 Sep 2024 15:10:18 +0500 Subject: [PATCH 9/9] call-log.sh -> call-log.mjs --- insert-call-log.sh | 2 -- manage-call-log.mjs | 24 ++++++++++++++++++++++++ remove-call-log.sh | 2 -- 3 files changed, 24 insertions(+), 4 deletions(-) delete mode 100644 insert-call-log.sh create mode 100644 manage-call-log.mjs delete mode 100644 remove-call-log.sh diff --git a/insert-call-log.sh b/insert-call-log.sh deleted file mode 100644 index ef0cdc685..000000000 --- a/insert-call-log.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! bin/bash -sed -i 's/--dts2peer/--dts2peer --call-log/g' package.json diff --git a/manage-call-log.mjs b/manage-call-log.mjs new file mode 100644 index 000000000..68fdc483d --- /dev/null +++ b/manage-call-log.mjs @@ -0,0 +1,24 @@ +import { readFileSync, writeFileSync } from 'fs'; + +const filePath = './package.json'; +const args = process.argv.slice(2); + +try { + if (args.length !== 1 || (args[0] !== '--add' && args[0] !== '--remove')) { + console.error('Usage: node manage-call-log.mjs --add | --remove'); + process.exit(1); + } else { + const action = args[0] + let data = readFileSync(filePath, 'utf8'); + let updatedData = null; + if (action === '--add') { + updatedData = data.replace(/--dts2peer/g, '--dts2peer --call-log'); + } else if (action === '--remove') { + updatedData = data.replace(/--dts2peer --call-log/g, '--dts2peer'); + } + writeFileSync(filePath, updatedData, 'utf8'); + console.log("Successfully updated the package.json file."); + } +} catch (error) { + console.error("Error reading or writing to package.json:", error); +} diff --git a/remove-call-log.sh b/remove-call-log.sh deleted file mode 100644 index f5fd1bc59..000000000 --- a/remove-call-log.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! bin/bash -sed -i 's/--dts2peer --call-log/--dts2peer/g' package.json -- Gitee