From 75b08a055e747ed7d4b3de01cd3257a2c4d54934 Mon Sep 17 00:00:00 2001 From: wangjunlin Date: Fri, 25 Mar 2022 12:08:27 +0800 Subject: [PATCH] fix code and copyright Signed-off-by: wangjunlin Change-Id: I3afe9c002602fd8b9053476419beaf92e95a8acd --- OAT.xml | 6 +-- .../test_bytecode_optimizer_for_js.js | 15 +++++++ ts2panda/src/compiler.ts | 39 ++++++++++--------- ts2panda/tests/regAllocator.test.ts | 2 +- ts2panda/ts2abc/ts2abc.cpp | 3 +- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/OAT.xml b/OAT.xml index 1578ebf..d70eb7e 100644 --- a/OAT.xml +++ b/OAT.xml @@ -56,11 +56,11 @@ Note:If the text contains special characters, please escape them according to th - + - + - + diff --git a/test_ecma_bcopt/test_bytecode_optimizer_for_js.js b/test_ecma_bcopt/test_bytecode_optimizer_for_js.js index b09c563..cd4e3aa 100755 --- a/test_ecma_bcopt/test_bytecode_optimizer_for_js.js +++ b/test_ecma_bcopt/test_bytecode_optimizer_for_js.js @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + let a = [1]; a[0] = 2; diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 7d64549..d0cc3c5 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -240,18 +240,18 @@ export class Compiler { hasAFChild = true; } }); - - if (hasAFChild) { - this.storeSpecialArg2LexEnv("4newTarget"); - this.storeSpecialArg2LexEnv("arguments"); - - if (ts.isConstructorDeclaration(rootNode) && rootNode.parent.heritageClauses) { - this.storeSpecialArg2LexEnv("4funcObj"); - return; - } - - this.storeSpecialArg2LexEnv("this"); + if (!hasAFChild) { + return ; } + this.storeSpecialArg2LexEnv("4newTarget"); + this.storeSpecialArg2LexEnv("arguments"); + + if (ts.isConstructorDeclaration(rootNode) && rootNode.parent.heritageClauses) { + this.storeSpecialArg2LexEnv("4funcObj"); + return; + } + + this.storeSpecialArg2LexEnv("this"); } } @@ -300,14 +300,15 @@ export class Compiler { compileReturnThis4Ctor(this, body.parent, unreachableFlag); return; } - - if (!unreachableFlag) { // exit GlobalScopefunction or Function Block return - if (this.funcBuilder instanceof AsyncFunctionBuilder) { - this.funcBuilder.resolve(NodeKind.Invalid, getVregisterCache(pandaGen, CacheList.undefined)); - pandaGen.return(NodeKind.Invalid); - } else { - pandaGen.returnUndefined(NodeKind.Invalid); - } + if (unreachableFlag) { + return ; + } + // exit GlobalScopefunction or Function Block return + if (this.funcBuilder instanceof AsyncFunctionBuilder) { + this.funcBuilder.resolve(NodeKind.Invalid, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.return(NodeKind.Invalid); + } else { + pandaGen.returnUndefined(NodeKind.Invalid); } } diff --git a/ts2panda/tests/regAllocator.test.ts b/ts2panda/tests/regAllocator.test.ts index 0ae3331..2888a14 100644 --- a/ts2panda/tests/regAllocator.test.ts +++ b/ts2panda/tests/regAllocator.test.ts @@ -91,7 +91,7 @@ describe("RegAllocator", function () { it("make spill for CalliDynRange", function () { /* since the bitwidth for CalliDynRange source register is 16 now, we do not need to make spill at all. - but later 16 might be changed to 8, then spill operation will be needed in some cases. this testcase is designed + but in case later 16 might be changed to 8, then spill operation will be needed in some cases. this testcase is designed for 8bits constraints. */ let string = ""; diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index fba8554..62cfa4b 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -820,10 +820,9 @@ int ParseJson(const std::string &data, Json::Value &rootValue) { JSONCPP_STRING errs; Json::CharReaderBuilder readerBuilder; - bool res; std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - res = jsonReader->parse(data.c_str(), data.c_str() + data.length(), &rootValue, &errs); + bool res = jsonReader->parse(data.c_str(), data.c_str() + data.length(), &rootValue, &errs); if (!res || !errs.empty()) { std::cerr << "ParseJson err. " << errs.c_str() << std::endl; return RETURN_FAILED;