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