diff --git a/clang/Makefile b/clang/Makefile index b438fe7..c7ac521 100644 --- a/clang/Makefile +++ b/clang/Makefile @@ -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) diff --git a/clang/find_clang.cr b/clang/find_clang.cr index a7a81a8..82a2796 100644 --- a/clang/find_clang.cr +++ b/clang/find_clang.cr @@ -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__) @@ -92,6 +92,7 @@ def shell_split(line) end when '"' # String marker in_string = !in_string + else end end @@ -127,6 +128,7 @@ while index < flags.size index += 1 when /^-L/ system_libs << flags[index][2..-1] + else end index += 1 diff --git a/clang/src/bindgen.cpp b/clang/src/bindgen.cpp index 33b2445..c75e57c 100644 --- a/clang/src/bindgen.cpp +++ b/clang/src/bindgen.cpp @@ -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 Options(clang::driver::createDriverOptTable()); +#endif // See bindgen_ast_consumer.cpp for more int main(int argc, const char **argv) { diff --git a/clang/src/bindgen_frontend_action.cpp b/clang/src/bindgen_frontend_action.cpp index e8e9139..4c34367 100644 --- a/clang/src/bindgen_frontend_action.cpp +++ b/clang/src/bindgen_frontend_action.cpp @@ -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(this->m_macros, preprocessor)); +#else preprocessor.addPPCallbacks(llvm::make_unique(this->m_macros, preprocessor)); +#endif return true; } std::unique_ptr BindgenFrontendAction::CreateASTConsumer(clang::CompilerInstance &ci, llvm::StringRef file) { +#if __clang_major__ >= 10 + return std::make_unique(this->m_macros, ci); +#else return llvm::make_unique(this->m_macros, ci); +#endif } diff --git a/clang/src/type_helper.cpp b/clang/src/type_helper.cpp index 2db9c10..9752e37 100644 --- a/clang/src/type_helper.cpp +++ b/clang/src/type_helper.cpp @@ -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(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(expr)) { return stringLiteralFromExpression(literal, bindExpr->getSubExpr()); } else if (const clang::CastExpr *castExpr = llvm::dyn_cast(expr)) {