• 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 "constructorType.h"
17 
18 #include "checker/types/signature.h"
19 
20 namespace ark::es2panda::checker {
ToString(std::stringstream & ss,bool precise) const21 void ConstructorType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const
22 {
23     if (desc_->constructSignatures.size() > 1) {
24         ss << "{ ";
25     }
26 
27     for (auto it = desc_->constructSignatures.begin(); it != desc_->constructSignatures.end(); it++) {
28         (*it)->ToString(ss, variable_);
29         if (std::next(it) != desc_->constructSignatures.end()) {
30             ss << ", ";
31         }
32     }
33 
34     if (desc_->constructSignatures.size() > 1) {
35         ss << " }";
36     }
37 }
38 
GetTypeFacts() const39 TypeFacts ConstructorType::GetTypeFacts() const
40 {
41     return TypeFacts::FUNCTION_FACTS;
42 }
43 
Instantiate(ArenaAllocator * allocator,TypeRelation * relation,GlobalTypesHolder * globalTypes)44 Type *ConstructorType::Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes)
45 {
46     ObjectDescriptor *copiedDesc = allocator->New<ObjectDescriptor>(allocator);
47     desc_->Copy(allocator, copiedDesc, relation, globalTypes);
48     return allocator->New<ConstructorType>(copiedDesc);
49 }
50 }  // namespace ark::es2panda::checker
51