[AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

llvm-svn: 318882
This commit is contained in:
Eugene Zelenko 2017-11-22 21:32:07 +00:00
parent 16e798873e
commit 2f8e66bbd8
2 changed files with 452 additions and 309 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===// //===- DeclObjC.cpp - ObjC Declaration AST Node Implementation ------------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -15,9 +15,27 @@
#include "clang/AST/ASTContext.h" #include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h" #include "clang/AST/ASTMutationListener.h"
#include "clang/AST/Attr.h" #include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Stmt.h" #include "clang/AST/Stmt.h"
#include "llvm/ADT/STLExtras.h" #include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <utility>
using namespace clang; using namespace clang;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -28,7 +46,6 @@ void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
List = nullptr; List = nullptr;
if (Elts == 0) return; // Setting to an empty list is a noop. if (Elts == 0) return; // Setting to an empty list is a noop.
List = new (Ctx) void*[Elts]; List = new (Ctx) void*[Elts];
NumElts = Elts; NumElts = Elts;
memcpy(List, InList, sizeof(void*)*Elts); memcpy(List, InList, sizeof(void*)*Elts);
@ -48,7 +65,7 @@ void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
// ObjCInterfaceDecl // ObjCInterfaceDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCContainerDecl::anchor() { } void ObjCContainerDecl::anchor() {}
/// getIvarDecl - This method looks up an ivar in this ContextDecl. /// getIvarDecl - This method looks up an ivar in this ContextDecl.
/// ///
@ -82,7 +99,6 @@ ObjCContainerDecl::getMethod(Selector Sel, bool isInstance,
// - (int) class_method; // - (int) class_method;
// + (float) class_method; // + (float) class_method;
// @end // @end
//
lookup_result R = lookup(Sel); lookup_result R = lookup(Sel);
for (lookup_iterator Meth = R.begin(), MethEnd = R.end(); for (lookup_iterator Meth = R.begin(), MethEnd = R.end();
Meth != MethEnd; ++Meth) { Meth != MethEnd; ++Meth) {
@ -280,7 +296,7 @@ ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
return nullptr; return nullptr;
} }
void ObjCInterfaceDecl::anchor() { } void ObjCInterfaceDecl::anchor() {}
ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const { ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const {
// If this particular declaration has a type parameter list, return it. // If this particular declaration has a type parameter list, return it.
@ -341,7 +357,6 @@ SourceLocation ObjCInterfaceDecl::getSuperClassLoc() const {
/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
/// with name 'PropertyId' in the primary class; including those in protocols /// with name 'PropertyId' in the primary class; including those in protocols
/// (direct or indirect) used by the primary class. /// (direct or indirect) used by the primary class.
///
ObjCPropertyDecl * ObjCPropertyDecl *
ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
IdentifierInfo *PropertyId, IdentifierInfo *PropertyId,
@ -409,8 +424,7 @@ const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const {
void ObjCInterfaceDecl::mergeClassExtensionProtocolList( void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
ObjCProtocolDecl *const* ExtList, unsigned ExtNum, ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
ASTContext &C) ASTContext &C) {
{
if (data().ExternallyCompleted) if (data().ExternallyCompleted)
LoadExternalDefinition(); LoadExternalDefinition();
@ -488,7 +502,7 @@ bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
return true; return true;
case DefinitionData::IDI_NotInherited: case DefinitionData::IDI_NotInherited:
return false; return false;
case DefinitionData::IDI_Unknown: { case DefinitionData::IDI_Unknown:
// If the class introduced initializers we conservatively assume that we // If the class introduced initializers we conservatively assume that we
// don't know if any of them is a designated initializer to avoid possible // don't know if any of them is a designated initializer to avoid possible
// misleading warnings. // misleading warnings.
@ -510,7 +524,6 @@ bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const {
return data().InheritedDesignatedInitializers == return data().InheritedDesignatedInitializers ==
DefinitionData::IDI_Inherited; DefinitionData::IDI_Inherited;
} }
}
llvm_unreachable("unexpected InheritedDesignatedInitializers value"); llvm_unreachable("unexpected InheritedDesignatedInitializers value");
} }
@ -902,7 +915,6 @@ ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
isInstanceMethod())) isInstanceMethod()))
return MD; return MD;
} else if (ObjCCategoryImplDecl *CImplD = } else if (ObjCCategoryImplDecl *CImplD =
dyn_cast<ObjCCategoryImplDecl>(CtxD)) { dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
@ -1312,7 +1324,8 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
if (!CheckOverrides) if (!CheckOverrides)
return nullptr; return nullptr;
typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy; using OverridesTy = SmallVector<const ObjCMethodDecl *, 8>;
OverridesTy Overrides; OverridesTy Overrides;
getOverriddenMethods(Overrides); getOverriddenMethods(Overrides);
for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end(); for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end();
@ -1328,7 +1341,7 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
// ObjCTypeParamDecl // ObjCTypeParamDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCTypeParamDecl::anchor() { } void ObjCTypeParamDecl::anchor() {}
ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc, ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc,
ObjCTypeParamVariance variance, ObjCTypeParamVariance variance,
@ -1373,14 +1386,12 @@ SourceRange ObjCTypeParamDecl::getSourceRange() const {
ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc, ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
ArrayRef<ObjCTypeParamDecl *> typeParams, ArrayRef<ObjCTypeParamDecl *> typeParams,
SourceLocation rAngleLoc) SourceLocation rAngleLoc)
: NumParams(typeParams.size()) : NumParams(typeParams.size()) {
{
Brackets.Begin = lAngleLoc.getRawEncoding(); Brackets.Begin = lAngleLoc.getRawEncoding();
Brackets.End = rAngleLoc.getRawEncoding(); Brackets.End = rAngleLoc.getRawEncoding();
std::copy(typeParams.begin(), typeParams.end(), begin()); std::copy(typeParams.begin(), typeParams.end(), begin());
} }
ObjCTypeParamList *ObjCTypeParamList::create( ObjCTypeParamList *ObjCTypeParamList::create(
ASTContext &ctx, ASTContext &ctx,
SourceLocation lAngleLoc, SourceLocation lAngleLoc,
@ -1438,8 +1449,7 @@ ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC,
ObjCInterfaceDecl *PrevDecl, ObjCInterfaceDecl *PrevDecl,
bool IsInternal) bool IsInternal)
: ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc), : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc),
redeclarable_base(C), TypeForDecl(nullptr), TypeParamList(nullptr), redeclarable_base(C) {
Data() {
setPreviousDecl(PrevDecl); setPreviousDecl(PrevDecl);
// Copy the 'data' pointer over. // Copy the 'data' pointer over.
@ -1518,19 +1528,22 @@ void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
} }
namespace { namespace {
struct SynthesizeIvarChunk {
uint64_t Size;
ObjCIvarDecl *Ivar;
SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
: Size(size), Ivar(ivar) {}
};
bool operator<(const SynthesizeIvarChunk & LHS, struct SynthesizeIvarChunk {
const SynthesizeIvarChunk &RHS) { uint64_t Size;
return LHS.Size < RHS.Size; ObjCIvarDecl *Ivar;
}
SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar)
: Size(size), Ivar(ivar) {}
};
bool operator<(const SynthesizeIvarChunk & LHS,
const SynthesizeIvarChunk &RHS) {
return LHS.Size < RHS.Size;
} }
} // namespace
/// all_declared_ivar_begin - return first ivar declared in this class, /// all_declared_ivar_begin - return first ivar declared in this class,
/// its extensions and its implementation. Lazily build the list on first /// its extensions and its implementation. Lazily build the list on first
/// access. /// access.
@ -1694,7 +1707,7 @@ bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
// ObjCIvarDecl // ObjCIvarDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCIvarDecl::anchor() { } void ObjCIvarDecl::anchor() {}
ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
SourceLocation StartLoc, SourceLocation StartLoc,
@ -1771,7 +1784,7 @@ QualType ObjCIvarDecl::getUsageType(QualType objectType) const {
// ObjCAtDefsFieldDecl // ObjCAtDefsFieldDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCAtDefsFieldDecl::anchor() { } void ObjCAtDefsFieldDecl::anchor() {}
ObjCAtDefsFieldDecl ObjCAtDefsFieldDecl
*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
@ -1791,14 +1804,14 @@ ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
// ObjCProtocolDecl // ObjCProtocolDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCProtocolDecl::anchor() { } void ObjCProtocolDecl::anchor() {}
ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC, ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC,
IdentifierInfo *Id, SourceLocation nameLoc, IdentifierInfo *Id, SourceLocation nameLoc,
SourceLocation atStartLoc, SourceLocation atStartLoc,
ObjCProtocolDecl *PrevDecl) ObjCProtocolDecl *PrevDecl)
: ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
redeclarable_base(C), Data() { redeclarable_base(C) {
setPreviousDecl(PrevDecl); setPreviousDecl(PrevDecl);
if (PrevDecl) if (PrevDecl)
Data = PrevDecl->Data; Data = PrevDecl->Data;
@ -1874,7 +1887,6 @@ void ObjCProtocolDecl::startDefinition() {
void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM, void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
PropertyDeclOrder &PO) const { PropertyDeclOrder &PO) const {
if (const ObjCProtocolDecl *PDecl = getDefinition()) { if (const ObjCProtocolDecl *PDecl = getDefinition()) {
for (auto *Prop : PDecl->properties()) { for (auto *Prop : PDecl->properties()) {
// Insert into PM if not there already. // Insert into PM if not there already.
@ -1921,7 +1933,7 @@ ObjCProtocolDecl::getObjCRuntimeNameAsString() const {
// ObjCCategoryDecl // ObjCCategoryDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCCategoryDecl::anchor() { } void ObjCCategoryDecl::anchor() {}
ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc, ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
SourceLocation ClassNameLoc, SourceLocation ClassNameLoc,
@ -1930,11 +1942,9 @@ ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
ObjCTypeParamList *typeParamList, ObjCTypeParamList *typeParamList,
SourceLocation IvarLBraceLoc, SourceLocation IvarLBraceLoc,
SourceLocation IvarRBraceLoc) SourceLocation IvarRBraceLoc)
: ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc), : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
ClassInterface(IDecl), TypeParamList(nullptr), ClassInterface(IDecl), CategoryNameLoc(CategoryNameLoc),
NextClassCategory(nullptr), CategoryNameLoc(CategoryNameLoc), IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc)
{
setTypeParamList(typeParamList); setTypeParamList(typeParamList);
} }
@ -1994,7 +2004,7 @@ void ObjCCategoryDecl::setTypeParamList(ObjCTypeParamList *TPL) {
// ObjCCategoryImplDecl // ObjCCategoryImplDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCCategoryImplDecl::anchor() { } void ObjCCategoryImplDecl::anchor() {}
ObjCCategoryImplDecl * ObjCCategoryImplDecl *
ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
@ -2023,8 +2033,7 @@ ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
return nullptr; return nullptr;
} }
void ObjCImplDecl::anchor() {}
void ObjCImplDecl::anchor() { }
void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
// FIXME: The context should be correct before we get here. // FIXME: The context should be correct before we get here.
@ -2052,7 +2061,6 @@ void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
/// properties implemented in this \@implementation block and returns /// properties implemented in this \@implementation block and returns
/// the implemented property that uses it. /// the implemented property that uses it.
///
ObjCPropertyImplDecl *ObjCImplDecl:: ObjCPropertyImplDecl *ObjCImplDecl::
FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
for (auto *PID : property_impls()) for (auto *PID : property_impls())
@ -2065,7 +2073,6 @@ FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
/// added to the list of those properties \@synthesized/\@dynamic in this /// added to the list of those properties \@synthesized/\@dynamic in this
/// category \@implementation block. /// category \@implementation block.
///
ObjCPropertyImplDecl *ObjCImplDecl:: ObjCPropertyImplDecl *ObjCImplDecl::
FindPropertyImplDecl(IdentifierInfo *Id, FindPropertyImplDecl(IdentifierInfo *Id,
ObjCPropertyQueryKind QueryKind) const { ObjCPropertyQueryKind QueryKind) const {
@ -2103,7 +2110,7 @@ raw_ostream &clang::operator<<(raw_ostream &OS,
// ObjCImplementationDecl // ObjCImplementationDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCImplementationDecl::anchor() { } void ObjCImplementationDecl::anchor() {}
ObjCImplementationDecl * ObjCImplementationDecl *
ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
@ -2155,7 +2162,7 @@ raw_ostream &clang::operator<<(raw_ostream &OS,
// ObjCCompatibleAliasDecl // ObjCCompatibleAliasDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCCompatibleAliasDecl::anchor() { } void ObjCCompatibleAliasDecl::anchor() {}
ObjCCompatibleAliasDecl * ObjCCompatibleAliasDecl *
ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
@ -2175,7 +2182,7 @@ ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
// ObjCPropertyDecl // ObjCPropertyDecl
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void ObjCPropertyDecl::anchor() { } void ObjCPropertyDecl::anchor() {}
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, SourceLocation L,