24#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/SmallString.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/Support/ErrorHandling.h"
28#include "llvm/Support/raw_ostream.h"
36 OS <<
"#define " << II.
getName();
42 for (; AI+1 != E; ++AI) {
43 OS << (*AI)->getName();
48 if ((*AI)->getName() ==
"__VA_ARGS__")
51 OS << (*AI)->getName();
66 for (
const auto &T : MI.
tokens()) {
67 if (T.hasLeadingSpace())
79class PrintPPOutputPPCallbacks :
public PPCallbacks {
88 bool EmittedTokensOnThisLine;
89 bool EmittedDirectiveOnThisLine;
93 bool DisableLineMarkers;
95 bool DumpIncludeDirectives;
96 bool UseLineDirectives;
97 bool IsFirstFileEntered;
98 bool MinimizeWhitespace;
105 PrintPPOutputPPCallbacks(
Preprocessor &pp, raw_ostream &os,
bool lineMarkers,
106 bool defines,
bool DumpIncludeDirectives,
107 bool UseLineDirectives,
bool MinimizeWhitespace,
109 : PP(pp),
SM(PP.getSourceManager()), ConcatInfo(PP),
OS(os),
110 DisableLineMarkers(lineMarkers), DumpDefines(defines),
111 DumpIncludeDirectives(DumpIncludeDirectives),
112 UseLineDirectives(UseLineDirectives),
113 MinimizeWhitespace(MinimizeWhitespace), DirectivesOnly(DirectivesOnly) {
115 CurFilename +=
"<uninit>";
116 EmittedTokensOnThisLine =
false;
117 EmittedDirectiveOnThisLine =
false;
120 IsFirstFileEntered =
false;
126 bool isMinimizeWhitespace()
const {
return MinimizeWhitespace; }
128 void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine =
true; }
129 bool hasEmittedTokensOnThisLine()
const {
return EmittedTokensOnThisLine; }
131 void setEmittedDirectiveOnThisLine() { EmittedDirectiveOnThisLine =
true; }
132 bool hasEmittedDirectiveOnThisLine()
const {
133 return EmittedDirectiveOnThisLine;
141 void startNewLineIfNeeded();
147 StringRef FileName,
bool IsAngled,
150 StringRef RelativePath,
const Module *Imported,
154 PragmaMessageKind Kind, StringRef Str)
override;
176 void HandleWhitespaceBeforeTok(
const Token &Tok,
bool RequireSpace,
177 bool RequireSameLine);
191 bool MoveToLine(
const Token &Tok,
bool RequireStartOfLine) {
196 return MoveToLine(TargetLine, RequireStartOfLine) || IsFirstInFile;
204 return MoveToLine(TargetLine, RequireStartOfLine);
206 bool MoveToLine(
unsigned LineNo,
bool RequireStartOfLine);
208 bool AvoidConcat(
const Token &PrevPrevTok,
const Token &PrevTok,
210 return ConcatInfo.
AvoidConcat(PrevPrevTok, PrevTok, Tok);
212 void WriteLineInfo(
unsigned LineNo,
const char *Extra=
nullptr,
213 unsigned ExtraLen=0);
214 bool LineMarkersAreDisabled()
const {
return DisableLineMarkers; }
215 void HandleNewlinesInToken(
const char *TokStr,
unsigned Len);
226 void BeginModule(
const Module *M);
227 void EndModule(
const Module *M);
231void PrintPPOutputPPCallbacks::WriteLineInfo(
unsigned LineNo,
234 startNewLineIfNeeded();
237 if (UseLineDirectives) {
238 OS <<
"#line" <<
' ' << LineNo <<
' ' <<
'"';
239 OS.write_escaped(CurFilename);
242 OS <<
'#' <<
' ' << LineNo <<
' ' <<
'"';
243 OS.write_escaped(CurFilename);
247 OS.write(Extra, ExtraLen);
261bool PrintPPOutputPPCallbacks::MoveToLine(
unsigned LineNo,
262 bool RequireStartOfLine) {
266 bool StartedNewLine =
false;
267 if ((RequireStartOfLine && EmittedTokensOnThisLine) ||
268 EmittedDirectiveOnThisLine) {
270 StartedNewLine =
true;
272 EmittedTokensOnThisLine =
false;
273 EmittedDirectiveOnThisLine =
false;
278 if (CurLine == LineNo) {
280 }
else if (MinimizeWhitespace && DisableLineMarkers) {
282 }
else if (!StartedNewLine && LineNo - CurLine == 1) {
287 StartedNewLine =
true;
288 }
else if (!DisableLineMarkers) {
289 if (LineNo - CurLine <= 8) {
290 const char *NewLines =
"\n\n\n\n\n\n\n\n";
291 OS.write(NewLines, LineNo - CurLine);
294 WriteLineInfo(LineNo,
nullptr, 0);
296 StartedNewLine =
true;
297 }
else if (EmittedTokensOnThisLine) {
301 StartedNewLine =
true;
304 if (StartedNewLine) {
305 EmittedTokensOnThisLine =
false;
306 EmittedDirectiveOnThisLine =
false;
310 return StartedNewLine;
313void PrintPPOutputPPCallbacks::startNewLineIfNeeded() {
314 if (EmittedTokensOnThisLine || EmittedDirectiveOnThisLine) {
316 EmittedTokensOnThisLine =
false;
317 EmittedDirectiveOnThisLine =
false;
325 FileChangeReason Reason,
341 MoveToLine(IncludeLoc,
false);
355 FileType = NewFileType;
357 if (DisableLineMarkers) {
358 if (!MinimizeWhitespace)
359 startNewLineIfNeeded();
364 WriteLineInfo(CurLine);
373 IsFirstFileEntered =
true;
379 WriteLineInfo(CurLine,
" 1", 2);
382 WriteLineInfo(CurLine,
" 2", 2);
386 WriteLineInfo(CurLine);
391void PrintPPOutputPPCallbacks::InclusionDirective(
394 StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
398 if (DumpIncludeDirectives) {
399 MoveToLine(HashLoc,
true);
400 const std::string TokenText = PP.
getSpelling(IncludeTok);
401 assert(!TokenText.empty());
402 OS <<
"#" << TokenText <<
" "
403 << (IsAngled ?
'<' :
'"') << FileName << (IsAngled ?
'>' :
'"')
404 <<
" /* clang -E -dI */";
405 setEmittedDirectiveOnThisLine();
411 case tok::pp_include:
413 case tok::pp_include_next:
414 MoveToLine(HashLoc,
true);
416 <<
" /* clang -E: implicit import for "
418 << (IsAngled ?
'<' :
'"') << FileName << (IsAngled ?
'>' :
'"')
420 setEmittedDirectiveOnThisLine();
423 case tok::pp___include_macros:
432 llvm_unreachable(
"unknown include directive kind");
439void PrintPPOutputPPCallbacks::BeginModule(
const Module *M) {
440 startNewLineIfNeeded();
442 setEmittedDirectiveOnThisLine();
446void PrintPPOutputPPCallbacks::EndModule(
const Module *M) {
447 startNewLineIfNeeded();
449 setEmittedDirectiveOnThisLine();
454void PrintPPOutputPPCallbacks::Ident(
SourceLocation Loc, StringRef S) {
455 MoveToLine(Loc,
true);
457 OS.write(
"#ident ", strlen(
"#ident "));
458 OS.write(S.begin(), S.size());
459 setEmittedTokensOnThisLine();
463void PrintPPOutputPPCallbacks::MacroDefined(
const Token &MacroNameTok,
468 if ((!DumpDefines && !DirectivesOnly) ||
474 if (DirectivesOnly && !MI->
isUsed()) {
476 if (
SM.isWrittenInBuiltinFile(DefLoc) ||
477 SM.isWrittenInCommandLineFile(DefLoc))
480 MoveToLine(DefLoc,
true);
482 setEmittedDirectiveOnThisLine();
485void PrintPPOutputPPCallbacks::MacroUndefined(
const Token &MacroNameTok,
490 if (!DumpDefines && !DirectivesOnly)
495 setEmittedDirectiveOnThisLine();
499 for (
unsigned char Char : Str) {
500 if (
isPrintable(Char) && Char !=
'\\' && Char !=
'"')
504 << (char)(
'0' + ((Char >> 6) & 7))
505 << (char)(
'0' + ((Char >> 3) & 7))
506 << (char)(
'0' + ((Char >> 0) & 7));
512 PragmaMessageKind Kind,
514 MoveToLine(Loc,
true);
532 if (Kind == PMK_Message)
534 setEmittedDirectiveOnThisLine();
538 StringRef DebugType) {
539 MoveToLine(Loc,
true);
541 OS <<
"#pragma clang __debug ";
544 setEmittedDirectiveOnThisLine();
547void PrintPPOutputPPCallbacks::
549 MoveToLine(Loc,
true);
550 OS <<
"#pragma " <<
Namespace <<
" diagnostic push";
551 setEmittedDirectiveOnThisLine();
554void PrintPPOutputPPCallbacks::
556 MoveToLine(Loc,
true);
557 OS <<
"#pragma " <<
Namespace <<
" diagnostic pop";
558 setEmittedDirectiveOnThisLine();
561void PrintPPOutputPPCallbacks::PragmaDiagnostic(
SourceLocation Loc,
565 MoveToLine(Loc,
true);
568 case diag::Severity::Remark:
571 case diag::Severity::Warning:
574 case diag::Severity::Error:
577 case diag::Severity::Ignored:
580 case diag::Severity::Fatal:
584 OS <<
" \"" << Str <<
'"';
585 setEmittedDirectiveOnThisLine();
589 PragmaWarningSpecifier WarningSpec,
591 MoveToLine(Loc,
true);
593 OS <<
"#pragma warning(";
594 switch(WarningSpec) {
595 case PWS_Default:
OS <<
"default";
break;
596 case PWS_Disable:
OS <<
"disable";
break;
597 case PWS_Error:
OS <<
"error";
break;
598 case PWS_Once:
OS <<
"once";
break;
599 case PWS_Suppress:
OS <<
"suppress";
break;
600 case PWS_Level1:
OS <<
'1';
break;
601 case PWS_Level2:
OS <<
'2';
break;
602 case PWS_Level3:
OS <<
'3';
break;
603 case PWS_Level4:
OS <<
'4';
break;
610 setEmittedDirectiveOnThisLine();
613void PrintPPOutputPPCallbacks::PragmaWarningPush(
SourceLocation Loc,
615 MoveToLine(Loc,
true);
616 OS <<
"#pragma warning(push";
620 setEmittedDirectiveOnThisLine();
623void PrintPPOutputPPCallbacks::PragmaWarningPop(
SourceLocation Loc) {
624 MoveToLine(Loc,
true);
625 OS <<
"#pragma warning(pop)";
626 setEmittedDirectiveOnThisLine();
629void PrintPPOutputPPCallbacks::PragmaExecCharsetPush(
SourceLocation Loc,
631 MoveToLine(Loc,
true);
632 OS <<
"#pragma character_execution_set(push";
636 setEmittedDirectiveOnThisLine();
639void PrintPPOutputPPCallbacks::PragmaExecCharsetPop(
SourceLocation Loc) {
640 MoveToLine(Loc,
true);
641 OS <<
"#pragma character_execution_set(pop)";
642 setEmittedDirectiveOnThisLine();
645void PrintPPOutputPPCallbacks::
647 MoveToLine(Loc,
true);
648 OS <<
"#pragma clang assume_nonnull begin";
649 setEmittedDirectiveOnThisLine();
652void PrintPPOutputPPCallbacks::
654 MoveToLine(Loc,
true);
655 OS <<
"#pragma clang assume_nonnull end";
656 setEmittedDirectiveOnThisLine();
659void PrintPPOutputPPCallbacks::HandleWhitespaceBeforeTok(
const Token &Tok,
661 bool RequireSameLine) {
664 if (Tok.
is(tok::eof) ||
666 !Tok.
is(tok::annot_module_begin) && !Tok.
is(tok::annot_module_end)))
670 if ((!RequireSameLine || EmittedDirectiveOnThisLine) &&
671 MoveToLine(Tok, EmittedDirectiveOnThisLine)) {
672 if (MinimizeWhitespace) {
674 if (Tok.
is(tok::hash))
679 unsigned ColNo =
SM.getExpansionColumnNumber(Tok.
getLocation());
694 if (ColNo <= 1 && Tok.
is(tok::hash))
698 for (; ColNo > 1; --ColNo)
709 ((EmittedTokensOnThisLine || EmittedDirectiveOnThisLine) &&
710 AvoidConcat(PrevPrevTok, PrevTok, Tok)))
714 PrevPrevTok = PrevTok;
718void PrintPPOutputPPCallbacks::HandleNewlinesInToken(
const char *TokStr,
720 unsigned NumNewlines = 0;
721 for (; Len; --Len, ++TokStr) {
722 if (*TokStr !=
'\n' &&
730 (TokStr[1] ==
'\n' || TokStr[1] ==
'\r') &&
731 TokStr[0] != TokStr[1]) {
737 if (NumNewlines == 0)
return;
739 CurLine += NumNewlines;
746 PrintPPOutputPPCallbacks *Callbacks;
749 bool ShouldExpandTokens;
751 UnknownPragmaHandler(
const char *prefix, PrintPPOutputPPCallbacks *callbacks,
752 bool RequireTokenExpansion)
753 : Prefix(prefix), Callbacks(callbacks),
754 ShouldExpandTokens(RequireTokenExpansion) {}
756 Token &PragmaTok)
override {
759 Callbacks->MoveToLine(PragmaTok.
getLocation(),
true);
760 Callbacks->OS.write(Prefix, strlen(Prefix));
761 Callbacks->setEmittedTokensOnThisLine();
763 if (ShouldExpandTokens) {
766 auto Toks = std::make_unique<Token[]>(1);
768 PP.EnterTokenStream(std::move(Toks), 1,
776 while (PragmaTok.
isNot(tok::eod)) {
777 Callbacks->HandleWhitespaceBeforeTok(PragmaTok, IsFirst,
781 Callbacks->OS.write(&TokSpell[0], TokSpell.size());
782 Callbacks->setEmittedTokensOnThisLine();
784 if (ShouldExpandTokens)
789 Callbacks->setEmittedDirectiveOnThisLine();
796 PrintPPOutputPPCallbacks *Callbacks,
798 bool DropComments = PP.
getLangOpts().TraditionalCPP &&
801 bool IsStartOfLine =
false;
813 Callbacks->HandleWhitespaceBeforeTok(Tok,
false,
816 if (DropComments && Tok.
is(tok::comment)) {
822 }
else if (Tok.
is(tok::eod)) {
829 IsStartOfLine =
true;
831 }
else if (Tok.
is(tok::annot_module_include)) {
835 IsStartOfLine =
true;
837 }
else if (Tok.
is(tok::annot_module_begin)) {
844 Callbacks->BeginModule(
847 IsStartOfLine =
true;
849 }
else if (Tok.
is(tok::annot_module_end)) {
850 Callbacks->EndModule(
853 IsStartOfLine =
true;
855 }
else if (Tok.
is(tok::annot_header_unit)) {
862 OS.write(Name.data(), Name.size());
863 Callbacks->HandleNewlinesInToken(Name.data(), Name.size());
874 }
else if (Tok.
getLength() < std::size(Buffer)) {
875 const char *TokPtr = Buffer;
877 OS.write(TokPtr, Len);
884 if (Tok.
getKind() == tok::comment || Tok.
getKind() == tok::unknown)
885 Callbacks->HandleNewlinesInToken(TokPtr, Len);
886 if (Tok.
is(tok::comment) && Len >= 2 && TokPtr[0] ==
'/' &&
890 Callbacks->setEmittedDirectiveOnThisLine();
894 OS.write(S.data(), S.size());
898 if (Tok.
getKind() == tok::comment || Tok.
getKind() == tok::unknown)
899 Callbacks->HandleNewlinesInToken(S.data(), S.size());
900 if (Tok.
is(tok::comment) && S.size() >= 2 && S[0] ==
'/' && S[1] ==
'/') {
903 Callbacks->setEmittedDirectiveOnThisLine();
906 Callbacks->setEmittedTokensOnThisLine();
907 IsStartOfLine =
false;
909 if (Tok.
is(tok::eof))
break;
917 return LHS->first->getName().compare(RHS->first->getName());
930 while (Tok.
isNot(tok::eof));
935 auto *MD = I->second.getLatest();
936 if (MD && MD->isDefined())
939 llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(),
MacroIDCompare);
941 for (
unsigned i = 0, e = MacrosByID.size(); i != e; ++i) {
957 assert(Opts.
ShowMacros &&
"Not yet implemented!");
966 PrintPPOutputPPCallbacks *Callbacks =
new PrintPPOutputPPCallbacks(
974 std::unique_ptr<UnknownPragmaHandler> MicrosoftExtHandler(
975 new UnknownPragmaHandler(
976 "#pragma", Callbacks,
979 std::unique_ptr<UnknownPragmaHandler> GCCHandler(
new UnknownPragmaHandler(
980 "#pragma GCC", Callbacks,
983 std::unique_ptr<UnknownPragmaHandler> ClangHandler(
new UnknownPragmaHandler(
984 "#pragma clang", Callbacks,
996 std::unique_ptr<UnknownPragmaHandler> OpenMPHandler(
997 new UnknownPragmaHandler(
"#pragma omp", Callbacks,
Defines the Diagnostic-related interfaces.
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines the PPCallbacks interface.
Defines the clang::Preprocessor interface.
static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI, Preprocessor &PP, raw_ostream &OS)
PrintMacroDefinition - Print a macro definition in a form that will be properly accepted back as a de...
static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, PrintPPOutputPPCallbacks *Callbacks, raw_ostream &OS)
std::pair< const IdentifierInfo *, MacroInfo * > id_macro_pair
static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS)
static int MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS)
static void outputPrintable(raw_ostream &OS, StringRef Str)
Defines the SourceManager interface.
Represents a character-granular source range.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
One of these records is kept for each identifier that is lexed.
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
StringRef getName() const
Return the actual identifier string.
Record the location of an inclusion directive, such as an #include or #import statement.
A description of the current definition of a macro.
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
const MacroInfo * getMacroInfo() const
Encapsulates the data about a macro definition (e.g.
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used.
bool isFunctionLike() const
const_tokens_iterator tokens_begin() const
param_iterator param_begin() const
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
bool tokens_empty() const
param_iterator param_end() const
ArrayRef< Token > tokens() const
bool isGNUVarargs() const
Describes a module or submodule.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
virtual void PragmaExecCharsetPop(SourceLocation Loc)
Callback invoked when a #pragma execution_character_set(pop) directive is read.
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic push directive is read.
virtual void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids)
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType)
Callback invoked when a #pragma clang __debug directive is read.
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID())
Callback invoked whenever a source file is entered or exited.
virtual void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef)
Hook called whenever a macro #undef is seen.
virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD)
Hook called whenever a macro definition is seen.
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str)
Callback invoked when a #pragma gcc diagnostic directive is read.
virtual void PragmaAssumeNonNullEnd(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull end directive is read.
virtual void PragmaAssumeNonNullBegin(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
virtual void Ident(SourceLocation Loc, StringRef str)
Callback invoked when a #ident or #sccs directive is read.
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str)
Callback invoked when a #pragma message directive is read.
virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str)
Callback invoked when a #pragma execution_character_set(push) directive is read.
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic pop directive is read.
virtual void PragmaWarningPop(SourceLocation Loc)
Callback invoked when a #pragma warning(pop) directive is read.
virtual void PragmaWarningPush(SourceLocation Loc, int Level)
Callback invoked when a #pragma warning(push) directive is read.
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken)=0
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g....
unsigned UseLineDirectives
Use #line instead of GCC-style # N.
unsigned ShowMacros
Print macro definitions.
unsigned ShowIncludeDirectives
Print includes, imports etc. within preprocessed output.
unsigned ShowMacroComments
Show comments, even in macros.
unsigned ShowCPP
Print normal preprocessed output.
unsigned MinimizeWhitespace
Ignore whitespace from input.
unsigned ShowComments
Show comments.
unsigned ShowLineMarkers
Show #line markers.
unsigned DirectivesOnly
Process directives but do not expand macros.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
void Lex(Token &Result)
Lex the next token for this preprocessor.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
macro_iterator macro_end(bool IncludeExternalMacros=true) const
SourceManager & getSourceManager() const
bool getCommentRetentionState() const
void SetMacroExpansionOnlyInDirectives()
Disables macro expansion everywhere except for preprocessor directives.
MacroMap::const_iterator macro_iterator
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
const LangOptions & getLangOpts() const
void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments)
Control whether the preprocessor retains comments in output.
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
TokenConcatenation class, which answers the question of "Is it safe to emit two tokens without a whit...
bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, const Token &Tok) const
AvoidConcat - If printing PrevTok immediately followed by Tok would cause the two individual tokens t...
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
bool isLiteral() const
Return true if this is a "literal", like a numeric constant, string, etc.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
void * getAnnotationValue() const
tok::TokenKind getKind() const
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
bool isNot(tok::TokenKind K) const
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
void startToken()
Reset all flags to cleared.
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts)
DoPrintPreprocessedInput - Implement -E mode.
Describes how and where the pragma was introduced.