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