1 /** 2 * Copyright (c) 2021 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_PARSER_INCLUDE_AST_CLASS_PROPERTY_H 17 #define ES2PANDA_PARSER_INCLUDE_AST_CLASS_PROPERTY_H 18 19 #include <ir/statement.h> 20 #include <ir/expression.h> 21 22 namespace panda::es2panda::compiler { 23 class PandaGen; 24 } // namespace panda::es2panda::compiler 25 26 namespace panda::es2panda::checker { 27 class Checker; 28 class Type; 29 } // namespace panda::es2panda::checker 30 31 namespace panda::es2panda::ir { 32 33 class Expression; 34 35 class ClassProperty : public Statement { 36 public: ClassProperty(Expression * key,Expression * value,Expression * typeAnnotation,ModifierFlags modifiers,ArenaVector<Decorator * > && decorators,bool isComputed,bool definite)37 explicit ClassProperty(Expression *key, Expression *value, Expression *typeAnnotation, ModifierFlags modifiers, 38 ArenaVector<Decorator *> &&decorators, bool isComputed, bool definite) 39 : Statement(AstNodeType::CLASS_PROPERTY), 40 key_(key), 41 value_(value), 42 typeAnnotation_(typeAnnotation), 43 modifiers_(modifiers), 44 decorators_(std::move(decorators)), 45 isComputed_(isComputed), 46 definite_(definite) 47 { 48 } 49 Key()50 const Expression *Key() const 51 { 52 return key_; 53 } 54 Key()55 Expression *Key() 56 { 57 return key_; 58 } 59 SetKey(Expression * key)60 void SetKey(Expression *key) 61 { 62 key_ = key; 63 } 64 Value()65 const Expression *Value() const 66 { 67 return value_; 68 } 69 Value()70 Expression *Value() 71 { 72 return value_; 73 } 74 TypeAnnotation()75 const Expression *TypeAnnotation() const 76 { 77 return typeAnnotation_; 78 } 79 TypeAnnotation()80 Expression *TypeAnnotation() 81 { 82 return typeAnnotation_; 83 } 84 Modifiers()85 ModifierFlags Modifiers() const 86 { 87 return modifiers_; 88 } 89 IsStatic()90 bool IsStatic() const 91 { 92 return (modifiers_ & ModifierFlags::STATIC) != 0; 93 } 94 Decorators()95 const ArenaVector<Decorator *> &Decorators() const 96 { 97 return decorators_; 98 } 99 HasDecorators()100 bool HasDecorators() const 101 { 102 return !decorators_.empty(); 103 } 104 IsComputed()105 bool IsComputed() const 106 { 107 return isComputed_; 108 } 109 IsPrivate()110 bool IsPrivate() const 111 { 112 return key_->IsPrivateIdentifier(); 113 } 114 SetComputed(bool computed)115 void SetComputed(bool computed) 116 { 117 isComputed_ = computed; 118 } 119 IsAutoAccessor()120 bool IsAutoAccessor() const 121 { 122 return (modifiers_ & ModifierFlags::ACCESSOR) != 0; 123 } 124 Definite()125 bool Definite() const 126 { 127 return definite_; 128 } 129 NeedCompileKey()130 bool NeedCompileKey() const 131 { 132 return !key_->IsLiteral(); 133 } 134 RemoveValue()135 void RemoveValue() 136 { 137 value_ = nullptr; 138 } 139 140 void Iterate(const NodeTraverser &cb) const override; 141 void Dump(ir::AstDumper *dumper) const override; 142 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 143 checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; 144 void UpdateChildNodes(const NodeUpdater &cb); 145 void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; 146 147 private: 148 Expression *key_; 149 Expression *value_; 150 Expression *typeAnnotation_; 151 ModifierFlags modifiers_; 152 ArenaVector<Decorator *> decorators_; 153 bool isComputed_; 154 bool definite_; 155 }; 156 157 } // namespace panda::es2panda::ir 158 159 #endif 160