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