-
Notifications
You must be signed in to change notification settings - Fork 35
Implement Demangle and IsClassPolymorphic APIs
#451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,51 @@ | |
| #include "clang/Frontend/CompilerInstance.h" | ||
| #include "clang/Sema/Sema.h" | ||
|
|
||
| #include "clang/AST/DeclBase.h" | ||
| #include "clang/AST/ASTDumper.h" | ||
| #include "clang/AST/Decl.h" | ||
| #include "clang/AST/DeclBase.h" | ||
| #include "clang/AST/GlobalDecl.h" | ||
|
|
||
| #include "llvm/Support/Valgrind.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| using namespace TestUtils; | ||
| using namespace llvm; | ||
| using namespace clang; | ||
|
|
||
| TEST(ScopeReflectionTest, Demangle) { | ||
| if (llvm::sys::RunningOnValgrind()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "llvm::sys::RunningOnValgrind" is directly included [misc-include-cleaner] unittests/CppInterOp/ScopeReflectionTest.cpp:14: + #include <llvm/Support/Valgrind.h> |
||
| GTEST_SKIP() << "XFAIL due to Valgrind report"; | ||
|
|
||
| std::string code = R"( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::string" is directly included [misc-include-cleaner] unittests/CppInterOp/ScopeReflectionTest.cpp:14: + #include <string> |
||
| int add(int x, int y) { return x + y; } | ||
| int add(double x, double y) { return x + y; } | ||
| )"; | ||
|
|
||
| std::vector<Decl*> Decls; | ||
| GetAllTopLevelDecls(code, Decls); | ||
| EXPECT_EQ(Decls.size(), 2); | ||
|
|
||
| auto Add_int = clang::GlobalDecl(static_cast<clang::NamedDecl*>(Decls[0])); | ||
| auto Add_double = clang::GlobalDecl(static_cast<clang::NamedDecl*>(Decls[1])); | ||
|
|
||
| std::string mangled_add_int; | ||
| std::string mangled_add_double; | ||
| compat::maybeMangleDeclName(Add_int, mangled_add_int); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "compat::maybeMangleDeclName" is directly included [misc-include-cleaner] unittests/CppInterOp/ScopeReflectionTest.cpp:3: - #include "clang-c/CXCppInterOp.h"
+ #include "/github/workspace/lib/Interpreter/Compatibility.h"
+ #include "clang-c/CXCppInterOp.h" |
||
| compat::maybeMangleDeclName(Add_double, mangled_add_double); | ||
|
|
||
| std::string demangled_add_int = Cpp::Demangle(mangled_add_int); | ||
| std::string demangled_add_double = Cpp::Demangle(mangled_add_double); | ||
|
|
||
| EXPECT_NE(demangled_add_int.find(Cpp::GetQualifiedCompleteName(Decls[0])), | ||
| std::string::npos); | ||
| EXPECT_NE(demangled_add_double.find(Cpp::GetQualifiedCompleteName(Decls[1])), | ||
| std::string::npos); | ||
| } | ||
|
|
||
| TEST(ScopeReflectionTest, IsAggregate) { | ||
| std::vector<Decl *> Decls; | ||
| std::string code = R"( | ||
|
|
@@ -59,6 +95,28 @@ TEST(ScopeReflectionTest, IsClass) { | |
| EXPECT_FALSE(Cpp::IsClass(Decls[2])); | ||
| } | ||
|
|
||
| TEST(ScopeReflectionTest, IsClassPolymorphic) { | ||
| std::vector<Decl*> Decls; | ||
| GetAllTopLevelDecls(R"( | ||
| namespace N {} | ||
|
|
||
| class C{}; | ||
|
|
||
| class C2 { | ||
| public: | ||
| virtual ~C2() {} | ||
| }; | ||
|
|
||
| int I; | ||
| )", | ||
| Decls); | ||
|
|
||
| EXPECT_FALSE(Cpp::IsClassPolymorphic(Decls[0])); | ||
| EXPECT_FALSE(Cpp::IsClassPolymorphic(Decls[1])); | ||
| EXPECT_TRUE(Cpp::IsClassPolymorphic(Decls[2])); | ||
| EXPECT_FALSE(Cpp::IsClassPolymorphic(Decls[3])); | ||
| } | ||
|
|
||
| TEST(ScopeReflectionTest, IsComplete) { | ||
| std::vector<Decl*> Decls; | ||
| std::string code = R"( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]