Commit d9db6583 authored by Gert Wollny's avatar Gert Wollny
Browse files

New upstream version 0.1+git20180702

parent 83da4ccc
Loading
Loading
Loading
Loading
+64 −7
Original line number Diff line number Diff line
@@ -33,7 +33,11 @@ if(NOT CastXML_INSTALL_DATA_DIR)
  set(CastXML_INSTALL_DATA_DIR share/castxml)
endif()
if(NOT CastXML_INSTALL_DOC_DIR)
  if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    set(CastXML_INSTALL_DOC_DIR share/doc/castxml)
  else()
    set(CastXML_INSTALL_DOC_DIR doc/castxml)
  endif()
endif()
if(NOT CastXML_INSTALL_MAN_DIR)
  set(CastXML_INSTALL_MAN_DIR man)
@@ -55,12 +59,51 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${std_cxx11}")
endif()

macro(hint_clang_from_llvm)
  if(LLVM_DIR AND NOT Clang_DIR)
    if(LLVM_DIR MATCHES "share/llvm/cmake$")
      # LLVM/Clang 3.8 installs in <prefix>/share/{llvm,clang}/cmake
      get_filename_component(Clang_DIR "${LLVM_DIR}/../../clang/cmake" ABSOLUTE)
    else()
      # LLVM/Clang 3.9+ installs in <prefix>/lib/cmake/{llvm,clang}
      get_filename_component(Clang_DIR "${LLVM_DIR}/../clang" ABSOLUTE)
    endif()
  endif()
endmacro()

macro(hint_llvm_from_clang)
  if(Clang_DIR AND NOT LLVM_DIR)
    if(Clang_DIR MATCHES "share/clang/cmake$")
      # LLVM/Clang 3.8 installs in <prefix>/share/{llvm,clang}/cmake
      get_filename_component(LLVM_DIR "${Clang_DIR}/../../llvm/cmake" ABSOLUTE)
    else()
      # LLVM/Clang 3.9+ installs in <prefix>/lib/cmake/{llvm,clang}
      get_filename_component(LLVM_DIR "${Clang_DIR}/../llvm" ABSOLUTE)
    endif()
  endif()
endmacro()

# Build scripts may set either LLVM_DIR or Clang_DIR.
hint_llvm_from_clang()
hint_clang_from_llvm()

# Clang 3.8+ installs its own CMake package.  Try it first.
find_package(Clang QUIET)

# If Clang did not find LLVM for us, give our search below a hint.
hint_llvm_from_clang()

# Clang 3.9+ automatically searches for LLVM.  For older versions we
# may need to search for LLVM directly.  Either way we require LLVM.
if(NOT LLVM_FOUND)
  find_package(LLVM REQUIRED)
endif()

if(DEFINED LLVM_BUILD_BINARY_DIR)
  message(FATAL_ERROR
    "LLVM_DIR refers to a LLVM/Clang build directory:\n"
    "  ${LLVM_DIR}\n"
    "Clang_DIR or LLVM_DIR refers to a LLVM/Clang build directory:\n"
    "  Clang_DIR=${Clang_DIR}\n"
    "  LLVM_DIR=${LLVM_DIR}\n"
    "CastXML must be built against a LLVM/Clang install tree as "
    "specified in\n"
    "  ${CastXML_SOURCE_DIR}/README.rst")
@@ -68,7 +111,7 @@ endif()

set(found_clang 0)
set(tried_clang)
foreach(inc ${LLVM_INCLUDE_DIRS})
foreach(inc ${CLANG_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS})
  if(EXISTS "${inc}/clang/AST/ASTConsumer.h")
    set(found_clang 1)
    break()
@@ -78,14 +121,16 @@ foreach(inc ${LLVM_INCLUDE_DIRS})
endforeach()
if(NOT found_clang)
  message(FATAL_ERROR
    "LLVM_DIR refers to a LLVM installation:\n"
    "  ${LLVM_DIR}\n"
    "Clang_DIR or LLVM_DIR refers to a LLVM/Clang installation:\n"
    "  Clang_DIR=${Clang_DIR}\n"
    "  LLVM_DIR=${LLVM_DIR}\n"
    "that does not have `clang/` headers in any include directory:\n"
    "${tried_clang}"
    )
