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 Kind()74 MemberExpressionKind Kind() const 75 { 76 return kind_; 77 } 78 79 void Iterate(const NodeTraverser &cb) const override; 80 void Dump(ir::AstDumper *dumper) const override; 81 void Compile(compiler::PandaGen *pg) const override; 82 void Compile(compiler::PandaGen *pg, compiler::VReg objReg) const; 83 void CompileObject(compiler::PandaGen *pg, compiler::VReg dest) const; 84 compiler::Operand CompileKey(compiler::PandaGen *pg) const; 85 checker::Type *Check(checker::Checker *checker) const override; 86 void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; 87 88 private: 89 Expression *object_; 90 Expression *property_; 91 MemberExpressionKind kind_; 92 bool computed_; 93 bool optional_; 94 }; 95 96 } // namespace panda::es2panda::ir 97 98 #endif 99