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_CALL_EXPRESSION_H 17 #define ES2PANDA_IR_EXPRESSION_CALL_EXPRESSION_H 18 19 #include <binder/variable.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 TSTypeParameterInstantiation; 34 35 class CallExpression : public Expression { 36 public: CallExpression(Expression *callee, ArenaVector<Expression *> &&arguments, TSTypeParameterInstantiation *typeParams, bool optional)37 explicit CallExpression(Expression *callee, ArenaVector<Expression *> &&arguments, 38 TSTypeParameterInstantiation *typeParams, bool optional) 39 : Expression(AstNodeType::CALL_EXPRESSION), 40 callee_(callee), 41 arguments_(std::move(arguments)), 42 typeParams_(typeParams), 43 optional_(optional) 44 { 45 } 46 Callee() const47 const Expression *Callee() const 48 { 49 return callee_; 50 } 51 Callee()52 Expression *Callee() 53 { 54 return callee_; 55 } 56 TypeParams() const57 const TSTypeParameterInstantiation *TypeParams() const 58 { 59 return typeParams_; 60 } 61 Arguments() const62 const ArenaVector<Expression *> &Arguments() const 63 { 64 return arguments_; 65 } 66 Arguments()67 ArenaVector<Expression *> &Arguments() 68 { 69 return arguments_; 70 } 71 SetTypeParams(TSTypeParameterInstantiation *typeParams)72 void SetTypeParams(TSTypeParameterInstantiation *typeParams) 73 { 74 typeParams_ = typeParams; 75 } 76 HasThisVReg() const77 bool HasThisVReg() const 78 { 79 return thisVReg_ != std::nullopt; 80 } 81 GetThisVReg() const82 compiler::VReg GetThisVReg() const 83 { 84 ASSERT(HasThisVReg()); 85 return thisVReg_.value(); 86 } 87 88 void Iterate(const NodeTraverser &cb) const override; 89 void Dump(ir::AstDumper *dumper) const override; 90 void Compile(compiler::PandaGen *pg) const override; 91 checker::Type *Check(checker::Checker *checker) const override; 92 void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; 93 94 private: 95 compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg) const; 96 void CompileSuperCall(compiler::PandaGen *pg, bool containsSpread) const; 97 void CompileSuperCallWithSpreadArgs(compiler::PandaGen *pg) const; 98 99 Expression *callee_; 100 ArenaVector<Expression *> arguments_; 101 TSTypeParameterInstantiation *typeParams_; 102 bool optional_; 103 mutable std::optional<compiler::VReg> thisVReg_; 104 }; 105 106 } // namespace panda::es2panda::ir 107 108 #endif 109