mirror of
https://github.com/nasa/trick.git
synced 2024-12-21 06:03:10 +00:00
ba47c2048c
Created a hook for the clang preprocessor. The hook does 2 things. It keeps track to which header files we have entered and exited. Second it searches for the use of TRICK_ICG. If we find an instance of TRICK_ICG we mark all of the included files from this point up the chain as requiring compensation. To compensate for using TRICK_ICG we write out the older offset statements to get the location of variables in classes/structures.
48 lines
1.9 KiB
C++
48 lines
1.9 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.
|
|
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) ;
|
|
|
|
// 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 ;
|
|
} ;
|