mirror of
https://github.com/nasa/trick.git
synced 2025-06-15 05:38:19 +00:00
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:
@ -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.
|
// 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) ;
|
std::string header_file_name = getFileName(ci , rec->RBRACELOC(), hsd) ;
|
||||||
char * rp = almostRealPath(header_file_name.c_str()) ;
|
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()
|
// mark the header as visited so PrintAttributes doesn't process it during addEmptyFiles()
|
||||||
pa.markHeaderAsVisited(header_file_name);
|
pa.markHeaderAsVisited(header_file_name);
|
||||||
return false ;
|
return false ;
|
||||||
@ -212,26 +212,26 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
//std::cout << " [34minherit_class_offset = " << inherit_class_offset << "[00m" << std::endl ;
|
//std::cout << " [34minherit_class_offset = " << inherit_class_offset << "[00m" << std::endl ;
|
||||||
//std::cout << " [34m" << getFileName(ci , rd->RBRACELOC(), hsd) << "[00m" << std::endl ;
|
//std::cout << " [34m" << getFileName(ci , rd->RBRACELOC(), hsd) << "[00m" << std::endl ;
|
||||||
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
||||||
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
if (inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd))) {
|
||||||
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescriptions(),
|
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescriptions(), inherit_class_offset, false) ;
|
||||||
inherit_class_offset, false) ;
|
// clear the field list in the inherited class so they are not freed when inherit_cvis
|
||||||
// clear the field list in the inherited class so they are not freed when inherit_cvis
|
// goes out of scope.
|
||||||
// goes out of scope.
|
inherit_cvis.get_class_data()->clearFieldDescription() ;
|
||||||
inherit_cvis.get_class_data()->clearFieldDescription() ;
|
// If we are inheriting from a template specialization, don't save the inherited class. This list
|
||||||
// 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
|
||||||
// is maintained to call init_attr of the inherited classes. A template specialization does not
|
// havethese attributes.
|
||||||
// havethese attributes.
|
if ( ! isTypeTemplateSpecialization(temp) ) {
|
||||||
if ( ! isTypeTemplateSpecialization(temp) ) {
|
// We want to save the inherited class data, but it's going to go out of scope so we need
|
||||||
// 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.
|
||||||
// to make a copy of it.
|
ClassValues * icv = new ClassValues(*(inherit_cvis.get_class_data())) ;
|
||||||
ClassValues * icv = new ClassValues(*(inherit_cvis.get_class_data())) ;
|
// The inherited classes of this inherited class are not required in the copy,
|
||||||
// The inherited classes of this inherited class are not required in the copy,
|
// and they are going out of scope
|
||||||
// and they are going out of scope
|
cval.saveInheritAncestry(icv) ;
|
||||||
cval.saveInheritAncestry(icv) ;
|
icv->clearInheritedClass() ;
|
||||||
icv->clearInheritedClass() ;
|
|
||||||
|
|
||||||
// Save the copy of the inherited class to the current class
|
// Save the copy of the inherited class to the current class
|
||||||
cval.addInheritedClass(inherit_cvis.get_class_data()->getFullyQualifiedTypeName()) ;
|
cval.addInheritedClass(inherit_cvis.get_class_data()->getFullyQualifiedTypeName()) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,10 +155,11 @@ void HeaderSearchDirs::AddDirsAndFiles(std::string env_var, std::vector<std::str
|
|||||||
std::ifstream file_or_dir(resolved_path) ;
|
std::ifstream file_or_dir(resolved_path) ;
|
||||||
file_or_dir.seekg(0, std::ios::end) ;
|
file_or_dir.seekg(0, std::ios::end) ;
|
||||||
if ( !file_or_dir.good()) {
|
if ( !file_or_dir.good()) {
|
||||||
var_list.push_back(std::string(resolved_path) + std::string("/"));
|
var_list.push_back(std::string(resolved_path) + "/");
|
||||||
} else {
|
} else {
|
||||||
var_list.push_back(std::string(resolved_path));
|
var_list.push_back(std::string(resolved_path));
|
||||||
}
|
}
|
||||||
|
free(resolved_path);
|
||||||
} else {
|
} else {
|
||||||
std::cout << bold(color(WARNING, "Warning")) << " Cannot find " <<
|
std::cout << bold(color(WARNING, "Warning")) << " Cannot find " <<
|
||||||
env_var << " path " << quote(bold(item)) << std::endl ;
|
env_var << " path " << quote(bold(item)) << std::endl ;
|
||||||
|
@ -481,7 +481,7 @@ bool PrintAttributes::isIgnored(ConstructValues& constructValues) {
|
|||||||
return ignored;
|
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());
|
char* temp = almostRealPath(header.c_str());
|
||||||
if (!temp) {
|
if (!temp) {
|
||||||
return true;
|
return true;
|
||||||
@ -494,7 +494,7 @@ bool PrintAttributes::isHeaderExcluded(const std::string& header) {
|
|||||||
* - in system directories
|
* - in system directories
|
||||||
* - in TRICK_EXCLUDE directories
|
* - in TRICK_EXCLUDE directories
|
||||||
* - in TRICK_ICG_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
|
* - whose Trick header comments preclude ICG
|
||||||
*/
|
*/
|
||||||
if (!hsd.isPathInUserDir(path)) {
|
if (!hsd.isPathInUserDir(path)) {
|
||||||
@ -515,7 +515,7 @@ bool PrintAttributes::isHeaderExcluded(const std::string& header) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hsd.isPathInExtLib(path)) {
|
if (hsd.isPathInExtLib(path) && exclude_ext_libs) {
|
||||||
if (verboseBuild) {
|
if (verboseBuild) {
|
||||||
std::cout << skipping << "TRICK_EXT_LIB_DIRS: " << underline(path, hsd.getPathInExtLib(path).size()) << std::endl;
|
std::cout << skipping << "TRICK_EXT_LIB_DIRS: " << underline(path, hsd.getPathInExtLib(path).size()) << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class PrintAttributes {
|
|||||||
/** Prints an enum to the io_src file */
|
/** Prints an enum to the io_src file */
|
||||||
virtual void printEnum( EnumValues * in_enum) ;
|
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);
|
void markHeaderAsVisited(const std::string& header);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Reference in New Issue
Block a user