Skip to content

Commit

Permalink
[v0.0.3] Fix of duplicates in type aliases (removed extra visitors) +…
Browse files Browse the repository at this point in the history
… added test for this case.
  • Loading branch information
DronCode committed Mar 19, 2024
1 parent c3e1966 commit f4b8da1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
4 changes: 0 additions & 4 deletions LLVM/include/RG3/LLVM/Visitors/CxxTypeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace rg3::llvm::visitors

bool VisitCXXRecordDecl(clang::CXXRecordDecl* cxxRecordDecl);

bool VisitTypedefDecl(clang::TypedefDecl* typedefDecl);

bool VisitTypeAliasDecl(clang::TypeAliasDecl* typeAliasDecl);

bool VisitTypedefNameDecl(clang::TypedefNameDecl* typedefNameDecl);

private:
Expand Down
10 changes: 0 additions & 10 deletions LLVM/source/Visitors/CxxTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,6 @@ namespace rg3::llvm::visitors
};
}

bool CxxTypeVisitor::VisitTypedefDecl(clang::TypedefDecl* typedefDecl)
{
return HandleNamedTypedefDecl(::llvm::dyn_cast<clang::TypedefNameDecl>(typedefDecl));
}

bool CxxTypeVisitor::VisitTypeAliasDecl(clang::TypeAliasDecl* typeAliasDecl)
{
return HandleNamedTypedefDecl(::llvm::dyn_cast<clang::TypedefNameDecl>(typeAliasDecl));
}

bool CxxTypeVisitor::VisitTypedefNameDecl(clang::TypedefNameDecl* typedefNameDecl)
{
return HandleNamedTypedefDecl(typedefNameDecl);
Expand Down
27 changes: 27 additions & 0 deletions Tests/Unit/source/Tests_TypeAliasing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ class Tests_TypeAliasing : public ::testing::Test
std::unique_ptr<rg3::llvm::CodeAnalyzer> g_Analyzer { nullptr };
};

TEST_F(Tests_TypeAliasing, CheckSingleReg)
{
g_Analyzer->setSourceCode(R"(
template <typename T> struct FakeT;
namespace gg {
/// @runtime
using f32 = float;
}
)");

g_Analyzer->getCompilerConfig().cppStandard = rg3::llvm::CxxStandard::CC_17;

const auto analyzeResult = g_Analyzer->analyze();

// expected to have 8 aliases
ASSERT_TRUE(analyzeResult.vIssues.empty()) << "No issues should be here";
ASSERT_EQ(analyzeResult.vFoundTypes.size(), 1) << "Only 1 type should be here";

ASSERT_EQ(analyzeResult.vFoundTypes[0]->getKind(), rg3::cpp::TypeKind::TK_ALIAS);
ASSERT_EQ(analyzeResult.vFoundTypes[0]->getName(), "f32");
ASSERT_EQ(analyzeResult.vFoundTypes[0]->getPrettyName(), "gg::f32");

auto asAlias = static_cast<const rg3::cpp::TypeAlias*>(analyzeResult.vFoundTypes[0].get()); // NOLINT(*-pro-type-static-cast-downcast)
ASSERT_EQ(asAlias->getTargetType().getRefName(), "float");
}

TEST_F(Tests_TypeAliasing, CheckTrivialTypeAliasing)
{
g_Analyzer->setSourceCode(R"(
Expand Down

0 comments on commit f4b8da1

Please sign in to comment.