PPCallbacks.h revision 198092
18499SN/A//===--- PPCallbacks.h - Callbacks for Preprocessor actions -----*- C++ -*-===// 212104Sddehaven// 38499SN/A// The LLVM Compiler Infrastructure 48499SN/A// 58499SN/A// This file is distributed under the University of Illinois Open Source 68499SN/A// License. See LICENSE.TXT for details. 78499SN/A// 88499SN/A//===----------------------------------------------------------------------===// 98499SN/A// 108499SN/A// This file defines the PPCallbacks interface. 118499SN/A// 128499SN/A//===----------------------------------------------------------------------===// 138499SN/A 148499SN/A#ifndef LLVM_CLANG_LEX_PPCALLBACKS_H 158499SN/A#define LLVM_CLANG_LEX_PPCALLBACKS_H 168499SN/A 178499SN/A#include "clang/Lex/DirectoryLookup.h" 188499SN/A#include "clang/Basic/SourceLocation.h" 198499SN/A#include <string> 208499SN/A 218499SN/Anamespace clang { 228499SN/A class SourceLocation; 238499SN/A class Token; 248499SN/A class IdentifierInfo; 258499SN/A class MacroInfo; 268499SN/A 278499SN/A/// PPCallbacks - This interface provides a way to observe the actions of the 288499SN/A/// preprocessor as it does its thing. Clients can define their hooks here to 298499SN/A/// implement preprocessor level tools. 308499SN/Aclass PPCallbacks { 318499SN/Apublic: 328499SN/A virtual ~PPCallbacks(); 338499SN/A 348499SN/A enum FileChangeReason { 358499SN/A EnterFile, ExitFile, SystemHeaderPragma, RenameFile 368499SN/A }; 378499SN/A 388499SN/A /// FileChanged - This callback is invoked whenever a source file is 398499SN/A /// entered or exited. The SourceLocation indicates the new location, and 4017102Sprr /// EnteringFile indicates whether this is because we are entering a new 418499SN/A /// #include'd file (when true) or whether we're exiting one because we ran 428499SN/A /// off the end (when false). 438499SN/A virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, 448499SN/A SrcMgr::CharacteristicKind FileType) { 458499SN/A } 468499SN/A 478499SN/A /// Ident - This callback is invoked when a #ident or #sccs directive is read. 488499SN/A /// 498499SN/A virtual void Ident(SourceLocation Loc, const std::string &str) { 508499SN/A } 518499SN/A 528499SN/A /// PragmaComment - This callback is invoked when a #pragma comment directive 538499SN/A /// is read. 548499SN/A /// 558499SN/A virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, 568499SN/A const std::string &Str) { 578499SN/A } 588499SN/A 598499SN/A /// MacroExpands - This is called by 608499SN/A /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is 618499SN/A /// found. 628499SN/A virtual void MacroExpands(const Token &Id, const MacroInfo* MI) { 638499SN/A } 648499SN/A 658499SN/A /// MacroDefined - This hook is called whenever a macro definition is seen. 668499SN/A virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) { 678499SN/A } 688499SN/A 698499SN/A /// MacroUndefined - This hook is called whenever a macro #undef is seen. 708499SN/A /// MI is released immediately following this callback. 718499SN/A virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) { 728499SN/A } 738499SN/A}; 748499SN/A 758499SN/A/// PPChainedCallbacks - Simple wrapper class for chaining callbacks. 768499SN/Aclass PPChainedCallbacks : public PPCallbacks { 778499SN/A PPCallbacks *First, *Second; 78 79public: 80 PPChainedCallbacks(PPCallbacks *_First, PPCallbacks *_Second) 81 : First(_First), Second(_Second) {} 82 ~PPChainedCallbacks() { 83 delete Second; 84 delete First; 85 } 86 87 virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, 88 SrcMgr::CharacteristicKind FileType) { 89 First->FileChanged(Loc, Reason, FileType); 90 Second->FileChanged(Loc, Reason, FileType); 91 } 92 93 virtual void Ident(SourceLocation Loc, const std::string &str) { 94 First->Ident(Loc, str); 95 Second->Ident(Loc, str); 96 } 97 98 virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, 99 const std::string &Str) { 100 First->PragmaComment(Loc, Kind, Str); 101 Second->PragmaComment(Loc, Kind, Str); 102 } 103 104 virtual void MacroExpands(const Token &Id, const MacroInfo* MI) { 105 First->MacroExpands(Id, MI); 106 Second->MacroExpands(Id, MI); 107 } 108 109 virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) { 110 First->MacroDefined(II, MI); 111 Second->MacroDefined(II, MI); 112 } 113 114 virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) { 115 First->MacroUndefined(II, MI); 116 Second->MacroUndefined(II, MI); 117 } 118}; 119 120} // end namespace clang 121 122#endif 123