trick/trick_source/codegen/Interface_Code_Gen/FindTrickICG.hh
Alex Lin f412125715 Is Trick ICG missing some uses of TRICK_ICG #608
Yes, it is, it's missing all of them.  Any clang/llvm version 3.5 and
above.  So it's been broken for a while.  We inherit from a
clang class that processes preprocessing statements.  If we override
virtual functions of a certain signature, we can inject our code into
the preprocessing process.  In this case we're looking for the use
of TRICK_ICG.  Clang changed the function signature in version 3.5.
From 3.5 on our functions were never called, so we never would find
TRICK_ICG.  I created new signatures for the functions post 3.5 so
they will work again.
2018-04-23 16:40:32 -05:00

55 lines
2.5 KiB
C++

#include <vector>
#include <string>
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/PPCallbacks.h"
#include "HeaderSearchDirs.hh"
/*
FindTrickICG searches preprocessor directives #if/#elif/#ifdef/#ifndef to see if they use TRICK_ICG
If they do reference TRICK_ICG we need to mark the stack of incude files that include the TRICK_ICG.
We also print a warning to the screen where the TRICK_ICG was found.
*/
class FindTrickICG : public clang::PPCallbacks {
public:
FindTrickICG(clang::CompilerInstance & in_ci , HeaderSearchDirs & in_hsd , bool in_print_msgs ) ;
// called when the file changes for a variety of reasons.
virtual void FileChanged(clang::SourceLocation Loc, FileChangeReason Reason,
clang::SrcMgr::CharacteristicKind FileType,
clang::FileID PrevFID = clang::FileID()) ;
// callbacks called when the preprocessor directives of types are processed.
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) ;
virtual void ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) ;
virtual void Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) ;
virtual void Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) ;
#else
virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) ;
virtual void ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) ;
virtual void Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) ;
virtual void Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) ;
#endif
// print a warning about using TRICK_ICG.
void print_header() ;
private:
// compiler instance to help locating file names
clang::CompilerInstance & ci ;
HeaderSearchDirs & hsd ;
// Are we printing warning messages?
bool print_msgs ;
// Have we printed the big warning about TRICK_ICG?
bool header_printed ;
// Using a vector as a stack to hold the stack of included headers we have entered.
std::vector<std::string> included_files ;
} ;