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 Modifiers()80 ModifierFlags Modifiers() const 81 { 82 return modifiers_; 83 } 84 IsStatic()85 bool IsStatic() const 86 { 87 return (modifiers_ & ModifierFlags::STATIC) != 0; 88 } 89 Decorators()90 const ArenaVector<Decorator *> &Decorators() const 91 { 92 return decorators_; 93 } 94 HasDecorators()95 bool HasDecorators() const 96 { 97 return !decorators_.empty(); 98 } 99 IsComputed()100 bool IsComputed() const 101 { 102 return isComputed_; 103 } 104 IsPrivate()105 bool IsPrivate() const 106 { 107 return key_->IsPrivateIdentifier(); 108 } 109 SetComputed(bool computed)110 void SetComputed(bool computed) 111 { 112 isComputed_ = computed; 113 } 114 IsAutoAccessor()115 bool IsAutoAccessor() const 116 { 117 return (modifiers_ & ModifierFlags::ACCESSOR) != 0; 118 } 119 Definite()120 bool Definite() const 121 { 122 return definite_; 123 } 124 NeedCompileKey()125 bool NeedCompileKey() const 126 { 127 return !key_->IsLiteral(); 128 } 129 130 void Iterate(const NodeTraverser &cb) const override; 131 void Dump(ir::AstDumper *dumper) const override; 132 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 133 checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; 134 void UpdateChildNodes(const NodeUpdater &cb); 135 void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; 136 137 private: 138 Expression *key_; 139 Expression *value_; 140 Expression *typeAnnotation_; 141 ModifierFlags modifiers_; 142 ArenaVector<Decorator *> decorators_; 143 bool isComputed_; 144 bool definite_; 145 }; 146 147 } // namespace panda::es2panda::ir 148 149 #endif 150