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