From 952b899093167a7a79ecbf68a90bcf15b05a1571 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Fri, 18 Sep 2015 13:18:05 -0500 Subject: [PATCH] ICG doesn't handle inherited template classes correctly When a template is in a namespace the type that is marked for the node containing the full definition of the type is elaborated. We need to go into the elaborated name and get the underlying type. Added code to do this and tests to see if the type we are checking is itself a template or the elaborated type is a template. Sorry, this probably only makes sense to me. refs #124 --- .../codegen/Interface_Code_Gen/ClassVisitor.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp index a4941f47..1156286b 100644 --- a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp @@ -122,6 +122,17 @@ bool CXXRecordVisitor::VisitType(clang::Type *t) { return true; } +static bool isTypeTemplateSpecialization(const clang::Type * type_ptr) { + if ( type_ptr->getTypeClass() == clang::Type::TemplateSpecialization ) { + return true ; + } else if ( type_ptr->getTypeClass() == clang::Type::Elaborated ) { + const clang::ElaboratedType * et = type_ptr->getAs() ; + //std::cout << "\ninherited Type = " << et->getNamedType().getTypePtr()->getTypeClassName() << "" << std::endl ; + return et->getNamedType().getTypePtr()->getTypeClass() == clang::Type::TemplateSpecialization ; + } + return false ; +} + bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { if ( debug_level >= 2 ) { rec->dump() ; std::cout << std::endl ; @@ -182,7 +193,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { // If we are inheriting from a template specialization, don't save the inherited class. This list // is maintained to call init_attr of the inherited classes. A template specialization does not have // these attributes. - if ( temp->getTypeClass() != clang::Type::TemplateSpecialization ) { + if ( ! isTypeTemplateSpecialization(temp) ) { // We want to save the inherited class data, but it's going to go out of scope so we need to make // a copy of it. ClassValues * icv = new ClassValues(*(inherit_cvis.get_class_data())) ; @@ -227,7 +238,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { // If we are inheriting from a template specialization, don't save the inherited class. This list // is maintained to call init_attr of the inherited classes. A template specialization does not have // these attributes. - if ( temp->getTypeClass() != clang::Type::TemplateSpecialization ) { + if ( ! isTypeTemplateSpecialization(temp) ) { ClassValues * icv = new ClassValues(*(inherit_cvis.get_class_data())) ; // The inherited classes of this inherted class are not required in the copy, and they are going out of scope icv->clearInheritedClass() ;