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