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() const50 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() const65 const Expression *Value() const 66 { 67 return value_; 68 } 69 Value()70 Expression *Value() 71 { 72 return value_; 73 } 74 TypeAnnotation() const75 const Expression *TypeAnnotation() const 76 { 77 return typeAnnotation_; 78 } 79 Modifiers() const80 ModifierFlags Modifiers() const 81 { 82 return modifiers_; 83 } 84 IsStatic() const85 bool IsStatic() const 86 { 87 return (modifiers_ & ModifierFlags::STATIC) != 0; 88 } 89 Decorators() const90 const ArenaVector<Decorator *> &Decorators() const 91 { 92 return decorators_; 93 } 94 HasDecorators() const95 bool HasDecorators() const 96 { 97 return !decorators_.empty(); 98 } 99 IsComputed() const100 bool IsComputed() const 101 { 102 return isComputed_; 103 } 104 IsPrivate() const105 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() const115 bool IsAutoAccessor() const 116 { 117 return (modifiers_ & ModifierFlags::ACCESSOR) != 0; 118 } 119 Definite() const120 bool Definite() const 121 { 122 return definite_; 123 } 124 NeedCompileKey() const125 bool NeedCompileKey() const 126 { 127 return !key_->IsLiteral(); 128 } 129 RemoveValue()130 void RemoveValue() 131 { 132 value_ = nullptr; 133 } 134 135 void Iterate(const NodeTraverser &cb) const override; 136 void Dump(ir::AstDumper *dumper) const override; 137 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 138 checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; 139 void UpdateChildNodes(const NodeUpdater &cb); 140 void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; 141 142 private: 143 Expression *key_; 144 Expression *value_; 145 Expression *typeAnnotation_; 146 ModifierFlags modifiers_; 147 ArenaVector<Decorator *> decorators_; 148 bool isComputed_; 149 bool definite_; 150 }; 151 152 } // namespace panda::es2panda::ir 153 154 #endif 155