1 /* 2 * Copyright (c) 2023 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_ELEMENTS_H 17 #define ECMASCRIPT_ELEMENTS_H 18 19 #include "ecmascript/global_env_constants.h" 20 #include "ecmascript/js_tagged_value.h" 21 #include "ecmascript/mem/c_containers.h" 22 23 namespace panda::ecmascript { 24 enum class ElementsKind : uint8_t { 25 NONE = 0x00UL, 26 HOLE = 0x01UL, 27 INT = 0x1UL << 1, // 2 28 DOUBLE = 0x1UL << 2, // 4 29 NUMBER = INT | DOUBLE, // 6 30 STRING = 0x1UL << 3, // 8 31 OBJECT = 0x1UL << 4, // 16 32 TAGGED = 0x1EUL, // 30 33 HOLE_INT = HOLE | INT, 34 HOLE_DOUBLE = HOLE | DOUBLE, 35 HOLE_NUMBER = HOLE | NUMBER, 36 HOLE_STRING = HOLE | STRING, 37 HOLE_OBJECT = HOLE | OBJECT, 38 HOLE_TAGGED = HOLE | TAGGED, 39 GENERIC = HOLE_TAGGED, 40 }; 41 42 class Elements { 43 public: 44 static CMap<ElementsKind, ConstantIndex> InitializeHClassMap(); 45 46 static std::string GetString(ElementsKind kind); 47 static bool IsInt(ElementsKind kind); 48 static bool IsDouble(ElementsKind kind); 49 static bool IsObject(ElementsKind kind); 50 static bool IsHole(ElementsKind kind); IsGeneric(ElementsKind kind)51 static bool IsGeneric(ElementsKind kind) 52 { 53 return kind == ElementsKind::GENERIC; 54 } 55 IsNone(ElementsKind kind)56 static bool IsNone(ElementsKind kind) 57 { 58 return kind == ElementsKind::NONE; 59 } 60 61 static ElementsKind MergeElementsKind(ElementsKind curKind, ElementsKind newKind); 62 static ElementsKind FixElementsKind(ElementsKind oldKind); 63 static ElementsKind ToElementsKind(JSTaggedValue value, ElementsKind kind); 64 }; 65 } // namespace panda::ecmascript 66 #endif // ECMASCRIPT_ELEMENTS_H 67