diff --git a/ecmascript/base/bit_helper.h b/ecmascript/base/bit_helper.h index fe9ffbeb10..d315587ccf 100644 --- a/ecmascript/base/bit_helper.h +++ b/ecmascript/base/bit_helper.h @@ -69,7 +69,7 @@ inline constexpr uint32_t CountLeadingZeros(T value) static_assert(std::numeric_limits::radix == RADIX, "Unexpected radix!"); static_assert(sizeof(T) == sizeof(uint64_t) || sizeof(T) <= sizeof(uint32_t), "Unsupported sizeof(T)"); if (value == 0) { - return sizeof(T) * 8; + return sizeof(T) * 8; // 8 : byte size } if (sizeof(T) == sizeof(uint64_t)) { return __builtin_clzll(static_cast(value)); @@ -107,7 +107,7 @@ inline constexpr uint32_t CountTrailingZeros(T value) static_assert(std::numeric_limits::radix == RADIX, "Unexpected radix!"); static_assert(sizeof(T) == sizeof(uint64_t) || sizeof(T) <= sizeof(uint32_t), "Unsupported sizeof(T)"); if (value == 0) { - return sizeof(T) * 8; + return sizeof(T) * 8; // 8 : byte size } if (sizeof(T) == sizeof(uint64_t)) { return __builtin_ctzll(static_cast(value)); diff --git a/ecmascript/builtins/builtins.cpp b/ecmascript/builtins/builtins.cpp index 298d4b3754..284aa97d3b 100644 --- a/ecmascript/builtins/builtins.cpp +++ b/ecmascript/builtins/builtins.cpp @@ -3646,7 +3646,7 @@ void Builtins::InitializeCjsModule(const JSHandle &env) const JSHandle loaded(factory_->NewEmptyJSObject()); JSHandle children(factory_->NewEmptyJSObject()); JSHandle cache = JSHandle::Cast(CjsModuleCache::Create(thread_, - CjsModuleCache::DEAULT_DICTIONART_CAPACITY)); + CjsModuleCache::DEAULT_DICTIONART_CAPACITY)); // CjsModule.prototype members SetNonConstantObject(cjsModulePrototype, "id", id); diff --git a/ecmascript/compiler/assembler/aarch64/assembler_aarch64.cpp b/ecmascript/compiler/assembler/aarch64/assembler_aarch64.cpp index 648b2b7e27..cc964c2dc6 100644 --- a/ecmascript/compiler/assembler/aarch64/assembler_aarch64.cpp +++ b/ecmascript/compiler/assembler/aarch64/assembler_aarch64.cpp @@ -35,14 +35,14 @@ LogicalImmediate LogicalImmediate::Create(uint64_t imm, int width) // First, determine the element size. unsigned int size = static_cast(width); do { - size /= 2; + size /= 2; // 2 : Divide by 2 uint64_t mask = (1ULL << size) - 1; if ((imm & mask) != ((imm >> size) & mask)) { - size *= 2; + size *= 2; // 2 : Multiply by 2 break; } - } while (size > 2); + } while (size > 2); // 2 : Greater than 2 // Second, determine the rotation to make the element be: 0^m 1^n. unsigned int cto = 0; @@ -408,7 +408,8 @@ void AssemblerAarch64::Mov(const Register &rd, const Immediate &imm) return; } // One to up three instruction sequence. - if (allOneHalfWords >= (halfWords - 2) || allZeroHalfWords >= (halfWords - 2)) { + if (allOneHalfWords >= (halfWords - 2) || // 2 : Must be greater than or equal to (halfWords -2) + allZeroHalfWords >= (halfWords - 2)) { // 2 : Must be greater than or equal to (halfWords -2) EmitMovInstruct(rd, immValue, allOneHalfWords, allZeroHalfWords); return; } @@ -755,12 +756,12 @@ void AssemblerAarch64::Lsr(const Register &rd, const Register &rn, unsigned shif // 31 : 31 32-bit variant Applies when sf == 0 && N == 0 && imms == 011111 // LSR , , # is equivalent to UBFM , , #, #31 // and is always the preferred disassembly - imms = 31; + imms = 31; // 31 : 32-bit variant Applies } else { // 63 : 63 64-bit variant Applies when sf == 1 && N == 1 && imms == 111111 // LSR , , # is equivalent to UBFM , , #, #63 // and is always the preferred disassembly - imms = 63; + imms = 63; // 63 : 64-bit variant Applies } Ubfm(rd, rn, shift, imms); } diff --git a/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h b/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h index c5cc55a0ea..990bffbe86 100644 --- a/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h +++ b/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h @@ -96,15 +96,15 @@ public: inline int GetRegSize() const { if (scale_ == B) { - return 8; + return 8; // 8 : RegSize } else if (scale_ == H) { - return 16; + return 16; // 16 : RegSize } else if (scale_ == S) { - return 32; + return 32; // 32 : RegSize } else if (scale_ == D) { - return 64; + return 64; // 64 : RegSize } else if (scale_ == Q) { - return 128; + return 128; // 128 : RegSize } LOG_ECMA(FATAL) << "this branch is unreachable"; UNREACHABLE(); diff --git a/ecmascript/compiler/interpreter_stub-inl.h b/ecmascript/compiler/interpreter_stub-inl.h index 26096e74e4..6dbd9c8f5f 100644 --- a/ecmascript/compiler/interpreter_stub-inl.h +++ b/ecmascript/compiler/interpreter_stub-inl.h @@ -104,9 +104,8 @@ GateRef InterpreterStubBuilder::ReadInst4_2(GateRef pc) GateRef InterpreterStubBuilder::ReadInst4_3(GateRef pc) { - // 2 : skip 1 byte of bytecode - return Int8And( - Int8LSR(Load(VariableType::INT8(), pc, IntPtr(2)), Int8(4)), Int8(0xf)); // 4 : read 4 byte of bytecode + return Int8And(Int8LSR(Load(VariableType::INT8(), pc, IntPtr(2)), // 2 : skip 1 byte of bytecode + Int8(4)), Int8(0xf)); // 4 : read 4 byte of bytecode } GateRef InterpreterStubBuilder::ReadInstSigned8_0(GateRef pc) @@ -352,7 +351,7 @@ void InterpreterStubBuilder::SetHomeObjectToFunction(GateRef glue, GateRef funct } void InterpreterStubBuilder::SetFrameState(GateRef glue, GateRef sp, GateRef function, GateRef acc, - GateRef env, GateRef pc, GateRef prev, GateRef type) + GateRef env, GateRef pc, GateRef prev, GateRef type) { GateRef state = GetFrame(sp); SetFunctionToFrame(glue, state, function); @@ -579,7 +578,7 @@ void InterpreterStubBuilder::DispatchBase(GateRef target, GateRef glue, Args... } void InterpreterStubBuilder::Dispatch(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, GateRef profileTypeInfo, - GateRef acc, GateRef hotnessCounter, GateRef format) + GateRef acc, GateRef hotnessCounter, GateRef format) { GateRef newPc = PtrAdd(pc, format); GateRef opcode = Load(VariableType::INT8(), newPc); @@ -589,7 +588,7 @@ void InterpreterStubBuilder::Dispatch(GateRef glue, GateRef sp, GateRef pc, Gate } void InterpreterStubBuilder::DispatchLast(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, - GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) + GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) { GateRef target = PtrMul(IntPtr(BytecodeStubCSigns::ID_ExceptionHandler), IntPtrSize()); DispatchBase(target, glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter); @@ -597,7 +596,7 @@ void InterpreterStubBuilder::DispatchLast(GateRef glue, GateRef sp, GateRef pc, } void InterpreterStubBuilder::DispatchDebugger(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, - GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) + GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) { GateRef opcode = Load(VariableType::INT8(), pc); GateRef target = PtrMul(ZExtInt32ToPtr(ZExtInt8ToInt32(opcode)), IntPtrSize()); @@ -607,7 +606,7 @@ void InterpreterStubBuilder::DispatchDebugger(GateRef glue, GateRef sp, GateRef } void InterpreterStubBuilder::DispatchDebuggerLast(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, - GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) + GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) { GateRef target = PtrMul(IntPtr(BytecodeStubCSigns::ID_ExceptionHandler), IntPtrSize()); auto args = { glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter }; diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index 28189544e3..d3c11c2baa 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -2688,9 +2688,8 @@ DECLARE_ASM_HANDLER(HandleSuspendgeneratorV8) varProfileTypeInfo = GetProfileTypeInfoFromMethod(method); varHotnessCounter = GetHotnessCounterFromMethod(method); GateRef jumpSize = GetCallSizeFromFrame(prevState); - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch), - { glue, currentSp, *varPc, *varConstpool, *varProfileTypeInfo, - *varAcc, *varHotnessCounter, jumpSize }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch), { glue, currentSp, *varPc, *varConstpool, + *varProfileTypeInfo, *varAcc, *varHotnessCounter, jumpSize }); Return(); } } @@ -2769,9 +2768,8 @@ DECLARE_ASM_HANDLER(HandleDeprecatedSuspendgeneratorPrefV8V8) varProfileTypeInfo = GetProfileTypeInfoFromMethod(method); varHotnessCounter = GetHotnessCounterFromMethod(method); GateRef jumpSize = GetCallSizeFromFrame(prevState); - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch), - { glue, currentSp, *varPc, *varConstpool, *varProfileTypeInfo, - *varAcc, *varHotnessCounter, jumpSize }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch), { glue, currentSp, *varPc, *varConstpool, + *varProfileTypeInfo, *varAcc, *varHotnessCounter, jumpSize }); Return(); } } @@ -3091,9 +3089,8 @@ DECLARE_ASM_HANDLER(HandleAsyncgeneratorresolveV8V8V8) varProfileTypeInfo = GetProfileTypeInfoFromMethod(method); varHotnessCounter = GetHotnessCounterFromMethod(method); GateRef jumpSize = GetCallSizeFromFrame(prevState); - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch), - { glue, currentSp, *varPc, *varConstpool, *varProfileTypeInfo, - *varAcc, *varHotnessCounter, jumpSize }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch), { glue, currentSp, *varPc, *varConstpool, + *varProfileTypeInfo, *varAcc, *varHotnessCounter, jumpSize }); Return(); } } @@ -4900,9 +4897,8 @@ DECLARE_ASM_HANDLER(BCDebuggerEntry) varProfileTypeInfo = GetProfileTypeInfoFromMethod(method); varHotnessCounter = GetHotnessCounterFromMethod(method); GateRef jumpSize = IntPtr(0); - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndRollback), - { glue, currentSp, *varPc, *varConstpool, *varProfileTypeInfo, - *varAcc, *varHotnessCounter, jumpSize }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndRollback), { glue, currentSp, *varPc, *varConstpool, + *varProfileTypeInfo, *varAcc, *varHotnessCounter, jumpSize }); Return(); } } diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index 8ae467ac1e..73dd773cc1 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -1844,7 +1844,8 @@ inline void StubBuilder::SetPrototypeToHClass(VariableType type, GateRef glue, G Store(type, glue, hClass, offset, proto); } -inline void StubBuilder::SetProtoChangeDetailsToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef protoChange) +inline void StubBuilder::SetProtoChangeDetailsToHClass(VariableType type, GateRef glue, + GateRef hClass, GateRef protoChange) { GateRef offset = IntPtr(JSHClass::PROTO_CHANGE_DETAILS_OFFSET); Store(type, glue, hClass, offset, protoChange); @@ -2137,9 +2138,8 @@ inline GateRef StubBuilder::IsSpecialContainer(GateRef jsType) inline GateRef StubBuilder::IsFastTypeArray(GateRef jsType) { - return BoolAnd( - Int32GreaterThanOrEqual(jsType, Int32(static_cast(JSType::JS_TYPED_ARRAY_FIRST))), - Int32LessThanOrEqual(jsType, Int32(static_cast(JSType::JS_FLOAT64_ARRAY)))); + return BoolAnd(Int32GreaterThanOrEqual(jsType, Int32(static_cast(JSType::JS_TYPED_ARRAY_FIRST))), + Int32LessThanOrEqual(jsType, Int32(static_cast(JSType::JS_FLOAT64_ARRAY)))); } inline GateRef StubBuilder::IsAccessorInternal(GateRef value) diff --git a/ecmascript/interpreter/interpreter-inl.h b/ecmascript/interpreter/interpreter-inl.h index 507474bab5..3324f9ac01 100644 --- a/ecmascript/interpreter/interpreter-inl.h +++ b/ecmascript/interpreter/interpreter-inl.h @@ -4002,7 +4002,6 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t uint16_t firstArgRegIdx = READ_INST_8_2(); LOG_INST() << "intrinsics::newobjRange " << numArgs << " v" << firstArgRegIdx; JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); - if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); methodHandle.Update(ctorFunc->GetMethod()); @@ -4138,7 +4137,6 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t uint16_t firstArgRegIdx = READ_INST_8_3(); LOG_INST() << "intrinsics::newobjRange " << numArgs << " v" << firstArgRegIdx; JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); - if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); methodHandle.Update(ctorFunc->GetMethod()); @@ -4275,7 +4273,6 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t uint16_t firstArgRegIdx = READ_INST_8_3(); LOG_INST() << "intrinsics::newobjRange " << numArgs << " v" << firstArgRegIdx; JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); - if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); methodHandle.Update(ctorFunc->GetMethod()); @@ -5074,7 +5071,6 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::resumegenerator"; uint16_t vs = READ_INST_8_1(); JSTaggedValue objVal = GET_VREG_VALUE(vs); - if (objVal.IsAsyncGeneratorObject()) { JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject()); SET_ACC(obj->GetResumeResult()); @@ -5101,7 +5097,6 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::getresumemode"; uint16_t vs = READ_INST_8_1(); JSTaggedValue objVal = GET_VREG_VALUE(vs); - if (objVal.IsAsyncGeneratorObject()) { JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject()); SET_ACC(JSTaggedValue(static_cast(obj->GetResumeMode()))); diff --git a/ecmascript/js_date.cpp b/ecmascript/js_date.cpp index b4c59642df..0e0ca1e12d 100644 --- a/ecmascript/js_date.cpp +++ b/ecmascript/js_date.cpp @@ -53,8 +53,7 @@ bool DateUtils::IsLeap(int64_t year) // static int64_t DateUtils::GetDaysInYear(int64_t year) { - int64_t number; - number = IsLeap(year) ? (DAYS_IN_YEAR + 1) : DAYS_IN_YEAR; + int64_t number = IsLeap(year) ? (DAYS_IN_YEAR + 1) : DAYS_IN_YEAR; return number; } @@ -276,8 +275,7 @@ JSTaggedValue JSDate::LocalParseStringToMs(const CString &str) int localHours = 0; int localMinutes = 0; int64_t localMs = 0; - CString::size_type localSpace; - localSpace = str.find(' ', index); + CString::size_type localSpace = str.find(' ', index); CString strMonth = str.substr(localSpace + 1, LENGTH_MONTH_NAME); for (int i = 0; i < MOUTH_PER_YEAR; i++) { if (strMonth == monthName[i]) { diff --git a/ecmascript/js_date_time_format.cpp b/ecmascript/js_date_time_format.cpp index af844f72c3..4c4eb0e3e3 100644 --- a/ecmascript/js_date_time_format.cpp +++ b/ecmascript/js_date_time_format.cpp @@ -1206,8 +1206,8 @@ JSHandle JSDateTimeFormat::ConstructFDateIntervalToJSArray(JSThread *th int index = 0; int32_t preEndPos = 0; // 2: number of elements - std::array begin {}; - std::array end {}; + std::array begin {}; // 2 : array size + std::array end {}; // 2 : array size begin[0] = begin[1] = end[0] = end[1] = 0; std::vector parts; diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index da9b46f4cd..22df0871ae 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -433,8 +433,7 @@ public: const char *localeCountry = locale.getCountry(); const char *localeScript = locale.getScript(); if (localeCountry[0] != '\0' && localeScript[0] != '\0') { - std::string removeCountry; - removeCountry = locale.getLanguage(); + std::string removeCountry = locale.getLanguage(); removeCountry.append("-"); removeCountry.append(localeScript); return CheckLocales(removeCountry.c_str(), key, packageName, res); diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 66ac9c34e8..0135ba4d2e 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -176,7 +176,7 @@ DEF_RUNTIME_STUBS(CallInternalSetter) RUNTIME_STUBS_HEADER(CallInternalSetter); JSHandle receiver = GetHArg(argv, argc, 0); // 0: means the zeroth parameter JSTaggedType argSetter = GetTArg(argv, argc, 1); // 1: means the first parameter - JSHandle value = GetHArg(argv, argc, 2); + JSHandle value = GetHArg(argv, argc, 2); // 2 : means the second parameter auto setter = AccessorData::Cast((reinterpret_cast(argSetter))); auto result = setter->CallInternalSet(thread, receiver, value, true); if (!result) { @@ -793,7 +793,6 @@ DEF_RUNTIME_STUBS(Exp) RUNTIME_STUBS_HEADER(Exp); JSTaggedValue baseValue = GetArg(argv, argc, 0); // 0: means the zeroth parameter JSTaggedValue exponentValue = GetArg(argv, argc, 1); // 1: means the first parameter - if (baseValue.IsNumber() && exponentValue.IsNumber()) { // fast path double doubleBase = baseValue.IsInt() ? baseValue.GetInt() : baseValue.GetDouble(); @@ -966,9 +965,9 @@ DEF_RUNTIME_STUBS(SuperCallSpread) DEF_RUNTIME_STUBS(OptSuperCallSpread) { RUNTIME_STUBS_HEADER(OptSuperCallSpread); - JSHandle func = GetHArg(argv, argc, 0); - JSHandle newTarget = GetHArg(argv, argc, 1); - JSHandle array = GetHArg(argv, argc, 2); + JSHandle func = GetHArg(argv, argc, 0); // 0: means the zeroth parameter + JSHandle newTarget = GetHArg(argv, argc, 1); // 1: means the first parameter + JSHandle array = GetHArg(argv, argc, 2); // 2: means the second parameter return RuntimeSuperCallSpread(thread, func, newTarget, array).GetRawData(); } diff --git a/test/typeinfer/add/add.js b/test/typeinfer/add/add.js index ed48168582..2327965213 100644 --- a/test/typeinfer/add/add.js +++ b/test/typeinfer/add/add.js @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2023 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 x = 0 let y = 3.14 let z = x + y diff --git a/tools/circuit_viewer/test/test_viewer.py b/tools/circuit_viewer/test/test_viewer.py index b4b38c45f5..366db4427c 100755 --- a/tools/circuit_viewer/test/test_viewer.py +++ b/tools/circuit_viewer/test/test_viewer.py @@ -1,11 +1,18 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 # -# HDF is dual licensed: you can use it either under the terms of -# the GPL, or the BSD license, at your option. -# See the LICENSE file in the root of this repository for complete details. +# 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. import os import shutil