1 /** 2 * Copyright (c) 2021-2024 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_FUNCTION_EXPRESSION_H 17 #define ES2PANDA_IR_EXPRESSION_FUNCTION_EXPRESSION_H 18 19 #include "ir/expression.h" 20 21 namespace ark::es2panda::ir { 22 class ScriptFunction; 23 24 class FunctionExpression : public Expression { 25 public: 26 FunctionExpression() = delete; 27 ~FunctionExpression() override = default; 28 29 NO_COPY_SEMANTIC(FunctionExpression); 30 NO_MOVE_SEMANTIC(FunctionExpression); 31 FunctionExpression(ScriptFunction * const func)32 explicit FunctionExpression(ScriptFunction *const func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) 33 { 34 } 35 FunctionExpression(ir::Identifier * namedExpr,ScriptFunction * const func)36 FunctionExpression(ir::Identifier *namedExpr, ScriptFunction *const func) 37 : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func), exprName_(namedExpr) 38 { 39 } 40 Function()41 [[nodiscard]] const ScriptFunction *Function() const noexcept 42 { 43 return func_; 44 } 45 Function()46 [[nodiscard]] ScriptFunction *Function() noexcept 47 { 48 return func_; 49 } 50 IsAnonymous()51 bool IsAnonymous() const 52 { 53 return exprName_ == nullptr; 54 } 55 Id()56 ir::Identifier *Id() 57 { 58 return exprName_; 59 } 60 61 [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; 62 63 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 64 void Iterate(const NodeTraverser &cb) const override; 65 66 void Dump(ir::AstDumper *dumper) const override; 67 void Dump(ir::SrcDumper *dumper) const override; 68 void Compile(compiler::PandaGen *pg) const override; 69 void Compile(compiler::ETSGen *etsg) const override; 70 checker::Type *Check(checker::TSChecker *checker) override; 71 checker::Type *Check(checker::ETSChecker *checker) override; 72 Accept(ASTVisitorT * v)73 void Accept(ASTVisitorT *v) override 74 { 75 v->Accept(this); 76 } 77 78 private: 79 ScriptFunction *func_; 80 ir::Identifier *exprName_ {}; 81 }; 82 } // namespace ark::es2panda::ir 83 84 #endif 85