Copybara import of the project:

--
fd2e99fa87c34f2fb1a20052c030ad7a4139b4e1 by Christian Blichmann <mail@blichmann.eu>:

Support LLVM >= 7.0.1 in Clang based header generator

This change glosses over small API changes introduced since LLVM/Clang
7.0.1, which ships with Debian Stable "Buster". Ubuntu 18.04 LTS "Bionic"
also shipped this (and subsequently updated to version 9).

Hence, compiling the generator should now work on all reasonable Debian
based distributions.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/sandboxed-api/pull/44 from cblichmann:20200609-llvm-version-compat fd2e99fa87c34f2fb1a20052c030ad7a4139b4e1
PiperOrigin-RevId: 315637014
Change-Id: I6585041d8bebade15e44c057b1a69287bbc0e733
This commit is contained in:
Christian Blichmann 2020-06-09 23:30:55 -07:00 committed by Copybara-Service
parent 726cabe2f7
commit c0c9d1dbf9
3 changed files with 24 additions and 2 deletions

View File

@ -12,9 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Minimum supported: LLVM 9
# Minimum supported: LLVM 7.0.1
find_package(LLVM REQUIRED)
find_package(Clang REQUIRED)
if(LLVM_VERSION VERSION_LESS "7.0.1")
message(FATAL_ERROR "SAPI header generator needs LLVM 7.0.1 or newer")
endif()
add_library(sapi_generator
diagnostics.cc

View File

@ -18,6 +18,7 @@
#include <string>
#include "absl/container/flat_hash_set.h"
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
@ -111,9 +112,15 @@ class GeneratorFactory : public clang::tooling::FrontendActionFactory {
: options_(std::move(options)) {}
private:
#if LLVM_VERSION_MAJOR >= 10
std::unique_ptr<clang::FrontendAction> create() override {
return absl::make_unique<GeneratorAction>(&options_);
}
#else
clang::FrontendAction* create() override {
return new GeneratorAction(&options_);
}
#endif
GeneratorOptions options_;
};

View File

@ -17,6 +17,18 @@
#include "absl/strings/str_cat.h"
namespace sapi {
namespace {
bool IsFunctionReferenceType(clang::QualType qual) {
#if LLVM_VERSION_MAJOR >= 9
return qual->isFunctionReferenceType();
#else
const auto* ref = qual->getAs<clang::ReferenceType>();
return ref && ref->getPointeeType()->isFunctionType();
#endif
}
} // namespace
void GatherRelatedTypes(clang::QualType qual, QualTypeSet* types) {
if (const auto* typedef_type = qual->getAs<clang::TypedefType>()) {
@ -25,7 +37,7 @@ void GatherRelatedTypes(clang::QualType qual, QualTypeSet* types) {
return;
}
if (qual->isFunctionPointerType() || qual->isFunctionReferenceType() ||
if (qual->isFunctionPointerType() || IsFunctionReferenceType(qual) ||
qual->isMemberFunctionPointerType()) {
if (const auto* function_type = qual->getPointeeOrArrayElementType()
->getAs<clang::FunctionProtoType>()) {