Skip to content

Commit 98c0ca0

Browse files
committed
Adapt to clang 8
1 parent 35a35e0 commit 98c0ca0

File tree

6 files changed

+39
-47
lines changed

6 files changed

+39
-47
lines changed

ClangTidy.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,24 @@ getCheckOptions(const ClangTidyOptions &Options,
230230
/// \param StoreCheckProfile If provided, and EnableCheckProfile is true,
231231
/// the profile will not be output to stderr, but will instead be stored
232232
/// as a JSON file in the specified directory.
233-
void runClangTidy(clang::tidy::ClangTidyContext &Context,
234-
const tooling::CompilationDatabase &Compilations,
235-
ArrayRef<std::string> InputFiles,
236-
llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS,
237-
bool EnableCheckProfile = false,
238-
llvm::StringRef StoreCheckProfile = StringRef());
233+
std::vector<ClangTidyError>
234+
runClangTidy(clang::tidy::ClangTidyContext &Context,
235+
const tooling::CompilationDatabase &Compilations,
236+
ArrayRef<std::string> InputFiles,
237+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
238+
bool EnableCheckProfile = false,
239+
llvm::StringRef StoreCheckProfile = StringRef());
239240

240241
// FIXME: This interface will need to be significantly extended to be useful.
241242
// FIXME: Implement confidence levels for displaying/fixing errors.
242243
//
243244
/// \brief Displays the found \p Errors to the users. If \p Fix is true, \p
244245
/// Errors containing fixes are automatically applied and reformatted. If no
245246
/// clang-format configuration file is found, the given \P FormatStyle is used.
246-
void handleErrors(ClangTidyContext &Context, bool Fix,
247+
void handleErrors(llvm::ArrayRef<ClangTidyError> Errors,
248+
ClangTidyContext &Context, bool Fix,
247249
unsigned &WarningsAsErrorsCount,
248-
llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS);
250+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS);
249251

250252
/// \brief Serializes replacements into YAML and writes them to the specified
251253
/// output stream.

ClangTidyDiagnosticConsumer.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class ClangTidyContext {
102102
/// \brief Initializes \c ClangTidyContext instance.
103103
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
104104
bool AllowEnablingAnalyzerAlphaCheckers = false);
105+
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
106+
// FIXME: this is required initialization, and should be a constructor param.
107+
// Fix the context -> diag engine -> consumer -> context initialization cycle.
108+
void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine) {
109+
this->DiagEngine = DiagEngine;
110+
}
105111

106112
~ClangTidyContext();
107113

@@ -160,12 +166,6 @@ class ClangTidyContext {
160166
/// counters.
161167
const ClangTidyStats &getStats() const { return Stats; }
162168

163-
/// \brief Returns all collected errors.
164-
ArrayRef<ClangTidyError> getErrors() const { return Errors; }
165-
166-
/// \brief Clears collected errors.
167-
void clearErrors() { Errors.clear(); }
168-
169169
/// \brief Control profile collection in clang-tidy.
170170
void setEnableProfiling(bool Profile);
171171
bool getEnableProfiling() const { return Profile; }
@@ -192,18 +192,9 @@ class ClangTidyContext {
192192
}
193193

194194
private:
195-
// Calls setDiagnosticsEngine() and storeError().
195+
// Writes to Stats.
196196
friend class ClangTidyDiagnosticConsumer;
197-
friend class ClangTidyPluginAction;
198-
199-
/// \brief Sets the \c DiagnosticsEngine so that Diagnostics can be generated
200-
/// correctly.
201-
void setDiagnosticsEngine(DiagnosticsEngine *Engine);
202197

203-
/// \brief Store an \p Error.
204-
void storeError(const ClangTidyError &Error);
205-
206-
std::vector<ClangTidyError> Errors;
207198
DiagnosticsEngine *DiagEngine;
208199
std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
209200

@@ -243,27 +234,25 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
243234
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
244235
const Diagnostic &Info) override;
245236

246-
/// \brief Flushes the internal diagnostics buffer to the ClangTidyContext.
247-
void finish() override;
237+
// Retrieve the diagnostics that were captured.
238+
std::vector<ClangTidyError> take();
248239

249240
private:
250241
void finalizeLastError();
251-
252-
void removeIncompatibleErrors(SmallVectorImpl<ClangTidyError> &Errors) const;
242+
void removeIncompatibleErrors();
253243

254244
/// \brief Returns the \c HeaderFilter constructed for the options set in the
255245
/// context.
256246
llvm::Regex *getHeaderFilter();
257247

258248
/// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
259249
/// according to the diagnostic \p Location.
260-
void checkFilters(SourceLocation Location);
250+
void checkFilters(SourceLocation Location, const SourceManager& Sources);
261251
bool passesLineFilter(StringRef FileName, unsigned LineNumber) const;
262252

263253
ClangTidyContext &Context;
264254
bool RemoveIncompatibleErrors;
265-
std::unique_ptr<DiagnosticsEngine> Diags;
266-
SmallVector<ClangTidyError, 8> Errors;
255+
std::vector<ClangTidyError> Errors;
267256
std::unique_ptr<llvm::Regex> HeaderFilter;
268257
bool LastErrorRelatesToUserCode;
269258
bool LastErrorPassesLineFilter;

