Skip to content

Commit

Permalink
Updated to use FileEntryRef to get name instead of FileEntry for clan…
Browse files Browse the repository at this point in the history
…g18+ due the corresponding function is deprecated for the applicable clang versions. (#1792)
  • Loading branch information
hchen99 authored Oct 15, 2024
1 parent 1bdabad commit 48029fe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
5 changes: 4 additions & 1 deletion trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,11 @@ std::set<std::string> 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() ) {
Expand Down
79 changes: 40 additions & 39 deletions trick_source/codegen/Interface_Code_Gen/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::FileEntryRef> 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 <iostream>
Expand Down
2 changes: 1 addition & 1 deletion trick_source/codegen/Interface_Code_Gen/Utilities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion trick_source/codegen/Interface_Code_Gen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48029fe

Please sign in to comment.