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