Skip to content

Commit

Permalink
Clang-10 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaWertun committed May 8, 2020
1 parent 9f51a21 commit 125f32c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion clang/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
IGNORE := $(shell crystal run find_clang.cr > Makefile.variables)
include Makefile.variables

STD_VER := c++11
CLANG_MAJOR := $(shell $(CLANG_BINARY) --version |awk '/clang version/{print $$3}' |cut -f1 -d.)
CLANG_GTE_10 := $(shell test $(CLANG_MAJOR) -ge 10 && echo yes)
ifeq ($(CLANG_GTE_10), yes)
STD_VER := c++14
endif

LIBS := $(CLANG_LIBS) -ldl -pthread -lz -lcurses -ltinfo -lpcre
DEFINES := -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
DBGFLAGS := -O0 -g -fno-inline-functions -fno-omit-frame-pointer
WARFLAGS := -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable
CXXFLAGS := $(DBGFLAGS) $(WARFLAGS) -fexceptions -fstack-protector-strong -std=c++11 $(DEFINES) -Iinclude $(CLANG_INCLUDES)
CXXFLAGS := $(DBGFLAGS) $(WARFLAGS) -fexceptions -fstack-protector-strong -std=$(STD_VER) $(DEFINES) -Iinclude $(CLANG_INCLUDES)

HEADERS := $(wildcard include/*.hpp)
SOURCES := $(wildcard src/*.cpp)
Expand Down
4 changes: 3 additions & 1 deletion clang/find_clang.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def find_clang_binary : String?
version:
min: "4.0.0"
command: "% --version"
regex: "clang version ([0-9.]+)"
regex: "clang version ([0-9.]+).*"
YAML

path_finder = Bindgen::FindPath.new(__DIR__)
Expand Down Expand Up @@ -92,6 +92,7 @@ def shell_split(line)
end
when '"' # String marker
in_string = !in_string
else
end
end

Expand Down Expand Up @@ -127,6 +128,7 @@ while index < flags.size
index += 1
when /^-L/
system_libs << flags[index][2..-1]
else
end

index += 1
Expand Down
4 changes: 4 additions & 0 deletions clang/src/bindgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include "bindgen_frontend_action.hpp"

static llvm::cl::OptionCategory BindgenCategory("bindgen options");
#if __clang_major__ >= 10
static const llvm::opt::OptTable& Options(clang::driver::getDriverOptTable());
#else
static std::unique_ptr<llvm::opt::OptTable> Options(clang::driver::createDriverOptTable());
#endif
// See bindgen_ast_consumer.cpp for more

int main(int argc, const char **argv) {
Expand Down
8 changes: 8 additions & 0 deletions clang/src/bindgen_frontend_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ bool BindgenFrontendAction::BeginSourceFileAction(clang::CompilerInstance &ci)
#endif
{
clang::Preprocessor &preprocessor = ci.getPreprocessor();
#if __clang_major__ >= 10
preprocessor.addPPCallbacks(std::make_unique<PreprocessorHandler>(this->m_macros, preprocessor));
#else
preprocessor.addPPCallbacks(llvm::make_unique<PreprocessorHandler>(this->m_macros, preprocessor));
#endif
return true;
}

std::unique_ptr<clang::ASTConsumer> BindgenFrontendAction::CreateASTConsumer(clang::CompilerInstance &ci, llvm::StringRef file) {
#if __clang_major__ >= 10
return std::make_unique<BindgenASTConsumer>(this->m_macros, ci);
#else
return llvm::make_unique<BindgenASTConsumer>(this->m_macros, ci);
#endif
}
4 changes: 4 additions & 0 deletions clang/src/type_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ static bool describesStringClass(const clang::CXXConstructorDecl *ctorDecl) {

static bool stringLiteralFromExpression(LiteralData &literal, const clang::Expr *expr) {
if (const clang::MaterializeTemporaryExpr *argExpr = llvm::dyn_cast<clang::MaterializeTemporaryExpr>(expr)) {
#if __clang_major__ >= 10
return stringLiteralFromExpression(literal, argExpr->getSubExpr());
#else
return stringLiteralFromExpression(literal, argExpr->GetTemporaryExpr());
#endif
} else if (const clang::CXXBindTemporaryExpr *bindExpr = llvm::dyn_cast<clang::CXXBindTemporaryExpr>(expr)) {
return stringLiteralFromExpression(literal, bindExpr->getSubExpr());
} else if (const clang::CastExpr *castExpr = llvm::dyn_cast<clang::CastExpr>(expr)) {
Expand Down

0 comments on commit 125f32c

Please sign in to comment.