From: Eugene Zelenko Date: Fri, 10 Nov 2017 00:59:22 +0000 (+0000) Subject: [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b99e597a0a356b8375c925c82119d6f2cfe4576;p=clang [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317854 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTUnresolvedSet.h b/include/clang/AST/ASTUnresolvedSet.h index 9078a0e802..3693aeccfe 100644 --- a/include/clang/AST/ASTUnresolvedSet.h +++ b/include/clang/AST/ASTUnresolvedSet.h @@ -1,4 +1,4 @@ -//===-- ASTUnresolvedSet.h - Unresolved sets of declarations ---*- C++ -*-===// +//===- ASTUnresolvedSet.h - Unresolved sets of declarations -----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -16,14 +16,22 @@ #define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H #include "clang/AST/ASTVector.h" +#include "clang/AST/DeclAccessPair.h" #include "clang/AST/UnresolvedSet.h" +#include "clang/Basic/Specifiers.h" +#include +#include namespace clang { +class NamedDecl; + /// \brief An UnresolvedSet-like class which uses the ASTContext's allocator. class ASTUnresolvedSet { + friend class LazyASTUnresolvedSet; + struct DeclsTy : ASTVector { - DeclsTy() {} + DeclsTy() = default; DeclsTy(ASTContext &C, unsigned N) : ASTVector(C, N) {} bool isLazy() const { return getTag(); } @@ -32,14 +40,12 @@ class ASTUnresolvedSet { DeclsTy Decls; - friend class LazyASTUnresolvedSet; - public: - ASTUnresolvedSet() {} + ASTUnresolvedSet() = default; ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {} - typedef UnresolvedSetIterator iterator; - typedef UnresolvedSetIterator const_iterator; + using iterator = UnresolvedSetIterator; + using const_iterator = UnresolvedSetIterator; iterator begin() { return iterator(Decls.begin()); } iterator end() { return iterator(Decls.end()); } @@ -98,13 +104,14 @@ public: } void reserve(ASTContext &C, unsigned N) { Impl.reserve(C, N); } + void addLazyDecl(ASTContext &C, uintptr_t ID, AccessSpecifier AS) { assert(Impl.empty() || Impl.Decls.isLazy()); Impl.Decls.setLazy(true); - Impl.addDecl(C, reinterpret_cast(ID << 2), AS); + Impl.addDecl(C, reinterpret_cast(ID << 2), AS); } }; } // namespace clang -#endif +#endif // LLVM_CLANG_AST_ASTUNRESOLVEDSET_H diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h index 717a9e9dff..80cd6b7007 100644 --- a/include/clang/AST/ASTVector.h +++ b/include/clang/AST/ASTVector.h @@ -1,4 +1,4 @@ -//===- ASTVector.h - Vector that uses ASTContext for allocation --*- C++ -*-=// +//===- ASTVector.h - Vector that uses ASTContext for allocation ---*- C++ -*-=// // // The LLVM Compiler Infrastructure // @@ -18,22 +18,26 @@ #ifndef LLVM_CLANG_AST_ASTVECTOR_H #define LLVM_CLANG_AST_ASTVECTOR_H -#include "clang/AST/AttrIterator.h" #include "llvm/ADT/PointerIntPair.h" -#include "llvm/Support/type_traits.h" #include +#include #include #include +#include #include +#include +#include namespace clang { - class ASTContext; + +class ASTContext; template class ASTVector { private: - T *Begin, *End; - llvm::PointerIntPair Capacity; + T *Begin = nullptr; + T *End = nullptr; + llvm::PointerIntPair Capacity; void setEnd(T *P) { this->End = P; } @@ -45,7 +49,7 @@ protected: public: // Default ctor - Initialize to empty. - ASTVector() : Begin(nullptr), End(nullptr), Capacity(nullptr, false) {} + ASTVector() : Capacity(nullptr, false) {} ASTVector(ASTVector &&O) : Begin(O.Begin), End(O.End), Capacity(O.Capacity) { O.Begin = O.End = nullptr; @@ -53,14 +57,15 @@ public: O.Capacity.setInt(false); } - ASTVector(const ASTContext &C, unsigned N) - : Begin(nullptr), End(nullptr), Capacity(nullptr, false) { + ASTVector(const ASTContext &C, unsigned N) : Capacity(nullptr, false) { reserve(C, N); } ASTVector &operator=(ASTVector &&RHS) { ASTVector O(std::move(RHS)); + using std::swap; + swap(Begin, O.Begin); swap(End, O.End); swap(Capacity, O.Capacity); @@ -74,19 +79,19 @@ public: } } - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef T* iterator; - typedef const T* const_iterator; + using size_type = size_t; + using difference_type = ptrdiff_t; + using value_type = T; + using iterator = T *; + using const_iterator = const T *; - typedef std::reverse_iterator const_reverse_iterator; - typedef std::reverse_iterator reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + using reverse_iterator = std::reverse_iterator; - typedef T& reference; - typedef const T& const_reference; - typedef T* pointer; - typedef const T* const_pointer; + using reference = T &; + using const_reference = const T &; + using pointer = T *; + using const_pointer = const T *; // forward iterator creation methods. iterator begin() { return Begin; } @@ -175,7 +180,6 @@ public: size_t capacity() const { return this->capacity_ptr() - Begin; } /// append - Add the specified range to the end of the SmallVector. - /// template void append(const ASTContext &C, in_iter in_start, in_iter in_end) { size_type NumInputs = std::distance(in_start, in_end); @@ -195,7 +199,6 @@ public: } /// append - Add the specified range to the end of the SmallVector. - /// void append(const ASTContext &C, size_type NumInputs, const T &Elt) { // Grow allocated space if needed. if (NumInputs > size_type(this->capacity_ptr()-this->end())) @@ -368,6 +371,7 @@ protected: const_iterator capacity_ptr() const { return (iterator) Capacity.getPointer(); } + iterator capacity_ptr() { return (iterator)Capacity.getPointer(); } }; @@ -401,5 +405,6 @@ void ASTVector::grow(const ASTContext &C, size_t MinSize) { Capacity.setPointer(Begin+NewCapacity); } -} // end: clang namespace -#endif +} // namespace clang + +#endif // LLVM_CLANG_AST_ASTVECTOR_H diff --git a/include/clang/AST/AttrIterator.h b/include/clang/AST/AttrIterator.h index fb9b049e5d..56807b4590 100644 --- a/include/clang/AST/AttrIterator.h +++ b/include/clang/AST/AttrIterator.h @@ -1,4 +1,4 @@ -//===--- AttrIterator.h - Classes for attribute iteration -------*- C++ -*-===// +//===- AttrIterator.h - Classes for attribute iteration ---------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,16 +15,23 @@ #define LLVM_CLANG_AST_ATTRITERATOR_H #include "clang/Basic/LLVM.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Casting.h" +#include +#include #include namespace clang { - class ASTContext; - class Attr; -} + +class ASTContext; +class Attr; + +} // namespace clang // Defined in ASTContext.h void *operator new(size_t Bytes, const clang::ASTContext &C, size_t Alignment = 8); + // FIXME: Being forced to not have a default argument here due to redeclaration // rules on default arguments sucks void *operator new[](size_t Bytes, const clang::ASTContext &C, @@ -39,13 +46,13 @@ void operator delete[](void *Ptr, const clang::ASTContext &C, size_t); namespace clang { /// AttrVec - A vector of Attr, which is how they are stored on the AST. -typedef SmallVector AttrVec; +using AttrVec = SmallVector; /// specific_attr_iterator - Iterates over a subrange of an AttrVec, only /// providing attributes that are of a specific type. template class specific_attr_iterator { - typedef typename Container::const_iterator Iterator; + using Iterator = typename Container::const_iterator; /// Current - The current, underlying iterator. /// In order to ensure we don't dereference an invalid iterator unless @@ -67,14 +74,14 @@ class specific_attr_iterator { } public: - typedef SpecificAttr* value_type; - typedef SpecificAttr* reference; - typedef SpecificAttr* pointer; - typedef std::forward_iterator_tag iterator_category; - typedef std::ptrdiff_t difference_type; + using value_type = SpecificAttr *; + using reference = SpecificAttr *; + using pointer = SpecificAttr *; + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; - specific_attr_iterator() : Current() { } - explicit specific_attr_iterator(Iterator i) : Current(i) { } + specific_attr_iterator() = default; + explicit specific_attr_iterator(Iterator i) : Current(i) {} reference operator*() const { AdvanceToNext(); @@ -136,6 +143,6 @@ inline SpecificAttr *getSpecificAttr(const Container& container) { return nullptr; } -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_AST_ATTRITERATOR_H diff --git a/include/clang/AST/BaseSubobject.h b/include/clang/AST/BaseSubobject.h index 66af023c82..fdb7e718fe 100644 --- a/include/clang/AST/BaseSubobject.h +++ b/include/clang/AST/BaseSubobject.h @@ -1,4 +1,4 @@ -//===--- BaseSubobject.h - BaseSubobject class ----------------------------===// +//===- BaseSubobject.h - BaseSubobject class --------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,12 +15,15 @@ #define LLVM_CLANG_AST_BASESUBOBJECT_H #include "clang/AST/CharUnits.h" -#include "clang/AST/DeclCXX.h" -#include "llvm/ADT/DenseMap.h" -#include "llvm/Support/DataTypes.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/Support/type_traits.h" +#include +#include namespace clang { + +class CXXRecordDecl; + // BaseSubobject - Uniquely identifies a direct or indirect base class. // Stores both the base class decl and the offset from the most derived class to // the base class. Used for vtable and VTT generation. @@ -32,9 +35,9 @@ class BaseSubobject { CharUnits BaseOffset; public: - BaseSubobject() { } + BaseSubobject() = default; BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset) - : Base(Base), BaseOffset(BaseOffset) { } + : Base(Base), BaseOffset(BaseOffset) {} /// getBase - Returns the base class declaration. const CXXRecordDecl *getBase() const { return Base; } @@ -47,7 +50,7 @@ public: } }; -} // end namespace clang +} // namespace clang namespace llvm { @@ -65,7 +68,8 @@ template<> struct DenseMapInfo { } static unsigned getHashValue(const clang::BaseSubobject &Base) { - typedef std::pair PairTy; + using PairTy = std::pair; + return DenseMapInfo::getHashValue(PairTy(Base.getBase(), Base.getBaseOffset())); } @@ -81,6 +85,6 @@ template <> struct isPodLike { static const bool value = true; }; -} +} // namespace llvm -#endif +#endif // LLVM_CLANG_AST_BASESUBOBJECT_H diff --git a/include/clang/AST/CommentVisitor.h b/include/clang/AST/CommentVisitor.h index 21641bfeb8..d1cc2d0a4e 100644 --- a/include/clang/AST/CommentVisitor.h +++ b/include/clang/AST/CommentVisitor.h @@ -1,4 +1,4 @@ -//===--- CommentVisitor.h - Visitor for Comment subclasses ------*- C++ -*-===// +//===- CommentVisitor.h - Visitor for Comment subclasses --------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -16,8 +16,8 @@ namespace clang { namespace comments { -template struct make_ptr { typedef T *type; }; -template struct make_const_ptr { typedef const T *type; }; +template struct make_ptr { using type = T *; }; +template struct make_const_ptr { using type = const T *; }; template