diff --git a/clang/include/clang/Tooling/NodeIntrospection.h b/clang/include/clang/Tooling/NodeIntrospection.h --- a/clang/include/clang/Tooling/NodeIntrospection.h +++ b/clang/include/clang/Tooling/NodeIntrospection.h @@ -15,8 +15,7 @@ #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/DeclarationName.h" - -#include +#include "llvm/ADT/IntrusiveRefCntPtr.h" #include namespace clang { @@ -30,16 +29,19 @@ namespace tooling { -class LocationCall { +class LocationCall; +using SharedLocationCall = llvm::IntrusiveRefCntPtr; + +class LocationCall : public llvm::ThreadSafeRefCountedBase { public: enum LocationCallFlags { NoFlags, ReturnsPointer, IsCast }; - LocationCall(std::shared_ptr on, std::string name, + LocationCall(SharedLocationCall on, std::string name, LocationCallFlags flags = NoFlags) - : m_on(on), m_name(name), m_flags(flags) {} - LocationCall(std::shared_ptr on, std::string name, + : m_flags(flags), m_on(std::move(on)), m_name(name) {} + LocationCall(SharedLocationCall on, std::string name, std::vector const &args, LocationCallFlags flags = NoFlags) - : m_on(on), m_name(name), m_flags(flags) {} + : m_flags(flags), m_on(std::move(on)), m_name(name) {} LocationCall *on() const { return m_on.get(); } StringRef name() const { return m_name; } @@ -48,10 +50,10 @@ bool isCast() const { return m_flags & IsCast; } private: - std::shared_ptr m_on; + LocationCallFlags m_flags; + SharedLocationCall m_on; std::string m_name; std::vector m_args; - LocationCallFlags m_flags; }; class LocationCallFormatterCpp { @@ -61,20 +63,20 @@ namespace internal { struct RangeLessThan { - bool operator()( - std::pair> const &LHS, - std::pair> const &RHS) const; + bool operator()(std::pair const &LHS, + std::pair const &RHS) const; + bool + operator()(std::pair const &LHS, + std::pair const &RHS) const; }; + } // namespace internal -template >> -using UniqueMultiMap = std::set, Comp>; +template +using UniqueMultiMap = std::set, internal::RangeLessThan>; -using SourceLocationMap = - UniqueMultiMap>; -using SourceRangeMap = - UniqueMultiMap, - internal::RangeLessThan>; +using SourceLocationMap = UniqueMultiMap; +using SourceRangeMap = UniqueMultiMap; struct NodeLocationAccessors { SourceLocationMap LocationAccessors; diff --git a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py --- a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py +++ b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py @@ -33,7 +33,7 @@ def GenerateBaseGetLocationsDeclaration(self, CladeName): self.implementationContent += \ """ -void GetLocationsImpl(std::shared_ptr const& Prefix, +void GetLocationsImpl(SharedLocationCall const& Prefix, clang::{0} const *Object, SourceLocationMap &Locs, SourceRangeMap &Rngs); """.format(CladeName) @@ -42,7 +42,7 @@ self.implementationContent += \ """ -static void GetLocations{0}(std::shared_ptr const& Prefix, +static void GetLocations{0}(SharedLocationCall const& Prefix, clang::{0} const &Object, SourceLocationMap &Locs, SourceRangeMap &Rngs) {{ @@ -53,7 +53,7 @@ self.implementationContent += \ """ Locs.insert(LocationAndString(Object.{0}(), - std::make_shared(Prefix, "{0}"))); + llvm::makeIntrusiveRefCnt(Prefix, "{0}"))); """.format(locName) self.implementationContent += '\n' @@ -63,7 +63,7 @@ self.implementationContent += \ """ Rngs.insert(RangeAndString(Object.{0}(), - std::make_shared(Prefix, "{0}"))); + llvm::makeIntrusiveRefCnt(Prefix, "{0}"))); """.format(rngName) self.implementationContent += '\n' @@ -83,7 +83,7 @@ 'GetLocations(clang::{0} const *Object)'.format(CladeName) ImplSignature = \ """ -GetLocationsImpl(std::shared_ptr const& Prefix, +GetLocationsImpl(SharedLocationCall const& Prefix, clang::{0} const *Object, SourceLocationMap &Locs, SourceRangeMap &Rngs) """.format(CladeName) @@ -108,7 +108,7 @@ """ {0} NodeIntrospection::{1} {{ NodeLocationAccessors Result; - std::shared_ptr Prefix; + SharedLocationCall Prefix; GetLocationsImpl(Prefix, Object, Result.LocationAccessors, Result.RangeAccessors); diff --git a/clang/lib/Tooling/NodeIntrospection.cpp b/clang/lib/Tooling/NodeIntrospection.cpp --- a/clang/lib/Tooling/NodeIntrospection.cpp +++ b/clang/lib/Tooling/NodeIntrospection.cpp @@ -36,8 +36,8 @@ namespace internal { bool RangeLessThan::operator()( - std::pair> const &LHS, - std::pair> const &RHS) const { + std::pair const &LHS, + std::pair const &RHS) const { if (!LHS.first.isValid() || !RHS.first.isValid()) return false; @@ -53,6 +53,13 @@ return LHS.second->name() < RHS.second->name(); } +bool RangeLessThan::operator()( + std::pair const &LHS, + std::pair const &RHS) const { + if (LHS.first == RHS.first) + return LHS.second->name() < RHS.second->name(); + return LHS.first < RHS.first; +} } // namespace internal } // namespace tooling