• 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 #ifndef ES2PANDA_COMPILER_CHECKER_TYPES_TS_INDEX_INFO_H
17 #define ES2PANDA_COMPILER_CHECKER_TYPES_TS_INDEX_INFO_H
18 
19 #include "checker/types/type.h"
20 
21 namespace ark::es2panda::checker {
22 class IndexInfo {
23 public:
IndexInfo(Type * type,util::StringView paramName,bool readonly)24     IndexInfo(Type *type, util::StringView paramName, bool readonly)
25         : type_(type), paramName_(paramName), readonly_(readonly)
26     {
27     }
28 
IndexInfo(Type * type,util::StringView paramName,bool readonly,const lexer::SourcePosition & pos)29     IndexInfo(Type *type, util::StringView paramName, bool readonly, const lexer::SourcePosition &pos)
30         : type_(type), paramName_(paramName), readonly_(readonly), pos_(pos)
31     {
32     }
33 
34     ~IndexInfo() = default;
35     NO_COPY_SEMANTIC(IndexInfo);
36     NO_MOVE_SEMANTIC(IndexInfo);
37 
GetType()38     Type *GetType()
39     {
40         return type_;
41     }
42 
GetType()43     const Type *GetType() const
44     {
45         return type_;
46     }
47 
SetType(Type * type)48     void SetType(Type *type)
49     {
50         type_ = type;
51     }
52 
ParamName()53     const util::StringView &ParamName()
54     {
55         return paramName_;
56     }
57 
Readonly()58     bool Readonly() const
59     {
60         return readonly_;
61     }
62 
Pos()63     const lexer::SourcePosition &Pos()
64     {
65         return pos_;
66     }
67 
68     void ToString(std::stringstream &ss, bool numIndex = true) const;
69     void Identical(TypeRelation *relation, IndexInfo *other);
70     void AssignmentTarget(TypeRelation *relation, IndexInfo *source);
71     IndexInfo *Copy(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes);
72 
73 private:
74     Type *type_;
75     util::StringView paramName_;
76     bool readonly_;
77     const lexer::SourcePosition pos_ {};
78 };
79 }  // namespace ark::es2panda::checker
80 
81 #endif /* TYPESCRIPT_TYPES_INDEX_INFO_H */
82