• 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 #ifndef ES2PANDA_COMPILER_TYPESCRIPT_TYPES_TYPE_PARAMETER_H
17 #define ES2PANDA_COMPILER_TYPESCRIPT_TYPES_TYPE_PARAMETER_H
18 
19 #include "type.h"
20 
21 namespace panda::es2panda::checker {
22 
23 class TypeParameter : public Type {
24 public:
TypeParameter(Type * constraint,Type * defaultType)25     TypeParameter(Type *constraint, Type *defaultType)
26         : Type(TypeFlag::TYPE_PARAMETER), constraint_(constraint), default_(defaultType)
27     {
28     }
29 
ConstraintType()30     const Type *ConstraintType() const
31     {
32         return constraint_;
33     }
34 
DefaultType()35     Type *DefaultType()
36     {
37         return default_;
38     }
39 
DefaultTypeRef()40     Type **DefaultTypeRef()
41     {
42         return &default_;
43     }
44 
SetDefaultType(Type * type)45     void SetDefaultType(Type *type)
46     {
47         default_ = type;
48     }
49 
50     void ToString(std::stringstream &ss) const override;
51     void Identical(TypeRelation *relation, Type *other) override;
52     void AssignmentTarget(TypeRelation *relation, Type *source) override;
53     TypeFacts GetTypeFacts() const override;
54     Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override;
55 
56 private:
57     Type *constraint_;
58     Type *default_;
59 };
60 
61 }  // namespace panda::es2panda::checker
62 
63 #endif /* TYPESCRIPT_TYPES_UNDEFINED_TYPE_H */
64