#include "Protocol.h"
#include "SourceCode.h"
#include "clang-include-cleaner/Record.h"
+#include "index/CanonicalIncludes.h"
#include "support/Logger.h"
+#include "support/Path.h"
#include "support/ThreadsafeFS.h"
#include "support/Trace.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/PPCallbacks.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
+#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <system_error>
+#include <tuple>
#include <utility>
#include <vector>
// Literal lines of the preamble contents.
std::vector<llvm::StringRef> Lines;
PreambleBounds Bounds = {0, false};
+ std::vector<PragmaMark> Marks;
};
/// Scans the preprocessor directives in the preamble section of the file by
SP.Bounds = Bounds;
PP.addPPCallbacks(
std::make_unique<DirectiveCollector>(PP, SP.TextualDirectives));
+ PP.addPPCallbacks(
+ collectPragmaMarksCallback(PP.getSourceManager(), SP.Marks));
if (llvm::Error Err = Action.Execute())
return std::move(Err);
Action.EndSourceFile();
}
PP.PatchedDiags = patchDiags(Baseline.Diags, *BaselineScan, *ModifiedScan);
+ PP.PatchedMarks = std::move(ModifiedScan->Marks);
dlog("Created preamble patch: {0}", Patch.str());
Patch.flush();
return PP;
llvm::ArrayRef<PragmaMark> PreamblePatch::marks() const {
if (PatchContents.empty())
return Baseline->Marks;
- // FIXME: Patch pragma marks.
- return {};
+ return PatchedMarks;
}
MainFileMacros PreamblePatch::mainFileMacros() const {
}
}
+MATCHER_P2(Mark, Range, Text, "") {
+ return std::tie(arg.Rng, arg.Trivia) == std::tie(Range, Text);
+}
+
TEST(PreamblePatch, MacroAndMarkHandling) {
Config Cfg;
Cfg.Diagnostics.AllowStalePreamble = true;
#ifndef FOO
#define FOO
#define BAR
-#pragma mark XX
+#pragma $x[[mark XX
+]]
+#pragma $y[[mark YY
+]]
#endif)cpp");
auto AST = createPatchedAST(Code.code(), NewCode.code());
// FIXME: Macros and marks have locations that need to be patched.
EXPECT_THAT(AST->getMacros().Names, IsEmpty());
- EXPECT_THAT(AST->getMarks(), IsEmpty());
+ EXPECT_THAT(AST->getMarks(),
+ UnorderedElementsAre(Mark(NewCode.range("x"), " XX"),
+ Mark(NewCode.range("y"), " YY")));
}
}