Skip to content

Commit

Permalink
Fix compilation with LLVM trunk
Browse files Browse the repository at this point in the history
Also silent falltrough warning
  • Loading branch information
ogoffart committed Jul 5, 2017
1 parent de96f77 commit a72fcff
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
6 changes: 4 additions & 2 deletions generator/annotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#include "stringbuilder.h"
#include "projectmanager.h"
#include "compat.h"

namespace
{
Expand Down Expand Up @@ -1091,14 +1092,14 @@ void Annotator::syntaxHighlight(Generator &generator, clang::FileID FID, clang::
// Chop off the u part of u8 prefix
++TokOffs;
--TokLen;
// FALL THROUGH to chop the 8
LLVM_FALLTHROUGH;
case tok::wide_string_literal:
case tok::utf16_string_literal:
case tok::utf32_string_literal:
// Chop off the L, u, U or 8 prefix
++TokOffs;
--TokLen;
// FALL THROUGH.
LLVM_FALLTHROUGH;
case tok::string_literal:
// FIXME: Exclude the optional ud-suffix from the highlighted range.
generator.addTag("q", {}, TokOffs, TokLen);
Expand All @@ -1109,6 +1110,7 @@ void Annotator::syntaxHighlight(Generator &generator, clang::FileID FID, clang::
case tok::utf32_char_constant:
++TokOffs;
--TokLen;
LLVM_FALLTHROUGH;
case tok::char_constant:
generator.addTag("kbd", {}, TokOffs, TokLen);
break;
Expand Down
4 changes: 4 additions & 0 deletions generator/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ template<typename T> struct MaybeUnique {
};
template<typename T> MaybeUnique<T> maybe_unique(T* val) { return {val}; }

#ifndef LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
#endif

13 changes: 11 additions & 2 deletions generator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct BrowserDiagnosticClient : clang::DiagnosticConsumer {
switch(DiagLevel) {
case clang::DiagnosticsEngine::Fatal:
std::cerr << "FATAL ";
LLVM_FALLTHROUGH;
case clang::DiagnosticsEngine::Error:
std::cerr << "Error: " << locationToString(Info.getLocation(), annotator.getSourceMgr())
<< ": " << diag.c_str() << std::endl;
Expand Down Expand Up @@ -304,8 +305,17 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
}

int main(int argc, const char **argv) {
std::string ErrorMessage;
std::unique_ptr<clang::tooling::CompilationDatabase> Compilations(
clang::tooling::FixedCompilationDatabase::loadFromCommandLine(argc, argv));
clang::tooling::FixedCompilationDatabase::loadFromCommandLine(argc, argv
#if CLANG_VERSION_MAJOR >= 5
, ErrorMessage
#endif
));
if (!ErrorMessage.empty()) {
std::cerr << ErrorMessage << std::endl;
ErrorMessage = {};
}

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

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


if (!Compilations && llvm::sys::fs::exists(BuildPath)) {
std::string ErrorMessage;
if (llvm::sys::fs::is_directory(BuildPath)) {
Compilations = std::unique_ptr<clang::tooling::CompilationDatabase>(
clang::tooling::CompilationDatabase::loadFromDirectory(BuildPath, ErrorMessage));
Expand Down
6 changes: 5 additions & 1 deletion generator/preprocessorcallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ void PreprocessorCallback::MacroDefined(const clang::Token& MacroNameTok, const
annotator.generator(FID).addTag("dfn", "class=\"macro\" id=\""% ref %"\" data-ref=\"" % ref % "\"", sm.getFileOffset(loc), MacroNameTok.getLength());
}

void PreprocessorCallback::MacroUndefined(const clang::Token& MacroNameTok, PreprocessorCallback::MyMacroDefinition MD)
void PreprocessorCallback::MacroUndefined(const clang::Token& MacroNameTok, PreprocessorCallback::MyMacroDefinition MD
#if CLANG_VERSION_MAJOR >= 5
, const clang::MacroDirective *
#endif
)
{
clang::SourceLocation loc = MacroNameTok.getLocation();
if (!loc.isValid() || !loc.isFileID())
Expand Down
6 changes: 5 additions & 1 deletion generator/preprocessorcallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class PreprocessorCallback : public clang::PPCallbacks {

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

void MacroUndefined(const clang::Token &MacroNameTok, MyMacroDefinition MD) override;
void MacroUndefined(const clang::Token &MacroNameTok, MyMacroDefinition MD
#if CLANG_VERSION_MAJOR >= 5
, const clang::MacroDirective *
#endif
) override;

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

0 comments on commit a72fcff

Please sign in to comment.