diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index 758a84cd..5d443163 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -395,8 +395,11 @@ std::set PrintAttributes::getEmptyFiles() { const clang::FileEntry * fe = (*fi).first ; #if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported std::string header_file_name = fe->getName() ; -#else +#elif (LIBCLANG_MAJOR >= 4 && LIBCLANG_MAJOR < 18) std::string header_file_name = fe->getName().str() ; +#else + const clang::FileEntryRef fer = fi->first ; + std::string header_file_name = fer.getName().str(); #endif if ( visited_files.find(header_file_name) != visited_files.end() ) { diff --git a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp index 39bec7d5..11080f27 100644 --- a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp +++ b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp @@ -66,68 +66,69 @@ std::string trim(const std::string& str, const std::string& whitespace ) { } bool isInUserCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) { - clang::FileID fid = ci.getSourceManager().getFileID(sl) ; bool ret = false ; - if ( ! fid.isInvalid() ) { - const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ; - if ( fe != NULL ) { -#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported - char * resolved_path = almostRealPath( fe->getName() ) ; -#else - char * resolved_path = almostRealPath( fe->getName().str() ) ; -#endif - if ( resolved_path != NULL ) { - if ( hsd.isPathInUserDir(resolved_path)) { - ret = true ; - } - free(resolved_path) ; - } + char* resolved_path = getResolvedPath(ci, sl); + + if ( resolved_path != NULL ) { + if ( hsd.isPathInUserDir(resolved_path)) { + ret = true ; } + free(resolved_path) ; } + return ret ; } bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) { - clang::FileID fid = ci.getSourceManager().getFileID(sl) ; bool ret = false ; - if ( ! fid.isInvalid() ) { - const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ; - if ( fe != NULL ) { -#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported - char * resolved_path = almostRealPath( fe->getName() ) ; -#else - char * resolved_path = almostRealPath( fe->getName().str() ) ; -#endif - if ( resolved_path != NULL ) { - if ( hsd.isPathInUserOrTrickDir(resolved_path)) { - ret = true ; - } - free(resolved_path) ; - } + char* resolved_path = getResolvedPath(ci, sl); + + if ( resolved_path != NULL ) { + if ( hsd.isPathInUserOrTrickDir(resolved_path)) { + ret = true ; } + free(resolved_path) ; } + return ret ; } std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) { - clang::FileID fid = ci.getSourceManager().getFileID(sl) ; std::string file_name; - char* resolved_path; + char* resolved_path = getResolvedPath(ci, sl); + + if (resolved_path != NULL ) { + if (hsd.isPathInUserDir(resolved_path)) { + file_name.append(resolved_path); + } + free(resolved_path); + } + + return file_name; +} + +char * getResolvedPath(clang::CompilerInstance & ci , clang::SourceLocation sl) { + clang::FileID fid = ci.getSourceManager().getFileID(sl) ; + char* resolved_path = NULL; + if ( ! fid.isInvalid() ) { const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ; if ( fe != NULL ) { #if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported - char * resolved_path = almostRealPath( fe->getName() ) ; + resolved_path = almostRealPath( fe->getName() ) ; +#elif (LIBCLANG_MAJOR >= 4 && LIBCLANG_MAJOR < 18) + resolved_path = almostRealPath( fe->getName().str() ) ; #else - char * resolved_path = almostRealPath( fe->getName().str() ) ; + const clang::CustomizableOptional cfer = ci.getSourceManager().getFileEntryRefForID(fid) ; + if (cfer.has_value()) { + resolved_path = almostRealPath( cfer->getName().str() ) ; + } + #endif - if ( resolved_path != NULL and hsd.isPathInUserDir(resolved_path)) { - file_name.append(resolved_path); - } - free(resolved_path); } } - return file_name; + + return resolved_path; } #include diff --git a/trick_source/codegen/Interface_Code_Gen/Utilities.hh b/trick_source/codegen/Interface_Code_Gen/Utilities.hh index 6fcfe13d..90491c0c 100644 --- a/trick_source/codegen/Interface_Code_Gen/Utilities.hh +++ b/trick_source/codegen/Interface_Code_Gen/Utilities.hh @@ -21,7 +21,7 @@ bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation s std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ; char * almostRealPath( const std::string& in_path ) ; char * almostRealPath( const char * in_path ) ; - +char * getResolvedPath(clang::CompilerInstance & ci , clang::SourceLocation sl); std::string color(const Color& color, const std::string& text); std::string bold(const std::string& text); std::string underline(const std::string& text); diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index 84380329..41d26c4a 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -312,7 +312,7 @@ int main(int argc, char * argv[]) { #if (LIBCLANG_MAJOR >= 10 && LIBCLANG_MAJOR < 18) const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath).get(); #elif (LIBCLANG_MAJOR >= 18) - clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath)); + const clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath)); #else const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath); #endif