Index: clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.h =================================================================== --- clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.h +++ clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.h @@ -30,17 +30,17 @@ HeaderMapCollector *Collector = nullptr) : Reporter(Reporter), SM(SM), Collector(Collector) {} - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override; - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; void EndOfMainFile() override; Index: clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.cpp =================================================================== --- clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.cpp +++ clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.cpp @@ -32,7 +32,8 @@ SymbolInfo::SymbolKind::Macro, FilePath, {}); } -void FindAllMacros::MacroDefined(const Token &MacroNameTok, +void FindAllMacros::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MD) { if (auto Symbol = CreateMacroSymbol(MacroNameTok, MD->getMacroInfo())) ++FileSymbols[*Symbol].Seen; @@ -51,12 +52,14 @@ MacroUsed(MacroNameTok, MD); } -void FindAllMacros::Ifdef(SourceLocation Loc, const Token &MacroNameTok, +void FindAllMacros::Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) { MacroUsed(MacroNameTok, MD); } -void FindAllMacros::Ifndef(SourceLocation Loc, const Token &MacroNameTok, +void FindAllMacros::Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) { MacroUsed(MacroNameTok, MD); } Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h =================================================================== --- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h +++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h @@ -77,46 +77,59 @@ // Handle all other callbacks. // Just parse to the corresponding location to generate PPCallbacks for the // corresponding range - void Ident(SourceLocation Loc, StringRef) override; + void Ident(SourceLocation HashLoc, SourceLocation Loc, StringRef) override; void PragmaDirective(PragmaIntroducer Introducer) override; - void PragmaComment(SourceLocation Loc, const IdentifierInfo *, - StringRef) override; - void PragmaDetectMismatch(SourceLocation Loc, StringRef, StringRef) override; - void PragmaDebug(SourceLocation Loc, StringRef) override; - void PragmaMessage(SourceLocation Loc, StringRef, PragmaMessageKind, - StringRef) override; - void PragmaDiagnosticPush(SourceLocation Loc, StringRef) override; - void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override; - void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity, - StringRef) override; + void PragmaComment(PragmaIntroducer Introducer, SourceLocation Loc, + const IdentifierInfo *, StringRef) override; + void PragmaDetectMismatch(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef, StringRef) override; + void PragmaDebug(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef) override; + void PragmaMessage(PragmaIntroducer Introducer, SourceLocation Loc, StringRef, + PragmaMessageKind, StringRef) override; + void PragmaDiagnosticPush(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef) override; + void PragmaDiagnosticPop(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef) override; + void PragmaDiagnostic(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef, diag::Severity, StringRef) override; void HasInclude(SourceLocation Loc, StringRef, bool, OptionalFileEntryRef, SrcMgr::CharacteristicKind) override; - void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *, + void PragmaOpenCLExtension(PragmaIntroducer Introducer, + SourceLocation NameLoc, const IdentifierInfo *, SourceLocation StateLoc, unsigned) override; - void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier, - ArrayRef) override; - void PragmaWarningPush(SourceLocation Loc, int) override; - void PragmaWarningPop(SourceLocation Loc) override; - void PragmaAssumeNonNullBegin(SourceLocation Loc) override; - void PragmaAssumeNonNullEnd(SourceLocation Loc) override; + void PragmaWarning(PragmaIntroducer Introducer, SourceLocation Loc, + PragmaWarningSpecifier, ArrayRef) override; + void PragmaWarningPush(PragmaIntroducer Introducer, SourceLocation Loc, + int) override; + void PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) override; + void PragmaAssumeNonNullBegin(PragmaIntroducer Introducer, + SourceLocation Loc) override; + void PragmaAssumeNonNullEnd(PragmaIntroducer Introducer, + SourceLocation Loc) override; void MacroExpands(const Token &MacroNameTok, const MacroDefinition &, SourceRange Range, const MacroArgs *) override; - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; - void MacroUndefined(const Token &, const MacroDefinition &, + void MacroUndefined(SourceLocation HashLoc, const Token &, + const MacroDefinition &, const MacroDirective *Undef) override; void Defined(const Token &MacroNameTok, const MacroDefinition &, SourceRange Range) override; void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; - void If(SourceLocation Loc, SourceRange, ConditionValueKind) override; - void Elif(SourceLocation Loc, SourceRange, ConditionValueKind, - SourceLocation) override; - void Ifdef(SourceLocation Loc, const Token &, + void If(SourceLocation HashLoc, SourceLocation Loc, SourceRange, + ConditionValueKind) override; + void Elif(SourceLocation HashLoc, SourceLocation Loc, SourceRange, + ConditionValueKind, SourceLocation) override; + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, const Token &, const MacroDefinition &) override; - void Ifndef(SourceLocation Loc, const Token &, + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, const Token &, const MacroDefinition &) override; - void Else(SourceLocation Loc, SourceLocation) override; - void Endif(SourceLocation Loc, SourceLocation) override; + void Else(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation) override; + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation) override; std::unique_ptr Recorder; // Set of all the modules visited. Avoids processing a module more than once. Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp =================================================================== --- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -182,45 +182,47 @@ // Handle all other callbacks. // Just parse to the corresponding location to generate the same callback for // the PPCallbacks registered in our custom preprocessor. -void ExpandModularHeadersPPCallbacks::Ident(SourceLocation Loc, StringRef) { +void ExpandModularHeadersPPCallbacks::Ident(SourceLocation HashLoc, + SourceLocation Loc, StringRef) { parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::PragmaDirective( PragmaIntroducer Introducer) { parseToLocation(Introducer.Loc); } -void ExpandModularHeadersPPCallbacks::PragmaComment(SourceLocation Loc, +void ExpandModularHeadersPPCallbacks::PragmaComment(PragmaIntroducer Introducer, + SourceLocation Loc, const IdentifierInfo *, StringRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaDetectMismatch(SourceLocation Loc, - StringRef, - StringRef) { +void ExpandModularHeadersPPCallbacks::PragmaDetectMismatch( + PragmaIntroducer Introducer, SourceLocation Loc, StringRef, StringRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaDebug(SourceLocation Loc, +void ExpandModularHeadersPPCallbacks::PragmaDebug(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaMessage(SourceLocation Loc, +void ExpandModularHeadersPPCallbacks::PragmaMessage(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef, PragmaMessageKind, StringRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaDiagnosticPush(SourceLocation Loc, - StringRef) { +void ExpandModularHeadersPPCallbacks::PragmaDiagnosticPush( + PragmaIntroducer Introducer, SourceLocation Loc, StringRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaDiagnosticPop(SourceLocation Loc, - StringRef) { +void ExpandModularHeadersPPCallbacks::PragmaDiagnosticPop( + PragmaIntroducer Introducer, SourceLocation Loc, StringRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc, - StringRef, - diag::Severity, - StringRef) { +void ExpandModularHeadersPPCallbacks::PragmaDiagnostic( + PragmaIntroducer Introducer, SourceLocation Loc, StringRef, diag::Severity, + StringRef) { parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef, @@ -229,29 +231,31 @@ parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::PragmaOpenCLExtension( - SourceLocation NameLoc, const IdentifierInfo *, SourceLocation StateLoc, - unsigned) { + PragmaIntroducer Introducer, SourceLocation NameLoc, const IdentifierInfo *, + SourceLocation StateLoc, unsigned) { // FIXME: Figure out whether it's the right location to parse to. parseToLocation(NameLoc); } -void ExpandModularHeadersPPCallbacks::PragmaWarning(SourceLocation Loc, +void ExpandModularHeadersPPCallbacks::PragmaWarning(PragmaIntroducer Introducer, + SourceLocation Loc, PragmaWarningSpecifier, ArrayRef) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaWarningPush(SourceLocation Loc, - int) { +void ExpandModularHeadersPPCallbacks::PragmaWarningPush( + PragmaIntroducer Introducer, SourceLocation Loc, int) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::PragmaWarningPop(SourceLocation Loc) { +void ExpandModularHeadersPPCallbacks::PragmaWarningPop( + PragmaIntroducer Introducer, SourceLocation Loc) { parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::PragmaAssumeNonNullBegin( - SourceLocation Loc) { + PragmaIntroducer Introducer, SourceLocation Loc) { parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::PragmaAssumeNonNullEnd( - SourceLocation Loc) { + PragmaIntroducer Introducer, SourceLocation Loc) { parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::MacroExpands(const Token &MacroNameTok, @@ -261,12 +265,14 @@ // FIXME: Figure out whether it's the right location to parse to. parseToLocation(Range.getBegin()); } -void ExpandModularHeadersPPCallbacks::MacroDefined(const Token &MacroNameTok, +void ExpandModularHeadersPPCallbacks::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MD) { parseToLocation(MD->getLocation()); } void ExpandModularHeadersPPCallbacks::MacroUndefined( - const Token &, const MacroDefinition &, const MacroDirective *Undef) { + SourceLocation HashLoc, const Token &, const MacroDefinition &, + const MacroDirective *Undef) { if (Undef) parseToLocation(Undef->getLocation()); } @@ -281,26 +287,32 @@ // FIXME: Figure out whether it's the right location to parse to. parseToLocation(EndifLoc); } -void ExpandModularHeadersPPCallbacks::If(SourceLocation Loc, SourceRange, +void ExpandModularHeadersPPCallbacks::If(SourceLocation HashLoc, + SourceLocation Loc, SourceRange, ConditionValueKind) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::Elif(SourceLocation Loc, SourceRange, +void ExpandModularHeadersPPCallbacks::Elif(SourceLocation HashLoc, + SourceLocation Loc, SourceRange, ConditionValueKind, SourceLocation) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::Ifdef(SourceLocation Loc, const Token &, +void ExpandModularHeadersPPCallbacks::Ifdef(SourceLocation HashLoc, + SourceLocation Loc, const Token &, const MacroDefinition &) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::Ifndef(SourceLocation Loc, const Token &, +void ExpandModularHeadersPPCallbacks::Ifndef(SourceLocation HashLoc, + SourceLocation Loc, const Token &, const MacroDefinition &) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::Else(SourceLocation Loc, SourceLocation) { +void ExpandModularHeadersPPCallbacks::Else(SourceLocation HashLoc, + SourceLocation Loc, SourceLocation) { parseToLocation(Loc); } -void ExpandModularHeadersPPCallbacks::Endif(SourceLocation Loc, +void ExpandModularHeadersPPCallbacks::Endif(SourceLocation HashLoc, + SourceLocation Loc, SourceLocation) { parseToLocation(Loc); } Index: clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp @@ -19,7 +19,7 @@ MacroParenthesesPPCallbacks(Preprocessor *PP, MacroParenthesesCheck *Check) : PP(PP), Check(Check) {} - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { replacementList(MacroNameTok, MD->getMacroInfo()); argument(MacroNameTok, MD->getMacroInfo()); Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp +++ clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp @@ -33,7 +33,7 @@ bool IgnoreCommandLine) : Check(Check), SM(SM), RegExp(RegExpStr), CheckCapsOnly(CapsOnly), IgnoreCommandLineMacros(IgnoreCommandLine) {} - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { if (SM.isWrittenInBuiltinFile(MD->getLocation()) || MD->getMacroInfo()->isUsedForHeaderGuard() || Index: clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp +++ clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp @@ -52,13 +52,14 @@ macroUsed(MacroNameTok, MD, Range.getBegin(), CheckAction::Rename); } - void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDefinition &MD, const MacroDirective *Undef) override { if (Undef != nullptr) macroUsed(MacroNameTok, MD, Undef->getLocation(), CheckAction::Warn); } - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { if (!ReplacementFound && MD != nullptr) { // We check if the newly defined macro is one of the target replacements. @@ -76,13 +77,13 @@ macroUsed(MacroNameTok, MD, Range.getBegin(), CheckAction::Warn); } - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { macroUsed(MacroNameTok, MD, Loc, CheckAction::Warn); } - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { macroUsed(MacroNameTok, MD, Loc, CheckAction::Warn); } Index: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp @@ -124,11 +124,12 @@ } // Keep track of macro definitions that look like enums. - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; // Undefining an enum-like macro results in the enum set being dropped. - void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDefinition &MD, const MacroDirective *Undef) override; // Conditional compilation clears any adjacent enum-like macros. @@ -138,42 +139,45 @@ // #if !defined(GUARD) // or // #ifndef GUARD - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override { conditionStart(Loc); checkCondition(ConditionRange); } - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { conditionStart(Loc); checkName(MacroNameTok); } - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { conditionStart(Loc); checkName(MacroNameTok); } - void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) override { + void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, + SourceLocation IfLoc) override { checkCondition(ConditionRange); } - void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { checkName(MacroNameTok); } - void Elifdef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) override { - PPCallbacks::Elifdef(Loc, ConditionRange, IfLoc); + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) override { + PPCallbacks::Elifdef(HashLoc, Loc, ConditionRange, IfLoc); } - void Elifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { checkName(MacroNameTok); } - void Elifndef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) override { - PPCallbacks::Elifndef(Loc, ConditionRange, IfLoc); + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) override { + PPCallbacks::Elifndef(HashLoc, Loc, ConditionRange, IfLoc); } - void Endif(SourceLocation Loc, SourceLocation IfLoc) override; + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override; void PragmaDirective(PragmaIntroducer Introducer) override; // After we've seen everything, issue warnings and fix-its. @@ -331,7 +335,8 @@ // Any defined but rejected macro is scanned for identifiers that // are to be excluded as enums. -void MacroToEnumCallbacks::MacroDefined(const Token &MacroNameTok, +void MacroToEnumCallbacks::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MD) { // Include guards are never candidates for becoming an enum. if (CurrentFile->GuardScanner == IncludeGuard::IfGuard) { @@ -365,7 +370,8 @@ // Any macro that is undefined removes all adjacent macros from consideration as // an enum and starts a new enum scan. -void MacroToEnumCallbacks::MacroUndefined(const Token &MacroNameTok, +void MacroToEnumCallbacks::MacroUndefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) { rememberExpressionName(MacroNameTok); @@ -384,7 +390,8 @@ CurrentFile->GuardScanner = IncludeGuard::None; } -void MacroToEnumCallbacks::Endif(SourceLocation Loc, SourceLocation IfLoc) { +void MacroToEnumCallbacks::Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) { // The if directive for the include guard isn't counted in the // ConditionScopes. if (CurrentFile->ConditionScopes == 0 && Index: clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp +++ clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp @@ -50,10 +50,11 @@ StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; - void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDefinition &MD, const MacroDirective *Undef) override; private: @@ -91,12 +92,14 @@ Files.back().push_back(FileName); } -void DuplicateIncludeCallbacks::MacroDefined(const Token &MacroNameTok, +void DuplicateIncludeCallbacks::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MD) { Files.back().clear(); } -void DuplicateIncludeCallbacks::MacroUndefined(const Token &MacroNameTok, +void DuplicateIncludeCallbacks::MacroUndefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) { Files.back().clear(); Index: clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -26,7 +26,8 @@ ElseAfterReturnCheck::ConditionalBranchMap &Collections, const SourceManager &SM) : Collections(Collections), SM(SM) {} - void Endif(SourceLocation Loc, SourceLocation IfLoc) override { + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override { if (!SM.isWrittenInSameFile(Loc, IfLoc)) return; SmallVectorImpl &Collection = Collections[SM.getFileID(Loc)]; Index: clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp +++ clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp @@ -34,7 +34,8 @@ Preprocessor &PP) : Check(Check), PP(PP) {} - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override { StringRef Condition = Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange), @@ -42,7 +43,8 @@ checkMacroRedundancy(Loc, Condition, IfStack, DK_If, DK_If, true); } - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MacroDefinition) override { std::string MacroName = PP.getSpelling(MacroNameTok); checkMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifdef, DK_Ifdef, true); @@ -50,7 +52,8 @@ false); } - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MacroDefinition) override { std::string MacroName = PP.getSpelling(MacroNameTok); checkMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifndef, DK_Ifndef, @@ -59,7 +62,8 @@ false); } - void Endif(SourceLocation Loc, SourceLocation IfLoc) override { + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override { if (!IfStack.empty() && IfLoc == IfStack.back().Loc) IfStack.pop_back(); if (!IfdefStack.empty() && IfLoc == IfdefStack.back().Loc) Index: clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp =================================================================== --- clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp +++ clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp @@ -42,8 +42,8 @@ } } - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (MD) return; @@ -52,14 +52,15 @@ std::make_pair(Loc, MacroNameTok.getLocation()); } - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { // Record all defined macros. We store the whole token to get info on the // name later. Macros.emplace_back(MacroNameTok, MD->getMacroInfo()); } - void Endif(SourceLocation Loc, SourceLocation IfLoc) override { + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override { // Record all #endif and the corresponding #ifs (including #ifndefs). EndIfs[IfLoc] = Loc; } Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -71,7 +71,7 @@ : PP(PP), Check(Check) {} /// MacroDefined calls checkMacro for macros in the main file - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { if (MD->getMacroInfo()->isBuiltinMacro()) return; Index: clang-tools-extra/clangd/CollectMacros.h =================================================================== --- clang-tools-extra/clangd/CollectMacros.h +++ clang-tools-extra/clangd/CollectMacros.h @@ -51,7 +51,8 @@ InMainFile = isInsideMainFile(Loc, SM); } - void MacroDefined(const Token &MacroName, const MacroDirective *MD) override { + void MacroDefined(SourceLocation HashLoc, const Token &MacroName, + const MacroDirective *MD) override { add(MacroName, MD->getMacroInfo(), /*IsDefinition=*/true); } @@ -60,19 +61,19 @@ add(MacroName, MD.getMacroInfo()); } - void MacroUndefined(const clang::Token &MacroName, + void MacroUndefined(SourceLocation HashLoc, const clang::Token &MacroName, const clang::MacroDefinition &MD, const clang::MacroDirective *Undef) override { add(MacroName, MD.getMacroInfo()); } - void Ifdef(SourceLocation Loc, const Token &MacroName, + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override { add(MacroName, MD.getMacroInfo()); } - void Ifndef(SourceLocation Loc, const Token &MacroName, - const MacroDefinition &MD) override { + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroName, const MacroDefinition &MD) override { add(MacroName, MD.getMacroInfo()); } Index: clang-tools-extra/clangd/CollectMacros.cpp =================================================================== --- clang-tools-extra/clangd/CollectMacros.cpp +++ clang-tools-extra/clangd/CollectMacros.cpp @@ -37,7 +37,8 @@ std::vector &Out) : SM(SM), Out(Out) {} - void PragmaMark(SourceLocation Loc, StringRef Trivia) override { + void PragmaMark(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Trivia) override { if (isInsideMainFile(Loc, SM)) { // FIXME: This range should just cover `XX` in `#pragma mark XX` and // `- XX` in `#pragma mark - XX`. Index: clang-tools-extra/clangd/Preamble.cpp =================================================================== --- clang-tools-extra/clangd/Preamble.cpp +++ clang-tools-extra/clangd/Preamble.cpp @@ -277,7 +277,7 @@ InMainFile = SM.isWrittenInMainFile(Loc); } - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { if (!InMainFile) return; Index: clang-tools-extra/include-cleaner/lib/Record.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/Record.cpp +++ clang-tools-extra/include-cleaner/lib/Record.cpp @@ -59,7 +59,8 @@ recordMacroRef(MacroName, *MD.getMacroInfo()); } - void MacroDefined(const Token &MacroName, const MacroDirective *MD) override { + void MacroDefined(SourceLocation HashLoc, const Token &MacroName, + const MacroDirective *MD) override { if (!Active) return; @@ -78,7 +79,8 @@ } } - void MacroUndefined(const Token &MacroName, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroName, + const MacroDefinition &MD, const MacroDirective *) override { if (!Active) return; @@ -86,16 +88,16 @@ recordMacroRef(MacroName, *MI); } - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!Active) return; if (const auto *MI = MD.getMacroInfo()) recordMacroRef(MacroNameTok, *MI, RefType::Ambiguous); } - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!Active) return; if (const auto *MI = MD.getMacroInfo()) @@ -104,15 +106,15 @@ using PPCallbacks::Elifdef; using PPCallbacks::Elifndef; - void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!Active) return; if (const auto *MI = MD.getMacroInfo()) recordMacroRef(MacroNameTok, *MI, RefType::Ambiguous); } - void Elifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!Active) return; if (const auto *MI = MD.getMacroInfo()) Index: clang-tools-extra/modularize/PreprocessorTracker.cpp =================================================================== --- clang-tools-extra/modularize/PreprocessorTracker.cpp +++ clang-tools-extra/modularize/PreprocessorTracker.cpp @@ -749,14 +749,18 @@ void Defined(const clang::Token &MacroNameTok, const clang::MacroDefinition &MD, clang::SourceRange Range) override; - void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, + void If(clang::SourceLocation HashLoc, clang::SourceLocation Loc, + clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionResult) override; - void Elif(clang::SourceLocation Loc, clang::SourceRange ConditionRange, + void Elif(clang::SourceLocation HashLoc, clang::SourceLocation Loc, + clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionResult, clang::SourceLocation IfLoc) override; - void Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, + void Ifdef(clang::SourceLocation HashLoc, clang::SourceLocation Loc, + const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) override; - void Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, + void Ifndef(clang::SourceLocation HashLoc, clang::SourceLocation Loc, + const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) override; private: @@ -1340,26 +1344,29 @@ (MI ? "true" : "false"), PPTracker.getCurrentInclusionPathHandle()); } -void PreprocessorCallbacks::If(clang::SourceLocation Loc, - clang::SourceRange ConditionRange, - clang::PPCallbacks::ConditionValueKind ConditionResult) { +void PreprocessorCallbacks::If( + clang::SourceLocation HashLoc, clang::SourceLocation Loc, + clang::SourceRange ConditionRange, + clang::PPCallbacks::ConditionValueKind ConditionResult) { std::string Unexpanded(getSourceString(PP, ConditionRange)); PPTracker.addConditionalExpansionInstance( PP, PPTracker.getCurrentHeaderHandle(), Loc, clang::tok::pp_if, ConditionResult, Unexpanded, PPTracker.getCurrentInclusionPathHandle()); } -void PreprocessorCallbacks::Elif(clang::SourceLocation Loc, - clang::SourceRange ConditionRange, - clang::PPCallbacks::ConditionValueKind ConditionResult, - clang::SourceLocation IfLoc) { +void PreprocessorCallbacks::Elif( + clang::SourceLocation HashLoc, clang::SourceLocation Loc, + clang::SourceRange ConditionRange, + clang::PPCallbacks::ConditionValueKind ConditionResult, + clang::SourceLocation IfLoc) { std::string Unexpanded(getSourceString(PP, ConditionRange)); PPTracker.addConditionalExpansionInstance( PP, PPTracker.getCurrentHeaderHandle(), Loc, clang::tok::pp_elif, ConditionResult, Unexpanded, PPTracker.getCurrentInclusionPathHandle()); } -void PreprocessorCallbacks::Ifdef(clang::SourceLocation Loc, +void PreprocessorCallbacks::Ifdef(clang::SourceLocation HashLoc, + clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) { clang::PPCallbacks::ConditionValueKind IsDefined = @@ -1370,7 +1377,8 @@ PPTracker.getCurrentInclusionPathHandle()); } -void PreprocessorCallbacks::Ifndef(clang::SourceLocation Loc, +void PreprocessorCallbacks::Ifndef(clang::SourceLocation HashLoc, + clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) { clang::PPCallbacks::ConditionValueKind IsNotDefined = Index: clang-tools-extra/pp-trace/PPCallbacksTracker.h =================================================================== --- clang-tools-extra/pp-trace/PPCallbacksTracker.h +++ clang-tools-extra/pp-trace/PPCallbacksTracker.h @@ -100,49 +100,65 @@ void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override; void EndOfMainFile() override; - void Ident(SourceLocation Loc, llvm::StringRef str) override; + void Ident(SourceLocation HashLoc, SourceLocation Loc, + llvm::StringRef str) override; void PragmaDirective(PragmaIntroducer Introducer) override; - void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, - llvm::StringRef Str) override; - void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name, + void PragmaComment(PragmaIntroducer Introducer, SourceLocation Loc, + const IdentifierInfo *Kind, llvm::StringRef Str) override; + void PragmaDetectMismatch(PragmaIntroducer Introducer, SourceLocation Loc, + llvm::StringRef Name, llvm::StringRef Value) override; - void PragmaDebug(SourceLocation Loc, llvm::StringRef DebugType) override; - void PragmaMessage(SourceLocation Loc, llvm::StringRef Namespace, + void PragmaDebug(PragmaIntroducer Introducer, SourceLocation Loc, + llvm::StringRef DebugType) override; + void PragmaMessage(PragmaIntroducer Introducer, SourceLocation Loc, + llvm::StringRef Namespace, PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) override; - void PragmaDiagnosticPush(SourceLocation Loc, + void PragmaDiagnosticPush(PragmaIntroducer Introducer, SourceLocation Loc, llvm::StringRef Namespace) override; - void PragmaDiagnosticPop(SourceLocation Loc, + void PragmaDiagnosticPop(PragmaIntroducer Introducer, SourceLocation Loc, llvm::StringRef Namespace) override; - void PragmaDiagnostic(SourceLocation Loc, llvm::StringRef Namespace, - diag::Severity mapping, llvm::StringRef Str) override; - void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, + void PragmaDiagnostic(PragmaIntroducer Introducer, SourceLocation Loc, + llvm::StringRef Namespace, diag::Severity mapping, + llvm::StringRef Str) override; + void PragmaOpenCLExtension(PragmaIntroducer Introducer, + SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) override; - void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, + void PragmaWarning(PragmaIntroducer Introducer, SourceLocation Loc, + PragmaWarningSpecifier WarningSpec, llvm::ArrayRef Ids) override; - void PragmaWarningPush(SourceLocation Loc, int Level) override; - void PragmaWarningPop(SourceLocation Loc) override; - void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override; - void PragmaExecCharsetPop(SourceLocation Loc) override; + void PragmaWarningPush(PragmaIntroducer Introducer, SourceLocation Loc, + int Level) override; + void PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) override; + void PragmaExecCharsetPush(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Str) override; + void PragmaExecCharsetPop(PragmaIntroducer Introducer, + SourceLocation Loc) override; void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override; - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; - void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDefinition &MD, const MacroDirective *Undef) override; void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override; void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override; - void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) override; - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Else(SourceLocation Loc, SourceLocation IfLoc) override; - void Endif(SourceLocation Loc, SourceLocation IfLoc) override; + void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, + SourceLocation IfLoc) override; + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Else(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override; + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override; // Helper functions. Index: clang-tools-extra/pp-trace/PPCallbacksTracker.cpp =================================================================== --- clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -164,7 +164,8 @@ void PPCallbacksTracker::EndOfMainFile() { beginCallback("EndOfMainFile"); } // Callback invoked when a #ident or #sccs directive is read. -void PPCallbacksTracker::Ident(SourceLocation Loc, llvm::StringRef Str) { +void PPCallbacksTracker::Ident(SourceLocation HashLoc, SourceLocation Loc, + llvm::StringRef Str) { beginCallback("Ident"); appendArgument("Loc", Loc); appendArgument("Str", Str); @@ -177,7 +178,8 @@ } // Callback invoked when a #pragma comment directive is read. -void PPCallbacksTracker::PragmaComment(SourceLocation Loc, +void PPCallbacksTracker::PragmaComment(PragmaIntroducer Introducer, + SourceLocation Loc, const IdentifierInfo *Kind, llvm::StringRef Str) { beginCallback("PragmaComment"); @@ -188,7 +190,8 @@ // Callback invoked when a #pragma detect_mismatch directive is // read. -void PPCallbacksTracker::PragmaDetectMismatch(SourceLocation Loc, +void PPCallbacksTracker::PragmaDetectMismatch(PragmaIntroducer Introducer, + SourceLocation Loc, llvm::StringRef Name, llvm::StringRef Value) { beginCallback("PragmaDetectMismatch"); @@ -198,7 +201,8 @@ } // Callback invoked when a #pragma clang __debug directive is read. -void PPCallbacksTracker::PragmaDebug(SourceLocation Loc, +void PPCallbacksTracker::PragmaDebug(PragmaIntroducer Introducer, + SourceLocation Loc, llvm::StringRef DebugType) { beginCallback("PragmaDebug"); appendArgument("Loc", Loc); @@ -206,7 +210,8 @@ } // Callback invoked when a #pragma message directive is read. -void PPCallbacksTracker::PragmaMessage(SourceLocation Loc, +void PPCallbacksTracker::PragmaMessage(PragmaIntroducer Introducer, + SourceLocation Loc, llvm::StringRef Namespace, PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) { @@ -219,7 +224,8 @@ // Callback invoked when a #pragma gcc diagnostic push directive // is read. -void PPCallbacksTracker::PragmaDiagnosticPush(SourceLocation Loc, +void PPCallbacksTracker::PragmaDiagnosticPush(PragmaIntroducer Introducer, + SourceLocation Loc, llvm::StringRef Namespace) { beginCallback("PragmaDiagnosticPush"); appendArgument("Loc", Loc); @@ -228,7 +234,8 @@ // Callback invoked when a #pragma gcc diagnostic pop directive // is read. -void PPCallbacksTracker::PragmaDiagnosticPop(SourceLocation Loc, +void PPCallbacksTracker::PragmaDiagnosticPop(PragmaIntroducer Introducer, + SourceLocation Loc, llvm::StringRef Namespace) { beginCallback("PragmaDiagnosticPop"); appendArgument("Loc", Loc); @@ -236,7 +243,8 @@ } // Callback invoked when a #pragma gcc diagnostic directive is read. -void PPCallbacksTracker::PragmaDiagnostic(SourceLocation Loc, +void PPCallbacksTracker::PragmaDiagnostic(PragmaIntroducer Introducer, + SourceLocation Loc, llvm::StringRef Namespace, diag::Severity Mapping, llvm::StringRef Str) { @@ -249,7 +257,8 @@ // Called when an OpenCL extension is either disabled or // enabled with a pragma. -void PPCallbacksTracker::PragmaOpenCLExtension(SourceLocation NameLoc, +void PPCallbacksTracker::PragmaOpenCLExtension(PragmaIntroducer Introducer, + SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) { @@ -261,7 +270,8 @@ } // Callback invoked when a #pragma warning directive is read. -void PPCallbacksTracker::PragmaWarning(SourceLocation Loc, +void PPCallbacksTracker::PragmaWarning(PragmaIntroducer Introducer, + SourceLocation Loc, PragmaWarningSpecifier WarningSpec, llvm::ArrayRef Ids) { beginCallback("PragmaWarning"); @@ -281,21 +291,24 @@ } // Callback invoked when a #pragma warning(push) directive is read. -void PPCallbacksTracker::PragmaWarningPush(SourceLocation Loc, int Level) { +void PPCallbacksTracker::PragmaWarningPush(PragmaIntroducer Introducer, + SourceLocation Loc, int Level) { beginCallback("PragmaWarningPush"); appendArgument("Loc", Loc); appendArgument("Level", Level); } // Callback invoked when a #pragma warning(pop) directive is read. -void PPCallbacksTracker::PragmaWarningPop(SourceLocation Loc) { +void PPCallbacksTracker::PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) { beginCallback("PragmaWarningPop"); appendArgument("Loc", Loc); } // Callback invoked when a #pragma execution_character_set(push) directive // is read. -void PPCallbacksTracker::PragmaExecCharsetPush(SourceLocation Loc, +void PPCallbacksTracker::PragmaExecCharsetPush(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Str) { beginCallback("PragmaExecCharsetPush"); appendArgument("Loc", Loc); @@ -304,7 +317,8 @@ // Callback invoked when a #pragma execution_character_set(pop) directive // is read. -void PPCallbacksTracker::PragmaExecCharsetPop(SourceLocation Loc) { +void PPCallbacksTracker::PragmaExecCharsetPop(PragmaIntroducer Introducer, + SourceLocation Loc) { beginCallback("PragmaExecCharsetPop"); appendArgument("Loc", Loc); } @@ -323,7 +337,8 @@ } // Hook called whenever a macro definition is seen. -void PPCallbacksTracker::MacroDefined(const Token &MacroNameTok, +void PPCallbacksTracker::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MacroDirective) { beginCallback("MacroDefined"); appendArgument("MacroNameTok", MacroNameTok); @@ -331,7 +346,8 @@ } // Hook called whenever a macro #undef is seen. -void PPCallbacksTracker::MacroUndefined(const Token &MacroNameTok, +void PPCallbacksTracker::MacroUndefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDefinition &MacroDefinition, const MacroDirective *Undef) { beginCallback("MacroUndefined"); @@ -357,7 +373,8 @@ } // Hook called whenever an #if is seen. -void PPCallbacksTracker::If(SourceLocation Loc, SourceRange ConditionRange, +void PPCallbacksTracker::If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) { beginCallback("If"); appendArgument("Loc", Loc); @@ -366,7 +383,8 @@ } // Hook called whenever an #elif is seen. -void PPCallbacksTracker::Elif(SourceLocation Loc, SourceRange ConditionRange, +void PPCallbacksTracker::Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) { beginCallback("Elif"); @@ -377,7 +395,8 @@ } // Hook called whenever an #ifdef is seen. -void PPCallbacksTracker::Ifdef(SourceLocation Loc, const Token &MacroNameTok, +void PPCallbacksTracker::Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MacroDefinition) { beginCallback("Ifdef"); appendArgument("Loc", Loc); @@ -386,7 +405,8 @@ } // Hook called whenever an #ifndef is seen. -void PPCallbacksTracker::Ifndef(SourceLocation Loc, const Token &MacroNameTok, +void PPCallbacksTracker::Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MacroDefinition) { beginCallback("Ifndef"); appendArgument("Loc", Loc); @@ -395,14 +415,16 @@ } // Hook called whenever an #else is seen. -void PPCallbacksTracker::Else(SourceLocation Loc, SourceLocation IfLoc) { +void PPCallbacksTracker::Else(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) { beginCallback("Else"); appendArgument("Loc", Loc); appendArgument("IfLoc", IfLoc); } // Hook called whenever an #endif is seen. -void PPCallbacksTracker::Endif(SourceLocation Loc, SourceLocation IfLoc) { +void PPCallbacksTracker::Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) { beginCallback("Endif"); appendArgument("Loc", Loc); appendArgument("IfLoc", IfLoc); Index: clang/include/clang/Lex/PPCallbacks.h =================================================================== --- clang/include/clang/Lex/PPCallbacks.h +++ clang/include/clang/Lex/PPCallbacks.h @@ -186,35 +186,36 @@ } /// Callback invoked when a \#ident or \#sccs directive is read. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc The location of the directive. /// \param str The text of the directive. /// - virtual void Ident(SourceLocation Loc, StringRef str) { - } + virtual void Ident(SourceLocation HashLoc, SourceLocation Loc, + StringRef str) {} /// Callback invoked when start reading any pragma directive. virtual void PragmaDirective(PragmaIntroducer Introducer) {} /// Callback invoked when a \#pragma comment directive is read. - virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, - StringRef Str) { - } + virtual void PragmaComment(PragmaIntroducer Introducer, SourceLocation Loc, + const IdentifierInfo *Kind, StringRef Str) {} /// Callback invoked when a \#pragma mark comment is read. - virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) { - } + virtual void PragmaMark(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Trivia) {} /// Callback invoked when a \#pragma detect_mismatch directive is /// read. - virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, - StringRef Value) { - } + virtual void PragmaDetectMismatch(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Name, + StringRef Value) {} /// Callback invoked when a \#pragma clang __debug directive is read. + /// \param Introducer The location and kind of the pragma directive. /// \param Loc The location of the debug directive. /// \param DebugType The identifier following __debug. - virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) { - } + virtual void PragmaDebug(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef DebugType) {} /// Determines the kind of \#pragma invoking a call to PragmaMessage. enum PragmaMessageKind { @@ -229,36 +230,36 @@ }; /// Callback invoked when a \#pragma message directive is read. + /// \param Introducer The location and kind of the pragma directive. /// \param Loc The location of the message directive. /// \param Namespace The namespace of the message directive. /// \param Kind The type of the message directive. /// \param Str The text of the message directive. - virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, - PragmaMessageKind Kind, StringRef Str) { - } + virtual void PragmaMessage(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace, PragmaMessageKind Kind, + StringRef Str) {} /// Callback invoked when a \#pragma gcc diagnostic push directive /// is read. - virtual void PragmaDiagnosticPush(SourceLocation Loc, - StringRef Namespace) { - } + virtual void PragmaDiagnosticPush(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Namespace) {} /// Callback invoked when a \#pragma gcc diagnostic pop directive /// is read. - virtual void PragmaDiagnosticPop(SourceLocation Loc, - StringRef Namespace) { - } + virtual void PragmaDiagnosticPop(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Namespace) {} /// Callback invoked when a \#pragma gcc diagnostic directive is read. - virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, - diag::Severity mapping, StringRef Str) {} + virtual void PragmaDiagnostic(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace, diag::Severity mapping, + StringRef Str) {} /// Called when an OpenCL extension is either disabled or /// enabled with a pragma. - virtual void PragmaOpenCLExtension(SourceLocation NameLoc, + virtual void PragmaOpenCLExtension(PragmaIntroducer Introducer, + SourceLocation NameLoc, const IdentifierInfo *Name, - SourceLocation StateLoc, unsigned State) { - } + SourceLocation StateLoc, unsigned State) {} /// Callback invoked when a \#pragma warning directive is read. enum PragmaWarningSpecifier { @@ -272,33 +273,37 @@ PWS_Level3, PWS_Level4, }; - virtual void PragmaWarning(SourceLocation Loc, + virtual void PragmaWarning(PragmaIntroducer Introducer, SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef Ids) {} /// Callback invoked when a \#pragma warning(push) directive is read. - virtual void PragmaWarningPush(SourceLocation Loc, int Level) { - } + virtual void PragmaWarningPush(PragmaIntroducer Introducer, + SourceLocation Loc, int Level) {} /// Callback invoked when a \#pragma warning(pop) directive is read. - virtual void PragmaWarningPop(SourceLocation Loc) { - } + virtual void PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) {} /// Callback invoked when a \#pragma execution_character_set(push) directive /// is read. - virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) {} + virtual void PragmaExecCharsetPush(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Str) {} /// Callback invoked when a \#pragma execution_character_set(pop) directive /// is read. - virtual void PragmaExecCharsetPop(SourceLocation Loc) {} + virtual void PragmaExecCharsetPop(PragmaIntroducer Introducer, + SourceLocation Loc) {} /// Callback invoked when a \#pragma clang assume_nonnull begin directive /// is read. - virtual void PragmaAssumeNonNullBegin(SourceLocation Loc) {} + virtual void PragmaAssumeNonNullBegin(PragmaIntroducer Introducer, + SourceLocation Loc) {} /// Callback invoked when a \#pragma clang assume_nonnull end directive /// is read. - virtual void PragmaAssumeNonNullEnd(SourceLocation Loc) {} + virtual void PragmaAssumeNonNullEnd(PragmaIntroducer Introducer, + SourceLocation Loc) {} /// Called by Preprocessor::HandleMacroExpandedIdentifier when a /// macro invocation is found. @@ -307,20 +312,19 @@ const MacroArgs *Args) {} /// Hook called whenever a macro definition is seen. - virtual void MacroDefined(const Token &MacroNameTok, - const MacroDirective *MD) { - } + virtual void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDirective *MD) {} /// Hook called whenever a macro \#undef is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param MacroNameTok The active Token /// \param MD A MacroDefinition for the named macro. /// \param Undef New MacroDirective if the macro was defined, null otherwise. /// /// MD is released immediately following this callback. - virtual void MacroUndefined(const Token &MacroNameTok, + virtual void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDefinition &MD, - const MacroDirective *Undef) { - } + const MacroDirective *Undef) {} /// Hook called whenever the 'defined' operator is seen. /// \param MD The MacroDirective if the name was a macro, null otherwise. @@ -348,84 +352,88 @@ }; /// Hook called whenever an \#if is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. /// \param ConditionValue The evaluated value of the condition. /// // FIXME: better to pass in a list (or tree!) of Tokens. - virtual void If(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue) { - } + virtual void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, + ConditionValueKind ConditionValue) {} /// Hook called whenever an \#elif is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. /// \param ConditionValue The evaluated value of the condition. /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. // FIXME: better to pass in a list (or tree!) of Tokens. - virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) { - } + virtual void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, + ConditionValueKind ConditionValue, SourceLocation IfLoc) {} /// Hook called whenever an \#ifdef is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param MacroNameTok Information on the token being tested. /// \param MD The MacroDefinition if the name was a macro, null otherwise. - virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) { - } + virtual void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) {} /// Hook called whenever an \#elifdef branch is taken. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param MacroNameTok Information on the token being tested. /// \param MD The MacroDefinition if the name was a macro, null otherwise. - virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) { - } + virtual void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) {} /// Hook called whenever an \#elifdef is skipped. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. // FIXME: better to pass in a list (or tree!) of Tokens. - virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) { - } + virtual void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) {} /// Hook called whenever an \#ifndef is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param MacroNameTok Information on the token being tested. /// \param MD The MacroDefiniton if the name was a macro, null otherwise. - virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) { - } + virtual void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) {} /// Hook called whenever an \#elifndef branch is taken. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param MacroNameTok Information on the token being tested. /// \param MD The MacroDefinition if the name was a macro, null otherwise. - virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) { - } + virtual void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) {} /// Hook called whenever an \#elifndef is skipped. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. // FIXME: better to pass in a list (or tree!) of Tokens. - virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) { - } + virtual void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) {} /// Hook called whenever an \#else is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. - virtual void Else(SourceLocation Loc, SourceLocation IfLoc) { - } + virtual void Else(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) {} /// Hook called whenever an \#endif is seen. + /// \param HashLoc The location of the '#' that starts the directive. /// \param Loc the source location of the directive. /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. - virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) { - } + virtual void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) {} }; /// Simple wrapper class for chaining callbacks. @@ -504,9 +512,10 @@ Second->EndOfMainFile(); } - void Ident(SourceLocation Loc, StringRef str) override { - First->Ident(Loc, str); - Second->Ident(Loc, str); + void Ident(SourceLocation HashLoc, SourceLocation Loc, + StringRef str) override { + First->Ident(HashLoc, Loc, str); + Second->Ident(HashLoc, Loc, str); } void PragmaDirective(PragmaIntroducer Introducer) override { @@ -514,94 +523,108 @@ Second->PragmaDirective(Introducer); } - void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, - StringRef Str) override { - First->PragmaComment(Loc, Kind, Str); - Second->PragmaComment(Loc, Kind, Str); + void PragmaComment(PragmaIntroducer Introducer, SourceLocation Loc, + const IdentifierInfo *Kind, StringRef Str) override { + First->PragmaComment(Introducer, Loc, Kind, Str); + Second->PragmaComment(Introducer, Loc, Kind, Str); } - void PragmaMark(SourceLocation Loc, StringRef Trivia) override { - First->PragmaMark(Loc, Trivia); - Second->PragmaMark(Loc, Trivia); + void PragmaMark(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Trivia) override { + First->PragmaMark(Introducer, Loc, Trivia); + Second->PragmaMark(Introducer, Loc, Trivia); } - void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, - StringRef Value) override { - First->PragmaDetectMismatch(Loc, Name, Value); - Second->PragmaDetectMismatch(Loc, Name, Value); + void PragmaDetectMismatch(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Name, StringRef Value) override { + First->PragmaDetectMismatch(Introducer, Loc, Name, Value); + Second->PragmaDetectMismatch(Introducer, Loc, Name, Value); } - void PragmaDebug(SourceLocation Loc, StringRef DebugType) override { - First->PragmaDebug(Loc, DebugType); - Second->PragmaDebug(Loc, DebugType); + void PragmaDebug(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef DebugType) override { + First->PragmaDebug(Introducer, Loc, DebugType); + Second->PragmaDebug(Introducer, Loc, DebugType); } - void PragmaMessage(SourceLocation Loc, StringRef Namespace, - PragmaMessageKind Kind, StringRef Str) override { - First->PragmaMessage(Loc, Namespace, Kind, Str); - Second->PragmaMessage(Loc, Namespace, Kind, Str); + void PragmaMessage(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace, PragmaMessageKind Kind, + StringRef Str) override { + First->PragmaMessage(Introducer, Loc, Namespace, Kind, Str); + Second->PragmaMessage(Introducer, Loc, Namespace, Kind, Str); } - void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override { - First->PragmaDiagnosticPush(Loc, Namespace); - Second->PragmaDiagnosticPush(Loc, Namespace); + void PragmaDiagnosticPush(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace) override { + First->PragmaDiagnosticPush(Introducer, Loc, Namespace); + Second->PragmaDiagnosticPush(Introducer, Loc, Namespace); } - void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override { - First->PragmaDiagnosticPop(Loc, Namespace); - Second->PragmaDiagnosticPop(Loc, Namespace); + void PragmaDiagnosticPop(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace) override { + First->PragmaDiagnosticPop(Introducer, Loc, Namespace); + Second->PragmaDiagnosticPop(Introducer, Loc, Namespace); } - void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, - diag::Severity mapping, StringRef Str) override { - First->PragmaDiagnostic(Loc, Namespace, mapping, Str); - Second->PragmaDiagnostic(Loc, Namespace, mapping, Str); + void PragmaDiagnostic(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace, diag::Severity mapping, + StringRef Str) override { + First->PragmaDiagnostic(Introducer, Loc, Namespace, mapping, Str); + Second->PragmaDiagnostic(Introducer, Loc, Namespace, mapping, Str); } void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType) override; - void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, + void PragmaOpenCLExtension(PragmaIntroducer Introducer, + SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) override { - First->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State); - Second->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State); + First->PragmaOpenCLExtension(Introducer, NameLoc, Name, StateLoc, State); + Second->PragmaOpenCLExtension(Introducer, NameLoc, Name, StateLoc, State); } - void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, + void PragmaWarning(PragmaIntroducer Introducer, SourceLocation Loc, + PragmaWarningSpecifier WarningSpec, ArrayRef Ids) override { - First->PragmaWarning(Loc, WarningSpec, Ids); - Second->PragmaWarning(Loc, WarningSpec, Ids); + First->PragmaWarning(Introducer, Loc, WarningSpec, Ids); + Second->PragmaWarning(Introducer, Loc, WarningSpec, Ids); } - void PragmaWarningPush(SourceLocation Loc, int Level) override { - First->PragmaWarningPush(Loc, Level); - Second->PragmaWarningPush(Loc, Level); + void PragmaWarningPush(PragmaIntroducer Introducer, SourceLocation Loc, + int Level) override { + First->PragmaWarningPush(Introducer, Loc, Level); + Second->PragmaWarningPush(Introducer, Loc, Level); } - void PragmaWarningPop(SourceLocation Loc) override { - First->PragmaWarningPop(Loc); - Second->PragmaWarningPop(Loc); + void PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) override { + First->PragmaWarningPop(Introducer, Loc); + Second->PragmaWarningPop(Introducer, Loc); } - void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override { - First->PragmaExecCharsetPush(Loc, Str); - Second->PragmaExecCharsetPush(Loc, Str); + void PragmaExecCharsetPush(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Str) override { + First->PragmaExecCharsetPush(Introducer, Loc, Str); + Second->PragmaExecCharsetPush(Introducer, Loc, Str); } - void PragmaExecCharsetPop(SourceLocation Loc) override { - First->PragmaExecCharsetPop(Loc); - Second->PragmaExecCharsetPop(Loc); + void PragmaExecCharsetPop(PragmaIntroducer Introducer, + SourceLocation Loc) override { + First->PragmaExecCharsetPop(Introducer, Loc); + Second->PragmaExecCharsetPop(Introducer, Loc); } - void PragmaAssumeNonNullBegin(SourceLocation Loc) override { - First->PragmaAssumeNonNullBegin(Loc); - Second->PragmaAssumeNonNullBegin(Loc); + void PragmaAssumeNonNullBegin(PragmaIntroducer Introducer, + SourceLocation Loc) override { + First->PragmaAssumeNonNullBegin(Introducer, Loc); + Second->PragmaAssumeNonNullBegin(Introducer, Loc); } - void PragmaAssumeNonNullEnd(SourceLocation Loc) override { - First->PragmaAssumeNonNullEnd(Loc); - Second->PragmaAssumeNonNullEnd(Loc); + void PragmaAssumeNonNullEnd(PragmaIntroducer Introducer, + SourceLocation Loc) override { + First->PragmaAssumeNonNullEnd(Introducer, Loc); + Second->PragmaAssumeNonNullEnd(Introducer, Loc); } void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, @@ -610,17 +633,17 @@ Second->MacroExpands(MacroNameTok, MD, Range, Args); } - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { - First->MacroDefined(MacroNameTok, MD); - Second->MacroDefined(MacroNameTok, MD); + First->MacroDefined(HashLoc, MacroNameTok, MD); + Second->MacroDefined(HashLoc, MacroNameTok, MD); } - void MacroUndefined(const Token &MacroNameTok, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override { - First->MacroUndefined(MacroNameTok, MD, Undef); - Second->MacroUndefined(MacroNameTok, MD, Undef); + First->MacroUndefined(HashLoc, MacroNameTok, MD, Undef); + Second->MacroUndefined(HashLoc, MacroNameTok, MD, Undef); } void Defined(const Token &MacroNameTok, const MacroDefinition &MD, @@ -635,69 +658,73 @@ } /// Hook called whenever an \#if is seen. - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override { - First->If(Loc, ConditionRange, ConditionValue); - Second->If(Loc, ConditionRange, ConditionValue); + First->If(HashLoc, Loc, ConditionRange, ConditionValue); + Second->If(HashLoc, Loc, ConditionRange, ConditionValue); } /// Hook called whenever an \#elif is seen. - void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) override { - First->Elif(Loc, ConditionRange, ConditionValue, IfLoc); - Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc); + void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, + SourceLocation IfLoc) override { + First->Elif(HashLoc, Loc, ConditionRange, ConditionValue, IfLoc); + Second->Elif(HashLoc, Loc, ConditionRange, ConditionValue, IfLoc); } /// Hook called whenever an \#ifdef is seen. - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { - First->Ifdef(Loc, MacroNameTok, MD); - Second->Ifdef(Loc, MacroNameTok, MD); + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { + First->Ifdef(HashLoc, Loc, MacroNameTok, MD); + Second->Ifdef(HashLoc, Loc, MacroNameTok, MD); } /// Hook called whenever an \#elifdef is taken. - void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { - First->Elifdef(Loc, MacroNameTok, MD); - Second->Elifdef(Loc, MacroNameTok, MD); + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { + First->Elifdef(HashLoc, Loc, MacroNameTok, MD); + Second->Elifdef(HashLoc, Loc, MacroNameTok, MD); } /// Hook called whenever an \#elifdef is skipped. - void Elifdef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) override { - First->Elifdef(Loc, ConditionRange, IfLoc); - Second->Elifdef(Loc, ConditionRange, IfLoc); + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) override { + First->Elifdef(HashLoc, Loc, ConditionRange, IfLoc); + Second->Elifdef(HashLoc, Loc, ConditionRange, IfLoc); } /// Hook called whenever an \#ifndef is seen. - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { - First->Ifndef(Loc, MacroNameTok, MD); - Second->Ifndef(Loc, MacroNameTok, MD); + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { + First->Ifndef(HashLoc, Loc, MacroNameTok, MD); + Second->Ifndef(HashLoc, Loc, MacroNameTok, MD); } /// Hook called whenever an \#elifndef is taken. - void Elifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { - First->Elifndef(Loc, MacroNameTok, MD); - Second->Elifndef(Loc, MacroNameTok, MD); + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { + First->Elifndef(HashLoc, Loc, MacroNameTok, MD); + Second->Elifndef(HashLoc, Loc, MacroNameTok, MD); } /// Hook called whenever an \#elifndef is skipped. - void Elifndef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) override { - First->Elifndef(Loc, ConditionRange, IfLoc); - Second->Elifndef(Loc, ConditionRange, IfLoc); + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) override { + First->Elifndef(HashLoc, Loc, ConditionRange, IfLoc); + Second->Elifndef(HashLoc, Loc, ConditionRange, IfLoc); } /// Hook called whenever an \#else is seen. - void Else(SourceLocation Loc, SourceLocation IfLoc) override { - First->Else(Loc, IfLoc); - Second->Else(Loc, IfLoc); + void Else(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override { + First->Else(HashLoc, Loc, IfLoc); + Second->Else(HashLoc, Loc, IfLoc); } /// Hook called whenever an \#endif is seen. - void Endif(SourceLocation Loc, SourceLocation IfLoc) override { - First->Endif(Loc, IfLoc); - Second->Endif(Loc, IfLoc); + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override { + First->Endif(HashLoc, Loc, IfLoc); + Second->Endif(HashLoc, Loc, IfLoc); } }; Index: clang/include/clang/Lex/PPConditionalDirectiveRecord.h =================================================================== --- clang/include/clang/Lex/PPConditionalDirectiveRecord.h +++ clang/include/clang/Lex/PPConditionalDirectiveRecord.h @@ -85,24 +85,28 @@ SourceLocation findConditionalDirectiveRegionLoc(SourceLocation Loc) const; private: - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override; - void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) override; - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Elifdef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) override; - void Elifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Elifndef(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) override; - void Else(SourceLocation Loc, SourceLocation IfLoc) override; - void Endif(SourceLocation Loc, SourceLocation IfLoc) override; + void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, + SourceLocation IfLoc) override; + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) override; + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, SourceLocation IfLoc) override; + void Else(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override; + void Endif(SourceLocation HashLoc, SourceLocation Loc, + SourceLocation IfLoc) override; }; } // end namespace clang Index: clang/include/clang/Lex/PreprocessingRecord.h =================================================================== --- clang/include/clang/Lex/PreprocessingRecord.h +++ clang/include/clang/Lex/PreprocessingRecord.h @@ -522,8 +522,10 @@ void MacroExpands(const Token &Id, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override; - void MacroDefined(const Token &Id, const MacroDirective *MD) override; - void MacroUndefined(const Token &Id, const MacroDefinition &MD, + void MacroDefined(SourceLocation HashLoc, const Token &Id, + const MacroDirective *MD) override; + void MacroUndefined(SourceLocation HashLoc, const Token &Id, + const MacroDefinition &MD, const MacroDirective *Undef) override; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, @@ -531,16 +533,17 @@ OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; using PPCallbacks::Elifdef; using PPCallbacks::Elifndef; - void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override; - void Elifndef(SourceLocation Loc, const Token &MacroNameTok, + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override; /// Hook called whenever the 'defined' operator is seen. Index: clang/include/clang/Lex/Preprocessor.h =================================================================== --- clang/include/clang/Lex/Preprocessor.h +++ clang/include/clang/Lex/Preprocessor.h @@ -2486,7 +2486,7 @@ void HandleLineDirective(); void HandleDigitDirective(Token &Tok); void HandleUserDiagnosticDirective(Token &Tok, bool isWarning); - void HandleIdentSCCSDirective(Token &Tok); + void HandleIdentSCCSDirective(SourceLocation HashLoc, Token &Tok); void HandleMacroPublicDirective(Token &Tok); void HandleMacroPrivateDirective(); @@ -2597,15 +2597,16 @@ void replayPreambleConditionalStack(); // Macro handling. - void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterHeaderGuard); - void HandleUndefDirective(); + void HandleDefineDirective(SourceLocation HashLoc, Token &Tok, + bool ImmediatelyAfterHeaderGuard); + void HandleUndefDirective(SourceLocation HashLoc); // Conditional Inclusion. void HandleIfdefDirective(Token &Result, const Token &HashToken, bool isIfndef, bool ReadAnyTokensBeforeDirective); void HandleIfDirective(Token &IfToken, const Token &HashToken, bool ReadAnyTokensBeforeDirective); - void HandleEndifDirective(Token &EndifToken); + void HandleEndifDirective(Token &EndifToken, const Token &HashToken); void HandleElseDirective(Token &Result, const Token &HashToken); void HandleElifFamilyDirective(Token &ElifToken, const Token &HashToken, tok::PPKeywordKind Kind); @@ -2615,7 +2616,7 @@ public: void HandlePragmaOnce(Token &OnceTok); - void HandlePragmaMark(Token &MarkTok); + void HandlePragmaMark(PragmaIntroducer Introducer, Token &MarkTok); void HandlePragmaPoison(); void HandlePragmaSystemHeader(Token &SysHeaderTok); void HandlePragmaDependency(Token &DependencyTok); Index: clang/lib/CodeGen/MacroPPCallbacks.h =================================================================== --- clang/lib/CodeGen/MacroPPCallbacks.h +++ clang/lib/CodeGen/MacroPPCallbacks.h @@ -106,13 +106,14 @@ SrcMgr::CharacteristicKind FileType) override; /// Hook called whenever a macro definition is seen. - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; /// Hook called whenever a macro \#undef is seen. /// /// MD is released immediately following this callback. - void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDefinition &MD, const MacroDirective *Undef) override; }; Index: clang/lib/CodeGen/MacroPPCallbacks.cpp =================================================================== --- clang/lib/CodeGen/MacroPPCallbacks.cpp +++ clang/lib/CodeGen/MacroPPCallbacks.cpp @@ -175,7 +175,8 @@ LastHashLoc = HashLoc; } -void MacroPPCallbacks::MacroDefined(const Token &MacroNameTok, +void MacroPPCallbacks::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MD) { IdentifierInfo *Id = MacroNameTok.getIdentifierInfo(); SourceLocation location = getCorrectLocation(MacroNameTok.getLocation()); @@ -188,7 +189,8 @@ Name.str(), Value.str()); } -void MacroPPCallbacks::MacroUndefined(const Token &MacroNameTok, +void MacroPPCallbacks::MacroUndefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) { IdentifierInfo *Id = MacroNameTok.getIdentifierInfo(); Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp =================================================================== --- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp @@ -241,7 +241,7 @@ Preprocessor &PP) : SM(SM), LCF(LCF), API(API), PP(PP) {} - void MacroDefined(const Token &MacroNameToken, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameToken, const MacroDirective *MD) override { auto *MacroInfo = MD->getMacroInfo(); @@ -259,7 +259,8 @@ // If a macro gets undefined at some point during preprocessing of the inputs // it means that it isn't an exposed API and we should therefore not add a // macro definition for it. - void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameToken, + const MacroDefinition &MD, const MacroDirective *Undef) override { // If this macro wasn't previously defined we don't need to do anything // here. Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -909,7 +909,7 @@ public: explicit MacroDefinitionTrackerPPCallbacks(unsigned &Hash) : Hash(Hash) {} - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { AddDefinedMacroToHash(MacroNameTok, Hash); } Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp =================================================================== --- clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -149,22 +149,35 @@ OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; - void Ident(SourceLocation Loc, StringRef str) override; - void PragmaMessage(SourceLocation Loc, StringRef Namespace, - PragmaMessageKind Kind, StringRef Str) override; - void PragmaDebug(SourceLocation Loc, StringRef DebugType) override; - void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override; - void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override; - void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, - diag::Severity Map, StringRef Str) override; - void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, + void Ident(SourceLocation HashLoc, SourceLocation Loc, + StringRef str) override; + void PragmaMessage(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace, PragmaMessageKind Kind, + StringRef Str) override; + void PragmaDebug(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef DebugType) override; + void PragmaDiagnosticPush(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace) override; + void PragmaDiagnosticPop(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace) override; + void PragmaDiagnostic(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Namespace, diag::Severity Map, + StringRef Str) override; + void PragmaWarning(PragmaIntroducer Introducer, SourceLocation Loc, + PragmaWarningSpecifier WarningSpec, ArrayRef Ids) override; - void PragmaWarningPush(SourceLocation Loc, int Level) override; - void PragmaWarningPop(SourceLocation Loc) override; - void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override; - void PragmaExecCharsetPop(SourceLocation Loc) override; - void PragmaAssumeNonNullBegin(SourceLocation Loc) override; - void PragmaAssumeNonNullEnd(SourceLocation Loc) override; + void PragmaWarningPush(PragmaIntroducer Introducer, SourceLocation Loc, + int Level) override; + void PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) override; + void PragmaExecCharsetPush(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Str) override; + void PragmaExecCharsetPop(PragmaIntroducer Introducer, + SourceLocation Loc) override; + void PragmaAssumeNonNullBegin(PragmaIntroducer Introducer, + SourceLocation Loc) override; + void PragmaAssumeNonNullEnd(PragmaIntroducer Introducer, + SourceLocation Loc) override; /// Insert whitespace before emitting the next token. /// @@ -215,11 +228,11 @@ void HandleNewlinesInToken(const char *TokStr, unsigned Len); /// MacroDefined - This hook is called whenever a macro definition is seen. - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override; /// MacroUndefined - This hook is called whenever a macro #undef is seen. - void MacroUndefined(const Token &MacroNameTok, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override; @@ -451,7 +464,8 @@ /// Ident - Handle #ident directives when read by the preprocessor. /// -void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, StringRef S) { +void PrintPPOutputPPCallbacks::Ident(SourceLocation HashLoc, SourceLocation Loc, + StringRef S) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS.write("#ident ", strlen("#ident ")); @@ -460,7 +474,8 @@ } /// MacroDefined - This hook is called whenever a macro definition is seen. -void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok, +void PrintPPOutputPPCallbacks::MacroDefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDirective *MD) { const MacroInfo *MI = MD->getMacroInfo(); // Print out macro definitions in -dD mode and when we have -fdirectives-only @@ -482,7 +497,8 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok, +void PrintPPOutputPPCallbacks::MacroUndefined(SourceLocation HashLoc, + const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) { // Print out macro definitions in -dD mode and when we have -fdirectives-only @@ -507,7 +523,8 @@ } } -void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc, +void PrintPPOutputPPCallbacks::PragmaMessage(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str) { @@ -534,7 +551,8 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaDebug(SourceLocation Loc, +void PrintPPOutputPPCallbacks::PragmaDebug(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef DebugType) { MoveToLine(Loc, /*RequireStartOfLine=*/true); @@ -544,21 +562,24 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks:: -PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) { +void PrintPPOutputPPCallbacks::PragmaDiagnosticPush(PragmaIntroducer Introducer, + SourceLocation Loc, + StringRef Namespace) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma " << Namespace << " diagnostic push"; setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks:: -PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) { +void PrintPPOutputPPCallbacks::PragmaDiagnosticPop(PragmaIntroducer Introducer, + SourceLocation Loc, + StringRef Namespace) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma " << Namespace << " diagnostic pop"; setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc, +void PrintPPOutputPPCallbacks::PragmaDiagnostic(PragmaIntroducer Introducer, + SourceLocation Loc, StringRef Namespace, diag::Severity Map, StringRef Str) { @@ -585,7 +606,8 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc, +void PrintPPOutputPPCallbacks::PragmaWarning(PragmaIntroducer Introducer, + SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef Ids) { MoveToLine(Loc, /*RequireStartOfLine=*/true); @@ -610,7 +632,8 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaWarningPush(SourceLocation Loc, +void PrintPPOutputPPCallbacks::PragmaWarningPush(PragmaIntroducer Introducer, + SourceLocation Loc, int Level) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma warning(push"; @@ -620,14 +643,15 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaWarningPop(SourceLocation Loc) { +void PrintPPOutputPPCallbacks::PragmaWarningPop(PragmaIntroducer Introducer, + SourceLocation Loc) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma warning(pop)"; setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaExecCharsetPush(SourceLocation Loc, - StringRef Str) { +void PrintPPOutputPPCallbacks::PragmaExecCharsetPush( + PragmaIntroducer Introducer, SourceLocation Loc, StringRef Str) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma character_execution_set(push"; if (!Str.empty()) @@ -636,21 +660,22 @@ setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks::PragmaExecCharsetPop(SourceLocation Loc) { +void PrintPPOutputPPCallbacks::PragmaExecCharsetPop(PragmaIntroducer Introducer, + SourceLocation Loc) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma character_execution_set(pop)"; setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks:: -PragmaAssumeNonNullBegin(SourceLocation Loc) { +void PrintPPOutputPPCallbacks::PragmaAssumeNonNullBegin( + PragmaIntroducer Introducer, SourceLocation Loc) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma clang assume_nonnull begin"; setEmittedDirectiveOnThisLine(); } -void PrintPPOutputPPCallbacks:: -PragmaAssumeNonNullEnd(SourceLocation Loc) { +void PrintPPOutputPPCallbacks::PragmaAssumeNonNullEnd( + PragmaIntroducer Introducer, SourceLocation Loc) { MoveToLine(Loc, /*RequireStartOfLine=*/true); OS << "#pragma clang assume_nonnull end"; setEmittedDirectiveOnThisLine(); Index: clang/lib/Frontend/Rewrite/InclusionRewriter.cpp =================================================================== --- clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -77,10 +77,12 @@ OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override; - void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) override; + void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, + SourceLocation IfLoc) override; void WriteLineInfo(StringRef Filename, int Line, SrcMgr::CharacteristicKind FileType, StringRef Extra = StringRef()); @@ -196,14 +198,16 @@ LastInclusionLocation = HashLoc; } -void InclusionRewriter::If(SourceLocation Loc, SourceRange ConditionRange, +void InclusionRewriter::If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) { auto P = IfConditions.insert(std::make_pair(Loc, ConditionValue == CVK_True)); (void)P; assert(P.second && "Unexpected revisitation of the same if directive"); } -void InclusionRewriter::Elif(SourceLocation Loc, SourceRange ConditionRange, +void InclusionRewriter::Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) { auto P = IfConditions.insert(std::make_pair(Loc, ConditionValue == CVK_True)); Index: clang/lib/Index/IndexingAction.cpp =================================================================== --- clang/lib/Index/IndexingAction.cpp +++ clang/lib/Index/IndexingAction.cpp @@ -36,14 +36,15 @@ Range.getBegin(), *MD.getMacroInfo()); } - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { IndexCtx->handleMacroDefined(*MacroNameTok.getIdentifierInfo(), MacroNameTok.getLocation(), *MD->getMacroInfo()); } - void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, + const MacroDefinition &MD, const MacroDirective *Undef) override { if (!MD.getMacroInfo()) // Ignore noop #undef. return; @@ -61,16 +62,16 @@ MacroNameTok.getLocation(), *MD.getMacroInfo()); } - void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!MD.getMacroInfo()) // Ignore non-existent macro. return; IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(), MacroNameTok.getLocation(), *MD.getMacroInfo()); } - void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!MD.getMacroInfo()) // Ignore nonexistent macro. return; IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(), @@ -80,16 +81,16 @@ using PPCallbacks::Elifdef; using PPCallbacks::Elifndef; - void Elifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!MD.getMacroInfo()) // Ignore non-existent macro. return; IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(), MacroNameTok.getLocation(), *MD.getMacroInfo()); } - void Elifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroDefinition &MD) override { + void Elifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) override { if (!MD.getMacroInfo()) // Ignore non-existent macro. return; IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(), Index: clang/lib/Lex/PPConditionalDirectiveRecord.cpp =================================================================== --- clang/lib/Lex/PPConditionalDirectiveRecord.cpp +++ clang/lib/Lex/PPConditionalDirectiveRecord.cpp @@ -72,28 +72,32 @@ CondDirectiveLocs.push_back(DirLoc); } -void PPConditionalDirectiveRecord::If(SourceLocation Loc, +void PPConditionalDirectiveRecord::If(SourceLocation HashLoc, + SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.push_back(Loc); } -void PPConditionalDirectiveRecord::Ifdef(SourceLocation Loc, +void PPConditionalDirectiveRecord::Ifdef(SourceLocation HashLoc, + SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.push_back(Loc); } -void PPConditionalDirectiveRecord::Ifndef(SourceLocation Loc, +void PPConditionalDirectiveRecord::Ifndef(SourceLocation HashLoc, + SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.push_back(Loc); } -void PPConditionalDirectiveRecord::Elif(SourceLocation Loc, +void PPConditionalDirectiveRecord::Elif(SourceLocation HashLoc, + SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) { @@ -101,35 +105,41 @@ CondDirectiveStack.back() = Loc; } -void PPConditionalDirectiveRecord::Elifdef(SourceLocation Loc, const Token &, +void PPConditionalDirectiveRecord::Elifdef(SourceLocation HashLoc, + SourceLocation Loc, const Token &, const MacroDefinition &) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; } -void PPConditionalDirectiveRecord::Elifdef(SourceLocation Loc, SourceRange, +void PPConditionalDirectiveRecord::Elifdef(SourceLocation HashLoc, + SourceLocation Loc, SourceRange, SourceLocation) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; } -void PPConditionalDirectiveRecord::Elifndef(SourceLocation Loc, const Token &, +void PPConditionalDirectiveRecord::Elifndef(SourceLocation HashLoc, + SourceLocation Loc, const Token &, const MacroDefinition &) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; } -void PPConditionalDirectiveRecord::Elifndef(SourceLocation Loc, SourceRange, +void PPConditionalDirectiveRecord::Elifndef(SourceLocation HashLoc, + SourceLocation Loc, SourceRange, SourceLocation) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; } -void PPConditionalDirectiveRecord::Else(SourceLocation Loc, +void PPConditionalDirectiveRecord::Else(SourceLocation HashLoc, + SourceLocation Loc, SourceLocation IfLoc) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; } -void PPConditionalDirectiveRecord::Endif(SourceLocation Loc, +void PPConditionalDirectiveRecord::Endif(SourceLocation HashLoc, + SourceLocation Loc, SourceLocation IfLoc) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); assert(!CondDirectiveStack.empty()); Index: clang/lib/Lex/PPDirectives.cpp =================================================================== --- clang/lib/Lex/PPDirectives.cpp +++ clang/lib/Lex/PPDirectives.cpp @@ -577,6 +577,7 @@ assert(Tok.is(tok::hash)); const char *Hashptr = CurLexer->getBufferLocation() - Tok.getLength(); assert(CurLexer->getSourceLocation(Hashptr) == Tok.getLocation()); + SourceLocation LastHashLoc = Tok.getLocation(); // Read the next token, the directive flavor. LexUnexpandedToken(Tok); @@ -658,7 +659,7 @@ endLoc = CheckEndOfDirective("endif"); CurPPLexer->LexingRawMode = true; if (Callbacks) - Callbacks->Endif(Tok.getLocation(), CondInfo.IfLoc); + Callbacks->Endif(LastHashLoc, Tok.getLocation(), CondInfo.IfLoc); break; } else { DiscardUntilEndOfDirective(); @@ -689,7 +690,7 @@ endLoc = CheckEndOfDirective("else"); CurPPLexer->LexingRawMode = true; if (Callbacks) - Callbacks->Else(Tok.getLocation(), CondInfo.IfLoc); + Callbacks->Else(LastHashLoc, Tok.getLocation(), CondInfo.IfLoc); break; } else { DiscardUntilEndOfDirective(); // C99 6.10p4. @@ -726,7 +727,7 @@ CurPPLexer->LexingRawMode = true; if (Callbacks) { Callbacks->Elif( - Tok.getLocation(), DER.ExprRange, + LastHashLoc, Tok.getLocation(), DER.ExprRange, (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False), CondInfo.IfLoc); } @@ -796,11 +797,11 @@ if (Callbacks) { if (IsElifDef) { - Callbacks->Elifdef(DirectiveToken.getLocation(), MacroNameTok, - MD); + Callbacks->Elifdef(LastHashLoc, DirectiveToken.getLocation(), + MacroNameTok, MD); } else { - Callbacks->Elifndef(DirectiveToken.getLocation(), MacroNameTok, - MD); + Callbacks->Elifndef(LastHashLoc, DirectiveToken.getLocation(), + MacroNameTok, MD); } } // If this condition is true, enter it! @@ -1093,7 +1094,7 @@ SourceLocation HashLoc) { if (const IdentifierInfo *II = Result.getIdentifierInfo()) { if (II->getPPKeywordID() == tok::pp_define) { - return HandleDefineDirective(Result, + return HandleDefineDirective(HashLoc, Result, /*ImmediatelyAfterHeaderGuard=*/false); } if (SkippingUntilPCHThroughHeader && @@ -1213,7 +1214,7 @@ case tok::pp_else: return HandleElseDirective(Result, SavedHash); case tok::pp_endif: - return HandleEndifDirective(Result); + return HandleEndifDirective(Result, SavedHash); // C99 6.10.2 - Source File Inclusion. case tok::pp_include: @@ -1225,9 +1226,10 @@ // C99 6.10.3 - Macro Replacement. case tok::pp_define: - return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef); + return HandleDefineDirective(SavedHash.getLocation(), Result, + ImmediatelyAfterTopLevelIfndef); case tok::pp_undef: - return HandleUndefDirective(); + return HandleUndefDirective(SavedHash.getLocation()); // C99 6.10.4 - Line Control. case tok::pp_line: @@ -1260,9 +1262,9 @@ return HandleUserDiagnosticDirective(Result, true); case tok::pp_ident: - return HandleIdentSCCSDirective(Result); + return HandleIdentSCCSDirective(SavedHash.getLocation(), Result); case tok::pp_sccs: - return HandleIdentSCCSDirective(Result); + return HandleIdentSCCSDirective(SavedHash.getLocation(), Result); case tok::pp_assert: //isExtension = true; // FIXME: implement #assert break; @@ -1636,7 +1638,8 @@ /// HandleIdentSCCSDirective - Handle a #ident/#sccs directive. /// -void Preprocessor::HandleIdentSCCSDirective(Token &Tok) { +void Preprocessor::HandleIdentSCCSDirective(SourceLocation HashLoc, + Token &Tok) { // Yes, this directive is an extension. Diag(Tok, diag::ext_pp_ident_directive); @@ -1666,7 +1669,7 @@ bool Invalid = false; std::string Str = getSpelling(StrTok, &Invalid); if (!Invalid) - Callbacks->Ident(Tok.getLocation(), Str); + Callbacks->Ident(HashLoc, Tok.getLocation(), Str); } } @@ -3008,7 +3011,8 @@ /// HandleDefineDirective - Implements \#define. This consumes the entire macro /// line then lets the caller lex the next real token. void Preprocessor::HandleDefineDirective( - Token &DefineTok, const bool ImmediatelyAfterHeaderGuard) { + SourceLocation HashLoc, Token &DefineTok, + const bool ImmediatelyAfterHeaderGuard) { ++NumDefined; Token MacroNameTok; @@ -3140,7 +3144,7 @@ // If the callbacks want to know, tell them about the macro definition. if (Callbacks) - Callbacks->MacroDefined(MacroNameTok, MD); + Callbacks->MacroDefined(HashLoc, MacroNameTok, MD); // If we're in MS compatibility mode and the macro being defined is the // assert macro, implicitly add a macro definition for static_assert to work @@ -3162,7 +3166,7 @@ /// HandleUndefDirective - Implements \#undef. /// -void Preprocessor::HandleUndefDirective() { +void Preprocessor::HandleUndefDirective(SourceLocation HashLoc) { ++NumUndefined; Token MacroNameTok; @@ -3197,7 +3201,7 @@ // If the callbacks want to know, tell them about the macro #undef. // Note: no matter if the macro was defined or not. if (Callbacks) - Callbacks->MacroUndefined(MacroNameTok, MD, Undef); + Callbacks->MacroUndefined(HashLoc, MacroNameTok, MD, Undef); if (Undef) appendMacroDirective(II, Undef); @@ -3259,9 +3263,11 @@ if (Callbacks) { if (isIfndef) - Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MD); + Callbacks->Ifndef(HashToken.getLocation(), DirectiveTok.getLocation(), + MacroNameTok, MD); else - Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD); + Callbacks->Ifdef(HashToken.getLocation(), DirectiveTok.getLocation(), + MacroNameTok, MD); } bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && @@ -3316,7 +3322,7 @@ if (Callbacks) Callbacks->If( - IfToken.getLocation(), DER.ExprRange, + HashToken.getLocation(), IfToken.getLocation(), DER.ExprRange, (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False)); bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && @@ -3342,7 +3348,8 @@ /// HandleEndifDirective - Implements the \#endif directive. /// -void Preprocessor::HandleEndifDirective(Token &EndifToken) { +void Preprocessor::HandleEndifDirective(Token &EndifToken, + const Token &HashToken) { ++NumEndif; // Check that this is the whole directive. @@ -3363,7 +3370,8 @@ "This code should only be reachable in the non-skipping case!"); if (Callbacks) - Callbacks->Endif(EndifToken.getLocation(), CondInfo.IfLoc); + Callbacks->Endif(HashToken.getLocation(), EndifToken.getLocation(), + CondInfo.IfLoc); } /// HandleElseDirective - Implements the \#else directive. @@ -3388,7 +3396,7 @@ if (CI.FoundElse) Diag(Result, diag::pp_err_else_after_else); if (Callbacks) - Callbacks->Else(Result.getLocation(), CI.IfLoc); + Callbacks->Else(HashToken.getLocation(), Result.getLocation(), CI.IfLoc); bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && getSourceManager().isInMainFile(Result.getLocation()); @@ -3455,14 +3463,16 @@ if (Callbacks) { switch (Kind) { case tok::pp_elif: - Callbacks->Elif(ElifToken.getLocation(), ConditionRange, - PPCallbacks::CVK_NotEvaluated, CI.IfLoc); + Callbacks->Elif(HashToken.getLocation(), ElifToken.getLocation(), + ConditionRange, PPCallbacks::CVK_NotEvaluated, CI.IfLoc); break; case tok::pp_elifdef: - Callbacks->Elifdef(ElifToken.getLocation(), ConditionRange, CI.IfLoc); + Callbacks->Elifdef(HashToken.getLocation(), ElifToken.getLocation(), + ConditionRange, CI.IfLoc); break; case tok::pp_elifndef: - Callbacks->Elifndef(ElifToken.getLocation(), ConditionRange, CI.IfLoc); + Callbacks->Elifndef(HashToken.getLocation(), ElifToken.getLocation(), + ConditionRange, CI.IfLoc); break; default: assert(false && "unexpected directive kind"); Index: clang/lib/Lex/Pragma.cpp =================================================================== --- clang/lib/Lex/Pragma.cpp +++ clang/lib/Lex/Pragma.cpp @@ -418,13 +418,14 @@ HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry()); } -void Preprocessor::HandlePragmaMark(Token &MarkTok) { +void Preprocessor::HandlePragmaMark(PragmaIntroducer Introducer, + Token &MarkTok) { assert(CurPPLexer && "No current lexer?"); SmallString<64> Buffer; CurLexer->ReadToEndOfLine(&Buffer); if (Callbacks) - Callbacks->PragmaMark(MarkTok.getLocation(), Buffer); + Callbacks->PragmaMark(Introducer, MarkTok.getLocation(), Buffer); } /// HandlePragmaPoison - Handle \#pragma GCC poison. PoisonTok is the 'poison'. @@ -1001,7 +1002,7 @@ void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &MarkTok) override { - PP.HandlePragmaMark(MarkTok); + PP.HandlePragmaMark(Introducer, MarkTok); } }; @@ -1206,7 +1207,7 @@ PPCallbacks *Callbacks = PP.getPPCallbacks(); if (Callbacks) - Callbacks->PragmaDebug(Tok.getLocation(), II->getName()); + Callbacks->PragmaDebug(Introducer, Tok.getLocation(), II->getName()); } void HandleCaptured(Preprocessor &PP) { @@ -1268,12 +1269,12 @@ if (!PP.getDiagnostics().popMappings(DiagLoc)) PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop); else if (Callbacks) - Callbacks->PragmaDiagnosticPop(DiagLoc, Namespace); + Callbacks->PragmaDiagnosticPop(Introducer, DiagLoc, Namespace); return; } else if (II->isStr("push")) { PP.getDiagnostics().pushMappings(DiagLoc); if (Callbacks) - Callbacks->PragmaDiagnosticPush(DiagLoc, Namespace); + Callbacks->PragmaDiagnosticPush(Introducer, DiagLoc, Namespace); return; } @@ -1324,7 +1325,8 @@ PP.Diag(StringLoc, diag::warn_pragma_diagnostic_unknown_warning) << WarningName; else if (Callbacks) - Callbacks->PragmaDiagnostic(DiagLoc, Namespace, SV, WarningName); + Callbacks->PragmaDiagnostic(Introducer, DiagLoc, Namespace, SV, + WarningName); } }; @@ -1378,14 +1380,14 @@ } PP.getDiagnostics().pushMappings(DiagLoc); if (Callbacks) - Callbacks->PragmaWarningPush(DiagLoc, Level); + Callbacks->PragmaWarningPush(Introducer, DiagLoc, Level); } else if (II && II->isStr("pop")) { // #pragma warning( pop ) PP.Lex(Tok); if (!PP.getDiagnostics().popMappings(DiagLoc)) PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop); else if (Callbacks) - Callbacks->PragmaWarningPop(DiagLoc); + Callbacks->PragmaWarningPop(Introducer, DiagLoc); } else { // #pragma warning( warning-specifier : warning-number-list // [; warning-specifier : warning-number-list...] ) @@ -1465,7 +1467,7 @@ } if (Callbacks) - Callbacks->PragmaWarning(DiagLoc, Specifier, Ids); + Callbacks->PragmaWarning(Introducer, DiagLoc, Specifier, Ids); // Parse the next specifier if there is a semicolon. if (Tok.isNot(tok::semi)) @@ -1527,12 +1529,12 @@ } } if (Callbacks) - Callbacks->PragmaExecCharsetPush(DiagLoc, "UTF-8"); + Callbacks->PragmaExecCharsetPush(Introducer, DiagLoc, "UTF-8"); } else if (II && II->isStr("pop")) { // #pragma execution_character_set( pop ) PP.Lex(Tok); if (Callbacks) - Callbacks->PragmaExecCharsetPop(DiagLoc); + Callbacks->PragmaExecCharsetPop(Introducer, DiagLoc); } else { PP.Diag(Tok, diag::warn_pragma_exec_charset_spec_invalid); return; @@ -1641,7 +1643,8 @@ // If the pragma is lexically sound, notify any interested PPCallbacks. if (PPCallbacks *Callbacks = PP.getPPCallbacks()) - Callbacks->PragmaMessage(MessageLoc, Namespace, Kind, MessageString); + Callbacks->PragmaMessage(Introducer, MessageLoc, Namespace, Kind, + MessageString); } }; @@ -1919,7 +1922,7 @@ } NewLoc = Loc; if (Callbacks) - Callbacks->PragmaAssumeNonNullBegin(NewLoc); + Callbacks->PragmaAssumeNonNullBegin(Introducer, NewLoc); } else { // Complain about attempts to leave an audit that doesn't exist. if (!BeginLoc.isValid()) { @@ -1928,7 +1931,7 @@ } NewLoc = SourceLocation(); if (Callbacks) - Callbacks->PragmaAssumeNonNullEnd(NewLoc); + Callbacks->PragmaAssumeNonNullEnd(Introducer, NewLoc); } PP.setPragmaAssumeNonNullLoc(NewLoc); Index: clang/lib/Lex/PreprocessingRecord.cpp =================================================================== --- clang/lib/Lex/PreprocessingRecord.cpp +++ clang/lib/Lex/PreprocessingRecord.cpp @@ -403,7 +403,8 @@ addPreprocessedEntity(new (*this) MacroExpansion(Def, Range)); } -void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok, +void PreprocessingRecord::Ifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) { // This is not actually a macro expansion but record it as a macro reference. if (MD) @@ -411,7 +412,8 @@ MacroNameTok.getLocation()); } -void PreprocessingRecord::Elifdef(SourceLocation Loc, const Token &MacroNameTok, +void PreprocessingRecord::Elifdef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) { // This is not actually a macro expansion but record it as a macro reference. if (MD) @@ -419,7 +421,8 @@ MacroNameTok.getLocation()); } -void PreprocessingRecord::Ifndef(SourceLocation Loc, const Token &MacroNameTok, +void PreprocessingRecord::Ifndef(SourceLocation HashLoc, SourceLocation Loc, + const Token &MacroNameTok, const MacroDefinition &MD) { // This is not actually a macro expansion but record it as a macro reference. if (MD) @@ -427,7 +430,7 @@ MacroNameTok.getLocation()); } -void PreprocessingRecord::Elifndef(SourceLocation Loc, +void PreprocessingRecord::Elifndef(SourceLocation HashLoc, SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) { // This is not actually a macro expansion but record it as a macro reference. @@ -458,7 +461,7 @@ addMacroExpansion(Id, MD.getMacroInfo(), Range); } -void PreprocessingRecord::MacroDefined(const Token &Id, +void PreprocessingRecord::MacroDefined(SourceLocation HashLoc, const Token &Id, const MacroDirective *MD) { const MacroInfo *MI = MD->getMacroInfo(); SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc()); @@ -468,7 +471,8 @@ MacroDefinitions[MI] = Def; } -void PreprocessingRecord::MacroUndefined(const Token &Id, +void PreprocessingRecord::MacroUndefined(SourceLocation HashLoc, + const Token &Id, const MacroDefinition &MD, const MacroDirective *Undef) { MD.forAllDefinitions([&](MacroInfo *MI) { MacroDefinitions.erase(MI); }); Index: clang/lib/Parse/ParsePragma.cpp =================================================================== --- clang/lib/Parse/ParsePragma.cpp +++ clang/lib/Parse/ParsePragma.cpp @@ -2585,7 +2585,7 @@ /*IsReinject=*/false); if (PP.getPPCallbacks()) - PP.getPPCallbacks()->PragmaOpenCLExtension(NameLoc, Ext, + PP.getPPCallbacks()->PragmaOpenCLExtension(Introducer, NameLoc, Ext, StateLoc, State); } @@ -3043,8 +3043,8 @@ // If the pragma is lexically sound, notify any interested PPCallbacks. if (PP.getPPCallbacks()) - PP.getPPCallbacks()->PragmaDetectMismatch(DetectMismatchLoc, NameString, - ValueString); + PP.getPPCallbacks()->PragmaDetectMismatch(Introducer, DetectMismatchLoc, + NameString, ValueString); Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString); } @@ -3124,7 +3124,8 @@ // If the pragma is lexically sound, notify any interested PPCallbacks. if (PP.getPPCallbacks()) - PP.getPPCallbacks()->PragmaComment(CommentLoc, II, ArgumentString); + PP.getPPCallbacks()->PragmaComment(Introducer, CommentLoc, II, + ArgumentString); Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString); } Index: clang/tools/libclang/Indexing.cpp =================================================================== --- clang/tools/libclang/Indexing.cpp +++ clang/tools/libclang/Indexing.cpp @@ -272,11 +272,12 @@ } /// MacroDefined - This hook is called whenever a macro definition is seen. - void MacroDefined(const Token &Id, const MacroDirective *MD) override {} + void MacroDefined(SourceLocation HashLoc, const Token &Id, + const MacroDirective *MD) override {} /// MacroUndefined - This hook is called whenever a macro #undef is seen. /// MI is released immediately following this callback. - void MacroUndefined(const Token &MacroNameTok, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *UD) override {} Index: clang/unittests/Basic/SourceManagerTest.cpp =================================================================== --- clang/unittests/Basic/SourceManagerTest.cpp +++ clang/unittests/Basic/SourceManagerTest.cpp @@ -510,15 +510,15 @@ public: explicit MacroTracker(std::vector &Macros) : Macros(Macros) { } - void MacroDefined(const Token &MacroNameTok, + void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDirective *MD) override { Macros.push_back(MacroAction(MD->getLocation(), MacroNameTok.getIdentifierInfo()->getName(), MacroAction::kDefinition)); } - void MacroUndefined(const Token &MacroNameTok, + void MacroUndefined(SourceLocation HashLoc, const Token &MacroNameTok, const MacroDefinition &MD, - const MacroDirective *UD) override { + const MacroDirective *UD) override { Macros.push_back( MacroAction(UD ? UD->getLocation() : SourceLocation(), MacroNameTok.getIdentifierInfo()->getName(), Index: clang/unittests/Lex/PPCallbacksTest.cpp =================================================================== --- clang/unittests/Lex/PPCallbacksTest.cpp +++ clang/unittests/Lex/PPCallbacksTest.cpp @@ -75,13 +75,15 @@ std::vector Results; - void If(SourceLocation Loc, SourceRange ConditionRange, + void If(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue) override { Results.emplace_back(ConditionRange, ConditionValue); } - void Elif(SourceLocation Loc, SourceRange ConditionRange, - ConditionValueKind ConditionValue, SourceLocation IfLoc) override { + void Elif(SourceLocation HashLoc, SourceLocation Loc, + SourceRange ConditionRange, ConditionValueKind ConditionValue, + SourceLocation IfLoc) override { Results.emplace_back(ConditionRange, ConditionValue); } }; @@ -96,14 +98,15 @@ PragmaOpenCLExtensionCallbacks() : Name("Not called."), State(99) {} - void PragmaOpenCLExtension(clang::SourceLocation NameLoc, + void PragmaOpenCLExtension(clang::PragmaIntroducer Introducer, + clang::SourceLocation NameLoc, const clang::IdentifierInfo *Name, clang::SourceLocation StateLoc, unsigned State) override { - this->NameLoc = NameLoc; - this->Name = Name->getName(); - this->StateLoc = StateLoc; - this->State = State; + this->NameLoc = NameLoc; + this->Name = Name->getName(); + this->StateLoc = StateLoc; + this->State = State; } SourceLocation NameLoc; @@ -121,7 +124,8 @@ std::vector Marks; - void PragmaMark(SourceLocation Loc, StringRef Trivia) override { + void PragmaMark(PragmaIntroducer Introducer, SourceLocation Loc, + StringRef Trivia) override { Marks.emplace_back(Mark{Loc, Trivia.str()}); } };