@@ -614,6 +614,29 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
614
614
return true ;
615
615
}
616
616
617
+ // / Pointer to the array(not the element!) must be on the stack when calling
618
+ // / this.
619
+ template <class Emitter >
620
+ bool ByteCodeExprGen<Emitter>::visitArrayElemInit(unsigned ElemIndex,
621
+ const Expr *Init) {
622
+ if (std::optional<PrimType> T = classify (Init->getType ())) {
623
+ // Visit the primitive element like normal.
624
+ if (!this ->visit (Init))
625
+ return false ;
626
+ return this ->emitInitElem (*T, ElemIndex, Init);
627
+ }
628
+
629
+ // Advance the pointer currently on the stack to the given
630
+ // dimension.
631
+ if (!this ->emitConstUint32 (ElemIndex, Init))
632
+ return false ;
633
+ if (!this ->emitArrayElemPtrUint32 (Init))
634
+ return false ;
635
+ if (!this ->visitInitializer (Init))
636
+ return false ;
637
+ return this ->emitPopPtr (Init);
638
+ }
639
+
617
640
template <class Emitter >
618
641
bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
619
642
// Handle discarding first.
@@ -642,25 +665,8 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
642
665
// FIXME: Array fillers.
643
666
unsigned ElementIndex = 0 ;
644
667
for (const Expr *Init : E->inits ()) {
645
- if (std::optional<PrimType> T = classify (Init->getType ())) {
646
- // Visit the primitive element like normal.
647
- if (!this ->visit (Init))
648
- return false ;
649
- if (!this ->emitInitElem (*T, ElementIndex, Init))
650
- return false ;
651
- } else {
652
- // Advance the pointer currently on the stack to the given
653
- // dimension.
654
- if (!this ->emitConstUint32 (ElementIndex, Init))
655
- return false ;
656
- if (!this ->emitArrayElemPtrUint32 (Init))
657
- return false ;
658
- if (!this ->visitInitializer (Init))
659
- return false ;
660
- if (!this ->emitPopPtr (Init))
661
- return false ;
662
- }
663
-
668
+ if (!this ->visitArrayElemInit (ElementIndex, Init))
669
+ return false ;
664
670
++ElementIndex;
665
671
}
666
672
return true ;
@@ -831,7 +837,6 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
831
837
const Expr *SubExpr = E->getSubExpr ();
832
838
const Expr *CommonExpr = E->getCommonExpr ();
833
839
size_t Size = E->getArraySize ().getZExtValue ();
834
- std::optional<PrimType> ElemT = classify (SubExpr->getType ());
835
840
836
841
// If the common expression is an opaque expression, we visit it
837
842
// here once so we have its value cached.
@@ -848,22 +853,8 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
848
853
ArrayIndexScope<Emitter> IndexScope (this , I);
849
854
BlockScope<Emitter> BS (this );
850
855
851
- if (ElemT) {
852
- if (!this ->visit (SubExpr))
853
- return false ;
854
- if (!this ->emitInitElem (*ElemT, I, E))
855
- return false ;
856
- } else {
857
- // Get to our array element and recurse into visitInitializer()
858
- if (!this ->emitConstUint64 (I, SubExpr))
859
- return false ;
860
- if (!this ->emitArrayElemPtrUint64 (SubExpr))
861
- return false ;
862
- if (!visitInitializer (SubExpr))
863
- return false ;
864
- if (!this ->emitPopPtr (E))
865
- return false ;
866
- }
856
+ if (!this ->visitArrayElemInit (I, SubExpr))
857
+ return false ;
867
858
}
868
859
return true ;
869
860
}
0 commit comments