};
/// A matcher that always returns true.
-///
-/// We only ever need one instance of this matcher, so we create a global one
-/// and reuse it to reduce the overhead of the matcher and increase the chance
-/// of cache hits.
class TrueMatcherImpl : public DynMatcherInterface {
public:
- TrueMatcherImpl() {
- Retain(); // Reference count will never become zero.
- }
+ TrueMatcherImpl() = default;
bool dynMatches(const DynTypedNode &, ASTMatchFinder *,
BoundNodesTreeBuilder *) const override {
} // namespace
-static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance;
-
bool ASTMatchFinder::isTraversalIgnoringImplicitNodes() const {
return getASTContext().getParentMapContext().getTraversalKind() ==
TK_IgnoreUnlessSpelledInSource;
}
DynTypedMatcher DynTypedMatcher::trueMatcher(ASTNodeKind NodeKind) {
- return DynTypedMatcher(NodeKind, NodeKind, &*TrueMatcherInstance);
+ // We only ever need one instance of TrueMatcherImpl, so we create a static
+ // instance and reuse it to reduce the overhead of the matcher and increase
+ // the chance of cache hits.
+ static const llvm::IntrusiveRefCntPtr<TrueMatcherImpl> Instance =
+ new TrueMatcherImpl();
+ return DynTypedMatcher(NodeKind, NodeKind, Instance);
}
bool DynTypedMatcher::canMatchNodesOfKind(ASTNodeKind Kind) const {
RefCountedBase(const RefCountedBase &) {}
RefCountedBase &operator=(const RefCountedBase &) = delete;
+#ifndef NDEBUG
+ ~RefCountedBase() {
+ assert(RefCount == 0 &&
+ "Destruction occured when there are still references to this.");
+ }
+#else
+ // Default the destructor in release builds, A trivial destructor may enable
+ // better codegen.
+ ~RefCountedBase() = default;
+#endif
+
+public:
void Retain() const { ++RefCount; }
void Release() const {
ThreadSafeRefCountedBase &
operator=(const ThreadSafeRefCountedBase &) = delete;
+#ifndef NDEBUG
+ ~ThreadSafeRefCountedBase() {
+ assert(RefCount == 0 &&
+ "Destruction occured when there are still references to this.");
+ }
+#else
+ // Default the destructor in release builds, A trivial destructor may enable
+ // better codegen.
+ ~ThreadSafeRefCountedBase() = default;
+#endif
+
public:
void Retain() const { RefCount.fetch_add(1, std::memory_order_relaxed); }