endif()

add_definitions(${LLVM_DEFINITIONS})
include_directories(${CLANG_INCLUDE_DIRS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
if(NOT DEFINED LLVM_VERSION_PATCH)
@@ -96,7 +141,19 @@ set(CLANG_RESOURCE_DIR "" CACHE PATH "Clang resource directory")
if(NOT CLANG_RESOURCE_DIR)
  set(v ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
  set(tried "")
  set(dirs "")
  foreach(d ${LLVM_LIBRARY_DIRS})
    # Clang resources are typically inside LLVM's library directory.
    list(APPEND dirs ${d})
    # Some distros use a layout of the form
    #     <prefix>/lib/llvm/<major-version>/lib
    #     <prefix>/lib/clang/<full-version>/include
    if("${d}" MATCHES "^(.*)/llvm/.*$")
      list(APPEND dirs "${CMAKE_MATCH_1}")
    endif()
  endforeach()
  # Look in each candidate directory for Clang resources.
  foreach(d ${dirs})
    if(IS_DIRECTORY "${d}/clang/${v}/include")
      set(CLANG_RESOURCE_DIR ${d}/clang/${v})
      break()
+7 −5
Original line number Diff line number Diff line
@@ -46,7 +46,9 @@ To build CastXML from source, first obtain the prerequisites:
* `LLVM/Clang`_ compiler SDK install tree built using the C++ compiler.
  This version of CastXML has been tested with LLVM/Clang

  - SVN revision ``280011``
  - SVN revision ``319768`` (trunk)
  - Release ``5.0``
  - Release ``4.0``
  - Release ``3.9``
  - Release ``3.8``
  - Release ``3.7``
@@ -58,10 +60,10 @@ Run CMake on the CastXML source tree to generate a build tree using
a C++ compiler compatible with that used to build the LLVM/Clang SDK.
CMake options include:

``LLVM_DIR``
  Location of the LLVM/Clang SDK.
  Set to ``<prefix>/share/llvm/cmake``, where ``<prefix>`` is the top
  of the LLVM/Clang SDK install tree.
``Clang_DIR``
  Location of the LLVM/Clang SDK.  Set to ``<prefix>/lib/cmake/clang``,
  where ``<prefix>`` is the top of the LLVM/Clang SDK install tree.
  Alternatively, ``LLVM_DIR`` may be set to ``<prefix>/lib/cmake/llvm``.

``SPHINX_EXECUTABLE``
  Location of the ``sphinx-build`` executable.
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@
#ifdef _MSC_VER
# pragma message(TO_DEFINE(_MSC_VER))
#endif
#ifdef _MSVC_LANG
# pragma message(TO_DEFINE(_MSVC_LANG))
#endif
#ifdef _MT
# pragma message(TO_DEFINE(_MT))
#endif
+64 −26
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.h"

#include <fstream>
@@ -472,9 +473,10 @@ class ASTVisitor : public ASTVisitorBase
  /** Output a function element using the name and flags given by
      the caller.  This encompasses functionality common to all the
      function declaration output methods.  */
  void OutputFunctionHelper(clang::FunctionDecl const* d, DumpNode const* dn,
                            const char* tag, std::string const& name,
                            unsigned int flags);
  void OutputFunctionHelper(
    clang::FunctionDecl const* d, DumpNode const* dn, const char* tag,
    unsigned int flags,
    llvm::Optional<std::string> const& name = llvm::Optional<std::string>());

  /** Output a function type element using the tag given by the caller.
      This encompasses functionality common to all the function type
@@ -512,6 +514,7 @@ class ASTVisitor : public ASTVisitorBase
  void OutputClassTemplateSpecializationDecl(
    clang::ClassTemplateSpecializationDecl const* d, DumpNode const* dn);
  void OutputTypedefDecl(clang::TypedefDecl const* d, DumpNode const* dn);
  void OutputTypeAliasDecl(clang::TypeAliasDecl const* d, DumpNode const* dn);
  void OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn);
  void OutputFieldDecl(clang::FieldDecl const* d, DumpNode const* dn);
  void OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn);
@@ -672,10 +675,6 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d,
      }
    }

    if (clang::dyn_cast<clang::TypeAliasDecl>(d)) {
      return DumpId();
    }

    if (clang::dyn_cast<clang::TypeAliasTemplateDecl>(d)) {
      return DumpId();
    }
@@ -732,6 +731,12 @@ ASTVisitor::DumpId ASTVisitor::AddTypeDumpNode(DumpType dt, bool complete,
      return this->AddTypeDumpNode(
        DumpType(t->getAs<clang::AttributedType>()->getEquivalentType(), c),
        complete, dq);
    case clang::Type::Auto: {
      clang::AutoType const* at = t->getAs<clang::AutoType>();
      if (at->isSugared()) {
        return this->AddTypeDumpNode(DumpType(at->desugar(), c), complete, dq);
      }
    } break;
    case clang::Type::Decayed:
      return this->AddTypeDumpNode(
        DumpType(t->getAs<clang::DecayedType>()->getDecayedType(), c),
@@ -1442,6 +1447,18 @@ void ASTVisitor::GetDeclAttributes(clang::Decl const* d,
  for (auto const* a : d->specific_attrs<clang::AnnotateAttr>()) {
    attrs.push_back("annotate(" + a->getAnnotation().str() + ")");
  }

  if (d->hasAttr<clang::DeprecatedAttr>()) {
    attrs.push_back("deprecated");
  }

  if (d->hasAttr<clang::DLLExportAttr>()) {
    attrs.push_back("dllexport");
  }

  if (d->hasAttr<clang::DLLImportAttr>()) {
    attrs.push_back("dllimport");
  }
}

void ASTVisitor::PrintThrowsAttribute(clang::FunctionProtoType const* fpt,
@@ -1508,13 +1525,13 @@ void ASTVisitor::PrintFloat128Type(DumpNode const* dn)

void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
                                      DumpNode const* dn, const char* tag,
                                      std::string const& name,
                                      unsigned int flags)
                                      unsigned int flags,
                                      llvm::Optional<std::string> const& name)
{
  this->OS << "  <" << tag;
  this->PrintIdAttribute(dn);
  if (!name.empty()) {
    this->PrintNameAttribute(name);
  if (name) {
    this->PrintNameAttribute(name.getValue());
  }
  if (flags & FH_Returns) {
    this->PrintReturnsAttribute(d->getReturnType(), dn->Complete);
@@ -1654,6 +1671,13 @@ void ASTVisitor::OutputFunctionArgument(clang::ParmVarDecl const* a,
    this->PrintNameAttribute(name);
  }
  this->PrintTypeAttribute(a->getType(), complete);

  if (a->getOriginalType() != a->getType()) {
    this->OS << " original_type=\"";
    this->PrintTypeIdRef(a->getOriginalType(), complete);
    this->OS << "\"";
  }

  this->PrintLocationAttribute(a);
  if (def) {
    this->OS << " default=\"";
@@ -1724,7 +1748,7 @@ void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,

  this->OS << "  <" << tag;
  this->PrintIdAttribute(dn);
  if (!d->isAnonymousStructOrUnion()) {
  if (!d->isAnonymousStructOrUnion() && !d->isLambda()) {
    std::string s;
    llvm::raw_string_ostream rso(s);
    d->getNameForDiagnostic(rso, this->PrintingPolicy, false);
@@ -1745,7 +1769,7 @@ void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,
    if (dx && dx->isAbstract()) {
      this->OS << " abstract=\"1\"";
    }
    if (dn->Complete && !d->isInvalidDecl()) {
    if (dn->Complete && !d->isInvalidDecl() && !d->isLambda()) {
      this->PrintMembersAttribute(d);
      doBases = dx && dx->getNumBases();
      if (doBases) {
@@ -1828,6 +1852,19 @@ void ASTVisitor::OutputTypedefDecl(clang::TypedefDecl const* d,
  this->OS << "/>\n";
}

void ASTVisitor::OutputTypeAliasDecl(clang::TypeAliasDecl const* d,
                                     DumpNode const* dn)
{
  this->OS << "  <Typedef";
  this->PrintIdAttribute(dn);
  this->PrintNameAttribute(d->getName().str());
  this->PrintTypeAttribute(d->getUnderlyingType(), dn->Complete);
  this->PrintContextAttribute(d);
  this->PrintLocationAttribute(d);
  this->PrintAttributesAttribute(d);
  this->OS << "/>\n";
}

void ASTVisitor::OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn)
{
  this->OS << "  <Enumeration";
@@ -1927,10 +1964,10 @@ void ASTVisitor::OutputFunctionDecl(clang::FunctionDecl const* d,
  }
  if (d->isOverloadedOperator()) {
    this->OutputFunctionHelper(
      d, dn, "OperatorFunction",
      clang::getOperatorSpelling(d->getOverloadedOperator()), flags);
      d, dn, "OperatorFunction", flags,
      std::string(clang::getOperatorSpelling(d->getOverloadedOperator())));
  } else if (clang::IdentifierInfo const* ii = d->getIdentifier()) {
    this->OutputFunctionHelper(d, dn, "Function", ii->getName().str(), flags);
    this->OutputFunctionHelper(d, dn, "Function", flags, ii->getName().str());
  } else {
    this->OutputUnimplementedDecl(d, dn);
  }
@@ -1960,10 +1997,10 @@ void ASTVisitor::OutputCXXMethodDecl(clang::CXXMethodDecl const* d,
  }
  if (d->isOverloadedOperator()) {
    this->OutputFunctionHelper(
      d, dn, "OperatorMethod",
      clang::getOperatorSpelling(d->getOverloadedOperator()), flags);
      d, dn, "OperatorMethod", flags,
      std::string(clang::getOperatorSpelling(d->getOverloadedOperator())));
  } else if (clang::IdentifierInfo const* ii = d->getIdentifier()) {
    this->OutputFunctionHelper(d, dn, "Method", ii->getName().str(), flags);
    this->OutputFunctionHelper(d, dn, "Method", flags, ii->getName().str());
  } else {
    this->OutputUnimplementedDecl(d, dn);
  }
@@ -1988,7 +2025,7 @@ void ASTVisitor::OutputCXXConversionDecl(clang::CXXConversionDecl const* d,
  if (d->isPure()) {
    flags |= FH_Pure;
  }
  this->OutputFunctionHelper(d, dn, "Converter", "", flags);
  this->OutputFunctionHelper(d, dn, "Converter", flags);
}

void ASTVisitor::OutputCXXConstructorDecl(clang::CXXConstructorDecl const* d,
@@ -2004,8 +2041,8 @@ void ASTVisitor::OutputCXXConstructorDecl(clang::CXXConstructorDecl const* d,
  if (d->isExplicit()) {
    flags |= FH_Explicit;
  }
  this->OutputFunctionHelper(d, dn, "Constructor", this->GetContextName(d),
                             flags);
  this->OutputFunctionHelper(d, dn, "Constructor", flags,
                             this->GetContextName(d));
}

void ASTVisitor::OutputCXXDestructorDecl(clang::CXXDestructorDecl const* d,
@@ -2024,8 +2061,8 @@ void ASTVisitor::OutputCXXDestructorDecl(clang::CXXDestructorDecl const* d,
  if (d->isPure()) {
    flags |= FH_Pure;
  }
  this->OutputFunctionHelper(d, dn, "Destructor", this->GetContextName(d),
                             flags);
  this->OutputFunctionHelper(d, dn, "Destructor", flags,
                             this->GetContextName(d));
}

void ASTVisitor::OutputBuiltinType(clang::BuiltinType const* t,
@@ -2097,6 +2134,7 @@ void ASTVisitor::OutputLValueReferenceType(clang::LValueReferenceType const* t,
  this->OS << "  <ReferenceType";
  this->PrintIdAttribute(dn);
  this->PrintTypeAttribute(t->getPointeeType(), false);
  this->PrintABIAttributes(this->CTX.getTypeInfo(t));
  this->OS << "/>\n";
}

@@ -2161,14 +2199,14 @@ void ASTVisitor::OutputStartXMLTags()
    // Start dump with castxml-compatible format.
    /* clang-format off */
    this->OS <<
      "<CastXML format=\"" << Opts.CastXmlEpicFormatVersion << ".1.0\">\n"
      "<CastXML format=\"" << Opts.CastXmlEpicFormatVersion << ".1.5\">\n"
      ;
    /* clang-format on */
  } else if (this->Opts.GccXml) {
    // Start dump with gccxml-compatible format (legacy).
    /* clang-format off */
    this->OS <<
      "<GCC_XML version=\"0.9.0\" cvs_revision=\"1.140\">\n"
      "<GCC_XML version=\"0.9.0\" cvs_revision=\"1.145\">\n"
      ;
    /* clang-format on */
  }
+52 −4
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ public:
            (m->isCopyAssignmentOperator() || m->isMoveAssignmentOperator());
        }
        if (mark) {
          clang::DiagnosticErrorTrap Trap(sema.getDiagnostics());
          /* Ensure the member is defined.  */
          sema.MarkFunctionReferenced(clang::SourceLocation(), m);
          if (c && c->isDefaulted() && c->isDefaultConstructor() &&
@@ -132,6 +133,9 @@ public:
               until they are used.  Force semantic checking.  */
            sema.DefineImplicitDefaultConstructor(clang::SourceLocation(), c);
          }
          if (Trap.hasErrorOccurred()) {
            m->setInvalidDecl();
          }
          /* Finish implicitly instantiated member.  */
          sema.PerformPendingInstantiations();
        }
@@ -312,6 +316,17 @@ protected:
      }
#endif

#if LLVM_VERSION_MAJOR < 6
      if (this->NeedHasUniqueObjectRepresentations(this->Opts.Predefines,
                                                   CI)) {
        // Clang 6 and above provide a __has_unique_object_representations
        // builtin needed in C++17 mode.  Provide an approximation for older
        // Clang versions.
        builtins += "\n"
                    "#define __has_unique_object_representations(x) false\n";
      }
#endif

      // Prevent glibc use of a GNU extension not implemented by Clang.
      if (this->NeedNoMathInlines(this->Opts.Predefines)) {
        builtins += "\n"
@@ -356,6 +371,14 @@ protected:
#endif
  }

#if LLVM_VERSION_MAJOR < 6
  bool NeedHasUniqueObjectRepresentations(
    std::string const& pd, clang::CompilerInstance const& CI) const
  {
    return (this->IsActualGNU(pd) && CI.getLangOpts().CPlusPlus1z);
  }
#endif

  bool NeedNoMathInlines(std::string const& pd) const
  {
    return (this->IsActualGNU(pd) &&
@@ -364,8 +387,12 @@ protected:
             pd.find("#define __NO_MATH_INLINES ") == pd.npos));
  }

  bool BeginSourceFileAction(clang::CompilerInstance& CI,
                             llvm::StringRef /*Filename*/)
  bool BeginSourceFileAction(clang::CompilerInstance& CI
#if LLVM_VERSION_MAJOR < 5
                             ,
                             llvm::StringRef /*Filename*/
#endif
                             ) override
  {
    CI.getPreprocessor().setPredefines(this->UpdatePredefines(CI));

@@ -641,7 +668,22 @@ int runClang(const char* const* argBeg, const char* const* argEnd,
              msc_ver = 1600;
            }
            if (msc_ver >= 1900) {
              long msvc_lang = 0;
              if (const char* l = strstr(pd.c_str(), "#define _MSVC_LANG ")) {
                l += 19;
                if (const char* le = strchr(l, '\n')) {
                  if (*(le - 1) == '\r') {
                    --le;
                  }
                  std::string const msvc_lang_str(l, le - l);
                  msvc_lang = std::strtol(msvc_lang_str.c_str(), nullptr, 10);
                }
              }
              if (msvc_lang >= 201703L) {
                args.push_back("-std=c++17");
              } else {
                args.push_back("-std=c++14");
              }
            } else if (msc_ver >= 1600) {
              args.push_back("-std=c++11");
            } else {
@@ -678,7 +720,13 @@ int runClang(const char* const* argBeg, const char* const* argEnd,
            std_date = 0;
          }
          std_flag += "++";
          if (std_date >= 201406L) {
          if (std_date >= 201703L) {
#if LLVM_VERSION_MAJOR >= 5
            std_flag += "17";
#else
            std_flag += "1z";
#endif
          } else if (std_date >= 201406L) {
            std_flag += "1z";
          } else if (std_date >= 201402L) {
            std_flag += "14";
Loading