248 #include "clang/Lex/LexDiagnostic.h"
249 #include "clang/Lex/MacroArgs.h"
250 #include "clang/Lex/PPCallbacks.h"
251 #include "llvm/ADT/SmallSet.h"
252 #include "llvm/ADT/StringSet.h"
253 #include "llvm/Support/raw_ostream.h"
270 clang::SourceLocation
Loc) {
272 return std::string(
"(none)");
274 return Loc.printToString(PP.getSourceManager());
279 clang::SourceLocation
Loc) {
281 size_t Offset = Source.find(
':', 2);
282 if (
Offset == std::string::npos)
284 return Source.substr(0,
Offset);
289 clang::SourceLocation
Loc,
int &
Line,
291 clang::PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(
Loc);
292 if (PLoc.isInvalid()) {
297 Line = PLoc.getLine();
298 Column = PLoc.getColumn();
303 clang::SourceRange
Range) {
304 clang::SourceLocation BeginLoc =
Range.getBegin();
305 clang::SourceLocation EndLoc =
Range.getEnd();
306 const char *BeginPtr = PP.getSourceManager().getCharacterData(BeginLoc);
307 const char *EndPtr = PP.getSourceManager().getCharacterData(EndLoc);
308 size_t Length = EndPtr - BeginPtr;
309 return llvm::StringRef(BeginPtr,
Length).trim().str();
314 clang::SourceLocation
Loc) {
315 const llvm::MemoryBuffer *MemBuffer =
316 PP.getSourceManager().getBuffer(PP.getSourceManager().getFileID(
Loc));
317 const char *Buffer = MemBuffer->getBufferStart();
318 const char *BufferEnd = MemBuffer->getBufferEnd();
319 const char *BeginPtr = PP.getSourceManager().getCharacterData(
Loc);
320 const char *EndPtr = BeginPtr;
321 while (BeginPtr > Buffer) {
322 if (*BeginPtr ==
'\n') {
328 while (EndPtr < BufferEnd) {
329 if (*EndPtr ==
'\n') {
334 size_t Length = EndPtr - BeginPtr;
335 return llvm::StringRef(BeginPtr,
Length).str();
339 static std::string
getSourceLine(clang::Preprocessor &PP, clang::FileID FileID,
341 const llvm::MemoryBuffer *MemBuffer = PP.getSourceManager().getBuffer(FileID);
342 const char *Buffer = MemBuffer->getBufferStart();
343 const char *BufferEnd = MemBuffer->getBufferEnd();
344 const char *BeginPtr = Buffer;
345 const char *EndPtr = BufferEnd;
350 while (Buffer < BufferEnd) {
351 if (*Buffer ==
'\n') {
352 if (++LineCounter ==
Line) {
353 BeginPtr = Buffer++ + 1;
360 while (Buffer < BufferEnd) {
361 if (*Buffer ==
'\n') {
367 size_t Length = EndPtr - BeginPtr;
368 return llvm::StringRef(BeginPtr,
Length).str();
377 clang::Preprocessor &PP,
378 llvm::StringRef MacroName,
379 const clang::MacroInfo *MI) {
380 clang::SourceLocation BeginLoc(
Range.getBegin());
381 const char *BeginPtr = PP.getSourceManager().getCharacterData(BeginLoc);
383 std::string Unexpanded;
384 if (MI->isFunctionLike()) {
385 clang::SourceLocation EndLoc(
Range.getEnd());
386 const char *EndPtr = PP.getSourceManager().getCharacterData(EndLoc) + 1;
387 Length = (EndPtr - BeginPtr) + 1;
389 Length = MacroName.size();
390 return llvm::StringRef(BeginPtr,
Length).trim().str();
402 llvm::StringRef MacroName,
403 const clang::MacroInfo *MI,
404 const clang::MacroArgs *Args) {
405 std::string Expanded;
407 for (
const auto &T : MI->tokens()) {
408 clang::IdentifierInfo *II = T.getIdentifierInfo();
409 int ArgNo = (II && Args ? MI->getParameterNum(II) : -1);
413 Expanded += PP.getSpelling(T);
416 std::string
Name = II->getName().str();
418 clang::MacroInfo *MacroInfo = PP.getMacroInfo(II);
419 if (MacroInfo && (
Name != MacroName))
427 const clang::Token *ResultArgToks;
428 const clang::Token *ArgTok = Args->getUnexpArgument(ArgNo);
429 if (Args->ArgNeedsPreexpansion(ArgTok, PP))
430 ResultArgToks = &(const_cast<clang::MacroArgs *>(Args))
431 ->getPreExpArgument(ArgNo, PP)[0];
433 ResultArgToks = ArgTok;
435 if (ResultArgToks->is(clang::tok::eof))
437 unsigned NumToks = clang::MacroArgs::getArgLength(ResultArgToks);
439 for (
unsigned ArgumentIndex = 0; ArgumentIndex < NumToks; ++ArgumentIndex) {
440 const clang::Token &AT = ResultArgToks[ArgumentIndex];
441 clang::IdentifierInfo *II = AT.getIdentifierInfo();
443 Expanded += PP.getSpelling(AT);
446 std::string
Name = II->getName().str();
447 clang::MacroInfo *MacroInfo = PP.getMacroInfo(II);
463 "(not evaluated)",
"false",
"true"
477 clang::SourceLocation
Loc)
483 PPItemKey(
const PPItemKey &Other)
487 bool operator==(
const PPItemKey &Other)
const {
488 if (
Name != Other.Name)
490 if (File != Other.File)
492 if (
Line != Other.Line)
494 return Column == Other.Column;
496 bool operator<(
const PPItemKey &Other)
const {
497 if (
Name < Other.Name)
499 else if (
Name > Other.Name)
501 if (File < Other.File)
503 else if (File > Other.File)
505 if (
Line < Other.Line)
507 else if (
Line > Other.Line)
509 return Column < Other.Column;
518 class HeaderInclusionPath {
520 HeaderInclusionPath(std::vector<HeaderHandle> HeaderInclusionPath)
521 :
Path(HeaderInclusionPath) {}
522 HeaderInclusionPath(
const HeaderInclusionPath &Other) :
Path(Other.
Path) {}
523 HeaderInclusionPath() {}
524 std::vector<HeaderHandle>
Path;
532 class MacroExpansionInstance {
542 MacroExpansionInstance() {}
556 if (!haveInclusionPathHandle(H))
576 class MacroExpansionTracker {
589 MacroExpansionTracker() {}
592 MacroExpansionInstance *
634 class ConditionalExpansionInstance {
640 ConditionalExpansionInstance() {}
654 if (!haveInclusionPathHandle(H))
671 class ConditionalTracker {
680 ConditionalTracker() {}
683 ConditionalExpansionInstance *
684 findConditionalExpansionInstance(clang::PPCallbacks::ConditionValueKind
ConditionValue) {
697 addConditionalExpansionInstance(clang::PPCallbacks::ConditionValueKind
ConditionValue,
716 class PreprocessorTrackerImpl;
724 class PreprocessorCallbacks :
public clang::PPCallbacks {
726 PreprocessorCallbacks(PreprocessorTrackerImpl &ppTracker,
727 clang::Preprocessor &PP, llvm::StringRef rootHeaderFile)
728 : PPTracker(ppTracker), PP(PP), RootHeaderFile(rootHeaderFile) {}
729 ~PreprocessorCallbacks()
override {}
732 void InclusionDirective(clang::SourceLocation HashLoc,
733 const clang::Token &IncludeTok,
735 clang::CharSourceRange FilenameRange,
736 const clang::FileEntry *File,
737 llvm::StringRef SearchPath,
738 llvm::StringRef RelativePath,
739 const clang::Module *Imported,
740 clang::SrcMgr::CharacteristicKind FileType)
override;
741 void FileChanged(clang::SourceLocation
Loc,
742 clang::PPCallbacks::FileChangeReason Reason,
743 clang::SrcMgr::CharacteristicKind FileType,
744 clang::FileID PrevFID = clang::FileID())
override;
745 void MacroExpands(
const clang::Token &MacroNameTok,
746 const clang::MacroDefinition &
MD, clang::SourceRange
Range,
747 const clang::MacroArgs *Args)
override;
748 void Defined(
const clang::Token &MacroNameTok,
749 const clang::MacroDefinition &
MD,
750 clang::SourceRange
Range)
override;
751 void If(clang::SourceLocation
Loc, clang::SourceRange ConditionRange,
752 clang::PPCallbacks::ConditionValueKind ConditionResult)
override;
753 void Elif(clang::SourceLocation
Loc, clang::SourceRange ConditionRange,
754 clang::PPCallbacks::ConditionValueKind ConditionResult,
755 clang::SourceLocation IfLoc)
override;
756 void Ifdef(clang::SourceLocation
Loc,
const clang::Token &MacroNameTok,
757 const clang::MacroDefinition &
MD)
override;
758 void Ifndef(clang::SourceLocation
Loc,
const clang::Token &MacroNameTok,
759 const clang::MacroDefinition &
MD)
override;
762 PreprocessorTrackerImpl &PPTracker;
763 clang::Preprocessor &PP;
764 std::string RootHeaderFile;
768 typedef std::map<PPItemKey, MacroExpansionTracker> MacroExpansionMap;
769 typedef std::map<PPItemKey, MacroExpansionTracker>::iterator
770 MacroExpansionMapIter;
773 typedef std::map<PPItemKey, ConditionalTracker> ConditionalExpansionMap;
774 typedef std::map<PPItemKey, ConditionalTracker>::iterator
775 ConditionalExpansionMapIter;
781 class PreprocessorTrackerImpl :
public PreprocessorTracker {
783 PreprocessorTrackerImpl(llvm::SmallVector<std::string, 32> &Headers,
784 bool DoBlockCheckHeaderListOnly)
787 InNestedHeader(false) {
789 for (llvm::ArrayRef<std::string>::iterator I = Headers.begin(),
796 ~PreprocessorTrackerImpl()
override {}
799 void handlePreprocessorEntry(clang::Preprocessor &PP,
800 llvm::StringRef rootHeaderFile)
override {
801 HeadersInThisCompile.clear();
802 assert((HeaderStack.size() == 0) &&
"Header stack should be empty.");
803 pushHeaderHandle(addHeader(rootHeaderFile));
804 PP.addPPCallbacks(std::make_unique<PreprocessorCallbacks>(*
this, PP,
808 void handlePreprocessorExit()
override { HeaderStack.clear(); }
814 void handleIncludeDirective(llvm::StringRef DirectivePath,
int DirectiveLine,
816 llvm::StringRef TargetPath)
override {
821 HeaderHandle CurrentHeaderHandle = findHeaderHandle(DirectivePath);
822 StringHandle IncludeHeaderHandle = addString(TargetPath);
823 for (std::vector<PPItemKey>::const_iterator I = IncludeDirectives.begin(),
824 E = IncludeDirectives.end();
827 if ((I->File == CurrentHeaderHandle) && (I->Line ==
DirectiveLine))
830 PPItemKey IncludeDirectiveItem(IncludeHeaderHandle, CurrentHeaderHandle,
832 IncludeDirectives.push_back(IncludeDirectiveItem);
838 bool checkForIncludesInBlock(clang::Preprocessor &PP,
839 clang::SourceRange BlockSourceRange,
840 const char *BlockIdentifierMessage,
841 llvm::raw_ostream &
OS)
override {
842 clang::SourceLocation BlockStartLoc = BlockSourceRange.getBegin();
843 clang::SourceLocation BlockEndLoc = BlockSourceRange.getEnd();
846 clang::FileID FileID = PP.getSourceManager().getFileID(BlockStartLoc);
849 HeaderHandle SourceHandle = findHeaderHandle(SourcePath);
850 if (SourceHandle == -1)
852 int BlockStartLine, BlockStartColumn, BlockEndLine, BlockEndColumn;
853 bool returnValue =
true;
858 for (std::vector<PPItemKey>::const_iterator I = IncludeDirectives.begin(),
859 E = IncludeDirectives.end();
862 if ((I->File == SourceHandle) && (I->Line >= BlockStartLine) &&
863 (I->Line < BlockEndLine)) {
865 OS << SourcePath <<
":" << I->Line <<
":" << I->Column <<
":\n";
868 OS << std::string(I->Column - 1,
' ') <<
"^\n";
869 OS <<
"error: Include directive within " << BlockIdentifierMessage
871 OS << SourcePath <<
":" << BlockStartLine <<
":" << BlockStartColumn
874 if (BlockStartColumn > 0)
875 OS << std::string(BlockStartColumn - 1,
' ') <<
"^\n";
876 OS <<
"The \"" << BlockIdentifierMessage <<
"\" block is here.\n";
883 void handleHeaderEntry(clang::Preprocessor &PP, llvm::StringRef HeaderPath) {
885 if (HeaderPath.startswith(
"<"))
888 if (H != getCurrentHeaderHandle())
892 InNestedHeader = !HeadersInThisCompile.insert(H).second;
896 void handleHeaderExit(llvm::StringRef HeaderPath) {
898 if (HeaderPath.startswith(
"<"))
902 if (isHeaderHandleInStack(H)) {
904 TH = getCurrentHeaderHandle();
906 }
while ((TH != H) && (HeaderStack.size() != 0));
908 InNestedHeader =
false;
913 return Strings.insert(Str).first->first();
918 std::string CanonicalPath(path);
919 std::replace(CanonicalPath.begin(), CanonicalPath.end(),
'\\',
'/');
920 return CanonicalPath;
924 bool isHeaderListHeader(llvm::StringRef HeaderPath)
const {
926 for (llvm::ArrayRef<std::string>::iterator I = HeaderList.begin(),
927 E = HeaderList.end();
929 if (*I == CanonicalPath)
937 HeaderHandle findHeaderHandle(llvm::StringRef HeaderPath)
const {
940 for (
auto I = HeaderPaths.begin(),
E = HeaderPaths.end(); I !=
E;
942 if (*I == CanonicalPath)
954 H = HeaderPaths.size();
955 HeaderPaths.push_back(addString(CanonicalPath));
963 return HeaderPaths[H];
969 HeaderStack.push_back(H);
970 return CurrentInclusionPathHandle = addInclusionPathHandle(HeaderStack);
973 void popHeaderHandle() {
975 if (HeaderStack.size() != 0) {
976 HeaderStack.pop_back();
977 CurrentInclusionPathHandle = addInclusionPathHandle(HeaderStack);
982 if (HeaderStack.size() != 0)
983 return HeaderStack.back();
989 for (
auto I = HeaderStack.begin(),
E = HeaderStack.end(); I !=
E; ++I) {
999 findInclusionPathHandle(
const std::vector<HeaderHandle> &
Path)
const {
1001 for (
auto I = InclusionPaths.begin(),
E = InclusionPaths.end(); I !=
E;
1003 if (I->Path ==
Path)
1011 addInclusionPathHandle(
const std::vector<HeaderHandle> &
Path) {
1014 H = InclusionPaths.size();
1015 InclusionPaths.push_back(HeaderInclusionPath(
Path));
1021 return CurrentInclusionPathHandle;
1025 const std::vector<HeaderHandle> &
1028 return InclusionPaths[H].Path;
1029 static std::vector<HeaderHandle>
Empty;
1034 void addMacroExpansionInstance(clang::Preprocessor &PP,
HeaderHandle H,
1035 clang::SourceLocation InstanceLoc,
1036 clang::SourceLocation DefinitionLoc,
1037 clang::IdentifierInfo *II,
1044 PPItemKey InstanceKey(PP, MacroName, H, InstanceLoc);
1045 PPItemKey DefinitionKey(PP, MacroName, H, DefinitionLoc);
1046 auto I = MacroExpansions.find(InstanceKey);
1048 if (I == MacroExpansions.end()) {
1055 MacroExpansions[InstanceKey] = MacroExpansionTracker(
1061 MacroExpansionTracker &CondTracker = I->second;
1063 MacroExpansionInstance *MacroInfo =
1064 CondTracker.findMacroExpansionInstance(addString(
MacroExpanded),
1074 CondTracker.addMacroExpansionInstance(
1083 addConditionalExpansionInstance(clang::Preprocessor &PP,
HeaderHandle H,
1084 clang::SourceLocation InstanceLoc,
1093 PPItemKey InstanceKey(PP, ConditionUnexpandedHandle, H, InstanceLoc);
1094 auto I = ConditionalExpansions.find(InstanceKey);
1096 if (I == ConditionalExpansions.end()) {
1100 ConditionalExpansions[InstanceKey] =
1105 ConditionalTracker &CondTracker = I->second;
1107 ConditionalExpansionInstance *MacroInfo =
1122 bool reportInconsistentMacros(llvm::raw_ostream &
OS)
override {
1123 bool ReturnValue =
false;
1125 for (
auto I = MacroExpansions.begin(),
E = MacroExpansions.end(); I !=
E;
1127 const PPItemKey &ItemKey = I->first;
1128 MacroExpansionTracker &MacroExpTracker = I->second;
1130 if (!MacroExpTracker.hasMismatch())
1135 OS << MacroExpTracker.InstanceSourceLine;
1136 if (ItemKey.Column > 0)
1137 OS << std::string(ItemKey.Column - 1,
' ') <<
"^\n";
1138 OS <<
"error: Macro instance '" << MacroExpTracker.MacroUnexpanded
1139 <<
"' has different values in this header, depending on how it was "
1142 for (
auto IMT = MacroExpTracker.MacroExpansionInstances.begin(),
1143 EMT = MacroExpTracker.MacroExpansionInstances.end();
1144 IMT != EMT; ++IMT) {
1145 MacroExpansionInstance &MacroInfo = *IMT;
1146 OS <<
" '" << MacroExpTracker.MacroUnexpanded <<
"' expanded to: '"
1147 << MacroInfo.MacroExpanded
1148 <<
"' with respect to these inclusion paths:\n";
1150 for (
auto IIP = MacroInfo.InclusionPathHandles.begin(),
1151 EIP = MacroInfo.InclusionPathHandles.end();
1152 IIP != EIP; ++IIP) {
1153 const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP);
1154 auto Count = (int)ip.size();
1157 OS << std::string((
Index * 2) + 4,
' ') << getHeaderFilePath(H)
1164 if (MacroInfo.DefinitionLocation.Line != ItemKey.Line) {
1165 OS << MacroInfo.DefinitionSourceLine;
1166 if (MacroInfo.DefinitionLocation.Column > 0)
1167 OS << std::string(MacroInfo.DefinitionLocation.Column - 1,
' ')
1169 OS <<
"Macro defined here.\n";
1171 OS <<
"(no macro definition)"
1180 bool reportInconsistentConditionals(llvm::raw_ostream &
OS)
override {
1181 bool ReturnValue =
false;
1183 for (
auto I = ConditionalExpansions.begin(),
1184 E = ConditionalExpansions.end();
1186 const PPItemKey &ItemKey = I->first;
1187 ConditionalTracker &CondTracker = I->second;
1188 if (!CondTracker.hasMismatch())
1193 OS << HeaderPaths[ItemKey.File] <<
":" << ItemKey.Line <<
":"
1194 << ItemKey.Column <<
"\n";
1195 OS <<
"#" << getDirectiveSpelling(CondTracker.DirectiveKind) <<
" "
1196 << CondTracker.ConditionUnexpanded <<
"\n";
1198 OS <<
"error: Conditional expression instance '"
1199 << CondTracker.ConditionUnexpanded
1200 <<
"' has different values in this header, depending on how it was "
1203 for (
auto IMT = CondTracker.ConditionalExpansionInstances.begin(),
1204 EMT = CondTracker.ConditionalExpansionInstances.end();
1205 IMT != EMT; ++IMT) {
1206 ConditionalExpansionInstance &MacroInfo = *IMT;
1207 OS <<
" '" << CondTracker.ConditionUnexpanded <<
"' expanded to: '"
1209 <<
"' with respect to these inclusion paths:\n";
1211 for (
auto IIP = MacroInfo.InclusionPathHandles.begin(),
1212 EIP = MacroInfo.InclusionPathHandles.end();
1213 IIP != EIP; ++IIP) {
1214 const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP);
1215 auto Count = (int)ip.size();
1218 OS << std::string((
Index * 2) + 4,
' ') << getHeaderFilePath(H)
1228 static const char *getDirectiveSpelling(clang::tok::PPKeywordKind kind) {
1230 case clang::tok::pp_if:
1232 case clang::tok::pp_elif:
1234 case clang::tok::pp_ifdef:
1236 case clang::tok::pp_ifndef:
1244 llvm::SmallVector<std::string, 32> HeaderList;
1248 std::vector<StringHandle> HeaderPaths;
1249 std::vector<HeaderHandle> HeaderStack;
1250 std::vector<HeaderInclusionPath> InclusionPaths;
1252 llvm::SmallSet<HeaderHandle, 32> HeadersInThisCompile;
1253 std::vector<PPItemKey> IncludeDirectives;
1254 MacroExpansionMap MacroExpansions;
1255 ConditionalExpansionMap ConditionalExpansions;
1256 bool InNestedHeader;
1268 llvm::SmallVector<std::string, 32> &Headers,
1269 bool DoBlockCheckHeaderListOnly) {
1270 return new PreprocessorTrackerImpl(Headers, DoBlockCheckHeaderListOnly);
1276 void PreprocessorCallbacks::InclusionDirective(
1277 clang::SourceLocation HashLoc,
const clang::Token &IncludeTok,
1279 clang::CharSourceRange FilenameRange,
const clang::FileEntry *File,
1280 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
1281 const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) {
1285 PPTracker.handleIncludeDirective(HeaderPath,
DirectiveLine, DirectiveColumn,
1290 void PreprocessorCallbacks::FileChanged(
1291 clang::SourceLocation
Loc, clang::PPCallbacks::FileChangeReason Reason,
1292 clang::SrcMgr::CharacteristicKind FileType, clang::FileID PrevFID) {
1298 const clang::FileEntry *F =
1299 PP.getSourceManager().getFileEntryForID(PrevFID);
1301 PPTracker.handleHeaderExit(F->getName());
1303 case SystemHeaderPragma:
1310 void PreprocessorCallbacks::MacroExpands(
const clang::Token &MacroNameTok,
1311 const clang::MacroDefinition &
MD,
1312 clang::SourceRange
Range,
1313 const clang::MacroArgs *Args) {
1314 clang::SourceLocation
Loc =
Range.getBegin();
1316 if (!
Loc.isFileID())
1318 clang::IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
1319 const clang::MacroInfo *MI =
MD.getMacroInfo();
1320 std::string MacroName = II->getName().str();
1323 PPTracker.addMacroExpansionInstance(
1324 PP, PPTracker.getCurrentHeaderHandle(),
Loc, MI->getDefinitionLoc(), II,
1325 Unexpanded, Expanded, PPTracker.getCurrentInclusionPathHandle());
1328 void PreprocessorCallbacks::Defined(
const clang::Token &MacroNameTok,
1329 const clang::MacroDefinition &
MD,
1330 clang::SourceRange
Range) {
1331 clang::SourceLocation
Loc(
Range.getBegin());
1332 clang::IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
1333 const clang::MacroInfo *MI =
MD.getMacroInfo();
1334 std::string MacroName = II->getName().str();
1336 PPTracker.addMacroExpansionInstance(
1337 PP, PPTracker.getCurrentHeaderHandle(),
Loc,
1338 (MI ? MI->getDefinitionLoc() :
Loc), II, Unexpanded,
1339 (MI ?
"true" :
"false"), PPTracker.getCurrentInclusionPathHandle());
1342 void PreprocessorCallbacks::If(clang::SourceLocation
Loc,
1343 clang::SourceRange ConditionRange,
1344 clang::PPCallbacks::ConditionValueKind ConditionResult) {
1346 PPTracker.addConditionalExpansionInstance(
1347 PP, PPTracker.getCurrentHeaderHandle(),
Loc, clang::tok::pp_if,
1348 ConditionResult, Unexpanded, PPTracker.getCurrentInclusionPathHandle());
1351 void PreprocessorCallbacks::Elif(clang::SourceLocation
Loc,
1352 clang::SourceRange ConditionRange,
1353 clang::PPCallbacks::ConditionValueKind ConditionResult,
1354 clang::SourceLocation IfLoc) {
1356 PPTracker.addConditionalExpansionInstance(
1357 PP, PPTracker.getCurrentHeaderHandle(),
Loc, clang::tok::pp_elif,
1358 ConditionResult, Unexpanded, PPTracker.getCurrentInclusionPathHandle());
1361 void PreprocessorCallbacks::Ifdef(clang::SourceLocation
Loc,
1362 const clang::Token &MacroNameTok,
1363 const clang::MacroDefinition &
MD) {
1364 clang::PPCallbacks::ConditionValueKind IsDefined =
1365 (
MD ? clang::PPCallbacks::CVK_True : clang::PPCallbacks::CVK_False );
1366 PPTracker.addConditionalExpansionInstance(
1367 PP, PPTracker.getCurrentHeaderHandle(),
Loc, clang::tok::pp_ifdef,
1368 IsDefined, PP.getSpelling(MacroNameTok),
1369 PPTracker.getCurrentInclusionPathHandle());
1372 void PreprocessorCallbacks::Ifndef(clang::SourceLocation
Loc,
1373 const clang::Token &MacroNameTok,
1374 const clang::MacroDefinition &
MD) {
1375 clang::PPCallbacks::ConditionValueKind IsNotDefined =
1376 (!
MD ? clang::PPCallbacks::CVK_True : clang::PPCallbacks::CVK_False );
1377 PPTracker.addConditionalExpansionInstance(
1378 PP, PPTracker.getCurrentHeaderHandle(),
Loc, clang::tok::pp_ifndef,
1379 IsNotDefined, PP.getSpelling(MacroNameTok),
1380 PPTracker.getCurrentInclusionPathHandle());