• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 #include "enumLiteralType.h"
17 
18 #include "varbinder/variable.h"
19 #include "checker/types/ts/enumType.h"
20 
21 namespace ark::es2panda::checker {
ToString(std::stringstream & ss,bool precise) const22 void EnumLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const
23 {
24     ss << name_;
25 }
26 
ToStringAsSrc(std::stringstream & ss) const27 void EnumLiteralType::ToStringAsSrc(std::stringstream &ss) const
28 {
29     ss << "typeof " << name_;
30 }
31 
Identical(TypeRelation * relation,Type * other)32 void EnumLiteralType::Identical([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other) {}
33 
AssignmentTarget(TypeRelation * relation,Type * source)34 void EnumLiteralType::AssignmentTarget(TypeRelation *relation, Type *source)
35 {
36     if (source->IsEnumType()) {
37         const EnumType *sourceEnumType = source->AsEnumType();
38 
39         if (variable_ == sourceEnumType->EnumVar()) {
40             relation->Result(true);
41         }
42     } else if (source->HasTypeFlag(TypeFlag::NUMBER_LIKE)) {
43         relation->Result(true);
44     }
45 }
46 
GetTypeFacts() const47 TypeFacts EnumLiteralType::GetTypeFacts() const
48 {
49     return TypeFacts::NUMBER_FACTS;
50 }
51 
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)52 Type *EnumLiteralType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation,
53                                    [[maybe_unused]] GlobalTypesHolder *globalTypes)
54 {
55     return allocator->New<EnumLiteralType>(name_, scope_, kind_);
56 }
57 }  // namespace ark::es2panda::checker
58