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 21 namespace panda::es2panda::compiler { 22 class PandaGen; 23 } // namespace panda::es2panda::compiler 24 25 namespace panda::es2panda::checker { 26 class Checker; 27 class Type; 28 } // namespace panda::es2panda::checker 29 30 namespace panda::es2panda::ir { 31 32 class Expression; 33 34 class ClassProperty : public Statement { 35 public: ClassProperty(Expression * key,Expression * value,Expression * typeAnnotation,ModifierFlags modifiers,ArenaVector<Decorator * > && decorators,bool isComputed,bool definite)36 explicit ClassProperty(Expression *key, Expression *value, Expression *typeAnnotation, ModifierFlags modifiers, 37 ArenaVector<Decorator *> &&decorators, bool isComputed, bool definite) 38 : Statement(AstNodeType::CLASS_PROPERTY), 39 key_(key), 40 value_(value), 41 typeAnnotation_(typeAnnotation), 42 modifiers_(modifiers), 43 decorators_(std::move(decorators)), 44 isComputed_(isComputed), 45 definite_(definite) 46 { 47 } 48 Key()49 const Expression *Key() const 50 { 51 return key_; 52 } 53 Key()54 Expression *Key() 55 { 56 return key_; 57 } 58 SetKey(Expression * key)59 void SetKey(Expression *key) 60 { 61 key_ = key; 62 } 63 Value()64 const Expression *Value() const 65 { 66 return value_; 67 } 68 Value()69 Expression *Value() 70 { 71 return value_; 72 } 73 TypeAnnotation()74 const Expression *TypeAnnotation() const 75 { 76 return typeAnnotation_; 77 } 78 Modifiers()79 ModifierFlags Modifiers() const 80 { 81 return modifiers_; 82 } 83 IsStatic()84 bool IsStatic() const 85 { 86 return (modifiers_ & ModifierFlags::STATIC) != 0; 87 } 88 Decorators()89 const ArenaVector<Decorator *> &Decorators() const 90 { 91 return decorators_; 92 } 93 HasDecorators()94 bool HasDecorators() const 95 { 96 return !decorators_.empty(); 97 } 98 IsComputed()99 bool IsComputed() const 100 { 101 return isComputed_; 102 } 103 Definite()104 bool Definite() const 105 { 106 return definite_; 107 } 108 109 void Iterate(const NodeTraverser &cb) const override; 110 void Dump(ir::AstDumper *dumper) const override; 111 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 112 checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; 113 void UpdateChildNodes(const NodeUpdater &cb); 114 void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; 115 116 private: 117 Expression *key_; 118 Expression *value_; 119 Expression *typeAnnotation_; 120 ModifierFlags modifiers_; 121 ArenaVector<Decorator *> decorators_; 122 bool isComputed_; 123 bool definite_; 124 }; 125 126 } // namespace panda::es2panda::ir 127 128 #endif 129