• 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 "numberType.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 NumberType::ToString(std::stringstream &ss) const
24 {
25     ss << "number";
26 }
27 
Identical(TypeRelation * relation,Type * other)28 void NumberType::Identical(TypeRelation *relation, Type *other)
29 {
30     if (other->IsNumberType()) {
31         relation->Result(true);
32     }
33 }
34 
AssignmentTarget(TypeRelation * relation,Type * source)35 void NumberType::AssignmentTarget(TypeRelation *relation, Type *source)
36 {
37     if (source->IsNumberLiteralType()) {
38         relation->Result(true);
39     } else if (source->IsEnumType()) {
40         const EnumType *sourceEnumType = source->AsEnumType();
41         const binder::EnumVariable *enumVar = sourceEnumType->EnumVar();
42 
43         if (std::holds_alternative<double>(enumVar->Value())) {
44             relation->Result(true);
45         }
46     }
47 }
48 
GetTypeFacts() const49 TypeFacts NumberType::GetTypeFacts() const
50 {
51     return TypeFacts::NUMBER_FACTS;
52 }
53 
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)54 Type *NumberType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation,
55                               [[maybe_unused]] GlobalTypesHolder *globalTypes)
56 {
57     return this;
58 }
59 
60 }  // namespace panda::es2panda::checker
61