From 7377c9eab36de7f9596acbd0e6828594643bc6af Mon Sep 17 00:00:00 2001 From: hufeng Date: Wed, 26 Jan 2022 12:07:47 +0800 Subject: [PATCH 1/5] fix JS-frontend codex issues Signed-off-by: hufeng Change-Id: I57c08cbe39061e112e08d8cde9c22efa1d55d6c4 --- ts2panda/ts2abc/ts2abc.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index b9918d6e0a..159491802e 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -195,7 +195,7 @@ static std::string ParseUnicodeEscapeString(const std::string &data) std::string tmpStr = data.substr(startIdx, index - startIdx); newData += ConvertUtf8ToMUtf8(tmpStr); std::string uStr = data.substr(index + UNICODE_ESCAPE_SYMBOL_LEN, UNICODE_CHARACTER_LEN); - uint16_t u16Data = std::stoi(uStr.c_str(), NULL, BASE); + uint16_t u16Data = static_cast(std::stoi(uStr.c_str(), NULL, BASE)); newData += ConvertUtf16ToMUtf8(&u16Data, 1); startIdx = index + UNICODE_ESCAPE_SYMBOL_LEN + UNICODE_CHARACTER_LEN; } @@ -393,11 +393,11 @@ static void ParseInstructionDebugInfo(const Json::Value &ins, panda::pandasm::In auto debugPosInfo = ins["debug_pos_info"]; if (GetDebugModeEnabled()) { if (debugPosInfo.isMember("boundLeft") && debugPosInfo["boundLeft"].isInt()) { - insDebug.bound_left = debugPosInfo["boundLeft"].asInt(); + insDebug.bound_left = debugPosInfo["boundLeft"].asUInt(); } if (debugPosInfo.isMember("boundRight") && debugPosInfo["boundRight"].isInt()) { - insDebug.bound_right = debugPosInfo["boundRight"].asInt(); + insDebug.bound_right = debugPosInfo["boundRight"].asUInt(); } if (debugPosInfo.isMember("wholeLine") && debugPosInfo["wholeLine"].isString()) { @@ -405,12 +405,12 @@ static void ParseInstructionDebugInfo(const Json::Value &ins, panda::pandasm::In } if (debugPosInfo.isMember("columnNum") && debugPosInfo["columnNum"].isInt()) { - insDebug.column_number = debugPosInfo["columnNum"].asInt(); + insDebug.column_number = debugPosInfo["columnNum"].asUInt(); } } if (debugPosInfo.isMember("lineNum") && debugPosInfo["lineNum"].isInt()) { - insDebug.line_number = debugPosInfo["lineNum"].asInt(); + insDebug.line_number = debugPosInfo["lineNum"].asUInt(); } } @@ -460,11 +460,11 @@ static int ParseVariablesDebugInfo(const Json::Value &function, panda::pandasm:: } if (variable.isMember("start") && variable["start"].isInt()) { - variableDebug.start = variable["start"].asInt(); + variableDebug.start = variable["start"].asUInt(); } if (variable.isMember("length") && variable["length"].isInt()) { - variableDebug.length = variable["length"].asInt(); + variableDebug.length = variable["length"].asUInt(); } pandaFunc.local_variable_debug.push_back(variableDebug); @@ -539,7 +539,7 @@ panda::pandasm::Function GetFunctionDefintion(const Json::Value &function) } } - int regsNum = 0; + uint32_t regsNum = 0; if (function.isMember("regs_num") && function["regs_num"].isInt()) { regsNum = function["regs_num"].asUInt(); } @@ -1011,7 +1011,7 @@ static bool ParseData(const std::string &data, panda::pandasm::Program &prog) bool isStartDollar = true; for (size_t idx = 0; idx < data.size(); idx++) { - if (data[idx] == '$' && data[idx - 1] != '#') { + if (data[idx] == '$' && (idx == 0 || data[idx - 1] != '#')) { if (isStartDollar) { pos = idx + 1; isStartDollar = false; @@ -1099,7 +1099,11 @@ bool HandleJsonFile(const std::string &input, std::string &data) } file.seekg(0, std::ios::end); - size_t fileSize = file.tellg(); + int64_t fileSize = file.tellg(); + if (fileSize == -1) { + std::cerr << "failed to get position in input sequence: " << fpath << std::endl; + return false; + } file.seekg(0, std::ios::beg); auto buf = std::vector(fileSize); file.read(reinterpret_cast(buf.data()), fileSize); -- Gitee From d801d1d15099437772299bfea745f35aed6a8ab1 Mon Sep 17 00:00:00 2001 From: hufeng Date: Wed, 26 Jan 2022 17:22:36 +0800 Subject: [PATCH 2/5] fix build-mc warning Signed-off-by: hufeng Change-Id: I2bfd39a3234a3d2ea26157ddf07146abcf1dd227 --- test262/config.py | 4 ++-- test262/run_sunspider.py | 4 ++-- test262/run_test262.py | 4 ++-- test262/utils.py | 4 ++-- ts2panda/ts2abc/BUILD.gn | 1 - 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/test262/config.py b/test262/config.py index 34670ad68a..3e4872c28a 100755 --- a/test262/config.py +++ b/test262/config.py @@ -1,5 +1,5 @@ -#!/usr/bin/python3 -# coding: utf-8 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ Copyright (c) 2021 Huawei Device Co., Ltd. diff --git a/test262/run_sunspider.py b/test262/run_sunspider.py index af5cdc6f94..3186621dc8 100755 --- a/test262/run_sunspider.py +++ b/test262/run_sunspider.py @@ -1,5 +1,5 @@ -#!/usr/bin/python3 -# coding: utf-8 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ Copyright (c) 2021 Huawei Device Co., Ltd. diff --git a/test262/run_test262.py b/test262/run_test262.py index 014c45062e..031019cb00 100755 --- a/test262/run_test262.py +++ b/test262/run_test262.py @@ -1,5 +1,5 @@ -#!/usr/bin/python3 -# coding: utf-8 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ Copyright (c) 2021 Huawei Device Co., Ltd. diff --git a/test262/utils.py b/test262/utils.py index 2d62db1db5..93225c3b89 100755 --- a/test262/utils.py +++ b/test262/utils.py @@ -1,5 +1,5 @@ -# coding: utf-8 -#!/usr/bin/python3 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ Copyright (c) 2021 Huawei Device Co., Ltd. diff --git a/ts2panda/ts2abc/BUILD.gn b/ts2panda/ts2abc/BUILD.gn index 7e9b058c91..01cd95db88 100755 --- a/ts2panda/ts2abc/BUILD.gn +++ b/ts2panda/ts2abc/BUILD.gn @@ -31,7 +31,6 @@ config("ts2abc_config") { configs = [ "$ark_root:ark_config", sdk_libc_secshared_config, - "$jsoncpp_root:jsoncpp_config", "$ark_root/libpandafile:arkfile_public_config", "$ark_root/libpandabase:arkbase_public_config", "$ark_root/runtime:arkruntime_public_config", -- Gitee From 7cf56a51ea153f4250bb10a3f0ad88399b75caea Mon Sep 17 00:00:00 2001 From: hufeng Date: Wed, 26 Jan 2022 21:09:44 +0800 Subject: [PATCH 3/5] restore some change Signed-off-by: hufeng Change-Id: Ia556099c81d24efc2358f798f3709ded1cd63402 --- ts2panda/ts2abc/ts2abc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 159491802e..0a42dc5ccd 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -1011,7 +1011,7 @@ static bool ParseData(const std::string &data, panda::pandasm::Program &prog) bool isStartDollar = true; for (size_t idx = 0; idx < data.size(); idx++) { - if (data[idx] == '$' && (idx == 0 || data[idx - 1] != '#')) { + if (data[idx] == '$' && data[idx - 1] != '#') { if (isStartDollar) { pos = idx + 1; isStartDollar = false; -- Gitee From 9a6ceff790afd007cf36679e9d74b3a7f71e8c75 Mon Sep 17 00:00:00 2001 From: hufeng Date: Tue, 15 Feb 2022 17:11:08 +0800 Subject: [PATCH 4/5] fix build_mc Signed-off-by: hufeng Change-Id: I40cb75977d6ddc3ed28ba484cb3cab416e8de054 --- test262/run_test262.py | 5 ++--- ts2panda/ts2abc/ts2abc.cpp | 23 ++++++++++++----------- ts2panda/ts2abc/ts2abc_options.h | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/test262/run_test262.py b/test262/run_test262.py index 031019cb00..baa936b005 100755 --- a/test262/run_test262.py +++ b/test262/run_test262.py @@ -265,9 +265,8 @@ class TestPrepare(): return files def get_tests_from_file(self, file): - fopen = open(file) - files = fopen.readlines() - fopen.close() + with open(file) as fopen: + files = fopen.readlines() return files def prepare_es2015_tests(self): diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 0a42dc5ccd..8805d8ce3b 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -41,10 +41,7 @@ namespace { int g_optLevel = 0; std::string g_optLogLevel = "error"; bool g_moduleModeEnabled = false; - const int LOG_BUFFER_SIZE = 1024; const int BASE = 16; - const int UNICODE_ESCAPE_SYMBOL_LEN = 2; - const int UNICODE_CHARACTER_LEN = 4; int g_literalArrayCount = 0; @@ -135,10 +132,11 @@ static void SetDebugModeEnabled(bool value) // Unified interface for debug log print static void Logd(const char *format, ...) { + const int logBufferSize = 1024; if (GetDebugLog()) { va_list valist; va_start(valist, format); - char logMsg[LOG_BUFFER_SIZE]; + char logMsg[logBufferSize]; int ret = vsnprintf_s(logMsg, sizeof(logMsg) - 1, sizeof(logMsg) - 1, format, valist); if (ret == -1) { va_end(valist); @@ -177,6 +175,8 @@ static std::string ConvertUtf8ToMUtf8(const std::string &data) static std::string ParseUnicodeEscapeString(const std::string &data) { + const int unicodeEscapeSymbolLen = 2; + const int unicodeCharacterLen = 4; std::string::size_type startIdx = 0; std::string newData = ""; std::string::size_type len = data.length(); @@ -188,16 +188,16 @@ static std::string ParseUnicodeEscapeString(const std::string &data) } if (index != 0 && data[index - 1] == '\\') { std::string tmpStr = data.substr(startIdx, index - 1 - startIdx) + - data.substr(index, UNICODE_ESCAPE_SYMBOL_LEN); // delete a '\\' + data.substr(index, unicodeEscapeSymbolLen); // delete a '\\' newData += ConvertUtf8ToMUtf8(tmpStr); - startIdx = index + UNICODE_ESCAPE_SYMBOL_LEN; + startIdx = index + unicodeEscapeSymbolLen; } else { std::string tmpStr = data.substr(startIdx, index - startIdx); newData += ConvertUtf8ToMUtf8(tmpStr); - std::string uStr = data.substr(index + UNICODE_ESCAPE_SYMBOL_LEN, UNICODE_CHARACTER_LEN); + std::string uStr = data.substr(index + unicodeEscapeSymbolLen, unicodeCharacterLen); uint16_t u16Data = static_cast(std::stoi(uStr.c_str(), NULL, BASE)); newData += ConvertUtf16ToMUtf8(&u16Data, 1); - startIdx = index + UNICODE_ESCAPE_SYMBOL_LEN + UNICODE_CHARACTER_LEN; + startIdx = index + unicodeEscapeSymbolLen + unicodeCharacterLen; } } if (startIdx != len) { @@ -294,12 +294,12 @@ static panda::pandasm::Record ParseRecord(const Json::Value &record) int boundLeft = -1; if (record.isMember("bound_left") && record["bound_left"].isInt()) { - boundLeft = record["bound_left"].asInt(); + boundLeft = record["bound_left"].asUInt(); } int boundRight = -1; if (record.isMember("bound_right") && record["bound_right"].isInt()) { - boundRight = record["bound_right"].asInt(); + boundRight = record["bound_right"].asUInt(); } int lineNumber = -1; @@ -1011,7 +1011,7 @@ static bool ParseData(const std::string &data, panda::pandasm::Program &prog) bool isStartDollar = true; for (size_t idx = 0; idx < data.size(); idx++) { - if (data[idx] == '$' && data[idx - 1] != '#') { + if (data[idx] == '$' && (idx ==0 || data[idx - 1] != '#')) { if (isStartDollar) { pos = idx + 1; isStartDollar = false; @@ -1119,6 +1119,7 @@ bool HandleJsonFile(const std::string &input, std::string &data) bool ReadFromPipe(std::string &data) { const size_t bufSize = 4096; + // the parent process open a pipe to this child process with fd of 3 const size_t fd = 3; char buff[bufSize + 1]; diff --git a/ts2panda/ts2abc/ts2abc_options.h b/ts2panda/ts2abc/ts2abc_options.h index 577166e624..86725c6c4e 100755 --- a/ts2panda/ts2abc/ts2abc_options.h +++ b/ts2panda/ts2abc/ts2abc_options.h @@ -1,4 +1,5 @@ -/* * Copyright (c) 2021 Huawei Device Co., Ltd. +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 44e9471734f53c3c5d130656f489633e3273f28e Mon Sep 17 00:00:00 2001 From: hufeng Date: Tue, 15 Feb 2022 17:14:51 +0800 Subject: [PATCH 5/5] minor fixs Signed-off-by: hufeng Change-Id: Ifdd2f571db8fa8cda996fd0cf58b1c7bf1f447af --- ts2panda/ts2abc/ts2abc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 8805d8ce3b..6d5e7b14a7 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -405,12 +405,12 @@ static void ParseInstructionDebugInfo(const Json::Value &ins, panda::pandasm::In } if (debugPosInfo.isMember("columnNum") && debugPosInfo["columnNum"].isInt()) { - insDebug.column_number = debugPosInfo["columnNum"].asUInt(); + insDebug.column_number = debugPosInfo["columnNum"].asInt(); } } if (debugPosInfo.isMember("lineNum") && debugPosInfo["lineNum"].isInt()) { - insDebug.line_number = debugPosInfo["lineNum"].asUInt(); + insDebug.line_number = debugPosInfo["lineNum"].asInt(); } } -- Gitee