26 #include "llvm/ADT/APInt.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/Path.h"
29 #include "llvm/Support/SaveAndRestore.h"
30 using namespace clang;
36 MacroInfo *Preprocessor::AllocateMacroInfo() {
37 MacroInfoChain *MIChain = BP.Allocate<MacroInfoChain>();
38 MIChain->Next = MIChainHead;
39 MIChainHead = MIChain;
50 unsigned SubModuleID) {
51 static_assert(llvm::AlignOf<MacroInfo>::Alignment >=
sizeof(SubModuleID),
52 "alignment for MacroInfo is less than the ID");
53 DeserializedMacroInfoChain *MIChain =
54 BP.Allocate<DeserializedMacroInfoChain>();
55 MIChain->Next = DeserialMIChainHead;
56 DeserialMIChainHead = MIChain;
60 MI->FromASTFile =
true;
61 MI->setOwningModuleID(SubModuleID);
71 Preprocessor::AllocateUndefMacroDirective(
SourceLocation UndefLoc) {
87 assert(Tmp.
isNot(
tok::eof) &&
"EOF seen while discarding directive tokens");
88 }
while (Tmp.
isNot(tok::eod));
105 if (Text.size() >= 2 && Text[0] ==
'_' &&
111 if (Lang.CPlusPlus) {
112 if (Text.find(
"__") != StringRef::npos)
125 if (Lang.CPlusPlus11 && (Text.equals(
"override") || Text.equals(
"final")))
142 if (MacroNameTok.
is(tok::eod))
143 return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
147 bool Invalid =
false;
148 std::string Spelling =
getSpelling(MacroNameTok, &Invalid);
150 return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
154 return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
159 ? diag::ext_pp_operator_used_as_macro_name
160 : diag::err_pp_operator_used_as_macro_name)
161 << II << MacroNameTok.
getKind();
170 return Diag(MacroNameTok, diag::err_defined_macro_name);
178 Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
188 (strcmp(SourceMgr.
getBufferName(MacroNameLoc),
"<built-in>") != 0)) {
203 Diag(MacroNameTok, diag::warn_pp_macro_is_reserved_id);
219 void Preprocessor::ReadMacroName(
Token &MacroNameTok,
MacroUse isDefineUndef,
224 if (MacroNameTok.
is(tok::code_completion)) {
236 if (MacroNameTok.
isNot(tok::eod)) {
237 MacroNameTok.
setKind(tok::eod);
258 while (Tmp.
is(tok::comment))
261 if (Tmp.
isNot(tok::eod)) {
267 if ((LangOpts.GNUMode || LangOpts.C99 || LangOpts.CPlusPlus) &&
270 Diag(Tmp, diag::ext_pp_extra_tokens_at_eol) << DirType << Hint;
285 void Preprocessor::SkipExcludedConditionalBlock(
SourceLocation IfTokenLoc,
286 bool FoundNonSkipPortion,
290 assert(!CurTokenLexer && CurPPLexer &&
"Lexing a macro, not a file?");
293 FoundNonSkipPortion, FoundElse);
296 PTHSkipExcludedConditionalBlock();
307 if (Tok.
is(tok::code_completion)) {
319 if (CurLexer->getFileLoc() != CodeCompletionFileLoc)
321 diag::err_pp_unterminated_conditional);
337 if (CurLexer) CurLexer->SetKeepWhitespaceMode(
false);
345 if (Tok.
isNot(tok::raw_identifier)) {
348 if (CurLexer) CurLexer->resetExtendedTokenMode();
359 char FirstChar = RI[0];
360 if (FirstChar >=
'a' && FirstChar <=
'z' &&
361 FirstChar !=
'i' && FirstChar !=
'e') {
364 if (CurLexer) CurLexer->resetExtendedTokenMode();
371 char DirectiveBuf[20];
377 unsigned IdLen = DirectiveStr.size();
381 if (CurLexer) CurLexer->resetExtendedTokenMode();
384 memcpy(DirectiveBuf, &DirectiveStr[0], IdLen);
385 Directive = StringRef(DirectiveBuf, IdLen);
388 if (Directive.startswith(
"if")) {
389 StringRef Sub = Directive.substr(2);
400 }
else if (Directive[0] ==
'e') {
401 StringRef Sub = Directive.substr(1);
407 assert(!InCond &&
"Can't be skipping if not in a conditional!");
422 }
else if (Sub ==
"lse") {
429 if (CondInfo.
FoundElse)
Diag(Tok, diag::pp_err_else_after_else);
449 }
else if (Sub ==
"lif") {
453 if (CondInfo.
FoundElse)
Diag(Tok, diag::pp_err_elif_after_else);
463 assert(CurPPLexer->
LexingRawMode &&
"We have to be skipping here!");
466 const bool CondValue = EvaluateDirectiveExpression(IfNDefMacro);
485 if (CurLexer) CurLexer->resetExtendedTokenMode();
499 void Preprocessor::PTHSkipExcludedConditionalBlock() {
503 assert(CurPTHLexer->LexingRawMode ==
false);
506 if (CurPTHLexer->SkipBlock()) {
510 bool InCond = CurPTHLexer->popConditionalLevel(CondInfo);
512 assert(!InCond &&
"Can't be skipping if not in a conditional!");
525 if (K == tok::pp_else) {
538 CurPTHLexer->ParsingPreprocessorDirective =
true;
540 CurPTHLexer->ParsingPreprocessorDirective =
false;
549 assert(K == tok::pp_elif);
554 Diag(Tok, diag::pp_err_elif_after_else);
563 CurPTHLexer->ParsingPreprocessorDirective =
true;
564 bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro);
565 CurPTHLexer->ParsingPreprocessorDirective =
false;
620 if (!FromDir && !FromFile) {
638 Includers.push_back(std::make_pair(
nullptr, MainFileDir));
641 Includers.push_back(std::make_pair(FileEnt, FileMgr.
getDirectory(
".")));
643 Includers.push_back(std::make_pair(FileEnt, FileEnt->
getDir()));
649 if (LangOpts.MSVCCompat && !isAngled) {
650 for (
unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
651 IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
652 if (IsFileLexer(ISEntry))
653 if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
654 Includers.push_back(std::make_pair(FileEnt, FileEnt->
getDir()));
659 CurDir = CurDirLookup;
667 Filename, FilenameLoc, isAngled, TmpFromDir, TmpCurDir,
668 Includers, SearchPath, RelativePath, RequestingModule,
669 SuggestedModule, SkipCache)) {
671 TmpFromDir = TmpCurDir;
673 if (FE == FromFile) {
675 FromDir = TmpFromDir;
684 Filename, FilenameLoc, isAngled, FromDir, CurDir, Includers, SearchPath,
685 RelativePath, RequestingModule, SuggestedModule, SkipCache);
687 if (SuggestedModule && !LangOpts.AsmPreprocessor)
689 RequestingModule, FilenameLoc, Filename, FE);
700 SearchPath, RelativePath,
703 if (SuggestedModule && !LangOpts.AsmPreprocessor)
705 RequestingModule, FilenameLoc, Filename, FE);
711 for (
unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
712 IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
713 if (IsFileLexer(ISEntry)) {
714 if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
716 Filename, CurFileEnt, SearchPath, RelativePath,
717 RequestingModule, SuggestedModule))) {
718 if (SuggestedModule && !LangOpts.AsmPreprocessor)
720 RequestingModule, FilenameLoc, Filename, FE);
739 : PP(pp), save(pp->DisableMacroExpansion) {
740 if (pp->MacroExpansionInDirectivesOverride)
741 pp->DisableMacroExpansion =
false;
744 PP->DisableMacroExpansion = save;
762 if (CurLexer) CurLexer->SetKeepWhitespaceMode(
false);
764 bool ImmediatelyAfterTopLevelIfndef =
792 switch (II->getPPKeywordID()) {
793 case tok::pp_include:
795 case tok::pp_include_next:
796 case tok::pp___include_macros:
798 Diag(Result, diag::err_embedded_directive) << II->getName();
805 Diag(Result, diag::ext_embedded_directive);
815 case tok::code_completion:
821 case tok::numeric_constant:
824 return HandleDigitDirective(Result);
834 return HandleIfDirective(Result, ReadAnyTokensBeforeDirective);
836 return HandleIfdefDirective(Result,
false,
true);
838 return HandleIfdefDirective(Result,
true, ReadAnyTokensBeforeDirective);
840 return HandleElifDirective(Result);
842 return HandleElseDirective(Result);
844 return HandleEndifDirective(Result);
847 case tok::pp_include:
850 case tok::pp___include_macros:
856 return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef);
858 return HandleUndefDirective(Result);
862 return HandleLineDirective(Result);
866 return HandleUserDiagnosticDirective(Result,
false);
875 case tok::pp_include_next:
878 case tok::pp_warning:
879 Diag(Result, diag::ext_pp_warning_directive);
880 return HandleUserDiagnosticDirective(Result,
true);
882 return HandleIdentSCCSDirective(Result);
884 return HandleIdentSCCSDirective(Result);
888 case tok::pp_unassert:
892 case tok::pp___public_macro:
894 return HandleMacroPublicDirective(Result);
897 case tok::pp___private_macro:
899 return HandleMacroPrivateDirective(Result);
917 if (Result.
is(tok::hashhash))
918 Toks[1].setKind(tok::unknown);
928 Diag(Result, diag::err_pp_invalid_directive);
940 bool IsGNULineDirective=
false) {
941 if (DigitTok.
isNot(tok::numeric_constant)) {
942 PP.
Diag(DigitTok, DiagID);
944 if (DigitTok.
isNot(tok::eod))
950 IntegerBuffer.resize(DigitTok.
getLength());
951 const char *DigitTokBegin = &IntegerBuffer[0];
952 bool Invalid =
false;
953 unsigned ActualLength = PP.
getSpelling(DigitTok, DigitTokBegin, &Invalid);
961 for (
unsigned i = 0; i != ActualLength; ++i) {
964 if (DigitTokBegin[i] ==
'\'')
967 if (!
isDigit(DigitTokBegin[i])) {
969 diag::err_pp_line_digit_sequence) << IsGNULineDirective;
974 unsigned NextVal = Val*10+(DigitTokBegin[i]-
'0');
976 PP.
Diag(DigitTok, DiagID);
983 if (DigitTokBegin[0] ==
'0' && Val)
985 << IsGNULineDirective;
997 void Preprocessor::HandleLineDirective(
Token &Tok) {
1005 if (
GetLineValue(DigitTok, LineNo, diag::err_pp_line_requires_integer,*
this))
1009 Diag(DigitTok, diag::ext_pp_line_zero);
1013 unsigned LineLimit = 32768U;
1014 if (LangOpts.C99 || LangOpts.CPlusPlus11)
1015 LineLimit = 2147483648U;
1016 if (LineNo >= LineLimit)
1017 Diag(DigitTok, diag::ext_pp_line_too_big) << LineLimit;
1018 else if (LangOpts.CPlusPlus11 && LineNo >= 32768U)
1019 Diag(DigitTok, diag::warn_cxx98_compat_pp_line_too_big);
1021 int FilenameID = -1;
1027 if (StrTok.
is(tok::eod))
1029 else if (StrTok.
isNot(tok::string_literal)) {
1030 Diag(StrTok, diag::err_pp_line_invalid_filename);
1033 Diag(StrTok, diag::err_invalid_string_udl);
1038 assert(Literal.isAscii() &&
"Didn't allow wide strings in");
1039 if (Literal.hadError)
1041 if (Literal.Pascal) {
1042 Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
1063 bool &IsSystemHeader,
bool &IsExternCHeader,
1068 if (FlagTok.
is(tok::eod))
return false;
1069 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag, PP))
1076 if (FlagTok.
is(tok::eod))
return false;
1077 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
1079 }
else if (FlagVal == 2) {
1096 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_pop);
1102 if (FlagTok.
is(tok::eod))
return false;
1103 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
1109 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_flag);
1114 IsSystemHeader =
true;
1117 if (FlagTok.
is(tok::eod))
return false;
1118 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag, PP))
1123 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_flag);
1128 IsExternCHeader =
true;
1131 if (FlagTok.
is(tok::eod))
return false;
1134 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_flag);
1146 void Preprocessor::HandleDigitDirective(
Token &DigitTok) {
1150 if (
GetLineValue(DigitTok, LineNo, diag::err_pp_linemarker_requires_integer,
1157 bool IsFileEntry =
false, IsFileExit =
false;
1158 bool IsSystemHeader =
false, IsExternCHeader =
false;
1159 int FilenameID = -1;
1163 if (StrTok.
is(tok::eod))
1165 else if (StrTok.
isNot(tok::string_literal)) {
1166 Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
1169 Diag(StrTok, diag::err_invalid_string_udl);
1174 assert(Literal.isAscii() &&
"Didn't allow wide strings in");
1175 if (Literal.hadError)
1177 if (Literal.Pascal) {
1178 Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
1185 IsSystemHeader, IsExternCHeader, *
this))
1191 IsFileEntry, IsFileExit,
1192 IsSystemHeader, IsExternCHeader);
1201 else if (IsFileExit)
1204 if (IsExternCHeader)
1206 else if (IsSystemHeader)
1216 void Preprocessor::HandleUserDiagnosticDirective(
Token &Tok,
1220 return CurPTHLexer->DiscardToEndOfLine();
1228 CurLexer->ReadToEndOfLine(&Message);
1232 StringRef Msg = StringRef(Message).ltrim(
" ");
1235 Diag(Tok, diag::pp_hash_warning) << Msg;
1237 Diag(Tok, diag::err_pp_hash_error) << Msg;
1242 void Preprocessor::HandleIdentSCCSDirective(
Token &Tok) {
1244 Diag(Tok, diag::ext_pp_ident_directive);
1251 if (StrTok.
isNot(tok::string_literal) &&
1252 StrTok.
isNot(tok::wide_string_literal)) {
1253 Diag(StrTok, diag::err_pp_malformed_ident);
1254 if (StrTok.
isNot(tok::eod))
1260 Diag(StrTok, diag::err_invalid_string_udl);
1276 void Preprocessor::HandleMacroPublicDirective(
Token &Tok) {
1278 ReadMacroName(MacroNameTok,
MU_Undef);
1281 if (MacroNameTok.
is(tok::eod))
1293 Diag(MacroNameTok, diag::err_pp_visibility_non_macro) << II;
1303 void Preprocessor::HandleMacroPrivateDirective(
Token &Tok) {
1305 ReadMacroName(MacroNameTok,
MU_Undef);
1308 if (MacroNameTok.
is(tok::eod))
1320 Diag(MacroNameTok, diag::err_pp_visibility_non_macro) << II;
1342 assert(!Buffer.empty() &&
"Can't have tokens with empty spellings!");
1346 if (Buffer[0] ==
'<') {
1347 if (Buffer.back() !=
'>') {
1348 Diag(Loc, diag::err_pp_expects_filename);
1349 Buffer = StringRef();
1353 }
else if (Buffer[0] ==
'"') {
1354 if (Buffer.back() !=
'"') {
1355 Diag(Loc, diag::err_pp_expects_filename);
1356 Buffer = StringRef();
1361 Diag(Loc, diag::err_pp_expects_filename);
1362 Buffer = StringRef();
1367 if (Buffer.size() <= 2) {
1368 Diag(Loc, diag::err_pp_empty_filename);
1369 Buffer = StringRef();
1374 Buffer = Buffer.substr(1, Buffer.size()-2);
1396 while (CurTok.
isNot(tok::eod)) {
1400 if (CurTok.
is(tok::code_completion)) {
1409 FilenameBuffer.push_back(
' ');
1412 unsigned PreAppendSize = FilenameBuffer.size();
1413 FilenameBuffer.resize(PreAppendSize+CurTok.
getLength());
1415 const char *BufPtr = &FilenameBuffer[PreAppendSize];
1419 if (BufPtr != &FilenameBuffer[PreAppendSize])
1420 memcpy(&FilenameBuffer[PreAppendSize], BufPtr, ActualLen);
1424 FilenameBuffer.resize(PreAppendSize+ActualLen);
1427 if (CurTok.
is(tok::greater))
1458 ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> Path,
1460 assert(PP.
getLangOpts().ObjC2 &&
"no import syntax available");
1463 for (
unsigned I = 0, N = Path.size();
I != N; ++
I) {
1466 PathString += Path[
I].first->getName();
1468 int IncludeKind = 0;
1471 case tok::pp_include:
1475 case tok::pp_import:
1479 case tok::pp_include_next:
1483 case tok::pp___include_macros:
1488 llvm_unreachable(
"unknown include directive kind");
1493 PP.
Diag(HashLoc, diag::warn_auto_module_import)
1494 << IncludeKind << PathString
1496 (
"@import " + PathString +
";").str());
1504 void Preprocessor::HandleIncludeDirective(
SourceLocation HashLoc,
1519 switch (FilenameTok.
getKind()) {
1524 case tok::angle_string_literal:
1525 case tok::string_literal:
1526 Filename =
getSpelling(FilenameTok, FilenameBuffer);
1534 FilenameBuffer.push_back(
'<');
1537 Filename = FilenameBuffer;
1548 StringRef OriginalFilename =
Filename;
1553 if (Filename.empty()) {
1565 if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
1566 Diag(FilenameTok, diag::err_pp_include_too_deep);
1571 if (PragmaARCCFCodeAuditedLoc.
isValid()) {
1572 Diag(HashLoc, diag::err_pp_include_in_arc_cf_code_audited);
1573 Diag(PragmaARCCFCodeAuditedLoc, diag::note_pragma_entered_here);
1580 if (PragmaAssumeNonNullLoc.
isValid()) {
1581 Diag(HashLoc, diag::err_pp_include_in_assume_nonnull);
1582 Diag(PragmaAssumeNonNullLoc, diag::note_pragma_entered_here);
1593 if (!NewName.empty())
1606 if (LangOpts.MSVCCompat) {
1607 NormalizedPath = Filename.str();
1608 #ifndef LLVM_ON_WIN32
1609 llvm::sys::path::native(NormalizedPath);
1613 FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename,
1614 isAngled, LookupFrom, LookupFromFile, CurDir,
1615 Callbacks ? &SearchPath :
nullptr, Callbacks ? &RelativePath :
nullptr,
1622 if (Callbacks->FileNotFound(Filename, RecoveryPath)) {
1631 LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename, isAngled,
1632 LookupFrom, LookupFromFile, CurDir,
nullptr,
nullptr,
1633 &SuggestedModule,
true);
1638 if (!SuppressIncludeNotFoundError) {
1645 LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename,
false,
1646 LookupFrom, LookupFromFile, CurDir,
1647 Callbacks ? &SearchPath :
nullptr,
1648 Callbacks ? &RelativePath :
nullptr,
1652 Diag(FilenameTok, diag::err_pp_file_not_found_not_fatal) <<
1660 Diag(FilenameTok, diag::err_pp_file_not_found) <<
Filename;
1668 bool ShouldEnter =
true;
1673 if (File && SuggestedModule &&
getLangOpts().Modules &&
1696 diag::note_implicit_top_level_module_import_here)
1708 std::reverse(Path.begin(), Path.end());
1722 assert((Imported ==
nullptr || Imported == SuggestedModule.
getModule()) &&
1723 "the imported module is different than the suggested one");
1726 ShouldEnter =
false;
1740 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd,
tok::eof);
1741 CurLexer->cutOffLexing();
1743 assert(CurPTHLexer &&
"#include but no current lexer set!");
1744 CurPTHLexer->getEOF(Result);
1753 Callbacks->InclusionDirective(
1754 HashLoc, IncludeTok,
1755 LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename, isAngled,
1756 FilenameRange, File, SearchPath, RelativePath,
1757 ShouldEnter ?
nullptr : SuggestedModule.
getModule());
1778 ShouldEnter =
false;
1780 Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
1786 if (
auto *M = SuggestedModule.
getModule()) {
1790 tok::pp___include_macros)
1803 assert(FID.
isValid() &&
"Expected valid file ID");
1810 if (
auto *M = SuggestedModule.
getModule()) {
1811 assert(!CurSubmodule &&
"should not have marked this as a module yet");
1816 EnterSubmodule(M, HashLoc);
1828 void Preprocessor::HandleIncludeNextDirective(
SourceLocation HashLoc,
1829 Token &IncludeNextTok) {
1830 Diag(IncludeNextTok, diag::ext_pp_include_next_directive);
1836 const FileEntry *LookupFromFile =
nullptr;
1839 Diag(IncludeNextTok, diag::pp_include_next_in_primary);
1840 }
else if (CurSubmodule) {
1843 assert(CurPPLexer &&
"#include_next directive in macro?");
1846 }
else if (!Lookup) {
1847 Diag(IncludeNextTok, diag::pp_include_next_absolute_path);
1853 return HandleIncludeDirective(HashLoc, IncludeNextTok, Lookup,
1858 void Preprocessor::HandleMicrosoftImportDirective(
Token &Tok) {
1864 Diag(Tok, diag::err_pp_import_directive_ms );
1875 if (!LangOpts.ObjC1) {
1876 if (LangOpts.MSVCCompat)
1877 return HandleMicrosoftImportDirective(ImportTok);
1878 Diag(ImportTok, diag::ext_pp_import_directive);
1880 return HandleIncludeDirective(HashLoc, ImportTok,
nullptr,
nullptr,
true);
1887 void Preprocessor::HandleIncludeMacrosDirective(
SourceLocation HashLoc,
1888 Token &IncludeMacrosTok) {
1892 if (strcmp(SourceMgr.
getBufferName(Loc),
"<built-in>") != 0) {
1894 diag::pp_include_macros_out_of_predefines);
1901 HandleIncludeDirective(HashLoc, IncludeMacrosTok);
1906 assert(TmpTok.
isNot(
tok::eof) &&
"Didn't find end of -imacros!");
1907 }
while (TmpTok.
isNot(tok::hashhash));
1918 bool Preprocessor::ReadMacroDefinitionArgList(
MacroInfo *MI,
Token &Tok) {
1926 if (Arguments.empty())
1929 Diag(Tok, diag::err_pp_expected_ident_in_arg_list);
1933 Diag(Tok, LangOpts.CPlusPlus11 ?
1934 diag::warn_cxx98_compat_variadic_macro :
1935 diag::ext_variadic_macro);
1938 if (LangOpts.OpenCL) {
1939 Diag(Tok, diag::err_pp_opencl_variadic_macros);
1945 if (Tok.
isNot(tok::r_paren)) {
1946 Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
1950 Arguments.push_back(Ident__VA_ARGS__);
1955 Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
1963 Diag(Tok, diag::err_pp_invalid_tok_in_arg_list);
1969 if (std::find(Arguments.begin(), Arguments.end(), II) !=
1971 Diag(Tok, diag::err_pp_duplicate_name_in_arg_list) << II;
1976 Arguments.push_back(II);
1983 Diag(Tok, diag::err_pp_expected_comma_in_arg_list);
1992 Diag(Tok, diag::ext_named_variadic_macro);
1996 if (Tok.
isNot(tok::r_paren)) {
1997 Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
2027 StringRef ValueText = II->
getName();
2028 StringRef TrimmedValue = ValueText;
2029 if (!ValueText.startswith(
"__")) {
2030 if (ValueText.startswith(
"_"))
2031 TrimmedValue = TrimmedValue.drop_front(1);
2035 TrimmedValue = TrimmedValue.drop_front(2);
2036 if (TrimmedValue.endswith(
"__"))
2037 TrimmedValue = TrimmedValue.drop_back(2);
2039 return TrimmedValue.equals(MacroText);
2046 return MacroName.
isOneOf(tok::kw_extern, tok::kw_inline, tok::kw_static,
2053 void Preprocessor::HandleDefineDirective(
Token &DefineTok,
2054 bool ImmediatelyAfterHeaderGuard) {
2058 bool MacroShadowsKeyword;
2059 ReadMacroName(MacroNameTok,
MU_Define, &MacroShadowsKeyword);
2062 if (MacroNameTok.
is(tok::eod))
2065 Token LastTok = MacroNameTok;
2069 if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments);
2080 if (Tok.is(tok::eod)) {
2081 if (ImmediatelyAfterHeaderGuard) {
2087 }
else if (Tok.hasLeadingSpace()) {
2091 }
else if (Tok.is(tok::l_paren)) {
2094 if (ReadMacroDefinitionArgList(MI, LastTok)) {
2106 assert(Ident__VA_ARGS__->
isPoisoned() &&
"__VA_ARGS__ should be poisoned!");
2112 }
else if (LangOpts.C99 || LangOpts.CPlusPlus11) {
2115 Diag(Tok, diag::ext_c99_whitespace_required_after_macro_name);
2124 if (Tok.is(tok::at))
2126 else if (Tok.is(tok::unknown)) {
2133 Diag(Tok, diag::ext_missing_whitespace_after_macro_name);
2135 Diag(Tok, diag::warn_missing_whitespace_after_macro_name);
2138 if (!Tok.is(tok::eod))
2144 while (Tok.isNot(tok::eod)) {
2155 while (Tok.isNot(tok::eod)) {
2158 if (Tok.isNot(tok::hash) && Tok.isNot(tok::hashhash)) {
2170 Tok.setKind(tok::unknown);
2178 if (Tok.is(tok::hashhash)) {
2187 if (Tok.is(tok::eod)) {
2193 if (NumTokens && Tok.getIdentifierInfo() == Ident__VA_ARGS__ &&
2206 if (Tok.getIdentifierInfo() ==
nullptr ||
2213 if (
getLangOpts().AsmPreprocessor && Tok.isNot(tok::eod)) {
2214 LastTok.
setKind(tok::unknown);
2218 Diag(Tok, diag::err_pp_stringize_not_parameter);
2236 if (MacroShadowsKeyword &&
2238 Diag(MacroNameTok, diag::warn_pp_macro_hides_keyword);
2247 if (NumTokens != 0) {
2266 auto isObjCProtectedMacro = [](
const IdentifierInfo *II) ->
bool {
2267 return II->
isStr(
"__strong") ||
2268 II->
isStr(
"__weak") ||
2269 II->
isStr(
"__unsafe_unretained") ||
2270 II->
isStr(
"__autoreleasing");
2273 SourceMgr.
getFileID(OtherMI->getDefinitionLoc())
2280 LangOpts.MicrosoftExt)) {
2283 assert(!OtherMI->isWarnIfUnused());
2292 if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused())
2293 Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
2297 if (OtherMI->isBuiltinMacro())
2298 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
2301 else if (!OtherMI->isAllowRedefinitionsWithoutWarning() &&
2302 !MI->
isIdenticalTo(*OtherMI, *
this, LangOpts.MicrosoftExt)) {
2305 Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
2308 if (OtherMI->isWarnIfUnused())
2309 WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
2326 Callbacks->MacroDefined(MacroNameTok, MD);
2331 void Preprocessor::HandleUndefDirective(
Token &UndefTok) {
2335 ReadMacroName(MacroNameTok,
MU_Undef);
2338 if (MacroNameTok.
is(tok::eod))
2351 Callbacks->MacroUndefined(MacroNameTok, MD);
2365 AllocateUndefMacroDirective(MacroNameTok.
getLocation()));
2378 void Preprocessor::HandleIfdefDirective(
Token &Result,
bool isIfndef,
2379 bool ReadAnyTokensBeforeDirective) {
2384 ReadMacroName(MacroNameTok);
2387 if (MacroNameTok.
is(tok::eod)) {
2390 SkipExcludedConditionalBlock(DirectiveTok.
getLocation(),
2407 if (!ReadAnyTokensBeforeDirective && !MI) {
2408 assert(isIfndef &&
"#ifdef shouldn't reach here");
2420 Callbacks->Ifndef(DirectiveTok.
getLocation(), MacroNameTok, MD);
2422 Callbacks->Ifdef(DirectiveTok.
getLocation(), MacroNameTok, MD);
2426 if (!MI == isIfndef) {
2433 SkipExcludedConditionalBlock(DirectiveTok.
getLocation(),
2441 void Preprocessor::HandleIfDirective(
Token &IfToken,
2442 bool ReadAnyTokensBeforeDirective) {
2448 const bool ConditionalTrue = EvaluateDirectiveExpression(IfNDefMacro);
2454 if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
2467 if (ConditionalTrue) {
2473 SkipExcludedConditionalBlock(IfToken.
getLocation(),
false,
2480 void Preprocessor::HandleEndifDirective(
Token &EndifToken) {
2489 Diag(EndifToken, diag::err_pp_endif_without_if);
2498 "This code should only be reachable in the non-skipping case!");
2506 void Preprocessor::HandleElseDirective(
Token &Result) {
2514 Diag(Result, diag::pp_err_else_without_if);
2523 if (CI.
FoundElse)
Diag(Result, diag::pp_err_else_after_else);
2529 SkipExcludedConditionalBlock(CI.
IfLoc,
true,
2535 void Preprocessor::HandleElifDirective(
Token &ElifToken) {
2547 Diag(ElifToken, diag::pp_err_elif_without_if);
2556 if (CI.
FoundElse)
Diag(ElifToken, diag::pp_err_elif_after_else);
2564 SkipExcludedConditionalBlock(CI.
IfLoc,
true,
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
SourceManager & getSourceManager() const
bool isPoisoned() const
Return true if this token has been poisoned.
bool getHasReadAnyTokensVal() const
getHasReadAnyTokensVal - This is used for the #ifndef hande-shake at the top of the file when reading...
static LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Module * getModuleForLocation(SourceLocation Loc)
Find the module that owns the source or header file that Loc points to.
MacroInfo * AllocateMacroInfo(SourceLocation L)
Allocate a new MacroInfo object with the provided SourceLocation.
bool ConcatenateIncludeName(SmallString< 128 > &FilenameBuffer, SourceLocation &End)
Handle cases where the #include name is expanded from a macro as multiple tokens, which need to be gl...
void AddTokenToBody(const Token &Tok)
Add the specified token to the replacement text for the macro.
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
void markMacroAsUsed(MacroInfo *MI)
A macro is used, update information about macros that need unused warnings.
Defines the clang::FileManager interface and associated types.
PPConditionalInfo & peekConditionalLevel()
Return the top of the conditional stack.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
static LLVM_READONLY bool isUppercase(unsigned char c)
Return true if this character is an uppercase ASCII letter: [A-Z].
static bool isReservedId(StringRef Text, const LangOptions &Lang)
Checks if the specified identifier is reserved in the specified language.
Defines the SourceManager interface.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, bool &IsSystemHeader, bool &IsExternCHeader, Preprocessor &PP)
ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line marker directive...
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
void pushConditionalLevel(SourceLocation DirectiveStart, bool WasSkipping, bool FoundNonSkip, bool FoundElse)
pushConditionalLevel - When we enter a #if directive, this keeps track of what we are currently in fo...
bool isObjectLike() const
Defines the clang::MacroInfo and clang::MacroDirective classes.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
std::unique_ptr< llvm::MemoryBuffer > Buffer
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID)
Add a line note to the line table for the FileID and offset specified by Loc.
A directive for an undefined macro.
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
void setCodeCompletionReached()
Note that we hit the code-completion point.
static void EnterAnnotationToken(Preprocessor &PP, SourceLocation Begin, SourceLocation End, tok::TokenKind Kind, void *AnnotationVal)
Push a token onto the token stream containing an annotation.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
void setIsWarnIfUnused(bool val)
Set the value of the IsWarnIfUnused flag.
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
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 ...
static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II)
std::string getFullModuleName() const
Retrieve the full name of this module, including the path from its top-level module.
Module * getModuleContainingLocation(SourceLocation Loc)
Find the module that contains the specified location, either directly or indirectly.
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
One of these records is kept for each identifier that is lexed.
A directive for a defined macro or a macro imported from a module.
bool ParsingPreprocessorDirective
True when parsing #XXX; turns '\n' into a tok::eod token.
std::pair< SourceLocation, SourceLocation > getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag=nullptr)
static void diagnoseAutoModuleImport(Preprocessor &PP, SourceLocation HashLoc, Token &IncludeTok, ArrayRef< std::pair< IdentifierInfo *, SourceLocation >> Path, SourceLocation PathEnd)
Produce a diagnostic informing the user that a #include or similar was implicitly treated as a module...
bool getImmediatelyAfterTopLevelIfndef() const
getImmediatelyAfterTopLevelIfndef - returns true if the last directive was an #ifndef at the beginnin...
SmallVector< PPConditionalInfo, 4 > ConditionalStack
Information about the set of #if/#ifdef/#ifndef blocks we are currently in.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
const LangOptions & getLangOpts() const
virtual void CodeCompleteDirective(bool InConditional)
Callback invoked when performing code completion for a preprocessor directive.
Token - This structure provides full information about a lexed token.
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
void setKind(tok::TokenKind K)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes a module or submodule.
bool isMissingExpected() const
Determines whether the module, which failed to load, was actually a submodule that we expected to see...
VerifyDiagnosticConsumer::Directive Directive
bool popConditionalLevel(PPConditionalInfo &CI)
popConditionalLevel - Remove an entry off the top of the conditional stack, returning information abo...
A directive for setting the module visibility of a macro.
void CheckEndOfDirective(const char *Directive, bool EnableMacros=false)
Ensure that the next token is a tok::eod token.
MacroUse
Context in which macro name is used.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
void HandleDirective(Token &Result)
Callback invoked when the lexer sees a # token at the start of a line.
Module * Parent
The parent of this module.
bool hadModuleLoaderFatalFailure() const
SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Char) const
Given a location that specifies the start of a token, return a new location that specifies a characte...
tok::TokenKind getKind() const
bool FoundNonSkip
True if we have emitted tokens already, and now we're in an #else block or something.
const TargetInfo & getTargetInfo() const
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
detail::InMemoryDirectory::const_iterator I
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
MacroDiag
Enumerates possible cases of #define/#undef a reserved identifier.
bool isCPlusPlusOperatorKeyword() const
void diagnoseHeaderInclusion(Module *RequestingModule, SourceLocation FilenameLoc, StringRef Filename, const FileEntry *File)
Reports errors if a module must not include a specific file.
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode), returns a reference to the text substring in the buffer if known.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
std::string CurrentModule
The name of the current module.
const DirectoryEntry * getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
Describes the result of attempting to load a module.
void setAnnotationValue(void *val)
bool LexingRawMode
True if in raw mode.
StringRef getName() const
Return the actual identifier string.
Represents a character-granular source range.
void setHasCommaPasting()
void makeModuleVisible(Module *M, SourceLocation Loc)
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
Defines the clang::Preprocessor interface.
const char * getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix. ...
ResetMacroExpansionHelper(Preprocessor *pp)
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
int getArgumentNum(const IdentifierInfo *Arg) const
Return the argument number of the specified identifier, or -1 if the identifier is not a formal argum...
void resetImmediatelyAfterTopLevelIfndef()
MultipleIncludeOpt MIOpt
A state machine that detects the #ifndef-wrapping a file idiom for the multiple-include optimization...
void SetDefinedMacro(IdentifierInfo *M, SourceLocation Loc)
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isNot(tok::TokenKind K) const
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
Information about the conditional stack (#if directives) currently active.
Represents an unpacked "presumed" location which can be presented to the user.
void setArgumentList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the argument list for this macro.
The result type of a method or function.
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
bool isC99Varargs() const
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
static CharSourceRange getCharRange(SourceRange R)
bool getSuppressSystemWarnings() const
virtual SourceLocation getSourceLocation()=0
Return the source location for the next observable location.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
MacroInfo * AllocateDeserializedMacroInfo(SourceLocation L, unsigned SubModuleID)
Allocate a new MacroInfo object loaded from an AST file.
void setIsFunctionLike()
Function/Object-likeness.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
bool WasSkipping
True if this was contained in a skipping directive, e.g., in a "\#if 0" block.
Encodes a location in the source.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
bool isValid() const
Return true if this is a valid SourceLocation object.
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
MacroDirective * getLocalMacroDirective(const IdentifierInfo *II) const
Given an identifier, return its latest non-imported MacroDirective if it is #define'd and not #undef'...
All of the names in this module are hidden.
void setAnnotationEndLoc(SourceLocation L)
Cached information about one file (either on disk or in the virtual file system). ...
void EnterTokenStream(const Token *Toks, unsigned NumToks, bool DisableMacroExpansion, bool OwnsTokens)
Add a "macro" context to the top of the include stack, which will cause the lexer to start returning ...
virtual void CodeCompleteInConditionalExclusion()
Callback invoked when performing code completion within a block of code that was excluded due to prep...
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
void setIdentifierInfo(IdentifierInfo *II)
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool isKeyword(const LangOptions &LangOpts)
Return true if this token is a keyword in the specified language.
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
const Token & getReplacementToken(unsigned Tok) const
FileID getMainFileID() const
Returns the FileID of the main source file.
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)) {...
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
unsigned getConditionalStackDepth() const
DiagnosticsEngine & getDiagnostics() const
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
SourceLocation IfLoc
Location where the conditional started.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
The pragma was introduced via #pragma.
void ExitTopLevelConditional()
Called when the lexer exits the top-level conditional.
Module * inferModuleFromLocation(FullSourceLoc Loc)
Infers the (sub)module based on the given source location and source manager.
static bool isConfigurationPattern(Token &MacroName, MacroInfo *MI, const LangOptions &LOptions)
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const
Return the file characteristic of the specified source location, indicating whether this is a normal ...
unsigned getLineTableFilenameID(StringRef Str)
Return the uniqued ID for the specified filename.
const MacroInfo * getMacroInfo() const
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II)
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
std::string ImplementationOfModule
The name of the module that the translation unit is an implementation of.
void EnterTopLevelConditional()
Invoked when a top level conditional (except #ifndef) is found.
Encapsulates the data about a macro definition (e.g.
SourceLocation DefinitionLoc
The location of the module definition.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Filename)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
bool isIdenticalTo(const MacroInfo &Other, Preprocessor &PP, bool Syntactically) const
Return true if the specified macro definition is equal to this macro in spelling, arguments...
std::pair< std::string, bool > Requirement
An individual requirement: a feature name and a flag indicating the required state of that feature...
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
static bool isInvalid(SourceLocation Loc, bool *Invalid)
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
KnownHeader findModuleForHeader(const FileEntry *File)
Retrieve the module that owns the given header file, if any.
void LexIncludeFilename(Token &Result)
After the preprocessor has parsed a #include, lex and (potentially) macro expand the filename...
Cached information about one directory (either on disk or in the virtual file system).
static bool GetLineValue(Token &DigitTok, unsigned &Val, unsigned DiagID, Preprocessor &PP, bool IsGNULineDirective=false)
GetLineValue - Convert a numeric token into an unsigned value, emitting Diagnostic DiagID if it is in...
virtual void CodeCompleteMacroName(bool IsDefinition)
Callback invoked when performing code completion in a context where the name of a macro is expected...
const FileEntry * LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, const DirectoryLookup *&CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
void EnterTopLevelIfndef(const IdentifierInfo *M, SourceLocation Loc)
Called when entering a top-level #ifndef directive (or the "\#if !defined" equivalent) without any pr...
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
A SourceLocation and its associated SourceManager.
void DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found...
unsigned getLength() const
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
const DirectoryEntry * getDir() const
Return the directory the file lives in.
bool FoundElse
True if we've seen a #else in this block.
This class handles loading and caching of source files into memory.
void startToken()
Reset all flags to cleared.
~ResetMacroExpansionHelper()
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
bool EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir, SourceLocation Loc)
Add a source file to the top of the include stack and start lexing tokens from it instead of the curr...
IdentifierInfo * getIdentifierInfo() const
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.