36 #include "llvm/ADT/ArrayRef.h"
37 #include "llvm/ADT/SmallString.h"
38 #include "llvm/ADT/SmallVector.h"
39 #include "llvm/ADT/STLExtras.h"
40 #include "llvm/ADT/StringSwitch.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/Support/AlignOf.h"
43 #include "llvm/Support/ErrorHandling.h"
44 #include "llvm/Support/Path.h"
52 using namespace clang;
59 auto *MIChain =
new (BP) MacroInfoChain{L, MIChainHead};
60 MIChainHead = MIChain;
70 Preprocessor::AllocateUndefMacroDirective(
SourceLocation UndefLoc) {
86 assert(Tmp.
isNot(
tok::eof) &&
"EOF seen while discarding directive tokens");
87 }
while (Tmp.
isNot(tok::eod));
104 if (Text.size() >= 2 && Text[0] ==
'_' &&
110 if (Lang.CPlusPlus) {
111 if (Text.find(
"__") != StringRef::npos)
124 if (Lang.CPlusPlus11 && (Text.equals(
"override") || Text.equals(
"final")))
146 if (::llvm::sys::path::begin(Include)->equals_lower(
"boost"))
151 static const size_t MaxStdHeaderNameLen = 18u;
152 if (Include.size() > MaxStdHeaderNameLen)
157 for (
char &Ch : LowerInclude) {
159 if (static_cast<unsigned char>(Ch) > 0x7f)
162 if (Ch >=
'A' && Ch <=
'Z')
165 else if (::llvm::sys::path::is_separator(Ch))
170 return llvm::StringSwitch<bool>(LowerInclude)
172 .Cases(
"assert.h",
"complex.h",
"ctype.h",
"errno.h",
"fenv.h",
true)
173 .Cases(
"float.h",
"inttypes.h",
"iso646.h",
"limits.h",
"locale.h",
true)
174 .Cases(
"math.h",
"setjmp.h",
"signal.h",
"stdalign.h",
"stdarg.h",
true)
175 .Cases(
"stdatomic.h",
"stdbool.h",
"stddef.h",
"stdint.h",
"stdio.h",
true)
176 .Cases(
"stdlib.h",
"stdnoreturn.h",
"string.h",
"tgmath.h",
"threads.h",
true)
177 .Cases(
"time.h",
"uchar.h",
"wchar.h",
"wctype.h",
true)
180 .Cases(
"cassert",
"ccomplex",
"cctype",
"cerrno",
"cfenv",
true)
181 .Cases(
"cfloat",
"cinttypes",
"ciso646",
"climits",
"clocale",
true)
182 .Cases(
"cmath",
"csetjmp",
"csignal",
"cstdalign",
"cstdarg",
true)
183 .Cases(
"cstdbool",
"cstddef",
"cstdint",
"cstdio",
"cstdlib",
true)
184 .Cases(
"cstring",
"ctgmath",
"ctime",
"cuchar",
"cwchar",
true)
185 .Case(
"cwctype",
true)
188 .Cases(
"algorithm",
"fstream",
"list",
"regex",
"thread",
true)
189 .Cases(
"array",
"functional",
"locale",
"scoped_allocator",
"tuple",
true)
190 .Cases(
"atomic",
"future",
"map",
"set",
"type_traits",
true)
191 .Cases(
"bitset",
"initializer_list",
"memory",
"shared_mutex",
"typeindex",
true)
192 .Cases(
"chrono",
"iomanip",
"mutex",
"sstream",
"typeinfo",
true)
193 .Cases(
"codecvt",
"ios",
"new",
"stack",
"unordered_map",
true)
194 .Cases(
"complex",
"iosfwd",
"numeric",
"stdexcept",
"unordered_set",
true)
195 .Cases(
"condition_variable",
"iostream",
"ostream",
"streambuf",
"utility",
true)
196 .Cases(
"deque",
"istream",
"queue",
"string",
"valarray",
true)
197 .Cases(
"exception",
"iterator",
"random",
"strstream",
"vector",
true)
198 .Cases(
"forward_list",
"limits",
"ratio",
"system_error",
true)
201 .Cases(
"aio.h",
"arpa/inet.h",
"cpio.h",
"dirent.h",
"dlfcn.h",
true)
202 .Cases(
"fcntl.h",
"fmtmsg.h",
"fnmatch.h",
"ftw.h",
"glob.h",
true)
203 .Cases(
"grp.h",
"iconv.h",
"langinfo.h",
"libgen.h",
"monetary.h",
true)
204 .Cases(
"mqueue.h",
"ndbm.h",
"net/if.h",
"netdb.h",
"netinet/in.h",
true)
205 .Cases(
"netinet/tcp.h",
"nl_types.h",
"poll.h",
"pthread.h",
"pwd.h",
true)
206 .Cases(
"regex.h",
"sched.h",
"search.h",
"semaphore.h",
"spawn.h",
true)
207 .Cases(
"strings.h",
"stropts.h",
"sys/ipc.h",
"sys/mman.h",
"sys/msg.h",
true)
208 .Cases(
"sys/resource.h",
"sys/select.h",
"sys/sem.h",
"sys/shm.h",
"sys/socket.h",
true)
209 .Cases(
"sys/stat.h",
"sys/statvfs.h",
"sys/time.h",
"sys/times.h",
"sys/types.h",
true)
210 .Cases(
"sys/uio.h",
"sys/un.h",
"sys/utsname.h",
"sys/wait.h",
"syslog.h",
true)
211 .Cases(
"tar.h",
"termios.h",
"trace.h",
"ulimit.h",
true)
212 .Cases(
"unistd.h",
"utime.h",
"utmpx.h",
"wordexp.h",
true)
219 if (MacroNameTok.
is(tok::eod))
220 return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
224 return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
230 ? diag::ext_pp_operator_used_as_macro_name
231 : diag::err_pp_operator_used_as_macro_name)
232 << II << MacroNameTok.
getKind();
239 return Diag(MacroNameTok, diag::err_defined_macro_name);
247 Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
272 Diag(MacroNameTok, diag::warn_pp_macro_is_reserved_id);
288 void Preprocessor::ReadMacroName(
Token &MacroNameTok,
MacroUse isDefineUndef,
293 if (MacroNameTok.
is(tok::code_completion)) {
305 if (MacroNameTok.
isNot(tok::eod)) {
306 MacroNameTok.
setKind(tok::eod);
327 while (Tmp.
is(tok::comment))
330 if (Tmp.
isNot(tok::eod)) {
336 if ((LangOpts.GNUMode || LangOpts.C99 || LangOpts.CPlusPlus) &&
339 Diag(Tmp, diag::ext_pp_extra_tokens_at_eol) << DirType << Hint;
352 void Preprocessor::SkipExcludedConditionalBlock(
SourceLocation IfTokenLoc,
353 bool FoundNonSkipPortion,
357 assert(!CurTokenLexer && CurPPLexer &&
"Lexing a macro, not a file?");
360 FoundNonSkipPortion, FoundElse);
363 PTHSkipExcludedConditionalBlock();
374 if (Tok.
is(tok::code_completion)) {
386 if (CurLexer->getFileLoc() != CodeCompletionFileLoc)
388 diag::err_pp_unterminated_conditional);
404 if (CurLexer) CurLexer->SetKeepWhitespaceMode(
false);
412 if (Tok.
isNot(tok::raw_identifier)) {
415 if (CurLexer) CurLexer->resetExtendedTokenMode();
426 char FirstChar = RI[0];
427 if (FirstChar >=
'a' && FirstChar <=
'z' &&
428 FirstChar !=
'i' && FirstChar !=
'e') {
431 if (CurLexer) CurLexer->resetExtendedTokenMode();
438 char DirectiveBuf[20];
444 size_t IdLen = DirectiveStr.size();
448 if (CurLexer) CurLexer->resetExtendedTokenMode();
451 memcpy(DirectiveBuf, &DirectiveStr[0], IdLen);
452 Directive = StringRef(DirectiveBuf, IdLen);
455 if (Directive.startswith(
"if")) {
456 StringRef Sub = Directive.substr(2);
467 }
else if (Directive[0] ==
'e') {
468 StringRef Sub = Directive.substr(1);
474 assert(!InCond &&
"Can't be skipping if not in a conditional!");
489 }
else if (Sub ==
"lse") {
496 if (CondInfo.
FoundElse)
Diag(Tok, diag::pp_err_else_after_else);
516 }
else if (Sub ==
"lif") {
520 if (CondInfo.
FoundElse)
Diag(Tok, diag::pp_err_elif_after_else);
530 assert(CurPPLexer->
LexingRawMode &&
"We have to be skipping here!");
533 const bool CondValue = EvaluateDirectiveExpression(IfNDefMacro).Conditional;
552 if (CurLexer) CurLexer->resetExtendedTokenMode();
566 void Preprocessor::PTHSkipExcludedConditionalBlock() {
569 assert(CurPTHLexer->LexingRawMode ==
false);
572 if (CurPTHLexer->SkipBlock()) {
576 bool InCond = CurPTHLexer->popConditionalLevel(CondInfo);
578 assert(!InCond &&
"Can't be skipping if not in a conditional!");
591 if (K == tok::pp_else) {
604 CurPTHLexer->ParsingPreprocessorDirective =
true;
606 CurPTHLexer->ParsingPreprocessorDirective =
false;
615 assert(K == tok::pp_elif);
620 Diag(Tok, diag::pp_err_elif_after_else);
629 CurPTHLexer->ParsingPreprocessorDirective =
true;
630 bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro).Conditional;
631 CurPTHLexer->ParsingPreprocessorDirective =
false;
667 assert(M &&
"no module to include");
688 bool InTextualHeader =
false;
690 if (!Header.getModule()->isSubModuleOf(TopM))
697 if (Header.isAccessibleFrom(IncM))
707 InTextualHeader =
true;
710 if (!InTextualHeader)
726 bool RequestingModuleIsModuleInterface = !SourceMgr.
isInMainFile(FilenameLoc);
732 bool BuildSystemModule =
false;
733 if (!FromDir && !FromFile) {
751 Includers.push_back(std::make_pair(
nullptr, MainFileDir));
753 }
else if ((FileEnt =
755 Includers.push_back(std::make_pair(FileEnt, FileMgr.
getDirectory(
".")));
757 Includers.push_back(std::make_pair(FileEnt, FileEnt->
getDir()));
763 if (LangOpts.MSVCCompat && !isAngled) {
764 for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
765 if (IsFileLexer(ISEntry))
766 if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
767 Includers.push_back(std::make_pair(FileEnt, FileEnt->
getDir()));
772 CurDir = CurDirLookup;
780 Filename, FilenameLoc, isAngled, TmpFromDir, TmpCurDir,
781 Includers, SearchPath, RelativePath, RequestingModule,
782 SuggestedModule,
nullptr, SkipCache)) {
784 TmpFromDir = TmpCurDir;
786 if (FE == FromFile) {
788 FromDir = TmpFromDir;
797 Filename, FilenameLoc, isAngled, FromDir, CurDir, Includers, SearchPath,
798 RelativePath, RequestingModule, SuggestedModule, IsMapped, SkipCache,
801 if (SuggestedModule && !LangOpts.AsmPreprocessor)
803 RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
815 SearchPath, RelativePath,
818 if (SuggestedModule && !LangOpts.AsmPreprocessor)
820 RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
827 for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
828 if (IsFileLexer(ISEntry)) {
829 if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
831 Filename, CurFileEnt, SearchPath, RelativePath,
832 RequestingModule, SuggestedModule))) {
833 if (SuggestedModule && !LangOpts.AsmPreprocessor)
835 RequestingModule, RequestingModuleIsModuleInterface,
836 FilenameLoc, Filename, FE);
854 : PP(pp), save(pp->DisableMacroExpansion) {
855 if (pp->MacroExpansionInDirectivesOverride)
856 pp->DisableMacroExpansion =
false;
860 PP->DisableMacroExpansion = save;
879 if (CurLexer) CurLexer->SetKeepWhitespaceMode(
false);
881 bool ImmediatelyAfterTopLevelIfndef =
909 switch (II->getPPKeywordID()) {
910 case tok::pp_include:
912 case tok::pp_include_next:
913 case tok::pp___include_macros:
915 Diag(Result, diag::err_embedded_directive) << II->getName();
922 Diag(Result, diag::ext_embedded_directive);
932 case tok::code_completion:
938 case tok::numeric_constant:
941 return HandleDigitDirective(Result);
951 return HandleIfDirective(Result, ReadAnyTokensBeforeDirective);
953 return HandleIfdefDirective(Result,
false,
true);
955 return HandleIfdefDirective(Result,
true, ReadAnyTokensBeforeDirective);
957 return HandleElifDirective(Result);
959 return HandleElseDirective(Result);
961 return HandleEndifDirective(Result);
964 case tok::pp_include:
967 case tok::pp___include_macros:
973 return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef);
975 return HandleUndefDirective();
979 return HandleLineDirective();
983 return HandleUserDiagnosticDirective(Result,
false);
992 case tok::pp_include_next:
995 case tok::pp_warning:
996 Diag(Result, diag::ext_pp_warning_directive);
997 return HandleUserDiagnosticDirective(Result,
true);
999 return HandleIdentSCCSDirective(Result);
1001 return HandleIdentSCCSDirective(Result);
1002 case tok::pp_assert:
1005 case tok::pp_unassert:
1009 case tok::pp___public_macro:
1011 return HandleMacroPublicDirective(Result);
1014 case tok::pp___private_macro:
1016 return HandleMacroPrivateDirective();
1027 auto Toks = llvm::make_unique<Token[]>(2);
1029 Toks[0] = SavedHash;
1034 if (Result.
is(tok::hashhash))
1035 Toks[1].setKind(tok::unknown);
1040 EnterTokenStream(std::move(Toks), 2,
false);
1045 Diag(Result, diag::err_pp_invalid_directive);
1057 bool IsGNULineDirective=
false) {
1058 if (DigitTok.
isNot(tok::numeric_constant)) {
1059 PP.
Diag(DigitTok, DiagID);
1061 if (DigitTok.
isNot(tok::eod))
1067 IntegerBuffer.resize(DigitTok.
getLength());
1068 const char *DigitTokBegin = &IntegerBuffer[0];
1069 bool Invalid =
false;
1070 unsigned ActualLength = PP.
getSpelling(DigitTok, DigitTokBegin, &Invalid);
1078 for (
unsigned i = 0; i != ActualLength; ++i) {
1081 if (DigitTokBegin[i] ==
'\'')
1084 if (!
isDigit(DigitTokBegin[i])) {
1086 diag::err_pp_line_digit_sequence) << IsGNULineDirective;
1091 unsigned NextVal = Val*10+(DigitTokBegin[i]-
'0');
1092 if (NextVal < Val) {
1093 PP.
Diag(DigitTok, DiagID);
1100 if (DigitTokBegin[0] ==
'0' && Val)
1102 << IsGNULineDirective;
1114 void Preprocessor::HandleLineDirective() {
1122 if (
GetLineValue(DigitTok, LineNo, diag::err_pp_line_requires_integer,*
this))
1126 Diag(DigitTok, diag::ext_pp_line_zero);
1130 unsigned LineLimit = 32768U;
1131 if (LangOpts.C99 || LangOpts.CPlusPlus11)
1132 LineLimit = 2147483648U;
1133 if (LineNo >= LineLimit)
1134 Diag(DigitTok, diag::ext_pp_line_too_big) << LineLimit;
1135 else if (LangOpts.CPlusPlus11 && LineNo >= 32768U)
1136 Diag(DigitTok, diag::warn_cxx98_compat_pp_line_too_big);
1138 int FilenameID = -1;
1144 if (StrTok.
is(tok::eod))
1146 else if (StrTok.
isNot(tok::string_literal)) {
1147 Diag(StrTok, diag::err_pp_line_invalid_filename);
1150 Diag(StrTok, diag::err_invalid_string_udl);
1155 assert(Literal.isAscii() &&
"Didn't allow wide strings in");
1156 if (Literal.hadError)
1158 if (Literal.Pascal) {
1159 Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
1193 if (FlagTok.
is(tok::eod))
return false;
1194 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag, PP))
1201 if (FlagTok.
is(tok::eod))
return false;
1202 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
1204 }
else if (FlagVal == 2) {
1221 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_pop);
1227 if (FlagTok.
is(tok::eod))
return false;
1228 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
1234 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_flag);
1242 if (FlagTok.
is(tok::eod))
return false;
1243 if (
GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag, PP))
1248 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_flag);
1256 if (FlagTok.
is(tok::eod))
return false;
1259 PP.
Diag(FlagTok, diag::err_pp_linemarker_invalid_flag);
1271 void Preprocessor::HandleDigitDirective(
Token &DigitTok) {
1275 if (
GetLineValue(DigitTok, LineNo, diag::err_pp_linemarker_requires_integer,
1282 bool IsFileEntry =
false, IsFileExit =
false;
1283 int FilenameID = -1;
1288 if (StrTok.
is(tok::eod)) {
1291 }
else if (StrTok.
isNot(tok::string_literal)) {
1292 Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
1295 Diag(StrTok, diag::err_invalid_string_udl);
1300 assert(Literal.isAscii() &&
"Didn't allow wide strings in");
1301 if (Literal.hadError)
1303 if (Literal.Pascal) {
1304 Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
1316 IsFileExit, FileKind);
1325 else if (IsFileExit)
1334 void Preprocessor::HandleUserDiagnosticDirective(
Token &Tok,
1338 return CurPTHLexer->DiscardToEndOfLine();
1346 CurLexer->ReadToEndOfLine(&Message);
1350 StringRef Msg = StringRef(Message).ltrim(
' ');
1353 Diag(Tok, diag::pp_hash_warning) << Msg;
1355 Diag(Tok, diag::err_pp_hash_error) << Msg;
1360 void Preprocessor::HandleIdentSCCSDirective(
Token &Tok) {
1362 Diag(Tok, diag::ext_pp_ident_directive);
1369 if (StrTok.
isNot(tok::string_literal) &&
1370 StrTok.
isNot(tok::wide_string_literal)) {
1371 Diag(StrTok, diag::err_pp_malformed_ident);
1372 if (StrTok.
isNot(tok::eod))
1378 Diag(StrTok, diag::err_invalid_string_udl);
1394 void Preprocessor::HandleMacroPublicDirective(
Token &Tok) {
1396 ReadMacroName(MacroNameTok,
MU_Undef);
1399 if (MacroNameTok.
is(tok::eod))
1411 Diag(MacroNameTok, diag::err_pp_visibility_non_macro) << II;
1421 void Preprocessor::HandleMacroPrivateDirective() {
1423 ReadMacroName(MacroNameTok,
MU_Undef);
1426 if (MacroNameTok.
is(tok::eod))
1438 Diag(MacroNameTok, diag::err_pp_visibility_non_macro) << II;
1460 assert(!Buffer.empty() &&
"Can't have tokens with empty spellings!");
1464 if (Buffer[0] ==
'<') {
1465 if (Buffer.back() !=
'>') {
1466 Diag(Loc, diag::err_pp_expects_filename);
1467 Buffer = StringRef();
1471 }
else if (Buffer[0] ==
'"') {
1472 if (Buffer.back() !=
'"') {
1473 Diag(Loc, diag::err_pp_expects_filename);
1474 Buffer = StringRef();
1479 Diag(Loc, diag::err_pp_expects_filename);
1480 Buffer = StringRef();
1485 if (Buffer.size() <= 2) {
1486 Diag(Loc, diag::err_pp_empty_filename);
1487 Buffer = StringRef();
1492 Buffer = Buffer.substr(1, Buffer.size()-2);
1514 while (CurTok.
isNot(tok::eod)) {
1518 if (CurTok.
is(tok::code_completion)) {
1527 FilenameBuffer.push_back(
' ');
1530 size_t PreAppendSize = FilenameBuffer.size();
1531 FilenameBuffer.resize(PreAppendSize+CurTok.
getLength());
1533 const char *BufPtr = &FilenameBuffer[PreAppendSize];
1537 if (BufPtr != &FilenameBuffer[PreAppendSize])
1538 memcpy(&FilenameBuffer[PreAppendSize], BufPtr, ActualLen);
1542 FilenameBuffer.resize(PreAppendSize+ActualLen);
1545 if (CurTok.
is(tok::greater))
1560 void *AnnotationVal) {
1563 auto Tok = llvm::make_unique<Token[]>(1);
1569 EnterTokenStream(std::move(Tok), 1,
true);
1576 ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> Path,
1578 assert(PP.
getLangOpts().ObjC2 &&
"no import syntax available");
1581 for (
size_t I = 0, N = Path.size();
I != N; ++
I) {
1584 PathString += Path[
I].first->getName();
1586 int IncludeKind = 0;
1589 case tok::pp_include:
1593 case tok::pp_import:
1597 case tok::pp_include_next:
1601 case tok::pp___include_macros:
1606 llvm_unreachable(
"unknown include directive kind");
1611 PP.
Diag(HashLoc, diag::warn_auto_module_import)
1612 << IncludeKind << PathString
1614 (
"@import " + PathString +
";").str());
1621 StringRef RealPathName) {
1622 auto RealPathComponentIter = llvm::sys::path::rbegin(RealPathName);
1623 auto RealPathComponentEnd = llvm::sys::path::rend(RealPathName);
1625 bool SuggestReplacement =
false;
1628 for (
auto &Component : llvm::reverse(Components)) {
1629 if (
"." == Component) {
1630 }
else if (
".." == Component) {
1634 }
else if (RealPathComponentIter != RealPathComponentEnd) {
1635 if (Component != *RealPathComponentIter) {
1639 SuggestReplacement = RealPathComponentIter->equals_lower(Component);
1640 if (!SuggestReplacement)
1642 Component = *RealPathComponentIter;
1644 ++RealPathComponentIter;
1647 return SuggestReplacement;
1655 if (M->
isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader))
1675 void Preprocessor::HandleIncludeDirective(
SourceLocation HashLoc,
1689 switch (FilenameTok.
getKind()) {
1694 case tok::angle_string_literal:
1695 case tok::string_literal:
1696 Filename =
getSpelling(FilenameTok, FilenameBuffer);
1704 FilenameBuffer.push_back(
'<');
1707 Filename = FilenameBuffer;
1718 StringRef OriginalFilename =
Filename;
1723 if (Filename.empty()) {
1735 if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
1736 Diag(FilenameTok, diag::err_pp_include_too_deep);
1741 if (PragmaARCCFCodeAuditedLoc.
isValid()) {
1742 Diag(HashLoc, diag::err_pp_include_in_arc_cf_code_audited);
1743 Diag(PragmaARCCFCodeAuditedLoc, diag::note_pragma_entered_here);
1750 if (PragmaAssumeNonNullLoc.
isValid()) {
1751 Diag(HashLoc, diag::err_pp_include_in_assume_nonnull);
1752 Diag(PragmaAssumeNonNullLoc, diag::note_pragma_entered_here);
1763 if (!NewName.empty())
1768 bool IsMapped =
false;
1777 if (LangOpts.MSVCCompat) {
1778 NormalizedPath = Filename.str();
1779 #ifndef LLVM_ON_WIN32
1780 llvm::sys::path::native(NormalizedPath);
1784 FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename,
1785 isAngled, LookupFrom, LookupFromFile, CurDir,
1786 Callbacks ? &SearchPath :
nullptr, Callbacks ? &RelativePath :
nullptr,
1787 &SuggestedModule, &IsMapped);
1793 if (Callbacks->FileNotFound(Filename, RecoveryPath)) {
1802 LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename, isAngled,
1803 LookupFrom, LookupFromFile, CurDir,
nullptr,
nullptr,
1804 &SuggestedModule, &IsMapped,
true);
1809 if (!SuppressIncludeNotFoundError) {
1816 LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename,
false,
1817 LookupFrom, LookupFromFile, CurDir,
1818 Callbacks ? &SearchPath :
nullptr,
1819 Callbacks ? &RelativePath :
nullptr, &SuggestedModule, &IsMapped);
1822 Diag(FilenameTok, diag::err_pp_file_not_found_not_fatal) <<
1830 Diag(FilenameTok, diag::err_pp_file_not_found) << Filename
1839 bool ShouldEnter =
true;
1841 if (PPOpts->SingleFileParseMode)
1842 ShouldEnter =
false;
1847 if (ShouldEnter && File && SuggestedModule &&
getLangOpts().Modules &&
1857 diag::note_implicit_top_level_module_import_here)
1869 std::reverse(Path.begin(), Path.end());
1883 assert((Imported ==
nullptr || Imported == SuggestedModule.
getModule()) &&
1884 "the imported module is different than the suggested one");
1887 ShouldEnter =
false;
1904 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd,
tok::eof);
1905 CurLexer->cutOffLexing();
1907 assert(CurPTHLexer &&
"#include but no current lexer set!");
1908 CurPTHLexer->getEOF(Result);
1925 bool SkipHeader =
false;
1926 if (ShouldEnter && File &&
1930 ShouldEnter =
false;
1936 Callbacks->InclusionDirective(
1937 HashLoc, IncludeTok,
1938 LangOpts.MSVCCompat ? NormalizedPath.c_str() :
Filename, isAngled,
1939 FilenameRange, File, SearchPath, RelativePath,
1940 ShouldEnter ?
nullptr : SuggestedModule.
getModule());
1941 if (SkipHeader && !SuggestedModule.
getModule())
1942 Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
1953 const bool CheckIncludePathPortability =
1954 !IsMapped && File && !File->tryGetRealPathName().empty();
1956 if (CheckIncludePathPortability) {
1957 StringRef
Name = LangOpts.MSVCCompat ? NormalizedPath.str() :
Filename;
1958 StringRef RealPathName = File->tryGetRealPathName();
1960 llvm::sys::path::end(Name));
1964 Path.reserve(Name.size()+2);
1965 Path.push_back(isAngled ?
'<' :
'"');
1966 bool isLeadingSeparator = llvm::sys::path::is_absolute(Name);
1967 for (
auto Component : Components) {
1968 if (isLeadingSeparator)
1969 isLeadingSeparator =
false;
1971 Path.append(Component);
1974 Path.size() <= Filename.size() ? Filename[Path.size()-1] :
1975 (isAngled ?
'>' :
'"'));
1980 diag::pp_nonportable_path : diag::pp_nonportable_system_path;
1982 Diag(FilenameTok, DiagId) << Path <<
1990 if (
auto *M = SuggestedModule.
getModule()) {
2002 tok::pp___include_macros)
2004 tok::annot_module_include, M);
2016 assert(FID.
isValid() &&
"Expected valid file ID");
2023 if (
auto *M = SuggestedModule.
getModule()) {
2031 assert(!CurLexerSubmodule &&
"should not have marked this as a module yet");
2032 CurLexerSubmodule = M;
2048 void Preprocessor::HandleIncludeNextDirective(
SourceLocation HashLoc,
2049 Token &IncludeNextTok) {
2050 Diag(IncludeNextTok, diag::ext_pp_include_next_directive);
2056 const FileEntry *LookupFromFile =
nullptr;
2063 Diag(IncludeNextTok, diag::pp_include_next_in_primary);
2064 }
else if (CurLexerSubmodule) {
2067 assert(CurPPLexer &&
"#include_next directive in macro?");
2070 }
else if (!Lookup) {
2071 Diag(IncludeNextTok, diag::pp_include_next_absolute_path);
2077 return HandleIncludeDirective(HashLoc, IncludeNextTok, Lookup,
2082 void Preprocessor::HandleMicrosoftImportDirective(
Token &Tok) {
2088 Diag(Tok, diag::err_pp_import_directive_ms );
2099 if (!LangOpts.ObjC1) {
2100 if (LangOpts.MSVCCompat)
2101 return HandleMicrosoftImportDirective(ImportTok);
2102 Diag(ImportTok, diag::ext_pp_import_directive);
2104 return HandleIncludeDirective(HashLoc, ImportTok,
nullptr,
nullptr,
true);
2111 void Preprocessor::HandleIncludeMacrosDirective(
SourceLocation HashLoc,
2112 Token &IncludeMacrosTok) {
2118 diag::pp_include_macros_out_of_predefines);
2125 HandleIncludeDirective(HashLoc, IncludeMacrosTok);
2130 assert(TmpTok.
isNot(
tok::eof) &&
"Didn't find end of -imacros!");
2131 }
while (TmpTok.
isNot(tok::hashhash));
2142 bool Preprocessor::ReadMacroParameterList(
MacroInfo *MI,
Token &Tok) {
2150 if (Arguments.empty())
2153 Diag(Tok, diag::err_pp_expected_ident_in_arg_list);
2157 Diag(Tok, LangOpts.CPlusPlus11 ?
2158 diag::warn_cxx98_compat_variadic_macro :
2159 diag::ext_variadic_macro);
2162 if (LangOpts.OpenCL) {
2163 Diag(Tok, diag::err_pp_opencl_variadic_macros);
2169 if (Tok.
isNot(tok::r_paren)) {
2170 Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
2174 Arguments.push_back(Ident__VA_ARGS__);
2179 Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
2187 Diag(Tok, diag::err_pp_invalid_tok_in_arg_list);
2193 if (std::find(Arguments.begin(), Arguments.end(), II) !=
2195 Diag(Tok, diag::err_pp_duplicate_name_in_arg_list) << II;
2200 Arguments.push_back(II);
2207 Diag(Tok, diag::err_pp_expected_comma_in_arg_list);
2216 Diag(Tok, diag::ext_named_variadic_macro);
2220 if (Tok.
isNot(tok::r_paren)) {
2221 Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
2251 StringRef ValueText = II->
getName();
2252 StringRef TrimmedValue = ValueText;
2253 if (!ValueText.startswith(
"__")) {
2254 if (ValueText.startswith(
"_"))
2255 TrimmedValue = TrimmedValue.drop_front(1);
2259 TrimmedValue = TrimmedValue.drop_front(2);
2260 if (TrimmedValue.endswith(
"__"))
2261 TrimmedValue = TrimmedValue.drop_back(2);
2263 return TrimmedValue.equals(MacroText);
2270 return MacroName.
isOneOf(tok::kw_extern, tok::kw_inline, tok::kw_static,
2283 MacroInfo *Preprocessor::ReadOptionalMacroParameterListAndBody(
2284 const Token &MacroNameTok,
const bool ImmediatelyAfterHeaderGuard) {
2286 Token LastTok = MacroNameTok;
2296 if (Tok.is(tok::eod)) {
2297 if (ImmediatelyAfterHeaderGuard) {
2303 }
else if (Tok.hasLeadingSpace()) {
2307 }
else if (Tok.is(tok::l_paren)) {
2310 if (ReadMacroParameterList(MI, LastTok)) {
2322 assert(Ident__VA_ARGS__->
isPoisoned() &&
"__VA_ARGS__ should be poisoned!");
2328 }
else if (LangOpts.C99 || LangOpts.CPlusPlus11) {
2331 Diag(Tok, diag::ext_c99_whitespace_required_after_macro_name);
2340 if (Tok.is(tok::at))
2342 else if (Tok.is(tok::unknown)) {
2349 Diag(Tok, diag::ext_missing_whitespace_after_macro_name);
2351 Diag(Tok, diag::warn_missing_whitespace_after_macro_name);
2354 if (!Tok.is(tok::eod))
2360 while (Tok.isNot(tok::eod)) {
2370 while (Tok.isNot(tok::eod)) {
2373 if (!Tok.isOneOf(tok::hash, tok::hashat, tok::hashhash)) {
2385 Tok.setKind(tok::unknown);
2393 if (Tok.is(tok::hashhash)) {
2401 if (Tok.is(tok::eod)) {
2407 if (NumTokens && Tok.getIdentifierInfo() == Ident__VA_ARGS__ &&
2420 if (Tok.getIdentifierInfo() ==
nullptr ||
2427 if (
getLangOpts().AsmPreprocessor && Tok.isNot(tok::eod)) {
2428 LastTok.
setKind(tok::unknown);
2432 Diag(Tok, diag::err_pp_stringize_not_parameter)
2433 << LastTok.
is(tok::hashat);
2458 void Preprocessor::HandleDefineDirective(
2459 Token &DefineTok,
const bool ImmediatelyAfterHeaderGuard) {
2463 bool MacroShadowsKeyword;
2464 ReadMacroName(MacroNameTok,
MU_Define, &MacroShadowsKeyword);
2467 if (MacroNameTok.
is(tok::eod))
2472 if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments);
2474 MacroInfo *
const MI = ReadOptionalMacroParameterListAndBody(
2475 MacroNameTok, ImmediatelyAfterHeaderGuard);
2479 if (MacroShadowsKeyword &&
2481 Diag(MacroNameTok, diag::warn_pp_macro_hides_keyword);
2486 if (NumTokens != 0) {
2505 auto isObjCProtectedMacro = [](
const IdentifierInfo *II) ->
bool {
2506 return II->
isStr(
"__strong") ||
2507 II->
isStr(
"__weak") ||
2508 II->
isStr(
"__unsafe_unretained") ||
2509 II->
isStr(
"__autoreleasing");
2512 SourceMgr.
getFileID(OtherMI->getDefinitionLoc())
2519 LangOpts.MicrosoftExt)) {
2522 assert(!OtherMI->isWarnIfUnused());
2531 if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused())
2532 Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
2536 if (OtherMI->isBuiltinMacro())
2537 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
2540 else if (!OtherMI->isAllowRedefinitionsWithoutWarning() &&
2541 !MI->
isIdenticalTo(*OtherMI, *
this, LangOpts.MicrosoftExt)) {
2544 Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
2547 if (OtherMI->isWarnIfUnused())
2548 WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
2565 Callbacks->MacroDefined(MacroNameTok, MD);
2570 void Preprocessor::HandleUndefDirective() {
2574 ReadMacroName(MacroNameTok,
MU_Undef);
2577 if (MacroNameTok.
is(tok::eod))
2596 Undef = AllocateUndefMacroDirective(MacroNameTok.
getLocation());
2602 Callbacks->MacroUndefined(MacroNameTok, MD, Undef);
2617 void Preprocessor::HandleIfdefDirective(
Token &Result,
bool isIfndef,
2618 bool ReadAnyTokensBeforeDirective) {
2623 ReadMacroName(MacroNameTok);
2626 if (MacroNameTok.
is(tok::eod)) {
2629 SkipExcludedConditionalBlock(DirectiveTok.
getLocation(),
2646 if (!ReadAnyTokensBeforeDirective && !MI) {
2647 assert(isIfndef &&
"#ifdef shouldn't reach here");
2659 Callbacks->Ifndef(DirectiveTok.
getLocation(), MacroNameTok, MD);
2661 Callbacks->Ifdef(DirectiveTok.
getLocation(), MacroNameTok, MD);
2665 if (PPOpts->SingleFileParseMode && !MI) {
2671 }
else if (!MI == isIfndef) {
2678 SkipExcludedConditionalBlock(DirectiveTok.
getLocation(),
2686 void Preprocessor::HandleIfDirective(
Token &IfToken,
2687 bool ReadAnyTokensBeforeDirective) {
2693 const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
2694 const bool ConditionalTrue = DER.Conditional;
2700 if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
2713 if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
2718 }
else if (ConditionalTrue) {
2724 SkipExcludedConditionalBlock(IfToken.
getLocation(),
false,
2731 void Preprocessor::HandleEndifDirective(
Token &EndifToken) {
2740 Diag(EndifToken, diag::err_pp_endif_without_if);
2749 "This code should only be reachable in the non-skipping case!");
2757 void Preprocessor::HandleElseDirective(
Token &Result) {
2765 Diag(Result, diag::pp_err_else_without_if);
2774 if (CI.
FoundElse)
Diag(Result, diag::pp_err_else_after_else);
2788 SkipExcludedConditionalBlock(CI.
IfLoc,
true,
2794 void Preprocessor::HandleElifDirective(
Token &ElifToken) {
2806 Diag(ElifToken, diag::pp_err_elif_without_if);
2815 if (CI.
FoundElse)
Diag(ElifToken, diag::pp_err_elif_after_else);
2831 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.
SourceLocation getEnd() const
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.
static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, SrcMgr::CharacteristicKind &FileKind, Preprocessor &PP)
ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line marker directive...
This header is part of the module (for layering purposes) but should be textually included...
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.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Defines the SourceManager interface.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Defines the clang::Module class, which describes a module in the source code.
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
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
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.
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 *IsMapped, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
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.
void setParameterList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the parameter list for this macro.
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)
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)
void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
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.
StringRef getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
const LangOptions & getLangOpts() const
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
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.
static bool trySimplifyPath(SmallVectorImpl< StringRef > &Components, StringRef RealPathName)
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...
ArrayRef< KnownHeader > findAllModulesForHeader(const FileEntry *File) const
Retrieve all the modules that contain the given header file.
void HandleDirective(Token &Result)
Callback invoked when the lexer sees a # token at the start of a line.
Concrete class used by the front-end to report problems and issues.
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.
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
bool isCPlusPlusOperatorKeyword() const
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, of which the main source file is a part.
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.
Exposes information about the current target.
void setAnnotationValue(void *val)
void diagnoseHeaderInclusion(Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, const FileEntry *File)
Reports errors if a module must not include a specific file.
Defines the clang::LangOptions interface.
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...
bool isKeyword(const LangOptions &LangOpts) const
Return true if this token is a keyword in the specified language.
static bool warnByDefaultOnWrongCase(StringRef Include)
Defines the clang::Preprocessor interface.
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.
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.
static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M)
Check that the given module is available, producing a diagnostic if not.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isNot(tok::TokenKind K) const
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location...
KnownHeader findModuleForHeader(const FileEntry *File, bool AllowTextual=false)
Retrieve the module that owns the given header file, if any.
Information about the conditional stack (#if directives) currently active.
Represents an unpacked "presumed" location which can be presented to the user.
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.
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). ...
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 Lex(Token &Result)
Lex the next token for this preprocessor.
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.
SourceLocation getBegin() const
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...
bool isConfigMismatch() const
Determines whether the module failed to load due to a configuration mismatch with an explicitly-named...
static bool isInvalid(LocType Loc, bool *Invalid)
The pragma was introduced via #pragma.
void ExitTopLevelConditional()
Called when the lexer exits the top-level conditional.
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
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i...
static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II)
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
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 FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
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).
Defines the PPCallbacks interface.
Defines the clang::TokenKind enum and support functions.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
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...
Defines the clang::SourceLocation class and associated facilities.
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...
const FileEntry * getModuleHeaderToIncludeForDiagnostics(SourceLocation IncLoc, Module *M, SourceLocation MLoc)
We want to produce a diagnostic at location IncLoc concerning a missing module import.
int getParameterNum(const IdentifierInfo *Arg) const
Return the parameter number of the specified identifier, or -1 if the identifier is not a formal para...
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.
void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, void *AnnotationVal)
Enter an annotation token into the token stream.
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.