PPCallbacks.h revision 41c17473e3ece9e60d97c5d9397866b7730cf7ee
1//===--- PPCallbacks.h - Callbacks for Preprocessor actions -----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the PPCallbacks interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_LEX_PPCALLBACKS_H 15#define LLVM_CLANG_LEX_PPCALLBACKS_H 16 17#include "clang/Lex/DirectoryLookup.h" 18#include "clang/Basic/SourceLocation.h" 19#include <string> 20 21namespace clang { 22 class SourceLocation; 23 class IdentifierInfo; 24 class MacroInfo; 25 26/// PPCallbacks - This interface provides a way to observe the actions of the 27/// preprocessor as it does its thing. Clients can define their hooks here to 28/// implement preprocessor level tools. 29class PPCallbacks { 30public: 31 virtual ~PPCallbacks(); 32 33 enum FileChangeReason { 34 EnterFile, ExitFile, SystemHeaderPragma, RenameFile 35 }; 36 37 /// FileChanged - This callback is invoked whenever a source file is 38 /// entered or exited. The SourceLocation indicates the new location, and 39 /// EnteringFile indicates whether this is because we are entering a new 40 /// #include'd file (when true) or whether we're exiting one because we ran 41 /// off the end (when false). 42 virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, 43 SrcMgr::CharacteristicKind FileType) { 44 } 45 46 /// Ident - This callback is invoked when a #ident or #sccs directive is read. 47 /// 48 virtual void Ident(SourceLocation Loc, const std::string &str) { 49 } 50 51 /// PragmaComment - This callback is invoked when a #pragma comment directive 52 /// is read. 53 /// 54 virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, 55 const std::string &Str) { 56 } 57 58 /// MacroExpands - This is called by 59 /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is 60 /// found. 61 virtual void MacroExpands(const Token &Id, const MacroInfo* MI) { 62 } 63 64 /// MacroDefined - This hook is called whenever a macro definition is seen. 65 virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) { 66 } 67 68 /// MacroUndefined - This hook is called whenever a macro #undef is seen. 69 /// MI is released immediately following this callback. 70 virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) { 71 } 72}; 73 74} // end namespace clang 75 76#endif 77