From 20d6a1a4cb6bcd8eec09caa3e613d3484b6952e6 Mon Sep 17 00:00:00 2001 From: jiangkaiwen Date: Sat, 14 Jan 2023 22:08:09 +0800 Subject: [PATCH] Fix codecheck warnings of security compliance in monthly branch 1.Line length not exceed 120 characters 2.Duplicate code is separated into a separate function Issue:I6AGJI Signed-off-by: jiangkaiwen Change-Id: I0a7b85fa9f867cb30c38bc9be3cd3a1338a722c9 --- es2panda/es2panda.cpp | 46 +++++++++++-------- es2panda/es2panda.h | 5 ++ ...led-iteration-continue-target-expected.txt | 5 ++ es2panda/test/runner.py | 10 ++-- ts2panda/ts2abc/ts2abc.cpp | 3 +- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 7c42974334..48a97b78bc 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include @@ -52,7 +51,7 @@ Compiler::~Compiler() delete compiler_; } -panda::pandasm::Program *createJsonContentProgram(std::string src, std::string rname) +panda::pandasm::Program *CreateJsonContentProgram(std::string src, std::string rname) { panda::es2panda::compiler::CompilerContext context(nullptr, false, false, false, false, true, src, "", util::StringView(rname)); @@ -71,17 +70,10 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil parser::ScriptKind kind(input.scriptKind); if (fname.substr(fname.find_last_of(".") + 1) == "json") { - return createJsonContentProgram(src, rname); + return CreateJsonContentProgram(src, rname); } - bool needDumpSymbolFile = !options.hotfixOptions.dumpSymbolTable.empty(); - bool needGeneratePatch = options.hotfixOptions.generatePatch && !options.hotfixOptions.symbolTable.empty(); - util::Hotfix *hotfixHelper = nullptr; - if (symbolTable && (needDumpSymbolFile || needGeneratePatch)) { - hotfixHelper = new util::Hotfix(needDumpSymbolFile, needGeneratePatch, input.recordName, symbolTable); - parser_->AddHotfixHelper(hotfixHelper); - compiler_->AddHotfixHelper(hotfixHelper); - } + auto *hotfixHelper = InitHotfixHelper(input, options, symbolTable); try { auto ast = parser_->Parse(fname, src, rname, kind); @@ -110,22 +102,38 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil sourcefile : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile, pkgName); - if (hotfixHelper) { - delete hotfixHelper; - hotfixHelper = nullptr; - } + CleanHotfixHelper(hotfixHelper); return prog; } catch (const class Error &e) { error_ = e; - if (hotfixHelper) { - delete hotfixHelper; - hotfixHelper = nullptr; - } + CleanHotfixHelper(hotfixHelper); return nullptr; } } +util::Hotfix *Compiler::InitHotfixHelper(const SourceFile &input, const CompilerOptions &options, + util::SymbolTable *symbolTable) +{ + bool needDumpSymbolFile = !options.hotfixOptions.dumpSymbolTable.empty(); + bool needGeneratePatch = options.hotfixOptions.generatePatch && !options.hotfixOptions.symbolTable.empty(); + util::Hotfix *hotfixHelper = nullptr; + if (symbolTable && (needDumpSymbolFile || needGeneratePatch)) { + hotfixHelper = new util::Hotfix(needDumpSymbolFile, needGeneratePatch, input.recordName, symbolTable); + parser_->AddHotfixHelper(hotfixHelper); + compiler_->AddHotfixHelper(hotfixHelper); + } + return hotfixHelper; +} + +void Compiler::CleanHotfixHelper(const util::Hotfix *hotfixHelper) +{ + if (hotfixHelper) { + delete hotfixHelper; + hotfixHelper = nullptr; + } +} + void Compiler::DumpAsm(const panda::pandasm::Program *prog) { compiler::CompilerImpl::DumpAsm(prog); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 8ac8084008..efe53ae44d 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -197,6 +198,10 @@ public: } private: + util::Hotfix *InitHotfixHelper(const SourceFile &input, const CompilerOptions &options, + util::SymbolTable *symbolTable); + static void CleanHotfixHelper(const util::Hotfix *hotfixHelper); + parser::ParserImpl *parser_; compiler::CompilerImpl *compiler_; std::unique_ptr transformer_ {nullptr}; diff --git a/es2panda/test/parser/js/test-labeled-iteration-continue-target-expected.txt b/es2panda/test/parser/js/test-labeled-iteration-continue-target-expected.txt index 6f1d4caf17..ee93c6f925 100644 --- a/es2panda/test/parser/js/test-labeled-iteration-continue-target-expected.txt +++ b/es2panda/test/parser/js/test-labeled-iteration-continue-target-expected.txt @@ -9,6 +9,7 @@ "id": { "type": "Identifier", "name": "a", + "decorators": [], "loc": { "start": { "line": 1, @@ -63,6 +64,7 @@ "label": { "type": "Identifier", "name": "target1", + "decorators": [], "loc": { "start": { "line": 2, @@ -79,6 +81,7 @@ "label": { "type": "Identifier", "name": "target2", + "decorators": [], "loc": { "start": { "line": 3, @@ -99,6 +102,7 @@ "argument": { "type": "Identifier", "name": "a", + "decorators": [], "loc": { "start": { "line": 4, @@ -129,6 +133,7 @@ "label": { "type": "Identifier", "name": "target1", + "decorators": [], "loc": { "start": { "line": 5, diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 960f59890f..1920314b73 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -393,7 +393,7 @@ class Runner: self.failed = 0 self.passed = 0 self.es2panda = path.join(args.build_dir, 'es2abc') - self.test_abc = path.join(args.build_dir, 'runner_test.abc') + self.build_dir = args.build_dir self.cmd_prefix = [] self.ark_js_vm = "" self.ld_library_path = "" @@ -794,9 +794,11 @@ class CompilerTest(Test): Test.__init__(self, test_path, flags) def run(self, runner): + test_abc_name = ("%s.abc" % (path.splitext(self.path)[0])).replace("/", "_") + test_abc_path = path.join(runner.build_dir, test_abc_name) es2abc_cmd = runner.cmd_prefix + [runner.es2panda] es2abc_cmd.extend(self.flags) - es2abc_cmd.extend(["--output=" + runner.test_abc]) + es2abc_cmd.extend(["--output=" + test_abc_path]) es2abc_cmd.append(self.path) self.log_cmd(es2abc_cmd) @@ -810,7 +812,7 @@ class CompilerTest(Test): ld_library_path = runner.ld_library_path os.environ.setdefault("LD_LIBRARY_PATH", ld_library_path) run_abc_cmd = [runner.ark_js_vm] - run_abc_cmd.extend([runner.test_abc]) + run_abc_cmd.extend([test_abc_path]) self.log_cmd(run_abc_cmd) process = subprocess.Popen(run_abc_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -827,7 +829,7 @@ class CompilerTest(Test): if not self.passed: self.error = err.decode("utf-8", errors="ignore") - os.remove(runner.test_abc) + os.remove(test_abc_path) return self diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 81b6348936..9d06625f78 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -1099,7 +1099,8 @@ static void ParseInputJsonFileContent(const Json::Value &rootValue, panda::panda auto inputJsonFileContentField = panda::pandasm::Field(LANG_EXT); inputJsonFileContentField.name = "jsonFileContent"; inputJsonFileContentField.type = panda::pandasm::Type("u32", 0); - inputJsonFileContentField.metadata->SetValue(panda::pandasm::ScalarValue::Create( + inputJsonFileContentField.metadata->SetValue( + panda::pandasm::ScalarValue::Create( static_cast(rootValue["ijfc"].asString()))); rec.field_list.emplace_back(std::move(inputJsonFileContentField)); } -- Gitee