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_IR_EXPRESSION_MEMBER_EXPRESSION_H 17 #define ES2PANDA_IR_EXPRESSION_MEMBER_EXPRESSION_H 18 19 #include <binder/variable.h> 20 #include <ir/expression.h> 21 #include <ir/irnode.h> 22 23 namespace panda::es2panda::compiler { 24 class PandaGen; 25 } // namespace panda::es2panda::compiler 26 27 namespace panda::es2panda::checker { 28 class Checker; 29 class Type; 30 } // namespace panda::es2panda::checker 31 32 namespace panda::es2panda::ir { 33 34 class MemberExpression : public Expression { 35 public: 36 enum class MemberExpressionKind { ELEMENT_ACCESS, PROPERTY_ACCESS }; 37 MemberExpression(Expression * object,Expression * property,MemberExpressionKind kind,bool computed,bool optional)38 explicit MemberExpression(Expression *object, Expression *property, MemberExpressionKind kind, 39 bool computed, bool optional) 40 : Expression(AstNodeType::MEMBER_EXPRESSION), 41 object_(object), 42 property_(property), 43 kind_(kind), 44 computed_(computed), 45 optional_(optional) 46 { 47 } 48 Object()49 const Expression *Object() const 50 { 51 return object_; 52 } 53 Object()54 Expression *Object() 55 { 56 return object_; 57 } 58 Property()59 const Expression *Property() const 60 { 61 return property_; 62 } 63 IsComputed()64 bool IsComputed() const 65 { 66 return computed_; 67 } 68 IsOptional()69 bool IsOptional() const 70 { 71 return optional_; 72 } 73 AccessPrivateProperty()74 bool AccessPrivateProperty() const 75 { 76 return property_->IsPrivateIdentifier(); 77 } 78 Kind()79 MemberExpressionKind Kind() const 80 { 81 return kind_; 82 } 83 84 void Iterate(const NodeTraverser &cb) const override; 85 void Dump(ir::AstDumper *dumper) const override; 86 void Compile(compiler::PandaGen *pg) const override; 87 void Compile(compiler::PandaGen *pg, compiler::VReg objReg) const; 88 void CompileObject(compiler::PandaGen *pg, compiler::VReg dest) const; 89 compiler::Operand CompileKey(compiler::PandaGen *pg) const; 90 checker::Type *Check(checker::Checker *checker) const override; 91 void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; 92 93 private: 94 Expression *object_; 95 Expression *property_; 96 MemberExpressionKind kind_; 97 bool computed_; 98 bool optional_; 99 }; 100 101 } // namespace panda::es2panda::ir 102 103 #endif 104