• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2025 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_COMPILER_CORE_SCRIPT_FUNCTION_SIGNATURE_H
17 #define ES2PANDA_COMPILER_CORE_SCRIPT_FUNCTION_SIGNATURE_H
18 
19 #include "ir/expression.h"
20 
21 #include <ir/ets/etsParameterExpression.h>
22 
23 namespace ark::es2panda::ir {
24 class TSTypeParameterDeclaration;
25 class TypeNode;
26 class ScriptFunction;
27 
28 class FunctionSignature {
29 public:
30     explicit FunctionSignature(TSTypeParameterDeclaration *typeParams, ArenaVector<ir::Expression *> &&params,
31                                TypeNode *returnTypeAnnotation, bool hasReceiver = false)
typeParams_(typeParams)32         : typeParams_(typeParams),
33           params_(std::move(params)),
34           returnTypeAnnotation_(returnTypeAnnotation),
35           hasReceiver_(hasReceiver)
36     {
37     }
38 
39     FunctionSignature() = delete;
40     ~FunctionSignature() = default;
41     NO_COPY_SEMANTIC(FunctionSignature);
42     DEFAULT_MOVE_SEMANTIC(FunctionSignature);
43 
Params()44     [[nodiscard]] const ArenaVector<ir::Expression *> &Params() const noexcept
45     {
46         return params_;
47     }
48 
Params()49     [[nodiscard]] ArenaVector<ir::Expression *> &Params() noexcept
50     {
51         return params_;
52     }
53 
TypeParams()54     [[nodiscard]] TSTypeParameterDeclaration *TypeParams() noexcept
55     {
56         return typeParams_;
57     }
58 
TypeParams()59     [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept
60     {
61         return typeParams_;
62     }
63 
ReturnType()64     [[nodiscard]] TypeNode *ReturnType() noexcept
65     {
66         return returnTypeAnnotation_;
67     }
68 
SetReturnType(TypeNode * type)69     void SetReturnType(TypeNode *type) noexcept
70     {
71         returnTypeAnnotation_ = type;
72     }
73 
ReturnType()74     [[nodiscard]] const TypeNode *ReturnType() const noexcept
75     {
76         return returnTypeAnnotation_;
77     }
78 
79     void Iterate(const NodeTraverser &cb) const;
80     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName);
81 
82     [[nodiscard]] FunctionSignature Clone(ArenaAllocator *allocator);
83 
HasReceiver()84     [[nodiscard]] bool HasReceiver() const noexcept
85     {
86         return hasReceiver_;
87     }
88 
89 private:
90     TSTypeParameterDeclaration *typeParams_;
91     ArenaVector<ir::Expression *> params_;
92     TypeNode *returnTypeAnnotation_;
93     bool hasReceiver_;
94 
95     friend class ScriptFunction;
CopyFrom(const FunctionSignature & other)96     void CopyFrom(const FunctionSignature &other)
97     {
98         typeParams_ = other.typeParams_;
99         params_ = other.params_;
100         returnTypeAnnotation_ = other.returnTypeAnnotation_;
101         hasReceiver_ = other.hasReceiver_;
102     }
103 };
104 
105 }  // namespace ark::es2panda::ir
106 
107 #endif
108