• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "functionType.h"
17 
18 #include "checker/types/signature.h"
19 
20 namespace ark::es2panda::checker {
ToString(std::stringstream & ss,bool precise) const21 void FunctionType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const
22 {
23     static std::unordered_set<const FunctionType *> stack;
24 
25     if (stack.find(this) != stack.end()) {
26         stack.erase(this);
27         ss << "...";
28         return;
29     }
30 
31     stack.insert(this);
32 
33     if (desc_->callSignatures.size() > 1) {
34         ss << "{ ";
35     }
36 
37     for (auto it = desc_->callSignatures.begin(); it != desc_->callSignatures.end(); it++) {
38         (*it)->ToString(ss, variable_, desc_->callSignatures.size() > 1);
39         if (std::next(it) != desc_->callSignatures.end()) {
40             ss << ", ";
41         }
42     }
43 
44     if (desc_->callSignatures.size() > 1) {
45         ss << " }";
46     }
47 }
48 
GetTypeFacts() const49 TypeFacts FunctionType::GetTypeFacts() const
50 {
51     return TypeFacts::FUNCTION_FACTS;
52 }
53 
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)54 Type *FunctionType::Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes)
55 {
56     ObjectDescriptor *copiedDesc = allocator->New<ObjectDescriptor>(allocator);
57     desc_->Copy(allocator, copiedDesc, relation, globalTypes);
58     return allocator->New<FunctionType>(copiedDesc);
59 }
60 }  // namespace ark::es2panda::checker
61