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