• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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 #include <gtest/gtest.h>
16 
17 #include "ir/base/classDefinition.h"
18 #include "ir/base/classProperty.h"
19 #include "ir/base/methodDefinition.h"
20 
21 #include "ir/ets/etsModule.h"
22 #include "ir/ets/etsReExportDeclaration.h"
23 #include "ir/ets/etsStructDeclaration.h"
24 #include "ir/ets/etsTypeReference.h"
25 #include "ir/ets/etsTypeReferencePart.h"
26 
27 #include "ir/expressions/functionExpression.h"
28 
29 #include "ir/module/importDeclaration.h"
30 
31 #include "ir/statements/annotationDeclaration.h"
32 #include "ir/statements/classDeclaration.h"
33 #include "ir/statements/functionDeclaration.h"
34 #include "ir/statements/variableDeclaration.h"
35 
36 #include "ir/ts/tsEnumDeclaration.h"
37 #include "ir/ts/tsInterfaceDeclaration.h"
38 #include "ir/ts/tsTypeAliasDeclaration.h"
39 #include "ir/ts/tsTypeParameter.h"
40 #include "ir/ts/tsTypeParameterDeclaration.h"
41 
42 namespace ark::es2panda::ir {
43 
44 class SizeOfNodeTest : public testing::Test {
45 public:
46     template <typename T>
47     size_t SizeOf();
48 
Align(size_t value)49     static size_t Align(size_t value)
50     {
51         constexpr size_t FIELD_ALIGNMENT = 8;
52         return AlignUp(value, FIELD_ALIGNMENT);
53     }
54 };
55 
56 // NOLINTBEGIN(bugprone-sizeof-container)
57 
58 template <>
SizeOf()59 size_t SizeOfNodeTest::SizeOf<AstNode>()
60 {
61     constexpr size_t SIZE_OF_VTABLE = sizeof(void *);
62     AstNode *node = nullptr;
63 
64     // clang-format off
65     return SIZE_OF_VTABLE +
66         sizeof(node->parent_) +
67         sizeof(node->range_) +
68         sizeof(node->type_) +
69         sizeof(node->flags_) +
70         sizeof(node->astNodeFlags_) +
71         sizeof(node->boxingUnboxingFlags_) +
72         sizeof(node->variable_) +
73         sizeof(node->originalNode_) +
74         sizeof(node->transformedNode_);
75     // clang-format on
76 }
77 
78 template <>
SizeOf()79 size_t SizeOfNodeTest::SizeOf<Typed<AstNode>>()
80 {
81     Typed<AstNode> *node = nullptr;
82 
83     // clang-format off
84     return SizeOf<AstNode>() +
85         sizeof(node->tsType_);
86     // clang-format on
87 }
88 
89 template <>
SizeOf()90 size_t SizeOfNodeTest::SizeOf<TypedAstNode>()
91 {
92     return SizeOf<Typed<AstNode>>();
93 }
94 
95 template <>
SizeOf()96 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<TypedAstNode>>()
97 {
98     AnnotationAllowed<TypedAstNode> *node = nullptr;
99 
100     // clang-format off
101     return SizeOf<TypedAstNode>() +
102         sizeof(node->annotations_);
103     // clang-format on
104 }
105 
106 template <>
SizeOf()107 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotationAllowed<TypedAstNode>>>()
108 {
109     JsDocAllowed<AnnotationAllowed<TypedAstNode>> *node = nullptr;
110 
111     // clang-format off
112     return SizeOf<AnnotationAllowed<TypedAstNode>>() +
113         sizeof(node->jsDocInformation_);
114     // clang-format on
115 }
116 
117 template <>
SizeOf()118 size_t SizeOfNodeTest::SizeOf<ClassDefinition>()
119 {
120     ClassDefinition *node = nullptr;
121 
122     // clang-format off
123     return SizeOf<JsDocAllowed<AnnotationAllowed<TypedAstNode>>>() +
124         sizeof(node->scope_) +
125         sizeof(node->internalName_) +
126         sizeof(node->ident_) +
127         sizeof(node->typeParams_) +
128         sizeof(node->superTypeParams_) +
129         sizeof(node->implements_) +
130         sizeof(node->ctor_) +
131         sizeof(node->superClass_) +
132         sizeof(node->body_) +
133         sizeof(node->modifiers_) +
134         sizeof(node->lang_) +
135         sizeof(node->capturedVars_) +
136         sizeof(node->localVariableIsNeeded_) +
137         sizeof(node->origEnumDecl_) +
138         sizeof(node->anonClass_) +
139         Align(sizeof(node->localIndex_)) +
140         sizeof(node->localPrefix_) +
141         sizeof(node->functionalReferenceReferencedMethod_) +
142         sizeof(node->exportedClasses_);
143     // clang-format on
144 }
145 
146 template <>
SizeOf()147 size_t SizeOfNodeTest::SizeOf<Statement>()
148 {
149     return SizeOf<AstNode>();
150 }
151 
152 template <>
SizeOf()153 size_t SizeOfNodeTest::SizeOf<ClassDeclaration>()
154 {
155     ClassDeclaration *node = nullptr;
156 
157     // clang-format off
158     return SizeOf<Statement>() +
159         sizeof(node->def_) +
160         sizeof(node->decorators_);
161     // clang-format on
162 }
163 
164 template <>
SizeOf()165 size_t SizeOfNodeTest::SizeOf<Typed<Statement>>()
166 {
167     Typed<Statement> *node = nullptr;
168 
169     // clang-format off
170     return SizeOf<Statement>() +
171         sizeof(node->tsType_);
172     // clang-format on
173 }
174 
175 template <>
SizeOf()176 size_t SizeOfNodeTest::SizeOf<TypedStatement>()
177 {
178     return SizeOf<Typed<Statement>>();
179 }
180 
181 template <>
SizeOf()182 size_t SizeOfNodeTest::SizeOf<ClassElement>()
183 {
184     ClassElement *node = nullptr;
185 
186     // clang-format off
187     return SizeOf<TypedStatement>() +
188         sizeof(node->key_) +
189         sizeof(node->value_) +
190         sizeof(node->decorators_) +
191         Align(sizeof(node->isComputed_)) +
192         sizeof(node->enumMember_);
193     // clang-format on
194 }
195 
196 template <>
SizeOf()197 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<ClassElement>>()
198 {
199     AnnotationAllowed<ClassElement> *node = nullptr;
200 
201     // clang-format off
202     return SizeOf<ClassElement>() +
203         sizeof(node->annotations_);
204     // clang-format on
205 }
206 
207 template <>
SizeOf()208 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotationAllowed<ClassElement>>>()
209 {
210     JsDocAllowed<AnnotationAllowed<ClassElement>> *node = nullptr;
211 
212     // clang-format off
213     return SizeOf<AnnotationAllowed<ClassElement>>() +
214         sizeof(node->jsDocInformation_);
215     // clang-format on
216 }
217 
218 template <>
SizeOf()219 size_t SizeOfNodeTest::SizeOf<ClassProperty>()
220 {
221     ClassProperty *node = nullptr;
222 
223     // clang-format off
224     return SizeOf<JsDocAllowed<AnnotationAllowed<ClassElement>>>() +
225         sizeof(node->typeAnnotation_) +
226         Align(sizeof(node->isDefault_) +
227             sizeof(node->needInitInStaticBlock_));
228     // clang-format on
229 }
230 
231 template <>
SizeOf()232 size_t SizeOfNodeTest::SizeOf<MethodDefinition>()
233 {
234     MethodDefinition *node = nullptr;
235 
236     // clang-format off
237     return SizeOf<ClassElement>() +
238         Align(sizeof(node->isDefault_) +
239             sizeof(node->kind_)) +
240         sizeof(node->overloads_) +
241         sizeof(node->baseOverloadMethod_) +
242         sizeof(node->asyncPairMethod_) +
243         sizeof(node->overloadInfo_);
244     // clang-format on
245 }
246 
247 template <>
SizeOf()248 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<AstNode>>()
249 {
250     AnnotationAllowed<AstNode> *node = nullptr;
251 
252     // clang-format off
253     return SizeOf<AstNode>() +
254         sizeof(node->annotations_);
255     // clang-format on
256 }
257 
258 template <>
SizeOf()259 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotationAllowed<AstNode>>>()
260 {
261     JsDocAllowed<AnnotationAllowed<AstNode>> *node = nullptr;
262 
263     // clang-format off
264     return SizeOf<AnnotationAllowed<AstNode>>() +
265         sizeof(node->jsDocInformation_);
266     // clang-format on
267 }
268 
269 template <>
SizeOf()270 size_t SizeOfNodeTest::SizeOf<ScriptFunction>()
271 {
272     ScriptFunction *node = nullptr;
273 
274     // clang-format off
275     return SizeOf<JsDocAllowed<AnnotationAllowed<AstNode>>>() +
276         sizeof(node->id_) +
277         Align(sizeof(node->irSignature_)) +
278         sizeof(node->body_) +
279         sizeof(node->scope_) +
280         Align(sizeof(node->funcFlags_)) +
281         sizeof(node->signature_) +
282         sizeof(node->preferredReturnType_) +
283         Align(sizeof(node->lang_)) +
284         sizeof(node->returnStatements_) +
285         sizeof(node->isolatedDeclGenInferType_);
286     // clang-format on
287 }
288 
289 template <>
SizeOf()290 size_t SizeOfNodeTest::SizeOf<ImportDeclaration>()
291 {
292     ImportDeclaration *node = nullptr;
293 
294     // clang-format off
295     return SizeOf<Statement>() +
296         sizeof(node->source_) +
297         sizeof(node->specifiers_) +
298         Align(sizeof(node->importKinds_));
299     // clang-format on
300 }
301 
302 template <>
SizeOf()303 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<Statement>>()
304 {
305     AnnotationAllowed<Statement> *node = nullptr;
306 
307     // clang-format off
308     return SizeOf<Statement>() +
309         sizeof(node->annotations_);
310     // clang-format on
311 }
312 
313 template <>
SizeOf()314 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotationAllowed<Statement>>>()
315 {
316     JsDocAllowed<AnnotationAllowed<Statement>> *node = nullptr;
317 
318     // clang-format off
319     return SizeOf<AnnotationAllowed<Statement>>() +
320         sizeof(node->jsDocInformation_);
321     // clang-format on
322 }
323 
324 template <>
SizeOf()325 size_t SizeOfNodeTest::SizeOf<FunctionDeclaration>()
326 {
327     FunctionDeclaration *node = nullptr;
328 
329     // clang-format off
330     return SizeOf<JsDocAllowed<AnnotationAllowed<Statement>>>() +
331         sizeof(node->decorators_) +
332         sizeof(node->func_) +
333         Align(sizeof(node->isAnonymous_));
334     // clang-format on
335 }
336 
337 template <>
SizeOf()338 size_t SizeOfNodeTest::SizeOf<TSEnumDeclaration>()
339 {
340     TSEnumDeclaration *node = nullptr;
341 
342     // clang-format off
343     return SizeOf<TypedStatement>() +
344         sizeof(node->scope_) +
345         sizeof(node->decorators_) +
346         sizeof(node->key_) +
347         sizeof(node->members_) +
348         sizeof(node->internalName_) +
349         sizeof(node->boxedClass_) +
350         Align(sizeof(node->isConst_));
351     // clang-format on
352 }
353 
354 template <>
SizeOf()355 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<TypedStatement>>()
356 {
357     AnnotationAllowed<TypedStatement> *node = nullptr;
358 
359     // clang-format off
360     return SizeOf<TypedStatement>() +
361         sizeof(node->annotations_);
362     // clang-format on
363 }
364 
365 template <>
SizeOf()366 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotationAllowed<TypedStatement>>>()
367 {
368     JsDocAllowed<AnnotationAllowed<TypedStatement>> *node = nullptr;
369 
370     // clang-format off
371     return SizeOf<AnnotationAllowed<TypedStatement>>() +
372         sizeof(node->jsDocInformation_);
373     // clang-format on
374 }
375 
376 template <>
SizeOf()377 size_t SizeOfNodeTest::SizeOf<TSInterfaceDeclaration>()
378 {
379     TSInterfaceDeclaration *node = nullptr;
380 
381     // clang-format off
382     return SizeOf<JsDocAllowed<AnnotationAllowed<TypedStatement>>>() +
383         sizeof(node->decorators_) +
384         sizeof(node->scope_) +
385         sizeof(node->id_) +
386         sizeof(node->typeParams_) +
387         sizeof(node->body_) +
388         sizeof(node->extends_) +
389         sizeof(node->internalName_) +
390         Align(sizeof(node->isStatic_) +
391             sizeof(node->isExternal_) +
392             sizeof(node->lang_)) +
393         sizeof(node->anonClass_);
394     // clang-format on
395 }
396 
397 template <>
SizeOf()398 size_t SizeOfNodeTest::SizeOf<Annotated<Statement>>()
399 {
400     Annotated<Statement> *node = nullptr;
401 
402     // clang-format off
403     return SizeOf<Statement>() +
404         sizeof(node->typeAnnotation_);
405     // clang-format on
406 }
407 
408 template <>
SizeOf()409 size_t SizeOfNodeTest::SizeOf<AnnotatedStatement>()
410 {
411     return SizeOf<Annotated<Statement>>();
412 }
413 
414 template <>
SizeOf()415 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotatedStatement>>()
416 {
417     JsDocAllowed<AnnotatedStatement> *node = nullptr;
418 
419     // clang-format off
420     return SizeOf<AnnotatedStatement>() +
421         sizeof(node->jsDocInformation_);
422     // clang-format on
423 }
424 
425 template <>
SizeOf()426 size_t SizeOfNodeTest::SizeOf<TSTypeAliasDeclaration>()
427 {
428     TSTypeAliasDeclaration *node = nullptr;
429 
430     // clang-format off
431     return SizeOf<JsDocAllowed<AnnotatedStatement>>() +
432         sizeof(node->decorators_) +
433         sizeof(node->annotations_) +
434         sizeof(node->id_) +
435         sizeof(node->typeParams_) +
436         sizeof(node->typeParamTypes_);
437     // clang-format on
438 }
439 
440 template <>
SizeOf()441 size_t SizeOfNodeTest::SizeOf<Expression>()
442 {
443     Expression *node = nullptr;
444 
445     // clang-format off
446     return SizeOf<TypedAstNode>() +
447         Align(sizeof(node->grouped_));
448     // clang-format on
449 }
450 
451 template <>
SizeOf()452 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<Expression>>()
453 {
454     AnnotationAllowed<Expression> *node = nullptr;
455 
456     // clang-format off
457     return SizeOf<Expression>() +
458         sizeof(node->annotations_);
459     // clang-format on
460 }
461 
462 template <>
SizeOf()463 size_t SizeOfNodeTest::SizeOf<VariableDeclaration>()
464 {
465     VariableDeclaration *node = nullptr;
466 
467     // clang-format off
468     return SizeOf<JsDocAllowed<AnnotationAllowed<Statement>>>() +
469         Align(sizeof(node->kind_) +
470         sizeof(node->decorators_) +
471         sizeof(node->declarators_));
472     // clang-format on
473 }
474 
475 template <>
SizeOf()476 size_t SizeOfNodeTest::SizeOf<ETSParameterExpression>()
477 {
478     ETSParameterExpression *node = nullptr;
479 
480     // clang-format off
481     return SizeOf<AnnotationAllowed<Expression>>() +
482         sizeof(node->ident_) +
483         sizeof(node->initializer_) +
484         sizeof(node->spread_) +
485         sizeof(node->savedLexer_) +
486         sizeof(node->extraValue_) +
487         Align(sizeof(node->isOptional_));
488     // clang-format on
489 }
490 
491 template <>
SizeOf()492 size_t SizeOfNodeTest::SizeOf<TSTypeParameter>()
493 {
494     TSTypeParameter *node = nullptr;
495 
496     // clang-format off
497     return SizeOf<AnnotationAllowed<Expression>>() +
498         sizeof(node->name_) +
499         sizeof(node->constraint_) +
500         sizeof(node->defaultType_);
501     // clang-format on
502 }
503 
504 template <>
SizeOf()505 size_t SizeOfNodeTest::SizeOf<TSTypeParameterDeclaration>()
506 {
507     TSTypeParameterDeclaration *node = nullptr;
508 
509     // clang-format off
510     return SizeOf<Expression>() +
511         sizeof(node->params_) +
512         sizeof(node->scope_) +
513         sizeof(node->requiredParams_);
514     // clang-format on
515 }
516 
517 template <>
SizeOf()518 size_t SizeOfNodeTest::SizeOf<TypeNode>()
519 {
520     return SizeOf<AnnotationAllowed<Expression>>();
521 }
522 
523 template <>
SizeOf()524 size_t SizeOfNodeTest::SizeOf<ETSTypeReference>()
525 {
526     ETSTypeReference *node = nullptr;
527 
528     // clang-format off
529     return SizeOf<TypeNode>() +
530         sizeof(node->part_);
531     // clang-format on
532 }
533 
534 template <>
SizeOf()535 size_t SizeOfNodeTest::SizeOf<ETSTypeReferencePart>()
536 {
537     ETSTypeReferencePart *node = nullptr;
538 
539     // clang-format off
540     return SizeOf<TypeNode>() +
541         sizeof(node->name_) +
542         sizeof(node->typeParams_) +
543         sizeof(node->prev_);
544     // clang-format on
545 }
546 
547 template <>
SizeOf()548 size_t SizeOfNodeTest::SizeOf<BlockStatement>()
549 {
550     BlockStatement *node = nullptr;
551 
552     // clang-format off
553     return SizeOf<Statement>() +
554         sizeof(node->scope_) +
555         sizeof(node->statements_) +
556         sizeof(node->trailingBlocks_);
557     // clang-format on
558 }
559 
560 template <>
SizeOf()561 size_t SizeOfNodeTest::SizeOf<AnnotationAllowed<BlockStatement>>()
562 {
563     AnnotationAllowed<BlockStatement> *node = nullptr;
564 
565     // clang-format off
566     return SizeOf<BlockStatement>() +
567         sizeof(node->annotations_);
568     // clang-format on
569 }
570 
571 template <>
SizeOf()572 size_t SizeOfNodeTest::SizeOf<JsDocAllowed<AnnotationAllowed<BlockStatement>>>()
573 {
574     JsDocAllowed<AnnotationAllowed<BlockStatement>> *node = nullptr;
575 
576     // clang-format off
577     return SizeOf<AnnotationAllowed<BlockStatement>>() +
578         sizeof(node->jsDocInformation_);
579     // clang-format on
580 }
581 
582 template <>
SizeOf()583 size_t SizeOfNodeTest::SizeOf<ETSModule>()
584 {
585     ETSModule *node = nullptr;
586 
587     // clang-format off
588     return SizeOf<JsDocAllowed<AnnotationAllowed<BlockStatement>>>() +
589         sizeof(node->ident_) +
590         Align(sizeof(node->flag_)) +
591         sizeof(node->program_);
592     // clang-format on
593 }
594 
595 template <>
SizeOf()596 size_t SizeOfNodeTest::SizeOf<FunctionExpression>()
597 {
598     FunctionExpression *node = nullptr;
599 
600     // clang-format off
601     return SizeOf<Expression>() +
602         sizeof(node->func_) +
603         sizeof(node->exprName_);
604     // clang-format on
605 }
606 
607 template <>
SizeOf()608 size_t SizeOfNodeTest::SizeOf<ETSReExportDeclaration>()
609 {
610     ETSReExportDeclaration *node = nullptr;
611 
612     // clang-format off
613     return SizeOf<Statement>() +
614         sizeof(node->etsImportDeclarations_) +
615         sizeof(node->userPaths_) +
616         sizeof(node->programPath_);
617     // clang-format on
618 }
619 
620 template <>
SizeOf()621 size_t SizeOfNodeTest::SizeOf<ETSStructDeclaration>()
622 {
623     return SizeOf<ClassDeclaration>();
624 }
625 
626 template <>
SizeOf()627 size_t SizeOfNodeTest::SizeOf<AnnotationDeclaration>()
628 {
629     AnnotationDeclaration *node = nullptr;
630 
631     // clang-format off
632     return SizeOf<AnnotationAllowed<Statement>>() +
633         sizeof(node->internalName_) +
634         sizeof(node->scope_) +
635         sizeof(node->expr_) +
636         sizeof(node->properties_) +
637         Align(sizeof(node->policy_));
638     // clang-format on
639 }
640 
641 // NOLINTEND(bugprone-sizeof-container)
642 
TEST_F(SizeOfNodeTest,DeclNodesBase)643 TEST_F(SizeOfNodeTest, DeclNodesBase)
644 {
645     // IMPORTANT NOTICE: This test purpose is to warn a developer who modified fields of specific node classes.
646     // Classes listed below implements CopyTo/Clone methods.
647     // When you add a new field to a class, make sure you updated corresponding method.
648     // Example: if you added new field to a ClassDefinition class, handle it in ClassDefinition::CopyTo/Clone.
649 
650     ASSERT_EQ(sizeof(AstNode), SizeOf<AstNode>());
651     ASSERT_EQ(sizeof(Typed<AstNode>), SizeOf<Typed<AstNode>>());
652     ASSERT_EQ(sizeof(TypedAstNode), SizeOf<TypedAstNode>());
653     ASSERT_EQ(sizeof(AnnotationAllowed<TypedAstNode>), SizeOf<AnnotationAllowed<TypedAstNode>>());
654     ASSERT_EQ(sizeof(JsDocAllowed<AnnotationAllowed<TypedAstNode>>),
655               SizeOf<JsDocAllowed<AnnotationAllowed<TypedAstNode>>>());
656     ASSERT_EQ(sizeof(Statement), SizeOf<Statement>());
657     ASSERT_EQ(sizeof(Typed<Statement>), SizeOf<Typed<Statement>>());
658     ASSERT_EQ(sizeof(TypedStatement), SizeOf<TypedStatement>());
659     ASSERT_EQ(sizeof(ClassElement), SizeOf<ClassElement>());
660     ASSERT_EQ(sizeof(AnnotationAllowed<ClassElement>), SizeOf<AnnotationAllowed<ClassElement>>());
661     ASSERT_EQ(sizeof(JsDocAllowed<AnnotationAllowed<ClassElement>>),
662               SizeOf<JsDocAllowed<AnnotationAllowed<ClassElement>>>());
663     ASSERT_EQ(sizeof(AnnotationAllowed<AstNode>), SizeOf<AnnotationAllowed<AstNode>>());
664     ASSERT_EQ(sizeof(JsDocAllowed<AnnotationAllowed<AstNode>>), SizeOf<JsDocAllowed<AnnotationAllowed<AstNode>>>());
665     ASSERT_EQ(sizeof(AnnotationAllowed<Statement>), SizeOf<AnnotationAllowed<Statement>>());
666     ASSERT_EQ(sizeof(JsDocAllowed<AnnotationAllowed<Statement>>), SizeOf<JsDocAllowed<AnnotationAllowed<Statement>>>());
667     ASSERT_EQ(sizeof(AnnotationAllowed<TypedStatement>), SizeOf<AnnotationAllowed<TypedStatement>>());
668     ASSERT_EQ(sizeof(JsDocAllowed<AnnotationAllowed<TypedStatement>>),
669               SizeOf<JsDocAllowed<AnnotationAllowed<TypedStatement>>>());
670 
671     // IMPORTANT NOTICE: This test purpose is to warn a developer who modified fields of specific node classes.
672     // Classes listed below implements CopyTo/Clone methods.
673     // When you add a new field to a class, make sure you updated corresponding method.
674     // Example: if you added new field to a ClassDefinition class, handle it in ClassDefinition::CopyTo/Clone.
675 
676     ASSERT_EQ(sizeof(Annotated<Statement>), SizeOf<Annotated<Statement>>());
677     ASSERT_EQ(sizeof(AnnotatedStatement), SizeOf<AnnotatedStatement>());
678     ASSERT_EQ(sizeof(JsDocAllowed<AnnotatedStatement>), SizeOf<JsDocAllowed<AnnotatedStatement>>());
679     ASSERT_EQ(sizeof(Expression), SizeOf<Expression>());
680     ASSERT_EQ(sizeof(AnnotationAllowed<Expression>), SizeOf<AnnotationAllowed<Expression>>());
681     ASSERT_EQ(sizeof(TypeNode), SizeOf<TypeNode>());
682     ASSERT_EQ(sizeof(BlockStatement), SizeOf<BlockStatement>());
683     ASSERT_EQ(sizeof(AnnotationAllowed<BlockStatement>), SizeOf<AnnotationAllowed<BlockStatement>>());
684 }
685 
TEST_F(SizeOfNodeTest,DeclNodesDerived)686 TEST_F(SizeOfNodeTest, DeclNodesDerived)
687 {
688     // IMPORTANT NOTICE: This test purpose is to warn a developer who modified fields of specific node classes.
689     // Classes listed below implements CopyTo/Clone methods.
690     // When you add a new field to a class, make sure you updated corresponding method.
691     // Example: if you added new field to a ClassDefinition class, handle it in ClassDefinition::CopyTo/Clone.
692 
693     ASSERT_EQ(sizeof(ClassDefinition), SizeOf<ClassDefinition>());
694     ASSERT_EQ(sizeof(ClassDeclaration), SizeOf<ClassDeclaration>());
695     ASSERT_EQ(sizeof(ClassProperty), SizeOf<ClassProperty>());
696     ASSERT_EQ(sizeof(MethodDefinition), SizeOf<MethodDefinition>());
697     ASSERT_EQ(sizeof(ScriptFunction), SizeOf<ScriptFunction>());
698     ASSERT_EQ(sizeof(ImportDeclaration), SizeOf<ImportDeclaration>());
699     ASSERT_EQ(sizeof(FunctionDeclaration), SizeOf<FunctionDeclaration>());
700     ASSERT_EQ(sizeof(TSEnumDeclaration), SizeOf<TSEnumDeclaration>());
701     ASSERT_EQ(sizeof(TSInterfaceDeclaration), SizeOf<TSInterfaceDeclaration>());
702     ASSERT_EQ(sizeof(TSTypeAliasDeclaration), SizeOf<TSTypeAliasDeclaration>());
703     ASSERT_EQ(sizeof(VariableDeclaration), SizeOf<VariableDeclaration>());
704 
705     // IMPORTANT NOTICE: This test purpose is to warn a developer who modified fields of specific node classes.
706     // Classes listed below implements CopyTo/Clone methods.
707     // When you add a new field to a class, make sure you updated corresponding method.
708     // Example: if you added new field to a ClassDefinition class, handle it in ClassDefinition::CopyTo/Clone.
709 
710     ASSERT_EQ(sizeof(ETSParameterExpression), SizeOf<ETSParameterExpression>());
711     ASSERT_EQ(sizeof(TSTypeParameter), SizeOf<TSTypeParameter>());
712     ASSERT_EQ(sizeof(TSTypeParameterDeclaration), SizeOf<TSTypeParameterDeclaration>());
713     ASSERT_EQ(sizeof(ETSTypeReference), SizeOf<ETSTypeReference>());
714     ASSERT_EQ(sizeof(ETSTypeReferencePart), SizeOf<ETSTypeReferencePart>());
715     ASSERT_EQ(sizeof(ETSModule), SizeOf<ETSModule>());
716     ASSERT_EQ(sizeof(FunctionExpression), SizeOf<FunctionExpression>());
717     ASSERT_EQ(sizeof(ETSReExportDeclaration), SizeOf<ETSReExportDeclaration>());
718     ASSERT_EQ(sizeof(ETSStructDeclaration), SizeOf<ETSStructDeclaration>());
719     ASSERT_EQ(sizeof(AnnotationDeclaration), SizeOf<AnnotationDeclaration>());
720 }
721 }  // namespace ark::es2panda::ir
722