Skip to content

Commit a72fcff

Browse files
committed
Fix compilation with LLVM trunk
Also silent falltrough warning
1 parent de96f77 commit a72fcff

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

generator/annotator.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#include "stringbuilder.h"
5252
#include "projectmanager.h"
53+
#include "compat.h"
5354

5455
namespace
5556
{
@@ -1091,14 +1092,14 @@ void Annotator::syntaxHighlight(Generator &generator, clang::FileID FID, clang::
10911092
// Chop off the u part of u8 prefix
10921093
++TokOffs;
10931094
--TokLen;
1094-
// FALL THROUGH to chop the 8
1095+
LLVM_FALLTHROUGH;
10951096
case tok::wide_string_literal:
10961097
case tok::utf16_string_literal:
10971098
case tok::utf32_string_literal:
10981099
// Chop off the L, u, U or 8 prefix
10991100
++TokOffs;
11001101
--TokLen;
1101-
// FALL THROUGH.
1102+
LLVM_FALLTHROUGH;
11021103
case tok::string_literal:
11031104
// FIXME: Exclude the optional ud-suffix from the highlighted range.
11041105
generator.addTag("q", {}, TokOffs, TokLen);
@@ -1109,6 +1110,7 @@ void Annotator::syntaxHighlight(Generator &generator, clang::FileID FID, clang::
11091110
case tok::utf32_char_constant:
11101111
++TokOffs;
11111112
--TokLen;
1113+
LLVM_FALLTHROUGH;
11121114
case tok::char_constant:
11131115
generator.addTag("kbd", {}, TokOffs, TokLen);
11141116
break;

generator/compat.h

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ template<typename T> struct MaybeUnique {
3131
};
3232
template<typename T> MaybeUnique<T> maybe_unique(T* val) { return {val}; }
3333

34+
#ifndef LLVM_FALLTHROUGH
35+
#define LLVM_FALLTHROUGH
36+
#endif
37+

generator/main.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct BrowserDiagnosticClient : clang::DiagnosticConsumer {
127127
switch(DiagLevel) {
128128
case clang::DiagnosticsEngine::Fatal:
129129
std::cerr << "FATAL ";
130+
LLVM_FALLTHROUGH;
130131
case clang::DiagnosticsEngine::Error:
131132
std::cerr << "Error: " << locationToString(Info.getLocation(), annotator.getSourceMgr())
132133
<< ": " << diag.c_str() << std::endl;
@@ -304,8 +305,17 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
304305
}
305306

306307
int main(int argc, const char **argv) {
308+
std::string ErrorMessage;
307309
std::unique_ptr<clang::tooling::CompilationDatabase> Compilations(
308-
clang::tooling::FixedCompilationDatabase::loadFromCommandLine(argc, argv));
310+
clang::tooling::FixedCompilationDatabase::loadFromCommandLine(argc, argv
311+
#if CLANG_VERSION_MAJOR >= 5
312+
, ErrorMessage
313+
#endif
314+
));
315+
if (!ErrorMessage.empty()) {
316+
std::cerr << ErrorMessage << std::endl;
317+
ErrorMessage = {};
318+
}
309319

310320
llvm::cl::ParseCommandLineOptions(argc, argv);
311321

@@ -341,7 +351,6 @@ int main(int argc, const char **argv) {
341351

342352

343353
if (!Compilations && llvm::sys::fs::exists(BuildPath)) {
344-
std::string ErrorMessage;
345354
if (llvm::sys::fs::is_directory(BuildPath)) {
346355
Compilations = std::unique_ptr<clang::tooling::CompilationDatabase>(
347356
clang::tooling::CompilationDatabase::loadFromDirectory(BuildPath, ErrorMessage));

generator/preprocessorcallback.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ void PreprocessorCallback::MacroDefined(const clang::Token& MacroNameTok, const
188188
annotator.generator(FID).addTag("dfn", "class=\"macro\" id=\""% ref %"\" data-ref=\"" % ref % "\"", sm.getFileOffset(loc), MacroNameTok.getLength());
189189
}
190190

191-
void PreprocessorCallback::MacroUndefined(const clang::Token& MacroNameTok, PreprocessorCallback::MyMacroDefinition MD)
191+
void PreprocessorCallback::MacroUndefined(const clang::Token& MacroNameTok, PreprocessorCallback::MyMacroDefinition MD
192+
#if CLANG_VERSION_MAJOR >= 5
193+
, const clang::MacroDirective *
194+
#endif
195+
)
192196
{
193197
clang::SourceLocation loc = MacroNameTok.getLocation();
194198
if (!loc.isValid() || !loc.isFileID())

generator/preprocessorcallback.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ class PreprocessorCallback : public clang::PPCallbacks {
5454

5555
void MacroDefined(const clang::Token &MacroNameTok, const clang::MacroDirective *MD) override;
5656

57-
void MacroUndefined(const clang::Token &MacroNameTok, MyMacroDefinition MD) override;
57+
void MacroUndefined(const clang::Token &MacroNameTok, MyMacroDefinition MD
58+
#if CLANG_VERSION_MAJOR >= 5
59+
, const clang::MacroDirective *
60+
#endif
61+
) override;
5862

5963
bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl<char> &RecoveryPath) override;
6064
void InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok, llvm::StringRef FileName,

0 commit comments

Comments
 (0)