@@ -600,3 +600,127 @@ TEST(TypeReflectionTest, IsFunctionPointerType) {
600
600
EXPECT_FALSE (
601
601
Cpp::IsFunctionPointerType (Cpp::GetVariableType (Cpp::GetNamed (" i" ))));
602
602
}
603
+
604
+ TEST (TypeReflectionTest, IntegerTypes) {
605
+ Cpp::CreateInterpreter ();
606
+ std::vector<Decl*> Decls;
607
+ std::string code = R"(
608
+ int a;
609
+ int *b;
610
+ double c;
611
+ enum A { x, y };
612
+ A evar = x;
613
+ char k;
614
+ long int l;
615
+ unsigned int m;
616
+ unsigned long n;
617
+ )" ;
618
+
619
+ GetAllTopLevelDecls (code, Decls);
620
+
621
+ EXPECT_TRUE (Cpp::IsIntegerType (Cpp::GetVariableType (Decls[0 ])));
622
+ EXPECT_FALSE (Cpp::IsIntegerType (Cpp::GetVariableType (Decls[1 ])));
623
+ EXPECT_FALSE (Cpp::IsIntegerType (Cpp::GetVariableType (Decls[2 ])));
624
+ EXPECT_TRUE (Cpp::IsIntegerType (Cpp::GetVariableType (Decls[4 ])));
625
+ EXPECT_TRUE (Cpp::IsIntegralType (Cpp::GetVariableType (Decls[5 ])));
626
+ EXPECT_TRUE (Cpp::IsIntegralType (Cpp::GetVariableType (Decls[6 ])));
627
+ EXPECT_TRUE (Cpp::IsUnsignedIntegerType (Cpp::GetVariableType (Decls[7 ])));
628
+ EXPECT_FALSE (Cpp::IsSignedIntegerType (Cpp::GetVariableType (Decls[8 ])));
629
+ }
630
+
631
+ TEST (TypeReflectionTest, VoidPtrType) {
632
+ Cpp::CreateInterpreter ();
633
+ std::vector<Decl*> Decls;
634
+ std::string code = R"(
635
+ class A {};
636
+ using VoidPtrType = void*;
637
+ VoidPtrType a = nullptr;
638
+ void * b = nullptr;
639
+ A *pa = nullptr;
640
+ )" ;
641
+
642
+ GetAllTopLevelDecls (code, Decls);
643
+
644
+ EXPECT_EQ (Cpp::GetTypeAsString (Cpp::GetVariableType (Decls[2 ])), " VoidPtrType" );
645
+ EXPECT_TRUE (Cpp::IsVoidPointerType (Cpp::GetVariableType (Decls[2 ])));
646
+ EXPECT_TRUE (Cpp::IsVoidPointerType (Cpp::GetVariableType (Decls[3 ])));
647
+ EXPECT_FALSE (Cpp::IsVoidPointerType (Cpp::GetVariableType (Decls[4 ])));
648
+ }
649
+
650
+ TEST (TypeReflectionTest, IsSameType) {
651
+ Cpp::CreateInterpreter ();
652
+ std::vector<Decl*> Decls;
653
+
654
+ std::string code = R"(
655
+ #include <cstdarg>
656
+ #include <iostream>
657
+
658
+ typedef std::va_list VaListAlias;
659
+ std::va_list va1;
660
+ VaListAlias va2;
661
+
662
+ const int ci = 0;
663
+ int const ic = 0;
664
+
665
+ signed int si1 = 0;
666
+ int si2 = 0;
667
+
668
+ void *x;
669
+ )" ;
670
+
671
+
672
+ GetAllTopLevelDecls (code, Decls);
673
+
674
+ #include < iostream>
675
+
676
+ ASTContext &Ctxt = Interp->getCI ()->getASTContext ();
677
+
678
+ Decls.assign (Decls.end () - 8 , Decls.end ());
679
+
680
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" bool" ), Ctxt.BoolTy .getAsOpaquePtr ()));
681
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" float" ), Ctxt.FloatTy .getAsOpaquePtr ()));
682
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" long" ), Ctxt.LongTy .getAsOpaquePtr ()));
683
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" long long" ), Ctxt.LongLongTy .getAsOpaquePtr ()));
684
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" short" ), Ctxt.ShortTy .getAsOpaquePtr ()));
685
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" char" ), Ctxt.SignedCharTy .getAsOpaquePtr ()));
686
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" unsigned char" ), Ctxt.UnsignedCharTy .getAsOpaquePtr ()));
687
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetType (" unsigned int" ), Ctxt.UnsignedIntTy .getAsOpaquePtr ()));
688
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetVariableType (Decls[7 ]), Ctxt.VoidPtrTy .getAsOpaquePtr ()));
689
+
690
+ // Expect the typedef to std::va_list to be the same type
691
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetVariableType (Decls[1 ]), Cpp::GetVariableType (Decls[2 ])));
692
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetVariableType (Decls[3 ]), Cpp::GetVariableType (Decls[4 ])));
693
+ EXPECT_TRUE (Cpp::IsSameType (Cpp::GetVariableType (Decls[5 ]), Cpp::GetVariableType (Decls[6 ])));
694
+ }
695
+
696
+ TEST (VariableReflectionTest, Is_Get_Reference) {
697
+ Cpp::CreateInterpreter ();
698
+ std::vector<Decl*> Decls;
699
+ std::string code = R"(
700
+ class A {};
701
+ int a;
702
+ int &b = a;
703
+ double c;
704
+ double &d = c;
705
+ A e;
706
+ A &f = e;
707
+ )" ;
708
+
709
+ GetAllTopLevelDecls (code, Decls);
710
+
711
+ EXPECT_FALSE (Cpp::IsReferenceType (Cpp::GetVariableType (Decls[1 ])));
712
+ EXPECT_TRUE (Cpp::IsReferenceType (Cpp::GetVariableType (Decls[2 ])));
713
+ EXPECT_FALSE (Cpp::IsReferenceType (Cpp::GetVariableType (Decls[3 ])));
714
+ EXPECT_TRUE (Cpp::IsReferenceType (Cpp::GetVariableType (Decls[4 ])));
715
+ EXPECT_FALSE (Cpp::IsReferenceType (Cpp::GetVariableType (Decls[5 ])));
716
+ EXPECT_TRUE (Cpp::IsReferenceType (Cpp::GetVariableType (Decls[6 ])));
717
+
718
+ EXPECT_EQ (Cpp::GetNonReferenceType (Cpp::GetVariableType (Decls[2 ])),
719
+ Cpp::GetVariableType (Decls[1 ]));
720
+ EXPECT_EQ (Cpp::GetNonReferenceType (Cpp::GetVariableType (Decls[4 ])),
721
+ Cpp::GetVariableType (Decls[3 ]));
722
+ EXPECT_EQ (Cpp::GetNonReferenceType (Cpp::GetVariableType (Decls[6 ])),
723
+ Cpp::GetVariableType (Decls[5 ]));
724
+
725
+ EXPECT_FALSE (Cpp::GetNonReferenceType (Cpp::GetVariableType (Decls[5 ])));
726
+ }
0 commit comments