Preprocessor.h revision 9594acf32de2939b15eafa8fe818607bfc56bf66
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Preprocessor.h - C Language Family Preprocessor --------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 55f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file was developed by Chris Lattner and is distributed under 65f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// the University of Illinois Open Source License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Preprocessor interface. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_LEX_PREPROCESSOR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_LEX_PREPROCESSOR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/IdentifierTable.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/Lexer.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/MacroExpander.h" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/SourceLocation.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SourceManager; 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileManager; 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileEntry; 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass HeaderSearch; 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PragmaNamespace; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PragmaHandler; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ScratchBuffer; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TargetInfo; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PPCallbacks; 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DirectoryLookup; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Preprocessor - This object forms engages in a tight little dance to 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// efficiently preprocess tokens. Lexers know only about tokens within a 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// single source file, and don't know anything about preprocessor-level issues 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// like the #include stack, token expansion, etc. 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Preprocessor { 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diagnostic &Diags; 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &Features; 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TargetInfo &Target; 445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileManager &FileMgr; 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceManager &SourceMgr; 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ScratchBuffer *ScratchBuf; 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer HeaderSearch &HeaderInfo; 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Identifiers for builtin macros and other builtins. 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__ 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__ 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident__INCLUDE_LEVEL__; // __INCLUDE_LEVEL__ 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident__BASE_FILE__; // __BASE_FILE__ 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident__TIMESTAMP__; // __TIMESTAMP__ 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident_Pragma, *Ident__VA_ARGS__; // _Pragma, __VA_ARGS__ 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation DATELoc, TIMELoc; 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum { 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MaxIncludeStackDepth - Maximum depth of #includes. 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MaxAllowedIncludeStackDepth = 200 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // State that is set before the preprocessor begins. 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool KeepComments : 1; 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool KeepMacroComments : 1; 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // State that changes while the preprocessor runs: 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DisableMacroExpansion : 1; // True if macro expansion is disabled. 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool InMacroArgs : 1; // True if parsing fn macro invocation args. 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Identifiers - This is mapping/lookup information for all identifiers in 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the program, including program keywords. 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierTable Identifiers; 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// PragmaHandlers - This tracks all of the pragmas that the client registered 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with this preprocessor. 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PragmaNamespace *PragmaHandlers; 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CurLexer - This is the current top of the stack that we're lexing from if 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// not expanding a macro. One of CurLexer and CurMacroExpander must be null. 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Lexer *CurLexer; 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CurLookup - The DirectoryLookup structure used to find the current 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FileEntry, if CurLexer is non-null and if applicable. This allows us to 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// implement #include_next and find directory-specific properties. 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *CurDirLookup; 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CurMacroExpander - This is the current macro we are expanding, if we are 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expanding a macro. One of CurLexer and CurMacroExpander must be null. 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MacroExpander *CurMacroExpander; 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// IncludeMacroStack - This keeps track of the stack of files currently 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #included, and macros currently being expanded from, not counting 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CurLexer/CurMacroExpander. 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer struct IncludeStackInfo { 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Lexer *TheLexer; 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *TheDirLookup; 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MacroExpander *TheMacroExpander; 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IncludeStackInfo(Lexer *L, const DirectoryLookup *D, MacroExpander *M) 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : TheLexer(L), TheDirLookup(D), TheMacroExpander(M) { 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::vector<IncludeStackInfo> IncludeMacroStack; 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Callbacks - These are actions invoked when some preprocessor activity is 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// encountered (e.g. a file is #included, etc). 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PPCallbacks *Callbacks; 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Various statistics we track for performance analysis. 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma; 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumIf, NumElse, NumEndif; 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumEnteredSourceFiles, MaxIncludeStackDepth; 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumMacroExpanded, NumFnMacroExpanded, NumBuiltinMacroExpanded; 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumFastMacroExpanded, NumTokenPaste, NumFastTokenPaste; 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumSkipped; 1179594acf32de2939b15eafa8fe818607bfc56bf66Chris Lattner 1189594acf32de2939b15eafa8fe818607bfc56bf66Chris Lattner /// MacroExpanderCache - Cache macro expanders to reduce malloc traffic. 1199594acf32de2939b15eafa8fe818607bfc56bf66Chris Lattner enum { MacroExpanderCacheSize = 8 }; 1209594acf32de2939b15eafa8fe818607bfc56bf66Chris Lattner unsigned NumCachedMacroExpanders; 1219594acf32de2939b15eafa8fe818607bfc56bf66Chris Lattner MacroExpander *MacroExpanderCache[MacroExpanderCacheSize]; 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target, 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceManager &SM, HeaderSearch &Headers); 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Preprocessor(); 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diagnostic &getDiagnostics() const { return Diags; } 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLangOptions() const { return Features; } 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TargetInfo &getTargetInfo() const { return Target; } 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileManager &getFileManager() const { return FileMgr; } 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceManager &getSourceManager() const { return SourceMgr; } 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; } 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierTable &getIdentifierTable() { return Identifiers; } 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SetCommentRetentionState - Control whether or not the preprocessor retains 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// comments in output. 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments) { 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer this->KeepComments = KeepComments | KeepMacroComments; 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer this->KeepMacroComments = KeepMacroComments; 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getCommentRetentionState() const { return KeepComments; } 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isCurrentLexer - Return true if we are lexing directly from the specified 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lexer. 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCurrentLexer(const Lexer *L) const { 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return CurLexer == L; 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isInPrimaryFile - Return true if we're in the top-level file, not in a 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #include. 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isInPrimaryFile() const; 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCurrentLexer - Return the current file lexer being lexed from. Note 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this ignores any potentially active macro expansions and _Pragma 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expansions going on at the time. 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Lexer *getCurrentFileLexer() const; 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getPPCallbacks/SetPPCallbacks - Accessors for preprocessor callbacks. 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PPCallbacks *getPPCallbacks() const { return Callbacks; } 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setPPCallbacks(PPCallbacks *C) { 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Callbacks = C; 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getIdentifierInfo - Return information about the specified preprocessor 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identifier token. The version of this method that takes two character 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// pointers is preferred unless the identifier is already available as a 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// string (this avoids allocation and copying of memory to construct an 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// std::string). 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *getIdentifierInfo(const char *NameStart, 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *NameEnd) { 1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return &Identifiers.get(NameStart, NameEnd); 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *getIdentifierInfo(const char *NameStr) { 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getIdentifierInfo(NameStr, NameStr+strlen(NameStr)); 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AddPragmaHandler - Add the specified pragma handler to the preprocessor. 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If 'Namespace' is non-null, then it is a token required to exist on the 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// pragma line before the pragma string starts, e.g. "STDC" or "GCC". 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void AddPragmaHandler(const char *Namespace, PragmaHandler *Handler); 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterSourceFile - Add a source file to the top of the include stack and 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// start lexing tokens from it instead of the current buffer. If isMainFile 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is true, this is the main file for the translation unit. 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterSourceFile(unsigned CurFileID, const DirectoryLookup *Dir, 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMainFile = false); 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterMacro - Add a Macro to the top of the include stack and start lexing 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens from it instead of the current buffer. Args specifies the 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens input to a function-like macro. 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterMacro(LexerToken &Identifier, MacroArgs *Args); 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterTokenStream - Add a "macro" context to the top of the include stack, 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// which will cause the lexer to start returning the specified tokens. Note 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that these tokens will be re-macro-expanded when/if expansion is enabled. 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This method assumes that the specified stream of tokens has a permanent 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// owner somewhere, so they do not need to be copied. 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterTokenStream(const LexerToken *Toks, unsigned NumToks); 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// RemoveTopOfLexerStack - Pop the current lexer/macro exp off the top of the 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lexer stack. This should only be used in situations where the current 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// state of the top-of-stack lexer is known. 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void RemoveTopOfLexerStack(); 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Lex - To lex a token from the preprocessor, just pull a token from the 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current lexer or macro object. 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Lex(LexerToken &Result) { 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (CurLexer) 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CurLexer->Lex(Result); 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CurMacroExpander->Lex(Result); 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LexNonComment - Lex a token. If it's a comment, keep lexing until we get 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// something not a comment. This is useful in -E -C mode where comments 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// would foul up preprocessor directive handling. 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void LexNonComment(LexerToken &Result) { 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer do 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Lex(Result); 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (Result.getKind() == tok::comment); 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LexUnexpandedToken - This is just like Lex, but this disables macro 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expansion of identifier tokens. 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void LexUnexpandedToken(LexerToken &Result) { 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Disable macro expansion. 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool OldVal = DisableMacroExpansion; 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DisableMacroExpansion = true; 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Lex the token. 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Lex(Result); 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Reenable it. 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DisableMacroExpansion = OldVal; 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Diag - Forwarding function for diagnostics. This emits a diagnostic at 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the specified LexerToken's location, translating the token's start 2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// position in the current buffer into a SourcePosition object for rendering. 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Diag(SourceLocation Loc, unsigned DiagID); 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg); 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Diag(const LexerToken &Tok, unsigned DiagID) { 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok.getLocation(), DiagID); 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Diag(const LexerToken &Tok, unsigned DiagID, const std::string &Msg) { 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diag(Tok.getLocation(), DiagID, Msg); 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token is the characters used to represent the token in the source file 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// after trigraph expansion and escaped-newline folding. In particular, this 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// wants to get the true, uncanonicalized, spelling of things like digraphs 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// UCNs, etc. 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string getSpelling(const LexerToken &Tok) const; 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getSpelling - This method is used to get the spelling of a token into a 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// preallocated buffer, instead of as an std::string. The caller is required 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// to allocate enough space for the token, which is guaranteed to be at least 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Tok.getLength() bytes long. The length of the actual result is returned. 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this method may do two possible things: it may either fill in 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the buffer specified with characters, or it may *change the input pointer* 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// to point to a constant buffer with the data already in it (avoiding a 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// copy). The caller is not allowed to modify the returned buffer pointer 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// if an internal buffer is returned. 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getSpelling(const LexerToken &Tok, const char *&Buffer) const; 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateString - Plop the specified string into a scratch buffer and return 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a location for it. If specified, the source location provides a source 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location for the token. 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation CreateString(const char *Buf, unsigned Len, 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation SourceLoc = SourceLocation()); 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DumpToken - Print the token to stderr, used for debugging. 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void DumpToken(const LexerToken &Tok, bool DumpFlags = false) const; 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void DumpMacro(const MacroInfo &MI) const; 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// IncrementPasteCounter - Increment the counters for the number of token 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// paste operations performed. If fast was specified, this is a 'fast paste' 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// case we handled. 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void IncrementPasteCounter(bool isFast) { 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isFast) 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++NumFastTokenPaste; 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++NumTokenPaste; 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void PrintStats(); 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Preprocessor callback methods. These are invoked by a lexer as various 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // directives and events are found. 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LookUpIdentifierInfo - Given a tok::identifier token, look up the 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identifier information for the token and install it into the token. 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *LookUpIdentifierInfo(LexerToken &Identifier, 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *BufPtr = 0); 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// HandleIdentifier - This callback is invoked when the lexer reads an 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identifier and has filled in the tokens IdentifierInfo member. This 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// callback potentially macro expands it or turns it into a named token (like 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 'for'). 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleIdentifier(LexerToken &Identifier); 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// HandleEndOfFile - This callback is invoked when the lexer hits the end of 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the current file. This either returns the EOF token and returns true, or 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// pops a level off the include stack and returns false, at which point the 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// client should call lex again. 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool HandleEndOfFile(LexerToken &Result, bool isEndOfMacro = false); 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// HandleEndOfMacro - This callback is invoked when the lexer hits the end of 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the current macro line. It returns true if Result is filled in with a 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token, or false if Lex should be called again. 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool HandleEndOfMacro(LexerToken &Result); 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// HandleDirective - This callback is invoked when the lexer sees a # token 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// at the start of a line. This consumes the directive, modifies the 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lexer/preprocessor state, and advances the lexer(s) so that the next token 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// read is the correct one. 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleDirective(LexerToken &Result); 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CheckEndOfDirective - Ensure that the next token is a tok::eom token. If 3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// not, emit a diagnostic and consume up until the eom. 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void CheckEndOfDirective(const char *Directive); 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DiscardUntilEndOfDirective - Read and discard all tokens remaining on the 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current line until the tok::eom token is found. 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void DiscardUntilEndOfDirective(); 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ReadMacroName - Lex and validate a macro name, which occurs after a 3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #define or #undef. This emits a diagnostic, sets the token kind to eom, 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and discards the rest of the macro line if the macro name is invalid. 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ReadMacroName(LexerToken &MacroNameTok, char isDefineUndef = 0); 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ReadMacroDefinitionArgList - The ( starting an argument list of a macro 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// definition has just been read. Lex the rest of the arguments and the 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// closing ), updating MI with what we learn. Return true if an error occurs 3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// parsing the arg list. 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ReadMacroDefinitionArgList(MacroInfo *MI); 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipExcludedConditionalBlock - We just read a #if or related directive and 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// decided that the subsequent tokens are in the #if'd out portion of the 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// file. Lex the rest of the file, until we see an #endif. If 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FoundNonSkipPortion is true, then we have already emitted code for part of 3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this #if directive, so #else/#elif blocks should never be entered. If 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FoundElse is false, then #else directives are ok, if not, then we have 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// already seen one so a #else directive is a duplicate. When this returns, 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the caller can lex the first valid token. 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool FoundNonSkipPortion, bool FoundElse); 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateDirectiveExpression - Evaluate an integer constant expression that 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// may occur after a #if or #elif directive and return it as a bool. If the 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression is equivalent to "!defined(X)" return X in IfNDefMacro. 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas: 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #pragma GCC poison/system_header/dependency and #pragma once. 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void RegisterBuiltinPragmas(); 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identifier table. 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void RegisterBuiltinMacros(); 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *RegisterBuiltinMacro(const char *Name); 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// HandleMacroExpandedIdentifier - If an identifier token is read that is to 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// be expanded as a macro, handle it and return the next token as 'Tok'. If 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the macro should not be expanded return true, otherwise return false. 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool HandleMacroExpandedIdentifier(LexerToken &Tok, MacroInfo *MI); 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNextPPTokenLParen - Determine whether the next preprocessor token to be 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lexed is a '('. If so, consume the token and return true, if not, this 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// method should have no observable side-effect on the lexed tokens. 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNextPPTokenLParen(); 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ReadFunctionLikeMacroArgs - After reading "MACRO(", this method is 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// invoked to read all of the formal arguments specified for the macro 3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// invocation. This returns null on error. 3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MacroArgs *ReadFunctionLikeMacroArgs(LexerToken &MacroName, MacroInfo *MI); 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// as a builtin macro, handle it and return the next token as 'Tok'. 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExpandBuiltinMacro(LexerToken &Tok); 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// return the first token after the directive. The _Pragma token has just 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// been read into 'Tok'. 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Handle_Pragma(LexerToken &Tok); 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterSourceFileWithLexer - Add a lexer to the top of the include stack and 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// start lexing tokens from it instead of the current buffer. 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir); 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// checked and spelled filename, e.g. as an operand of #include. This returns 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// true if the input filename was in <>'s or false if it were in ""'s. The 4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// caller is expected to provide a buffer that is large enough to hold the 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// spelling of the filename, but is also expected to handle the case when 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method decides to use a different buffer. 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool GetIncludeFilenameSpelling(const LexerToken &FNTok, 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *&BufStart, const char *&BufEnd); 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file, 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// return null on failure. isAngled indicates whether the file reference is 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// for system #include's or not (i.e. using <> instead of ""). 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd, 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAngled, const DirectoryLookup *FromDir, 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *&CurDir); 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Handle*Directive - implement the various preprocessor directives. These 4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// should side-effect the current preprocessor object so that the next call 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// to Lex() will return the appropriate token next. 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleUserDiagnosticDirective(LexerToken &Tok, bool isWarning); 4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleIdentSCCSDirective(LexerToken &Tok); 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // File inclusion. 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleIncludeDirective(LexerToken &Tok, 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *LookupFrom = 0, 4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isImport = false); 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleIncludeNextDirective(LexerToken &Tok); 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleImportDirective(LexerToken &Tok); 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Macro handling. 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleDefineDirective(LexerToken &Tok, bool isTargetSpecific); 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleUndefDirective(LexerToken &Tok); 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleDefineOtherTargetDirective(LexerToken &Tok); 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // HandleAssertDirective(LexerToken &Tok); 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // HandleUnassertDirective(LexerToken &Tok); 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Conditional Inclusion. 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleIfdefDirective(LexerToken &Tok, bool isIfndef, 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ReadAnyTokensBeforeDirective); 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleIfDirective(LexerToken &Tok, bool ReadAnyTokensBeforeDirective); 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleEndifDirective(LexerToken &Tok); 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleElseDirective(LexerToken &Tok); 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandleElifDirective(LexerToken &Tok); 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Pragmas. 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandlePragmaDirective(); 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandlePragmaOnce(LexerToken &OnceTok); 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandlePragmaPoison(LexerToken &PoisonTok); 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandlePragmaSystemHeader(LexerToken &SysHeaderTok); 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void HandlePragmaDependency(LexerToken &DependencyTok); 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 460