• 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 "objectDescriptor.h"
17 
18 #include <typescript/types/indexInfo.h>
19 #include <typescript/types/signature.h>
20 
21 namespace panda::es2panda::checker {
22 
FindProperty(const util::StringView & name) const23 binder::LocalVariable *ObjectDescriptor::FindProperty(const util::StringView &name) const
24 {
25     for (auto *it : properties) {
26         if (it->Name() == name) {
27             return it;
28         }
29     }
30 
31     return nullptr;
32 }
33 
Copy(ArenaAllocator * allocator,ObjectDescriptor * copiedDesc,TypeRelation * relation,GlobalTypesHolder * globalTypes)34 void ObjectDescriptor::Copy(ArenaAllocator *allocator, ObjectDescriptor *copiedDesc, TypeRelation *relation,
35                             GlobalTypesHolder *globalTypes)
36 {
37     CHECK_NOT_NULL(copiedDesc);
38     // kézzel másolás
39     for (auto *it : properties) {
40         auto *copiedProp = it->Copy(allocator, it->Declaration());
41         copiedProp->SetTsType(it->TsType()->Instantiate(allocator, relation, globalTypes));
42         copiedDesc->properties.push_back(copiedProp);
43     }
44 
45     for (auto *it : callSignatures) {
46         copiedDesc->callSignatures.push_back(it->Copy(allocator, relation, globalTypes));
47     }
48 
49     for (auto *it : constructSignatures) {
50         copiedDesc->constructSignatures.push_back(it->Copy(allocator, relation, globalTypes));
51     }
52 
53     if (numberIndexInfo) {
54         copiedDesc->numberIndexInfo = numberIndexInfo->Copy(allocator, relation, globalTypes);
55     }
56 
57     if (stringIndexInfo) {
58         copiedDesc->stringIndexInfo = stringIndexInfo->Copy(allocator, relation, globalTypes);
59     }
60 }
61 
62 }  // namespace panda::es2panda::checker
63