|
12 | 12 | //===----------------------------------------------------------------------===//
|
13 | 13 |
|
14 | 14 | #include "../../clang-tidy/ClangTidyCheck.h"
|
15 |
| -#include "../../clang-tidy/ClangTidyModule.h" |
16 |
| -#include "../../clang-tidy/ClangTidyModuleRegistry.h" |
17 | 15 | #include "AST.h"
|
18 | 16 | #include "Annotations.h"
|
19 | 17 | #include "Compiler.h"
|
|
29 | 27 | #include "clang/Basic/SourceLocation.h"
|
30 | 28 | #include "clang/Basic/SourceManager.h"
|
31 | 29 | #include "clang/Basic/TokenKinds.h"
|
32 |
| -#include "clang/Lex/PPCallbacks.h" |
33 |
| -#include "clang/Lex/Token.h" |
34 | 30 | #include "clang/Tooling/Syntax/Tokens.h"
|
35 | 31 | #include "llvm/ADT/StringRef.h"
|
36 | 32 | #include "llvm/Testing/Support/Error.h"
|
@@ -96,10 +92,6 @@ MATCHER_P(withTemplateArgs, ArgName, "") {
|
96 | 92 | return false;
|
97 | 93 | }
|
98 | 94 |
|
99 |
| -MATCHER_P(rangeIs, R, "") { |
100 |
| - return arg.beginOffset() == R.Begin && arg.endOffset() == R.End; |
101 |
| -} |
102 |
| - |
103 | 95 | MATCHER_P(pragmaTrivia, P, "") { return arg.Trivia == P; }
|
104 | 96 |
|
105 | 97 | MATCHER(eqInc, "") {
|
@@ -352,123 +344,6 @@ TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
|
352 | 344 |
|
353 | 345 | MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
|
354 | 346 |
|
355 |
| -TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) { |
356 |
| - struct Inclusion { |
357 |
| - Inclusion(const SourceManager &SM, SourceLocation HashLoc, |
358 |
| - const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, |
359 |
| - CharSourceRange FilenameRange) |
360 |
| - : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok), |
361 |
| - IncDirective(IncludeTok.getIdentifierInfo()->getName()), |
362 |
| - FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second), |
363 |
| - FileName(FileName), IsAngled(IsAngled) { |
364 |
| - EXPECT_EQ( |
365 |
| - toSourceCode(SM, FilenameRange.getAsRange()).drop_back().drop_front(), |
366 |
| - FileName); |
367 |
| - } |
368 |
| - size_t HashOffset; |
369 |
| - syntax::Token IncTok; |
370 |
| - llvm::StringRef IncDirective; |
371 |
| - size_t FileNameOffset; |
372 |
| - llvm::StringRef FileName; |
373 |
| - bool IsAngled; |
374 |
| - }; |
375 |
| - static std::vector<Inclusion> Includes; |
376 |
| - static std::vector<syntax::Token> SkippedFiles; |
377 |
| - struct ReplayPreamblePPCallback : public PPCallbacks { |
378 |
| - const SourceManager &SM; |
379 |
| - explicit ReplayPreamblePPCallback(const SourceManager &SM) : SM(SM) {} |
380 |
| - |
381 |
| - void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, |
382 |
| - StringRef FileName, bool IsAngled, |
383 |
| - CharSourceRange FilenameRange, OptionalFileEntryRef, |
384 |
| - StringRef, StringRef, const clang::Module *, |
385 |
| - SrcMgr::CharacteristicKind) override { |
386 |
| - Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled, |
387 |
| - FilenameRange); |
388 |
| - } |
389 |
| - |
390 |
| - void FileSkipped(const FileEntryRef &, const Token &FilenameTok, |
391 |
| - SrcMgr::CharacteristicKind) override { |
392 |
| - SkippedFiles.emplace_back(FilenameTok); |
393 |
| - } |
394 |
| - }; |
395 |
| - struct ReplayPreambleCheck : public tidy::ClangTidyCheck { |
396 |
| - ReplayPreambleCheck(StringRef Name, tidy::ClangTidyContext *Context) |
397 |
| - : ClangTidyCheck(Name, Context) {} |
398 |
| - void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, |
399 |
| - Preprocessor *ModuleExpanderPP) override { |
400 |
| - PP->addPPCallbacks(::std::make_unique<ReplayPreamblePPCallback>(SM)); |
401 |
| - } |
402 |
| - }; |
403 |
| - struct ReplayPreambleModule : public tidy::ClangTidyModule { |
404 |
| - void |
405 |
| - addCheckFactories(tidy::ClangTidyCheckFactories &CheckFactories) override { |
406 |
| - CheckFactories.registerCheck<ReplayPreambleCheck>( |
407 |
| - "replay-preamble-check"); |
408 |
| - } |
409 |
| - }; |
410 |
| - |
411 |
| - static tidy::ClangTidyModuleRegistry::Add<ReplayPreambleModule> X( |
412 |
| - "replay-preamble-module", ""); |
413 |
| - TestTU TU; |
414 |
| - // This check records inclusion directives replayed by clangd. |
415 |
| - TU.ClangTidyProvider = addTidyChecks("replay-preamble-check"); |
416 |
| - llvm::Annotations Test(R"cpp( |
417 |
| - $hash^#$include[[import]] $filebegin^"$filerange[[bar.h]]" |
418 |
| - $hash^#$include[[include_next]] $filebegin^"$filerange[[baz.h]]" |
419 |
| - $hash^#$include[[include]] $filebegin^<$filerange[[a.h]]>)cpp"); |
420 |
| - llvm::StringRef Code = Test.code(); |
421 |
| - TU.Code = Code.str(); |
422 |
| - TU.AdditionalFiles["bar.h"] = ""; |
423 |
| - TU.AdditionalFiles["baz.h"] = ""; |
424 |
| - TU.AdditionalFiles["a.h"] = ""; |
425 |
| - // Since we are also testing #import directives, and they don't make much |
426 |
| - // sense in c++ (also they actually break on windows), just set language to |
427 |
| - // obj-c. |
428 |
| - TU.ExtraArgs = {"-isystem.", "-xobjective-c"}; |
429 |
| - |
430 |
| - const auto &AST = TU.build(); |
431 |
| - const auto &SM = AST.getSourceManager(); |
432 |
| - |
433 |
| - auto HashLocs = Test.points("hash"); |
434 |
| - ASSERT_EQ(HashLocs.size(), Includes.size()); |
435 |
| - auto IncludeRanges = Test.ranges("include"); |
436 |
| - ASSERT_EQ(IncludeRanges.size(), Includes.size()); |
437 |
| - auto FileBeginLocs = Test.points("filebegin"); |
438 |
| - ASSERT_EQ(FileBeginLocs.size(), Includes.size()); |
439 |
| - auto FileRanges = Test.ranges("filerange"); |
440 |
| - ASSERT_EQ(FileRanges.size(), Includes.size()); |
441 |
| - |
442 |
| - ASSERT_EQ(SkippedFiles.size(), Includes.size()); |
443 |
| - for (size_t I = 0; I < Includes.size(); ++I) { |
444 |
| - const auto &Inc = Includes[I]; |
445 |
| - |
446 |
| - EXPECT_EQ(Inc.HashOffset, HashLocs[I]); |
447 |
| - |
448 |
| - auto IncRange = IncludeRanges[I]; |
449 |
| - EXPECT_THAT(Inc.IncTok.range(SM), rangeIs(IncRange)); |
450 |
| - EXPECT_EQ(Inc.IncTok.kind(), tok::identifier); |
451 |
| - EXPECT_EQ(Inc.IncDirective, |
452 |
| - Code.substr(IncRange.Begin, IncRange.End - IncRange.Begin)); |
453 |
| - |
454 |
| - EXPECT_EQ(Inc.FileNameOffset, FileBeginLocs[I]); |
455 |
| - EXPECT_EQ(Inc.IsAngled, Code[FileBeginLocs[I]] == '<'); |
456 |
| - |
457 |
| - auto FileRange = FileRanges[I]; |
458 |
| - EXPECT_EQ(Inc.FileName, |
459 |
| - Code.substr(FileRange.Begin, FileRange.End - FileRange.Begin)); |
460 |
| - |
461 |
| - EXPECT_EQ(SM.getDecomposedLoc(SkippedFiles[I].location()).second, |
462 |
| - Inc.FileNameOffset); |
463 |
| - // This also contains quotes/angles so increment the range by one from both |
464 |
| - // sides. |
465 |
| - EXPECT_EQ( |
466 |
| - SkippedFiles[I].text(SM), |
467 |
| - Code.substr(FileRange.Begin - 1, FileRange.End - FileRange.Begin + 2)); |
468 |
| - EXPECT_EQ(SkippedFiles[I].kind(), tok::header_name); |
469 |
| - } |
470 |
| -} |
471 |
| - |
472 | 347 | TEST(ParsedASTTest, PatchesAdditionalIncludes) {
|
473 | 348 | llvm::StringLiteral ModifiedContents = R"cpp(
|
474 | 349 | #include "baz.h"
|
|
0 commit comments