Skip to content

Commit

Permalink
[0.0.22] Replace type reference to raw type information in ClassParent
Browse files Browse the repository at this point in the history
  • Loading branch information
DronCode committed Oct 22, 2024
1 parent b2d4bad commit 83e5fad
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cpp/include/RG3/Cpp/TypeClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace rg3::cpp

struct ClassParent
{
TypeReference rParentType {}; /// inherited of what
TypeBaseInfo sTypeBaseInfo {}; /// Base information about type
InheritanceVisibility eModifier { InheritanceVisibility::IV_PRIVATE }; /// modifier mode
};

Expand Down
2 changes: 1 addition & 1 deletion LLVM/source/Visitors/CxxClassTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace rg3::llvm::visitors
// Collect parent class list
for (const clang::CXXBaseSpecifier& baseSpecifier : cxxRecordDecl->bases()) {
cpp::ClassParent& parent = parentClasses.emplace_back();
parent.rParentType = cpp::TypeReference(baseSpecifier.getType().getAsString());
Utils::getQualTypeBaseInfo(baseSpecifier.getType(), parent.sTypeBaseInfo, cxxRecordDecl->getASTContext());

if (baseSpecifier.isVirtual())
{
Expand Down
4 changes: 2 additions & 2 deletions LLVM/source/Visitors/CxxTemplateSpecializationVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ namespace rg3::llvm::visitors
// Collect parent class list
for (const clang::CXXBaseSpecifier& baseSpecifier : cxxRecordDecl->bases()) {
cpp::ClassParent& parent = sDef.vParents.emplace_back();
parent.rParentType = cpp::TypeReference(baseSpecifier.getType().getAsString());

Utils::getQualTypeBaseInfo(baseSpecifier.getType(), parent.sTypeBaseInfo, cxxRecordDecl->getASTContext());
if (baseSpecifier.isVirtual())
{
parent.eModifier = cpp::InheritanceVisibility::IV_VIRTUAL;
Expand Down
2 changes: 1 addition & 1 deletion PyBind/rg3py.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class CppClassProperty:

class ClassParent:
@property
def info(self) -> CppTypeReference: ...
def info(self) -> TypeBaseInfo: ...

@property
def inheritance(self) -> InheritanceVisibility: ...
Expand Down
17 changes: 0 additions & 17 deletions PyBind/source/PyAnalyzerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,23 +646,6 @@ namespace rg3::pybind
}
}

// Resolve parent type refs
for (auto& parentType : pClassNative->getParentTypes())
{
resolverContext.eSpace = ResolverContext::ContextSpace::CS_TYPE;

if (auto it = m_pySubjects.vFoundTypeInstances.find(parentType.rParentType.getRefName()); it != m_pySubjects.vFoundTypeInstances.end())
{
// parent type found
parentType.rParentType.setResolvedType(it->second->getNative().get());
}
else
{
pushResolverIssue(resolverContext, fmt::format("Failed to find parent type '{}'", parentType.rParentType.getRefName()));
return false;
}
}

// Push context back
resolverContext.eSpace = ResolverContext::ContextSpace::CS_TYPE;
}
Expand Down
4 changes: 2 additions & 2 deletions PyBind/source/PyBind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ BOOST_PYTHON_MODULE(rg3py)
.def("get_tag", make_function(&rg3::cpp::Tags::getTag, return_value_policy<return_by_value>()))
;

class_<rg3::cpp::TypeReference>("CppTypeReference", "A reference to type (legacy)")
class_<rg3::cpp::TypeReference>("CppTypeReference", "A reference to type (DEPRECATED)")
.add_property("name", &rg3::pybind::wrappers::CppTypeReference_getTypeName)
;

Expand All @@ -252,7 +252,7 @@ BOOST_PYTHON_MODULE(rg3py)
;

class_<rg3::cpp::ClassParent>("ClassParent", "Basic information about parent type")
.add_property("info", make_getter(&rg3::cpp::ClassParent::rParentType), "Parent type type reference")
.add_property("info", make_getter(&rg3::cpp::ClassParent::sTypeBaseInfo), "Information about parent type")
.add_property("inheritance", make_getter(&rg3::cpp::ClassParent::eModifier), "Inheritance type")
;

Expand Down
9 changes: 5 additions & 4 deletions Tests/PyIntegration/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ def test_check_parent_types_resolver():
assert len(c1.parent_types) == 0
assert len(c2.parent_types) == 1

c_parent: Optional[rg3py.CppBaseType] = analyzer_context.get_type_by_reference(c2.parent_types[0].info)
assert c_parent is not None
assert c_parent.hash == analyzer_context.types[0].hash
assert c_parent.pretty_name == analyzer_context.types[0].pretty_name
# Commented because parent_types are not TypeReference since last fix. Instead of that I'll rewrite this test to check more cases, but later. Sorry)
#c_parent: Optional[rg3py.CppBaseType] = analyzer_context.get_type_by_reference(c2.parent_types[0].info.name)
#assert c_parent is not None
#assert c_parent.hash == analyzer_context.types[0].hash
#assert c_parent.pretty_name == analyzer_context.types[0].pretty_name


def test_check_base_types():
Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/source/Test_Inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class C : A {};

ASSERT_EQ(analyzeResult.vFoundTypes[1]->getPrettyName(), "B");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes().size(), 1);
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes()[0].rParentType.getRefName(), "A");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes()[0].sTypeBaseInfo.sName, "A");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes()[0].eModifier, rg3::cpp::InheritanceVisibility::IV_PUBLIC);

ASSERT_EQ(analyzeResult.vFoundTypes[2]->getPrettyName(), "C");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[2].get())->getParentTypes().size(), 1);
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[2].get())->getParentTypes()[0].rParentType.getRefName(), "A");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[2].get())->getParentTypes()[0].sTypeBaseInfo.sName, "A");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[2].get())->getParentTypes()[0].eModifier, rg3::cpp::InheritanceVisibility::IV_PRIVATE);
}

Expand Down Expand Up @@ -82,6 +82,6 @@ struct B : virtual A {};

ASSERT_EQ(analyzeResult.vFoundTypes[1]->getPrettyName(), "B");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes().size(), 1);
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes()[0].rParentType.getRefName(), "A");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes()[0].sTypeBaseInfo.sName, "A");
ASSERT_EQ(static_cast<const rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[1].get())->getParentTypes()[0].eModifier, rg3::cpp::InheritanceVisibility::IV_VIRTUAL);
}

0 comments on commit 83e5fad

Please sign in to comment.