mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
1dcc6f74c9
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I91EN4 Signed-off-by: Gymee <yumeijie@huawei.com> Change-Id: I8f5a77fc4d85374bf90095ad0d4d8ac3b43aa5aa
89 lines
4.2 KiB
C++
89 lines
4.2 KiB
C++
/*
|
|
* 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
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef ECMASCRIPT_GLOBAL_ENV_CONSTANTS_INL_H
|
|
#define ECMASCRIPT_GLOBAL_ENV_CONSTANTS_INL_H
|
|
|
|
#include "ecmascript/global_env_constants.h"
|
|
|
|
#include "ecmascript/ecma_macros.h"
|
|
#include "ecmascript/js_handle.h"
|
|
|
|
namespace panda::ecmascript {
|
|
inline const JSTaggedValue *GlobalEnvConstants::BeginSlot() const
|
|
{
|
|
return &constants_[static_cast<int>(ConstantIndex::CONSTANT_BEGIN)];
|
|
}
|
|
|
|
inline const JSTaggedValue *GlobalEnvConstants::EndSlot() const
|
|
{
|
|
return &constants_[static_cast<int>(ConstantIndex::CONSTANT_END)];
|
|
}
|
|
|
|
inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSTaggedValue value)
|
|
{
|
|
DASSERT_PRINT(index >= ConstantIndex::CONSTANT_BEGIN && index < ConstantIndex::CONSTANT_END,
|
|
"Root Index out of bound");
|
|
constants_[static_cast<int>(index)] = value;
|
|
}
|
|
|
|
template<typename T>
|
|
inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSHandle<T> value)
|
|
{
|
|
DASSERT_PRINT(index >= ConstantIndex::CONSTANT_BEGIN && index < ConstantIndex::CONSTANT_END,
|
|
"Root Index out of bound");
|
|
constants_[static_cast<int>(index)] = value.GetTaggedValue();
|
|
}
|
|
|
|
inline uintptr_t GlobalEnvConstants::GetGlobalConstantAddr(ConstantIndex index) const
|
|
{
|
|
return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast<uint32_t>(index);
|
|
}
|
|
|
|
// clang-format off
|
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
|
#define DECL_GET_IMPL_COMMON(Type, Name, Index) \
|
|
inline const Type GlobalEnvConstants::Get##Name() const \
|
|
{ \
|
|
return constants_[static_cast<int>(ConstantIndex::Index)]; \
|
|
} \
|
|
inline const JSHandle<Type> GlobalEnvConstants::GetHandled##Name() const \
|
|
{ \
|
|
return JSHandle<Type>(reinterpret_cast<uintptr_t>( \
|
|
&constants_[static_cast<int>(ConstantIndex::Index)])); \
|
|
} \
|
|
inline size_t GlobalEnvConstants::GetOffsetOf##Name() \
|
|
{ \
|
|
return sizeof(JSTaggedValue) \
|
|
* static_cast<int>(ConstantIndex::Index); \
|
|
}
|
|
|
|
#define DECL_GET_IMPL_STRING(Name, Index, Token) DECL_GET_IMPL_COMMON(JSTaggedValue, Name, Index)
|
|
#define DECL_GET_IMPL_WITH_TYPE(Type, Name, Index, Desc) DECL_GET_IMPL_COMMON(Type, Name, Index)
|
|
SHARED_GLOBAL_ENV_CONSTANT_CLASS(DECL_GET_IMPL_WITH_TYPE) // NOLINT(readability-const-return-type)
|
|
SHARED_GLOBAL_ENV_CONSTANT_STRING(DECL_GET_IMPL_STRING) // NOLINT(readability-const-return-type)
|
|
SHARED_GLOBAL_ENV_CONSTANT_ACCESSOR(DECL_GET_IMPL_WITH_TYPE) // NOLINT(readability-const-return-type)
|
|
SHARED_GLOBAL_ENV_CONSTANT_SPECIAL(DECL_GET_IMPL_WITH_TYPE); // NOLINT(readability-const-return-type)
|
|
GLOBAL_ENV_CONSTANT_CLASS(DECL_GET_IMPL_WITH_TYPE) // NOLINT(readability-const-return-type)
|
|
GLOBAL_ENV_CONSTANT_SPECIAL(DECL_GET_IMPL_WITH_TYPE) // NOLINT(readability-const-return-type)
|
|
GLOBAL_ENV_CONSTANT_CONSTANT(DECL_GET_IMPL_WITH_TYPE) // NOLINT(readability-const-return-type)
|
|
GLOBAL_ENV_CACHES(DECL_GET_IMPL_WITH_TYPE) // NOLINT(readability-const-return-type)
|
|
#undef DECL_GET_IMPL_WITH_TYPE
|
|
#undef DECL_GET_IMPL_STRING
|
|
#undef DECL_GET_IMPL_COMMON
|
|
// clang-format on
|
|
} // namespace panda::ecmascript
|
|
#endif // ECMASCRIPT_GLOBAL_ENV_CONSTANTS_INL_H
|