mirror of
https://github.com/nasa/trick.git
synced 2024-12-19 21:27:54 +00:00
Updated to use FileEntryRef to get name instead of FileEntry for clang18+ due the corresponding function is deprecated for the applicable clang versions. (#1792)
This commit is contained in:
parent
1bdabadcbe
commit
48029fe031
@ -395,8 +395,11 @@ std::set<std::string> PrintAttributes::getEmptyFiles() {
|
|||||||
const clang::FileEntry * fe = (*fi).first ;
|
const clang::FileEntry * fe = (*fi).first ;
|
||||||
#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported
|
#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported
|
||||||
std::string header_file_name = fe->getName() ;
|
std::string header_file_name = fe->getName() ;
|
||||||
#else
|
#elif (LIBCLANG_MAJOR >= 4 && LIBCLANG_MAJOR < 18)
|
||||||
std::string header_file_name = fe->getName().str() ;
|
std::string header_file_name = fe->getName().str() ;
|
||||||
|
#else
|
||||||
|
const clang::FileEntryRef fer = fi->first ;
|
||||||
|
std::string header_file_name = fer.getName().str();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( visited_files.find(header_file_name) != visited_files.end() ) {
|
if ( visited_files.find(header_file_name) != visited_files.end() ) {
|
||||||
|
@ -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 ) {
|
bool isInUserCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
|
||||||
clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
|
|
||||||
bool ret = false ;
|
bool ret = false ;
|
||||||
if ( ! fid.isInvalid() ) {
|
char* resolved_path = getResolvedPath(ci, sl);
|
||||||
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
|
|
||||||
if ( fe != NULL ) {
|
if ( resolved_path != NULL ) {
|
||||||
#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported
|
if ( hsd.isPathInUserDir(resolved_path)) {
|
||||||
char * resolved_path = almostRealPath( fe->getName() ) ;
|
ret = true ;
|
||||||
#else
|
|
||||||
char * resolved_path = almostRealPath( fe->getName().str() ) ;
|
|
||||||
#endif
|
|
||||||
if ( resolved_path != NULL ) {
|
|
||||||
if ( hsd.isPathInUserDir(resolved_path)) {
|
|
||||||
ret = true ;
|
|
||||||
}
|
|
||||||
free(resolved_path) ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
free(resolved_path) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret ;
|
return ret ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
|
bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
|
||||||
clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
|
|
||||||
bool ret = false ;
|
bool ret = false ;
|
||||||
if ( ! fid.isInvalid() ) {
|
char* resolved_path = getResolvedPath(ci, sl);
|
||||||
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
|
|
||||||
if ( fe != NULL ) {
|
if ( resolved_path != NULL ) {
|
||||||
#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported
|
if ( hsd.isPathInUserOrTrickDir(resolved_path)) {
|
||||||
char * resolved_path = almostRealPath( fe->getName() ) ;
|
ret = true ;
|
||||||
#else
|
|
||||||
char * resolved_path = almostRealPath( fe->getName().str() ) ;
|
|
||||||
#endif
|
|
||||||
if ( resolved_path != NULL ) {
|
|
||||||
if ( hsd.isPathInUserOrTrickDir(resolved_path)) {
|
|
||||||
ret = true ;
|
|
||||||
}
|
|
||||||
free(resolved_path) ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
free(resolved_path) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret ;
|
return ret ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
|
std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
|
||||||
clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
|
|
||||||
std::string file_name;
|
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() ) {
|
if ( ! fid.isInvalid() ) {
|
||||||
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
|
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
|
||||||
if ( fe != NULL ) {
|
if ( fe != NULL ) {
|
||||||
#if (LIBCLANG_MAJOR < 4) // TODO delete when RHEL 7 no longer supported
|
#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
|
#else
|
||||||
char * resolved_path = almostRealPath( fe->getName().str() ) ;
|
const clang::CustomizableOptional<clang::FileEntryRef> cfer = ci.getSourceManager().getFileEntryRefForID(fid) ;
|
||||||
|
if (cfer.has_value()) {
|
||||||
|
resolved_path = almostRealPath( cfer->getName().str() ) ;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#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 <iostream>
|
#include <iostream>
|
||||||
|
@ -21,7 +21,7 @@ bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation s
|
|||||||
std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ;
|
std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ;
|
||||||
char * almostRealPath( const std::string& in_path ) ;
|
char * almostRealPath( const std::string& in_path ) ;
|
||||||
char * almostRealPath( const char * 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 color(const Color& color, const std::string& text);
|
||||||
std::string bold(const std::string& text);
|
std::string bold(const std::string& text);
|
||||||
std::string underline(const std::string& text);
|
std::string underline(const std::string& text);
|
||||||
|
@ -312,7 +312,7 @@ int main(int argc, char * argv[]) {
|
|||||||
#if (LIBCLANG_MAJOR >= 10 && LIBCLANG_MAJOR < 18)
|
#if (LIBCLANG_MAJOR >= 10 && LIBCLANG_MAJOR < 18)
|
||||||
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath).get();
|
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath).get();
|
||||||
#elif (LIBCLANG_MAJOR >= 18)
|
#elif (LIBCLANG_MAJOR >= 18)
|
||||||
clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath));
|
const clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath));
|
||||||
#else
|
#else
|
||||||
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath);
|
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user