Fix io code for classes with excluded parents

Check the return value of CXXRecordVisitor::TraverseCXXRecordDecl and
don't add information from excluded parents.
Add a parameter to PrintAttributes::isHeaderExcluded to toggle exlusion
of TRICK_EXT_LIB_DIRS paths. When traversing a CXX record, we don't
actually want to skip these paths since their io code should exist in
the Trickified library.
Fix memory leak.

Refs #435
This commit is contained in:
Derek Bankieris 2017-05-24 09:57:07 -05:00
parent 56bdafc68b
commit 1dbeb3e2d4
4 changed files with 26 additions and 25 deletions

View File

@ -152,7 +152,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
// Return false to stop processing if this header file is excluded by one of many reasons.
std::string header_file_name = getFileName(ci , rec->RBRACELOC(), hsd) ;
char * rp = almostRealPath(header_file_name.c_str()) ;
if ( rp == NULL || pa.isHeaderExcluded(header_file_name) ) {
if ( rp == NULL || pa.isHeaderExcluded(header_file_name, false) ) {
// mark the header as visited so PrintAttributes doesn't process it during addEmptyFiles()
pa.markHeaderAsVisited(header_file_name);
return false ;
@ -212,26 +212,26 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
//std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ;
//std::cout << " " << getFileName(ci , rd->RBRACELOC(), hsd) << "" << std::endl ;
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescriptions(),
inherit_class_offset, false) ;
// clear the field list in the inherited class so they are not freed when inherit_cvis
// goes out of scope.
inherit_cvis.get_class_data()->clearFieldDescription() ;
// 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
// havethese attributes.
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())) ;
// The inherited classes of this inherited class are not required in the copy,
// and they are going out of scope
cval.saveInheritAncestry(icv) ;
icv->clearInheritedClass() ;
if (inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd))) {
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescriptions(), inherit_class_offset, false) ;
// clear the field list in the inherited class so they are not freed when inherit_cvis
// goes out of scope.
inherit_cvis.get_class_data()->clearFieldDescription() ;
// 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
// havethese attributes.
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())) ;
// The inherited classes of this inherited class are not required in the copy,
// and they are going out of scope
cval.saveInheritAncestry(icv) ;
icv->clearInheritedClass() ;
// Save the copy of the inherited class to the current class
cval.addInheritedClass(inherit_cvis.get_class_data()->getFullyQualifiedTypeName()) ;
// Save the copy of the inherited class to the current class
cval.addInheritedClass(inherit_cvis.get_class_data()->getFullyQualifiedTypeName()) ;
}
}
}
}

View File

@ -155,10 +155,11 @@ void HeaderSearchDirs::AddDirsAndFiles(std::string env_var, std::vector<std::str
std::ifstream file_or_dir(resolved_path) ;
file_or_dir.seekg(0, std::ios::end) ;
if ( !file_or_dir.good()) {
var_list.push_back(std::string(resolved_path) + std::string("/"));
var_list.push_back(std::string(resolved_path) + "/");
} else {
var_list.push_back(std::string(resolved_path));
}
free(resolved_path);
} else {
std::cout << bold(color(WARNING, "Warning")) << " Cannot find " <<
env_var << " path " << quote(bold(item)) << std::endl ;

View File

@ -481,7 +481,7 @@ bool PrintAttributes::isIgnored(ConstructValues& constructValues) {
return ignored;
}
bool PrintAttributes::isHeaderExcluded(const std::string& header) {
bool PrintAttributes::isHeaderExcluded(const std::string& header, bool exclude_ext_libs) {
char* temp = almostRealPath(header.c_str());
if (!temp) {
return true;
@ -494,7 +494,7 @@ bool PrintAttributes::isHeaderExcluded(const std::string& header) {
* - in system directories
* - in TRICK_EXCLUDE directories
* - in TRICK_ICG_EXCLUDE directories
* - in TRICK_EXT_LIB_DIRS directories
* - in TRICK_EXT_LIB_DIRS directories (if requested)
* - whose Trick header comments preclude ICG
*/
if (!hsd.isPathInUserDir(path)) {
@ -515,7 +515,7 @@ bool PrintAttributes::isHeaderExcluded(const std::string& header) {
return true;
}
if (hsd.isPathInExtLib(path)) {
if (hsd.isPathInExtLib(path) && exclude_ext_libs) {
if (verboseBuild) {
std::cout << skipping << "TRICK_EXT_LIB_DIRS: " << underline(path, hsd.getPathInExtLib(path).size()) << std::endl;
}

View File

@ -55,7 +55,7 @@ class PrintAttributes {
/** Prints an enum to the io_src file */
virtual void printEnum( EnumValues * in_enum) ;
bool isHeaderExcluded(const std::string& header);
bool isHeaderExcluded(const std::string& header, bool exclude_ext_libs = true);
void markHeaderAsVisited(const std::string& header);
protected: