• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 ES2PANDA_COMPILER_CHECKER_TYPES_ETS_ENUM_TYPE_H
17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_ENUM_TYPE_H
18 
19 #include "checker/types/ets/etsObjectType.h"
20 #include "checker/types/ets/etsObjectTypeConstants.h"
21 #include "checker/types/typeFlag.h"
22 
23 namespace ark::es2panda::checker {
24 
25 class ETSEnumType : public ETSObjectType {
26 public:
ETSEnumType(ArenaAllocator * allocator,util::StringView name,util::StringView internalName,ir::AstNode * declNode,TypeRelation * relation)27     explicit ETSEnumType(ArenaAllocator *allocator, util::StringView name, util::StringView internalName,
28                          ir::AstNode *declNode, TypeRelation *relation)
29         : ETSObjectType(allocator, name, internalName,
30                         std::make_tuple(declNode, ETSObjectFlags::CLASS | ETSObjectFlags::ENUM_OBJECT, relation))
31     {
32     }
33 
34     NO_COPY_SEMANTIC(ETSEnumType);
35     NO_MOVE_SEMANTIC(ETSEnumType);
36 
37     ETSEnumType() = delete;
38     ~ETSEnumType() override = default;
39 
40     static constexpr std::string_view const TO_STRING_METHOD_NAME {"toString"};
41     static constexpr std::string_view const VALUE_OF_METHOD_NAME {"valueOf"};
42     static constexpr std::string_view const GET_NAME_METHOD_NAME {"getName"};
43     static constexpr std::string_view const GET_VALUE_OF_METHOD_NAME {"getValueOf"};
44     static constexpr std::string_view const FROM_VALUE_METHOD_NAME {"fromValue"};
45     static constexpr std::string_view const VALUES_METHOD_NAME {"values"};
46     static constexpr std::string_view const GET_ORDINAL_METHOD_NAME {"getOrdinal"};
47     static constexpr std::string_view const DOLLAR_GET_METHOD_NAME {"$_get"};
48 };
49 
50 class ETSIntEnumType : public ETSEnumType {
51 public:
ETSIntEnumType(ArenaAllocator * allocator,util::StringView name,util::StringView internalName,ir::AstNode * declNode,TypeRelation * relation)52     explicit ETSIntEnumType(ArenaAllocator *allocator, util::StringView name, util::StringView internalName,
53                             ir::AstNode *declNode, TypeRelation *relation)
54         : ETSEnumType(allocator, name, internalName, declNode, relation)
55     {
56         AddTypeFlag(checker::TypeFlag::ETS_INT_ENUM);
57     }
58 
59     NO_COPY_SEMANTIC(ETSIntEnumType);
60     NO_MOVE_SEMANTIC(ETSIntEnumType);
61 
62     ETSIntEnumType() = delete;
63     ~ETSIntEnumType() override = default;
64 
65     bool AssignmentSource(TypeRelation *relation, Type *target) override;
66     void AssignmentTarget(TypeRelation *relation, Type *source) override;
67     void Cast(TypeRelation *relation, Type *target) override;
68     void CastTarget(TypeRelation *relation, Type *source) override;
69 };
70 
71 class ETSStringEnumType : public ETSEnumType {
72 public:
ETSStringEnumType(ArenaAllocator * allocator,util::StringView name,util::StringView internalName,ir::AstNode * declNode,TypeRelation * relation)73     explicit ETSStringEnumType(ArenaAllocator *allocator, util::StringView name, util::StringView internalName,
74                                ir::AstNode *declNode, TypeRelation *relation)
75         : ETSEnumType(allocator, name, internalName, declNode, relation)
76     {
77         AddTypeFlag(checker::TypeFlag::ETS_STRING_ENUM);
78     }
79 
80     NO_COPY_SEMANTIC(ETSStringEnumType);
81     NO_MOVE_SEMANTIC(ETSStringEnumType);
82 
83     ETSStringEnumType() = delete;
84     ~ETSStringEnumType() override = default;
85 
86     bool AssignmentSource(TypeRelation *relation, Type *target) override;
87     void AssignmentTarget(TypeRelation *relation, Type *source) override;
88     void Cast(TypeRelation *relation, Type *target) override;
89     void CastTarget(TypeRelation *relation, Type *source) override;
90 };
91 
92 }  // namespace ark::es2panda::checker
93 
94 #endif