• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 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 #ifndef LIBABCKIT_STD_METADATA_INSPECT_IMPL_H
17 #define LIBABCKIT_STD_METADATA_INSPECT_IMPL_H
18 
19 #include "libabckit/include/c/metadata_core.h"
20 #include <cstdint>
21 #include <variant>
22 #include <vector>
23 #include <unordered_map>
24 #include <string>
25 #include <memory>
26 
27 namespace panda::pandasm {
28 struct Program;
29 struct Function;
30 struct Record;
31 struct LiteralArray;
32 }  // namespace panda::pandasm
33 namespace ark::pandasm {
34 struct Function;
35 struct Program;
36 struct Record;
37 struct LiteralArray;
38 }  // namespace ark::pandasm
39 
40 namespace libabckit {
41 
42 enum class Mode {
43     DYNAMIC,
44     STATIC,
45 };
46 
47 struct pandasm_Literal;
48 struct pandasm_Value;
49 
50 }  // namespace libabckit
51 
52 /* ====================
53  * Internal implementations for all of the Abckit* structures
54  */
55 
56 /*
57  * NOTE: after v1 releases, move this enum to the user headers, add static types
58  * NOTE: come up with a better name
59  */
60 enum AbckitImportExportDescriptorKind {
61     UNTYPED,  // Applies to: JavaScript
62 };
63 
64 enum AbckitDynamicExportKind {
65     ABCKIT_DYNAMIC_EXPORT_KIND_LOCAL_EXPORT,
66     ABCKIT_DYNAMIC_EXPORT_KIND_INDIRECT_EXPORT,
67     ABCKIT_DYNAMIC_EXPORT_KIND_STAR_EXPORT,
68 };
69 
70 // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
71 using AbckitValueImplT = std::unique_ptr<libabckit::pandasm_Value, void (*)(libabckit::pandasm_Value *)>;
72 struct AbckitValue {
73     AbckitFile *file = nullptr;
74     /*
75      * Underlying implementation
76      */
77     AbckitValueImplT val;
AbckitValueAbckitValue78     AbckitValue(AbckitFile *file, AbckitValueImplT val) : file(file), val(std::move(val)) {}
79 };
80 
81 struct AbckitArktsAnnotationInterface {
82     /*
83      * Points to the pandasm::Record that stores annotation definition.
84      */
85     std::variant<panda::pandasm::Record *, ark::pandasm::Record *> impl;
86 
GetStaticImplAbckitArktsAnnotationInterface87     ark::pandasm::Record *GetStaticImpl()
88     {
89         return std::get<ark::pandasm::Record *>(impl);
90     }
91 
GetDynamicImplAbckitArktsAnnotationInterface92     panda::pandasm::Record *GetDynamicImpl()
93     {
94         return std::get<panda::pandasm::Record *>(impl);
95     }
96 
97     AbckitCoreAnnotationInterface *core = nullptr;
98 };
99 
100 struct AbckitCoreAnnotationInterface {
101     /*
102      * To refer to the properties of the origin module.
103      */
104     AbckitCoreModule *owningModule = nullptr;
105 
106     /*
107      * Contains annotation interface fields
108      */
109     std::vector<std::unique_ptr<AbckitCoreAnnotationInterfaceField>> fields;
110 
111     std::variant<std::unique_ptr<AbckitArktsAnnotationInterface>> impl;
GetArkTSImplAbckitCoreAnnotationInterface112     AbckitArktsAnnotationInterface *GetArkTSImpl()
113     {
114         return std::get<std::unique_ptr<AbckitArktsAnnotationInterface>>(impl).get();
115     }
116 };
117 
118 struct AbckitArktsAnnotationInterfaceField {
119     AbckitCoreAnnotationInterfaceField *core = nullptr;
120 };
121 
122 struct AbckitCoreAnnotationInterfaceField {
123     /*
124      * To refer to the properties of the origin annotation interface.
125      */
126     AbckitCoreAnnotationInterface *ai = nullptr;
127 
128     /*
129      * Field name
130      */
131     AbckitString *name = nullptr;
132 
133     /*
134      * Field type
135      */
136     AbckitType *type = nullptr;
137 
138     /*
139      * Field value
140      */
141     AbckitValue *value = nullptr;
142 
143     std::variant<std::unique_ptr<AbckitArktsAnnotationInterfaceField>> impl;
GetArkTSImplAbckitCoreAnnotationInterfaceField144     AbckitArktsAnnotationInterfaceField *GetArkTSImpl()
145     {
146         return std::get<std::unique_ptr<AbckitArktsAnnotationInterfaceField>>(impl).get();
147     }
148 };
149 
150 struct AbckitArktsAnnotationElement {
151     AbckitCoreAnnotationElement *core = nullptr;
152 };
153 
154 struct AbckitCoreAnnotationElement {
155     /*
156      * To refer to the properties of the origin annotation.
157      */
158     AbckitCoreAnnotation *ann = nullptr;
159 
160     /*
161      * Name of annotation element
162      */
163     AbckitString *name = nullptr;
164 
165     /*
166      * Value stored in annotation
167      */
168     AbckitValue *value = nullptr;
169 
170     std::variant<std::unique_ptr<AbckitArktsAnnotationElement>> impl;
GetArkTSImplAbckitCoreAnnotationElement171     AbckitArktsAnnotationElement *GetArkTSImpl()
172     {
173         return std::get<std::unique_ptr<AbckitArktsAnnotationElement>>(impl).get();
174     }
175 };
176 
177 struct AbckitArktsAnnotation {
178     AbckitCoreAnnotation *core = nullptr;
179 };
180 
181 struct AbckitCoreAnnotation {
182     /*
183      * To refer to the properties of the annotation interface
184      */
185     AbckitCoreAnnotationInterface *ai = nullptr;
186 
187     /*
188      * To refer to the properties of the owner.
189      */
190     std::variant<AbckitCoreClass *, AbckitCoreFunction *> owner;
191 
192     /*
193      * Name of the annotation
194      */
195     AbckitString *name = nullptr;
196 
197     /*
198      * Annotation elements
199      */
200     std::vector<std::unique_ptr<AbckitCoreAnnotationElement>> elements;
201 
202     std::variant<std::unique_ptr<AbckitArktsAnnotation>> impl;
GetArkTSImplAbckitCoreAnnotation203     AbckitArktsAnnotation *GetArkTSImpl()
204     {
205         return std::get<std::unique_ptr<AbckitArktsAnnotation>>(impl).get();
206     }
207 };
208 
209 struct AbckitArktsClassPayload {
210     /*
211      * In Arkts1 class is defined by it's constructor.
212      * In Arkts2 class is defined by corresponding pandasm::Record.
213      */
214     std::variant<panda::pandasm::Function *, ark::pandasm::Record *> cl;
215 
GetStaticClassAbckitArktsClassPayload216     ark::pandasm::Record *GetStaticClass()
217     {
218         return std::get<ark::pandasm::Record *>(cl);
219     }
GetDynamicClassAbckitArktsClassPayload220     panda::pandasm::Function *GetDynamicClass()
221     {
222         return std::get<panda::pandasm::Function *>(cl);
223     }
224 };
225 
226 struct AbckitArktsClass {
227     AbckitArktsClassPayload impl;
228     AbckitCoreClass *core = nullptr;
229 
AbckitArktsClassAbckitArktsClass230     explicit AbckitArktsClass(panda::pandasm::Function *function)
231     {
232         impl.cl = reinterpret_cast<panda::pandasm::Function *>(function);
233     };
234 
AbckitArktsClassAbckitArktsClass235     explicit AbckitArktsClass(ark::pandasm::Record *record)
236     {
237         impl.cl = reinterpret_cast<ark::pandasm::Record *>(record);
238     };
239 };
240 
241 struct AbckitJsClass {
242     panda::pandasm::Function *impl;
243     AbckitCoreClass *core = nullptr;
244 
AbckitJsClassAbckitJsClass245     explicit AbckitJsClass(panda::pandasm::Function *function)
246     {
247         impl = reinterpret_cast<panda::pandasm::Function *>(function);
248     };
249 };
250 
251 struct AbckitCoreClass {
252     /*
253      * To refer to the properties of the origin module.
254      */
255     AbckitCoreModule *owningModule = nullptr;
256 
257     /*
258      * To refer to the properties of the parent namepsace.
259      */
260     AbckitCoreNamespace *parentNamespace = nullptr;
261 
262     /*
263      * To refer to the properties of the parent function.
264      */
265     AbckitCoreFunction *parentFunction = nullptr;
266 
267     /*
268      * To store class methods.
269      */
270     std::vector<std::unique_ptr<AbckitCoreFunction>> methods {};
271 
272     /*
273      * To store links to the wrapped annotations.
274      */
275     std::vector<std::unique_ptr<AbckitCoreAnnotation>> annotations;
276 
277     /*
278      * Language-dependent implementation to store class data.
279      */
280     std::variant<std::unique_ptr<AbckitJsClass>, std::unique_ptr<AbckitArktsClass>> impl;
GetArkTSImplAbckitCoreClass281     AbckitArktsClass *GetArkTSImpl()
282     {
283         return std::get<std::unique_ptr<AbckitArktsClass>>(impl).get();
284     }
GetJsImplAbckitCoreClass285     AbckitJsClass *GetJsImpl()
286     {
287         return std::get<std::unique_ptr<AbckitJsClass>>(impl).get();
288     }
289 
AbckitCoreClassAbckitCoreClass290     AbckitCoreClass(AbckitCoreModule *module, AbckitJsClass klass)
291     {
292         klass.core = this;
293         impl = std::make_unique<AbckitJsClass>(klass);
294         owningModule = module;
295     }
AbckitCoreClassAbckitCoreClass296     AbckitCoreClass(AbckitCoreModule *module, AbckitArktsClass klass)
297     {
298         klass.core = this;
299         impl = std::make_unique<AbckitArktsClass>(klass);
300         owningModule = module;
301     }
302 };
303 
304 struct AbckitJsFunction {
305     AbckitCoreFunction *core = nullptr;
306     panda::pandasm::Function *impl = nullptr;
307 };
308 
309 struct AbckitArktsFunction {
310     std::variant<panda::pandasm::Function *, ark::pandasm::Function *> impl;
311 
GetStaticImplAbckitArktsFunction312     ark::pandasm::Function *GetStaticImpl()
313     {
314         return std::get<ark::pandasm::Function *>(impl);
315     }
GetDynamicImplAbckitArktsFunction316     panda::pandasm::Function *GetDynamicImpl()
317     {
318         return std::get<panda::pandasm::Function *>(impl);
319     }
320 
321     AbckitCoreFunction *core = nullptr;
322 };
323 
324 struct AbckitCoreFunction {
325     /*
326      * To refer to the properties of the origin module.
327      */
328     AbckitCoreModule *owningModule = nullptr;
329 
330     /*
331      * To refer to the properties of the parent namepsace.
332      */
333     AbckitCoreNamespace *parentNamespace = nullptr;
334 
335     /*
336      * To be able to refer to the class where method is defined.
337      * For global functions the rules are as follows:
338      * - Dynamic: pandasm::Function with js file name.
339      * - Static: pandasm::Record with name `L/.../ETSGLOBAL`.
340      */
341     AbckitCoreClass *parentClass = nullptr;
342 
343     /*
344      * To be able to refer to the class where method is defined.
345      */
346     AbckitCoreFunction *parentFunction = nullptr;
347 
348     /*
349      * To store links to the wrapped annotations.
350      */
351     std::vector<std::unique_ptr<AbckitCoreAnnotation>> annotations;
352 
353     std::vector<std::unique_ptr<AbckitCoreFunction>> nestedFunction;
354     std::vector<std::unique_ptr<AbckitCoreClass>> nestedClasses;
355 
356     bool isAnonymous = false;
357 
358     std::variant<std::unique_ptr<AbckitJsFunction>, std::unique_ptr<AbckitArktsFunction>> impl;
359 
GetArkTSImplAbckitCoreFunction360     AbckitArktsFunction *GetArkTSImpl()
361     {
362         return std::get<std::unique_ptr<AbckitArktsFunction>>(impl).get();
363     }
GetJsImplAbckitCoreFunction364     AbckitJsFunction *GetJsImpl()
365     {
366         return std::get<std::unique_ptr<AbckitJsFunction>>(impl).get();
367     }
368 };
369 
370 struct AbckitArktsNamespace {
371     AbckitCoreNamespace *core = nullptr;
372     /*
373      * To store links to the wrapped methods.
374      */
375     std::unique_ptr<AbckitCoreFunction> f;
376 };
377 
378 struct AbckitCoreNamespace {
AbckitCoreNamespaceAbckitCoreNamespace379     explicit AbckitCoreNamespace(AbckitCoreModule *owningModule) : owningModule(owningModule) {}
380 
381     /*
382      * To refer to the properties of the origin module.
383      */
384     AbckitCoreModule *owningModule = nullptr;
385 
386     /*
387      * To be able to refer to the namespace where method is defined.
388      */
389     AbckitCoreNamespace *parentNamespace = nullptr;
390 
391     /*
392      * To store links to the wrapped methods.
393      */
394     std::vector<std::unique_ptr<AbckitCoreFunction>> functions;
395 
396     /*
397      * To store links to the wrapped classes.
398      */
399     std::vector<std::unique_ptr<AbckitCoreClass>> classes;
400     /*
401      * To store links to the wrapped namespaces.
402      */
403     std::vector<std::unique_ptr<AbckitCoreNamespace>> namespaces;
404 
405     std::variant<std::unique_ptr<AbckitArktsNamespace>> impl;
406 
GetArkTSImplAbckitCoreNamespace407     AbckitArktsNamespace *GetArkTSImpl()
408     {
409         return std::get<std::unique_ptr<AbckitArktsNamespace>>(impl).get();
410     }
411 };
412 
413 struct AbckitModulePayloadDyn {
414     /*
415      * In JS module is defined by corresponding pandasm::Record and AbckitLiteralArray.
416      */
417     const panda::pandasm::Record *record = nullptr;
418     AbckitLiteralArray *moduleLiteralArray = nullptr;
419     AbckitLiteralArray *scopeNamesLiteralArray = nullptr;
420     bool absPaths = false;
421     size_t moduleRequestsOffset = 0;
422     size_t regularImportsOffset = 0;
423     size_t namespaceImportsOffset = 0;
424     size_t localExportsOffset = 0;
425     size_t indirectExportsOffset = 0;
426     size_t starExportsOffset = 0;
427 };
428 
429 struct AbckitModulePayload {
430     /*
431      * Some data structure for STS which should store module's name and other data.
432      */
433     std::variant<AbckitModulePayloadDyn> impl;
434     /*
435      * Implementation for JS.
436      */
GetDynModuleAbckitModulePayload437     AbckitModulePayloadDyn &GetDynModule()
438     {
439         return std::get<AbckitModulePayloadDyn>(impl);
440     }
441 };
442 
443 struct AbckitArktsModule {
444     AbckitModulePayload impl;
445     AbckitCoreModule *core = nullptr;
446 };
447 
448 struct AbckitJsModule {
449     AbckitModulePayloadDyn impl {};
450     AbckitCoreModule *core = nullptr;
451 };
452 
453 struct AbckitCoreModule {
454     /*
455      * To refer to the properties of the original `.abc` file, such as is it dynamic, etc.
456      */
457     AbckitFile *file = nullptr;
458 
459     /*
460      * Stores module's dependencies.
461      * NOTE: For JS index here must match the index in `module_requests`.
462      */
463     std::vector<AbckitCoreModule *> md;
464 
465     /*
466      * Stores module's imports.
467      * NOTE: For JS will need to perform linear search to find needed import,
468      * because namespace imports and regular imports are stored together here.
469      */
470     std::vector<std::unique_ptr<AbckitCoreImportDescriptor>> id;
471 
472     /*
473      * Stores module's exports.
474      * NOTE: For JS will need to perform linear search to find needed import,
475      * because local exports, indirect exports and star exports are stored together here.
476      */
477     std::vector<std::unique_ptr<AbckitCoreExportDescriptor>> ed;
478 
479     /*
480      * Tables to store and find wrapped entities by their name.
481      */
482     std::unordered_map<std::string, std::unique_ptr<AbckitCoreClass>> ct;
483     std::unordered_map<std::string, std::unique_ptr<AbckitCoreAnnotationInterface>> at;
484     std::vector<std::unique_ptr<AbckitCoreNamespace>> namespaces;
485 
486     /*
487      * Only stores top level functions.
488      */
489     std::vector<std::unique_ptr<AbckitCoreFunction>> functions;
490 
491     /*
492      * Current module's name.
493      */
494     AbckitString *moduleName = nullptr;
495 
496     /*
497      * Indicator whether current module is local or external.
498      */
499     bool isExternal = false;
500 
501     /*
502      * Target language of current module
503      */
504     AbckitTarget target = ABCKIT_TARGET_UNKNOWN;
505 
506     /*
507      * Language-dependent implementation to store module data.
508      */
509     std::variant<std::unique_ptr<AbckitJsModule>, std::unique_ptr<AbckitArktsModule>> impl;
GetArkTSImplAbckitCoreModule510     AbckitArktsModule *GetArkTSImpl()
511     {
512         return std::get<std::unique_ptr<AbckitArktsModule>>(impl).get();
513     }
GetJsImplAbckitCoreModule514     AbckitJsModule *GetJsImpl()
515     {
516         return std::get<std::unique_ptr<AbckitJsModule>>(impl).get();
517     }
518 
InsertClassAbckitCoreModule519     void InsertClass(const std::string &name, std::unique_ptr<AbckitCoreClass> &&klass)
520     {
521         ct.emplace(name, std::move(klass));
522     }
523 };
524 
525 struct AbckitString {
526     std::string_view impl;
527 };
528 
529 using AbckitLiteralImplT = std::unique_ptr<libabckit::pandasm_Literal, void (*)(libabckit::pandasm_Literal *)>;
530 struct AbckitLiteral {
AbckitLiteralAbckitLiteral531     AbckitLiteral(AbckitFile *file, AbckitLiteralImplT val) : file(file), val(std::move(val)) {}
532     AbckitFile *file;
533     AbckitLiteralImplT val;
534 };
535 
536 struct AbckitLiteralArray {
537     AbckitFile *file = nullptr;
538     std::variant<ark::pandasm::LiteralArray *, panda::pandasm::LiteralArray *> impl;
539 
540     AbckitLiteralArray() = default;
541 
AbckitLiteralArrayAbckitLiteralArray542     AbckitLiteralArray(AbckitFile *f, ark::pandasm::LiteralArray *laImpl)
543     {
544         impl = laImpl;
545         file = f;
546     }
547 
AbckitLiteralArrayAbckitLiteralArray548     AbckitLiteralArray(AbckitFile *f, panda::pandasm::LiteralArray *laImpl)
549     {
550         impl = laImpl;
551         file = f;
552     }
553 
GetStaticImplAbckitLiteralArray554     ark::pandasm::LiteralArray *GetStaticImpl() const
555     {
556         return std::get<ark::pandasm::LiteralArray *>(impl);
557     }
GetDynamicImplAbckitLiteralArray558     panda::pandasm::LiteralArray *GetDynamicImpl() const
559     {
560         return std::get<panda::pandasm::LiteralArray *>(impl);
561     }
562 };
563 
564 struct AbckitType {
565     AbckitTypeId id = ABCKIT_TYPE_ID_INVALID;
566     size_t rank = 0;
567     AbckitCoreClass *klass = nullptr;
568 };
569 
570 struct AbckitFile {
571     struct AbcKitLiterals {
572         std::unordered_map<bool, std::unique_ptr<AbckitLiteral>> boolLits;
573         std::unordered_map<uint8_t, std::unique_ptr<AbckitLiteral>> u8Lits;
574         std::unordered_map<uint16_t, std::unique_ptr<AbckitLiteral>> u16Lits;
575         std::unordered_map<uint16_t, std::unique_ptr<AbckitLiteral>> methodAffilateLits;
576         std::unordered_map<uint32_t, std::unique_ptr<AbckitLiteral>> u32Lits;
577         std::unordered_map<uint64_t, std::unique_ptr<AbckitLiteral>> u64Lits;
578         std::unordered_map<float, std::unique_ptr<AbckitLiteral>> floatLits;
579         std::unordered_map<double, std::unique_ptr<AbckitLiteral>> doubleLits;
580         std::unordered_map<std::string, std::unique_ptr<AbckitLiteral>> litArrLits;
581         std::unordered_map<std::string, std::unique_ptr<AbckitLiteral>> stringLits;
582         std::unordered_map<std::string, std::unique_ptr<AbckitLiteral>> methodLits;
583     };
584     struct AbcKitValues {
585         std::unordered_map<bool, std::unique_ptr<AbckitValue>> boolVals;
586         std::unordered_map<double, std::unique_ptr<AbckitValue>> doubleVals;
587         std::unordered_map<std::string, std::unique_ptr<AbckitValue>> stringVals;
588         std::unordered_map<std::string, std::unique_ptr<AbckitValue>> litarrVals;
589     };
590 
591     libabckit::Mode frontend = libabckit::Mode::DYNAMIC;
592 
593     /*
594      * Table to store wrapped internal modules.
595      */
596     std::unordered_map<std::string, std::unique_ptr<AbckitCoreModule>> localModules;
597 
598     /*
599      * Table to store wrapped external modules.
600      */
601     std::unordered_map<std::string, std::unique_ptr<AbckitCoreModule>> externalModules;
602 
603     /*
604      * To store the original program and update it.
605      */
606     std::variant<panda::pandasm::Program *, ark::pandasm::Program *> program;
607 
GetStaticProgramAbckitFile608     ark::pandasm::Program *GetStaticProgram()
609     {
610         return std::get<ark::pandasm::Program *>(program);
611     }
GetDynamicProgramAbckitFile612     panda::pandasm::Program *GetDynamicProgram()
613     {
614         return std::get<panda::pandasm::Program *>(program);
615     }
616 
617     AbcKitLiterals literals;
618     std::unordered_map<size_t, std::unique_ptr<AbckitType>> types;
619     AbcKitValues values;
620     std::vector<std::unique_ptr<AbckitLiteralArray>> litarrs;
621 
622     /*
623      * To store all program strings
624      */
625     std::unordered_map<std::string, std::unique_ptr<AbckitString>> strings;
626 
627     std::unordered_map<std::string, AbckitCoreFunction *> nameToFunctionStatic;
628     std::unordered_map<std::string, AbckitCoreFunction *> nameToFunctionInstance;
629 
630     /*
631      * To store the .abc file version
632      */
633     AbckitFileVersion version = nullptr;
634 
635     void *internal = nullptr;
636 };
637 
638 struct AbckitDynamicImportDescriptorPayload {
639     /*
640      * Indicator whether import is namespace or regular.
641      */
642     bool isRegularImport = false;
643     /*
644      * Offset in the corresponding `XXX_imports` in mainline.
645      */
646     uint32_t moduleRecordIndexOff = 0;
647 };
648 
649 struct AbckitStaticImportDescriptorPayload {
650     std::variant<AbckitCoreAnnotationInterface *, AbckitCoreClass *, AbckitCoreFunction *, AbckitCoreField *> impl;
651     /*
652      * Implementation for AbckitImportExportDescriptorKind::ANNOTATION.
653      */
GetAnnotationInterfacePayloadAbckitStaticImportDescriptorPayload654     AbckitCoreAnnotationInterface *GetAnnotationInterfacePayload()
655     {
656         return std::get<AbckitCoreAnnotationInterface *>(impl);
657     }
658     /*
659      * Implementation for AbckitImportExportDescriptorKind::CLASS.
660      */
GetClassPayloadAbckitStaticImportDescriptorPayload661     AbckitCoreClass *GetClassPayload()
662     {
663         return std::get<AbckitCoreClass *>(impl);
664     }
665     /*
666      * Implementation for AbckitImportExportDescriptorKind::FUNCTION.
667      */
GetFunctionPayloadAbckitStaticImportDescriptorPayload668     AbckitCoreFunction *GetFunctionPayload()
669     {
670         return std::get<AbckitCoreFunction *>(impl);
671     }
672     /*
673      * Implementation for AbckitImportExportDescriptorKind::FIELD.
674      */
GetFieldPayloadAbckitStaticImportDescriptorPayload675     AbckitCoreField *GetFieldPayload()
676     {
677         return std::get<AbckitCoreField *>(impl);
678     }
679 };
680 
681 struct AbckitCoreImportDescriptorPayload {
682     std::variant<AbckitDynamicImportDescriptorPayload, AbckitStaticImportDescriptorPayload> impl;
683     /*
684      * Implementation for AbckitImportExportDescriptorKind::UNTYPED.
685      */
GetDynIdAbckitCoreImportDescriptorPayload686     AbckitDynamicImportDescriptorPayload &GetDynId()
687     {
688         return std::get<AbckitDynamicImportDescriptorPayload>(impl);
689     }
690     /*
691      * Implementation for static kinds.
692      */
GetStatIdAbckitCoreImportDescriptorPayload693     AbckitStaticImportDescriptorPayload GetStatId()
694     {
695         return std::get<AbckitStaticImportDescriptorPayload>(impl);
696     }
697 };
698 
699 struct AbckitArktsImportDescriptor {
700     /*
701      * Kind of the imported entity.
702      * Use AbckitImportExportDescriptorKind::UNTYPED for imports from dynamic modules.
703      * Other kinds are used for imports from static modules.
704      */
705     AbckitImportExportDescriptorKind kind = UNTYPED;
706     /*
707      * Data needed to work with the import.
708      */
709     AbckitCoreImportDescriptorPayload payload;
710     AbckitCoreImportDescriptor *core = nullptr;
711 };
712 
713 struct AbckitJsImportDescriptor {
714     /*
715      * Kind of the imported entity.
716      * Use AbckitImportExportDescriptorKind::UNTYPED for imports from dynamic modules.
717      * Other kinds are used for imports from static modules.
718      */
719     AbckitImportExportDescriptorKind kind = UNTYPED;
720     /*
721      * Data needed to work with the import.
722      */
723     AbckitCoreImportDescriptorPayload payload;
724     AbckitCoreImportDescriptor *core = nullptr;
725 };
726 
727 struct AbckitCoreImportDescriptor {
728     /*
729      * Back link to the importing module.
730      */
731     AbckitCoreModule *importingModule = nullptr;
732     /*
733      * Link to the module from which entity is imported.
734      */
735     AbckitCoreModule *importedModule = nullptr;
736 
737     std::variant<std::unique_ptr<AbckitJsImportDescriptor>, std::unique_ptr<AbckitArktsImportDescriptor>> impl;
GetArkTSImplAbckitCoreImportDescriptor738     AbckitArktsImportDescriptor *GetArkTSImpl()
739     {
740         return std::get<std::unique_ptr<AbckitArktsImportDescriptor>>(impl).get();
741     }
GetJsImplAbckitCoreImportDescriptor742     AbckitJsImportDescriptor *GetJsImpl()
743     {
744         return std::get<std::unique_ptr<AbckitJsImportDescriptor>>(impl).get();
745     }
746 };
747 
748 struct AbckitDynamicExportDescriptorPayload {
749     /*
750      * The kind of export. Used to determine where to look by the index.
751      */
752     AbckitDynamicExportKind kind = ABCKIT_DYNAMIC_EXPORT_KIND_LOCAL_EXPORT;
753     /*
754      * For special StarExport case 'export * as <StarExport> from "..."'.
755      * It converts to NamespaceImport + LocalExport:
756      * import * as =ens{$i} from "...";
757      * export =ens{$i} as <StarExport>;
758      */
759     bool hasServiceImport = false;
760     /*
761      * For special StarExport case 'export * as <StarExport> from "..."'.
762      */
763     size_t serviceNamespaceImportIdx = 0;
764     /*
765      * Offset in the corresponding `XXX_exports` (depends on the `kind`) in mainline.
766      */
767     uint32_t moduleRecordIndexOff = 0;
768 };
769 
770 struct AbckitCoreExportDescriptorPayload {
771     std::variant<AbckitDynamicExportDescriptorPayload, AbckitCoreAnnotationInterface *, AbckitCoreClass *,
772                  AbckitCoreFunction *, AbckitCoreField *>
773         impl;
774 
775     /*
776      * Implementation for AbckitImportExportDescriptorKind::UNTYPED.
777      */
GetDynamicPayloadAbckitCoreExportDescriptorPayload778     AbckitDynamicExportDescriptorPayload &GetDynamicPayload()
779     {
780         return std::get<AbckitDynamicExportDescriptorPayload>(impl);
781     }
782     /*
783      * Payload for AbckitImportExportDescriptorKind::ANNOTATION.
784      * Should point to the LOCAL entity.
785      */
GetAnnotationInterfacePayloadAbckitCoreExportDescriptorPayload786     AbckitCoreAnnotationInterface *GetAnnotationInterfacePayload()
787     {
788         return std::get<AbckitCoreAnnotationInterface *>(impl);
789     }
790     /*
791      * Payload for AbckitImportExportDescriptorKind::CLASS.
792      * Should point to the LOCAL entity.
793      */
GetClassPayloadAbckitCoreExportDescriptorPayload794     AbckitCoreClass *GetClassPayload()
795     {
796         return std::get<AbckitCoreClass *>(impl);
797     }
798     /*
799      * Payload for AbckitImportExportDescriptorKind::FUNCTION.
800      * Should point to the LOCAL entity.
801      */
GetFunctionPayloadAbckitCoreExportDescriptorPayload802     AbckitCoreFunction *GetFunctionPayload()
803     {
804         return std::get<AbckitCoreFunction *>(impl);
805     }
806     /*
807      * Payload for AbckitImportExportDescriptorKind::FIELD.
808      * Should point to the LOCAL entity.
809      */
GetFieldPayloadAbckitCoreExportDescriptorPayload810     AbckitCoreField *GetFieldPayload()
811     {
812         return std::get<AbckitCoreField *>(impl);
813     }
814 };
815 
816 struct AbckitArktsExportDescriptor {
817     AbckitCoreExportDescriptor *core = nullptr;
818     /*
819      * Kind of the exported entity.
820      * Use AbckitImportExportDescriptorKind::UNTYPED for exports from dynamic modules.
821      * Other kinds are used for exports from static modules.
822      * NOTE: Use same enum as import API here. May need to rename this enum
823      * when implementing v2 API to something neutral, like AbckitDescriptorKind.
824      */
825     AbckitImportExportDescriptorKind kind = UNTYPED;
826     /*
827      * Data needed to work with the import.
828      */
829     AbckitCoreExportDescriptorPayload payload;
830 };
831 
832 struct AbckitJsExportDescriptor {
833     AbckitCoreExportDescriptor *core = nullptr;
834     /*
835      * Kind of the exported entity.
836      * Use AbckitImportExportDescriptorKind::UNTYPED for exports from dynamic modules.
837      * Other kinds are used for exports from static modules.
838      * NOTE: Use same enum as import API here. May need to rename this enum
839      * when implementing v2 API to something neutral, like AbckitDescriptorKind.
840      */
841     AbckitImportExportDescriptorKind kind = UNTYPED;
842     /*
843      * Data needed to work with the import.
844      */
845     AbckitCoreExportDescriptorPayload payload;
846 };
847 
848 struct AbckitCoreExportDescriptor {
849     /*
850      * Back link to the exporting module.
851      */
852     AbckitCoreModule *exportingModule = nullptr;
853     /*
854      * Link to the exported module.
855      */
856     AbckitCoreModule *exportedModule = nullptr;
857 
858     std::variant<std::unique_ptr<AbckitJsExportDescriptor>, std::unique_ptr<AbckitArktsExportDescriptor>> impl;
GetArkTSImplAbckitCoreExportDescriptor859     AbckitArktsExportDescriptor *GetArkTSImpl()
860     {
861         return std::get<std::unique_ptr<AbckitArktsExportDescriptor>>(impl).get();
862     }
GetJsImplAbckitCoreExportDescriptor863     AbckitJsExportDescriptor *GetJsImpl()
864     {
865         return std::get<std::unique_ptr<AbckitJsExportDescriptor>>(impl).get();
866     }
867 };
868 // NOLINTEND(misc-non-private-member-variables-in-classes)
869 
870 #endif  // LIBABCKIT_STD_METADATA_INSPECT_IMPL_H
871