ClangTidyOptions.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
1111
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
1212

13+
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1314
#include "llvm/ADT/Optional.h"
1415
#include "llvm/ADT/StringMap.h"
1516
#include "llvm/ADT/StringRef.h"
16-
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1717
#include "llvm/Support/ErrorOr.h"
18-
#include "clang/Basic/VirtualFileSystem.h"
18+
#include "llvm/Support/VirtualFileSystem.h"
1919
#include <functional>
2020
#include <map>
2121
#include <string>
@@ -218,10 +218,11 @@ class FileOptionsProvider : public DefaultOptionsProvider {
218218
///
219219
/// If any of the \param OverrideOptions fields are set, they will override
220220
/// whatever options are read from the configuration file.
221-
FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
222-
const ClangTidyOptions &DefaultOptions,
223-
const ClangTidyOptions &OverrideOptions,
224-
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
221+
FileOptionsProvider(
222+
const ClangTidyGlobalOptions &GlobalOptions,
223+
const ClangTidyOptions &DefaultOptions,
224+
const ClangTidyOptions &OverrideOptions,
225+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
225226

226227
/// \brief Initializes the \c FileOptionsProvider instance with a custom set
227228
/// of configuration file handlers.
@@ -255,7 +256,7 @@ class FileOptionsProvider : public DefaultOptionsProvider {
255256
llvm::StringMap<OptionsSource> CachedOptions;
256257
ClangTidyOptions OverrideOptions;
257258
ConfigFileHandlers ConfigHandlers;
258-
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS;
259+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
259260
};
260261

261262
/// \brief Parses LineFilter from JSON and stores it to the \p Options.

aliceO2/SizeofCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void SizeofCheck::check(const MatchFinder::MatchResult &Result) {
3131

3232
// is argument of sizeof a Type?
3333
if (Expr->isArgumentType()) {
34-
diag(Expr->getLocStart(), "consider using sizeof() on instance instead on direct type");
34+
diag(Expr->getBeginLoc(), "consider using sizeof() on instance instead on direct type");
3535
return;
3636
}
3737

@@ -41,7 +41,7 @@ void SizeofCheck::check(const MatchFinder::MatchResult &Result) {
4141
}
4242

4343
// no parens -> issue warning
44-
diag(Expr->getLocStart(), "consider using parens () for arguments to sizeof");
44+
diag(Expr->getBeginLoc(), "consider using parens () for arguments to sizeof");
4545
}
4646

4747
} // namespace aliceO2

reporting/VirtFuncLister.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void VirtFuncLister::check(const MatchFinder::MatchResult &Result) {
4747
auto enditer = MatchedDecl->end_overridden_methods();
4848

4949
if (iter == enditer) {
50-
SourceLocation loc = MatchedDecl->getLocStart();//getLocation();
50+
SourceLocation loc = MatchedDecl->getBeginLoc();//getLocation();
5151
loc.dump(SM);
5252
llvm::errs() << "VIRTUAL-START-DECLARATION \n";
5353
} else {
@@ -69,10 +69,10 @@ void VirtFuncLister::check(const MatchFinder::MatchResult &Result) {
6969
enditer = (*iter)->end_overridden_methods();
7070
iter = (*iter)->begin_overridden_methods();
7171
}
72-
SourceLocation loc = (*lastiter)->getLocStart();//getLocation();
72+
SourceLocation loc = (*lastiter)->getBeginLoc();//getLocation();
7373
loc.dump(SM);
7474
llvm::errs() << " OVERRIDEN-AT ";
75-
loc = MatchedDecl->getLocStart();//getLocation();
75+
loc = MatchedDecl->getBeginLoc();//getLocation();
7676
loc.dump(SM);
7777
llvm::errs() << "\n";
7878
}

tool/ClangTidyMain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ static int clangTidyMain(int argc, const char **argv) {
421421

422422
ClangTidyContext Context(std::move(OwningOptionsProvider),
423423
AllowEnablingAnalyzerAlphaCheckers);
424-
runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS,
425-
EnableCheckProfile, ProfilePrefix);
426-
ArrayRef<ClangTidyError> Errors = Context.getErrors();
424+
std::vector<ClangTidyError> Errors =
425+
runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS,
426+
EnableCheckProfile, ProfilePrefix);
427427
bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) {
428428
return E.DiagLevel == ClangTidyError::Error;
429429
}) != Errors.end();
@@ -433,7 +433,7 @@ static int clangTidyMain(int argc, const char **argv) {
433433
unsigned WErrorCount = 0;
434434

435435
// -fix-errors implies -fix.
436-
handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount,
436+
handleErrors(Errors, Context, (FixErrors || Fix) && !DisableFixes, WErrorCount,
437437
BaseFS);
438438

439439
if (!ExportFixes.empty() && !Errors.empty()) {

0 commit comments

Comments
 (0)