• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_JSPANDAFILE_CONSTPOOL_VALUE_H
17 #define ECMASCRIPT_JSPANDAFILE_CONSTPOOL_VALUE_H
18 
19 #include "libpandabase/utils/bit_field.h"
20 
21 namespace panda::ecmascript {
22 enum class ConstPoolType : uint8_t {
23     STRING,
24     BASE_FUNCTION,
25     NC_FUNCTION,
26     GENERATOR_FUNCTION,
27     ASYNC_FUNCTION,
28     CLASS_FUNCTION,
29     METHOD,
30     ARRAY_LITERAL,
31     OBJECT_LITERAL,
32     CLASS_LITERAL,
33     ASYNC_GENERATOR_FUNCTION,
34 };
35 
36 class ConstPoolValue {
37 public:
ConstPoolValue(ConstPoolType type,uint32_t index)38     ConstPoolValue(ConstPoolType type, uint32_t index)
39         : value_(ConstPoolIndexField::Encode(index) | ConstPoolTypeField::Encode(type))
40     {
41     }
42 
ConstPoolValue(uint64_t v)43     explicit ConstPoolValue(uint64_t v) : value_(v) {}
44     ~ConstPoolValue() = default;
45     NO_COPY_SEMANTIC(ConstPoolValue);
46     NO_MOVE_SEMANTIC(ConstPoolValue);
47 
GetValue()48     inline uint64_t GetValue() const
49     {
50         return value_;
51     }
52 
GetConstpoolIndex()53     inline uint32_t GetConstpoolIndex() const
54     {
55         return ConstPoolIndexField::Get(value_);
56     }
57 
GetConstpoolType()58     inline ConstPoolType GetConstpoolType() const
59     {
60         return ConstPoolTypeField::Get(value_);
61     }
62 
63 private:
64     // NOLINTNEXTLINE(readability-magic-numbers)
65     using ConstPoolIndexField = BitField<uint32_t, 0, 32>;  // 32: 32 bit
66     // NOLINTNEXTLINE(readability-magic-numbers)
67     using ConstPoolTypeField = BitField<ConstPoolType, 32, 4>;  // 32: offset, 4: 4bit
68 
69     uint64_t value_ {0};
70 };
71 }  // namespace panda::ecmascript
72 
73 #endif  // ECMASCRIPT_JSPANDAFILE_CONSTPOOL_VALUE_H