forked from OSchip/llvm-project
Allow getting all source locations of selector identifiers in a ObjCMethodDecl.
Instead of always storing all source locations for the selector identifiers we check whether all the identifiers are in a "standard" position; "standard" position is -Immediately before the arguments: -(id)first:(int)x second:(int)y; -With a space between the arguments: -(id)first: (int)x second: (int)y; -For nullary selectors, immediately before ';': -(void)release; In such cases we infer the locations instead of storing them. llvm-svn: 140989
This commit is contained in:
parent
b98e3714f2
commit
b8c3aaf479
|
@ -15,6 +15,7 @@
|
||||||
#define LLVM_CLANG_AST_DECLOBJC_H
|
#define LLVM_CLANG_AST_DECLOBJC_H
|
||||||
|
|
||||||
#include "clang/AST/Decl.h"
|
#include "clang/AST/Decl.h"
|
||||||
|
#include "clang/AST/SelectorLocationsKind.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
@ -137,6 +138,10 @@ private:
|
||||||
|
|
||||||
/// \brief Indicates whether this method has a related result type.
|
/// \brief Indicates whether this method has a related result type.
|
||||||
unsigned RelatedResultType : 1;
|
unsigned RelatedResultType : 1;
|
||||||
|
|
||||||
|
/// \brief Whether the locations of the selector identifiers are in a
|
||||||
|
/// "standard" position, a enum SelectorLocationsKind.
|
||||||
|
unsigned SelLocsKind : 2;
|
||||||
|
|
||||||
// Result type of this method.
|
// Result type of this method.
|
||||||
QualType MethodDeclType;
|
QualType MethodDeclType;
|
||||||
|
@ -144,9 +149,10 @@ private:
|
||||||
// Type source information for the result type.
|
// Type source information for the result type.
|
||||||
TypeSourceInfo *ResultTInfo;
|
TypeSourceInfo *ResultTInfo;
|
||||||
|
|
||||||
/// ParamInfo - List of pointers to VarDecls for the formal parameters of this
|
/// \brief Array of ParmVarDecls for the formal parameters of this method
|
||||||
/// Method.
|
/// and optionally followed by selector locations.
|
||||||
ObjCList<ParmVarDecl> ParamInfo;
|
void *ParamsAndSelLocs;
|
||||||
|
unsigned NumParams;
|
||||||
|
|
||||||
/// List of attributes for this method declaration.
|
/// List of attributes for this method declaration.
|
||||||
SourceLocation EndLoc; // the location of the ';' or '}'.
|
SourceLocation EndLoc; // the location of the ';' or '}'.
|
||||||
|
@ -162,6 +168,43 @@ private:
|
||||||
/// constructed by createImplicitParams.
|
/// constructed by createImplicitParams.
|
||||||
ImplicitParamDecl *CmdDecl;
|
ImplicitParamDecl *CmdDecl;
|
||||||
|
|
||||||
|
SelectorLocationsKind getSelLocsKind() const {
|
||||||
|
return (SelectorLocationsKind)SelLocsKind;
|
||||||
|
}
|
||||||
|
bool hasStandardSelLocs() const {
|
||||||
|
return getSelLocsKind() != SelLoc_NonStandard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Get a pointer to the stored selector identifiers locations array.
|
||||||
|
/// No locations will be stored if HasStandardSelLocs is true.
|
||||||
|
SourceLocation *getStoredSelLocs() {
|
||||||
|
return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
|
||||||
|
}
|
||||||
|
const SourceLocation *getStoredSelLocs() const {
|
||||||
|
return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Get a pointer to the stored selector identifiers locations array.
|
||||||
|
/// No locations will be stored if HasStandardSelLocs is true.
|
||||||
|
ParmVarDecl **getParams() {
|
||||||
|
return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
|
||||||
|
}
|
||||||
|
const ParmVarDecl *const *getParams() const {
|
||||||
|
return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Get the number of stored selector identifiers locations.
|
||||||
|
/// No locations will be stored if HasStandardSelLocs is true.
|
||||||
|
unsigned getNumStoredSelLocs() const {
|
||||||
|
if (hasStandardSelLocs())
|
||||||
|
return 0;
|
||||||
|
return getNumSelectorLocs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setParamsAndSelLocs(ASTContext &C,
|
||||||
|
ArrayRef<ParmVarDecl*> Params,
|
||||||
|
ArrayRef<SourceLocation> SelLocs);
|
||||||
|
|
||||||
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
|
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
|
||||||
Selector SelInfo, QualType T,
|
Selector SelInfo, QualType T,
|
||||||
TypeSourceInfo *ResultTInfo,
|
TypeSourceInfo *ResultTInfo,
|
||||||
|
@ -180,7 +223,9 @@ private:
|
||||||
IsDefined(isDefined),
|
IsDefined(isDefined),
|
||||||
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
|
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
|
||||||
RelatedResultType(HasRelatedResultType),
|
RelatedResultType(HasRelatedResultType),
|
||||||
|
SelLocsKind(SelLoc_StandardNoSpace),
|
||||||
MethodDeclType(T), ResultTInfo(ResultTInfo),
|
MethodDeclType(T), ResultTInfo(ResultTInfo),
|
||||||
|
ParamsAndSelLocs(0), NumParams(0),
|
||||||
EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
|
EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
|
||||||
setImplicit(isImplicitlyDeclared);
|
setImplicit(isImplicitlyDeclared);
|
||||||
}
|
}
|
||||||
|
@ -194,7 +239,6 @@ public:
|
||||||
static ObjCMethodDecl *Create(ASTContext &C,
|
static ObjCMethodDecl *Create(ASTContext &C,
|
||||||
SourceLocation beginLoc,
|
SourceLocation beginLoc,
|
||||||
SourceLocation endLoc,
|
SourceLocation endLoc,
|
||||||
ArrayRef<SourceLocation> SelLocs,
|
|
||||||
Selector SelInfo,
|
Selector SelInfo,
|
||||||
QualType T,
|
QualType T,
|
||||||
TypeSourceInfo *ResultTInfo,
|
TypeSourceInfo *ResultTInfo,
|
||||||
|
@ -232,6 +276,29 @@ public:
|
||||||
return SourceRange(getLocation(), EndLoc);
|
return SourceRange(getLocation(), EndLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SourceLocation getSelectorStartLoc() const { return getSelectorLoc(0); }
|
||||||
|
SourceLocation getSelectorLoc(unsigned Index) const {
|
||||||
|
assert(Index < getNumSelectorLocs() && "Index out of range!");
|
||||||
|
if (hasStandardSelLocs())
|
||||||
|
return getStandardSelectorLoc(Index, getSelector(),
|
||||||
|
getSelLocsKind() == SelLoc_StandardWithSpace,
|
||||||
|
llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
|
||||||
|
NumParams),
|
||||||
|
EndLoc);
|
||||||
|
return getStoredSelLocs()[Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
|
||||||
|
|
||||||
|
unsigned getNumSelectorLocs() const {
|
||||||
|
if (isImplicit())
|
||||||
|
return 0;
|
||||||
|
Selector Sel = getSelector();
|
||||||
|
if (Sel.isUnarySelector())
|
||||||
|
return 1;
|
||||||
|
return Sel.getNumArgs();
|
||||||
|
}
|
||||||
|
|
||||||
ObjCInterfaceDecl *getClassInterface();
|
ObjCInterfaceDecl *getClassInterface();
|
||||||
const ObjCInterfaceDecl *getClassInterface() const {
|
const ObjCInterfaceDecl *getClassInterface() const {
|
||||||
return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
|
return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
|
||||||
|
@ -252,23 +319,27 @@ public:
|
||||||
void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
|
void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
|
||||||
|
|
||||||
// Iterator access to formal parameters.
|
// Iterator access to formal parameters.
|
||||||
unsigned param_size() const { return ParamInfo.size(); }
|
unsigned param_size() const { return NumParams; }
|
||||||
typedef ObjCList<ParmVarDecl>::iterator param_iterator;
|
typedef const ParmVarDecl *const *param_const_iterator;
|
||||||
param_iterator param_begin() const { return ParamInfo.begin(); }
|
typedef ParmVarDecl *const *param_iterator;
|
||||||
param_iterator param_end() const { return ParamInfo.end(); }
|
param_const_iterator param_begin() const { return getParams(); }
|
||||||
|
param_const_iterator param_end() const { return getParams() + NumParams; }
|
||||||
|
param_iterator param_begin() { return getParams(); }
|
||||||
|
param_iterator param_end() { return getParams() + NumParams; }
|
||||||
// This method returns and of the parameters which are part of the selector
|
// This method returns and of the parameters which are part of the selector
|
||||||
// name mangling requirements.
|
// name mangling requirements.
|
||||||
param_iterator sel_param_end() const {
|
param_const_iterator sel_param_end() const {
|
||||||
return ParamInfo.begin() + getSelector().getNumArgs();
|
return param_begin() + getSelector().getNumArgs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num) {
|
void setMethodParams(ASTContext &C,
|
||||||
ParamInfo.set(List, Num, C);
|
ArrayRef<ParmVarDecl*> Params,
|
||||||
}
|
ArrayRef<SourceLocation> SelLocs);
|
||||||
|
|
||||||
// Iterator access to parameter types.
|
// Iterator access to parameter types.
|
||||||
typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
|
typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
|
||||||
typedef llvm::mapped_iterator<param_iterator, deref_fun> arg_type_iterator;
|
typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
|
||||||
|
arg_type_iterator;
|
||||||
|
|
||||||
arg_type_iterator arg_type_begin() const {
|
arg_type_iterator arg_type_begin() const {
|
||||||
return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
|
return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
|
||||||
|
@ -331,6 +402,9 @@ public:
|
||||||
static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
|
static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
|
||||||
return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
|
return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend class ASTDeclReader;
|
||||||
|
friend class ASTDeclWriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// ObjCContainerDecl - Represents a container for method declarations.
|
/// ObjCContainerDecl - Represents a container for method declarations.
|
||||||
|
|
|
@ -360,12 +360,12 @@ public:
|
||||||
QualType ArgType;
|
QualType ArgType;
|
||||||
if (isImplicitProperty()) {
|
if (isImplicitProperty()) {
|
||||||
const ObjCMethodDecl *Setter = getImplicitPropertySetter();
|
const ObjCMethodDecl *Setter = getImplicitPropertySetter();
|
||||||
ObjCMethodDecl::param_iterator P = Setter->param_begin();
|
ObjCMethodDecl::param_const_iterator P = Setter->param_begin();
|
||||||
ArgType = (*P)->getType();
|
ArgType = (*P)->getType();
|
||||||
} else {
|
} else {
|
||||||
if (ObjCPropertyDecl *PDecl = getExplicitProperty())
|
if (ObjCPropertyDecl *PDecl = getExplicitProperty())
|
||||||
if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) {
|
if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) {
|
||||||
ObjCMethodDecl::param_iterator P = Setter->param_begin();
|
ObjCMethodDecl::param_const_iterator P = Setter->param_begin();
|
||||||
ArgType = (*P)->getType();
|
ArgType = (*P)->getType();
|
||||||
}
|
}
|
||||||
if (ArgType.isNull())
|
if (ArgType.isNull())
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace clang {
|
||||||
class Selector;
|
class Selector;
|
||||||
class SourceLocation;
|
class SourceLocation;
|
||||||
class Expr;
|
class Expr;
|
||||||
|
class ParmVarDecl;
|
||||||
|
|
||||||
/// \brief Whether all locations of the selector identifiers are in a
|
/// \brief Whether all locations of the selector identifiers are in a
|
||||||
/// "standard" position.
|
/// "standard" position.
|
||||||
|
@ -59,6 +60,24 @@ SourceLocation getStandardSelectorLoc(unsigned Index,
|
||||||
ArrayRef<Expr *> Args,
|
ArrayRef<Expr *> Args,
|
||||||
SourceLocation EndLoc);
|
SourceLocation EndLoc);
|
||||||
|
|
||||||
|
/// \brief Returns true if all \arg SelLocs are in a "standard" location.
|
||||||
|
SelectorLocationsKind hasStandardSelectorLocs(Selector Sel,
|
||||||
|
ArrayRef<SourceLocation> SelLocs,
|
||||||
|
ArrayRef<ParmVarDecl *> Args,
|
||||||
|
SourceLocation EndLoc);
|
||||||
|
|
||||||
|
/// \brief Get the "standard" location of a selector identifier, e.g:
|
||||||
|
/// For nullary selectors, immediately before ']': "[foo release]"
|
||||||
|
///
|
||||||
|
/// \param WithArgSpace if true the standard location is with a space apart
|
||||||
|
/// before arguments: "-(id)first: (int)x second: (int)y;"
|
||||||
|
/// If false: "-(id)first:(int)x second:(int)y;"
|
||||||
|
SourceLocation getStandardSelectorLoc(unsigned Index,
|
||||||
|
Selector Sel,
|
||||||
|
bool WithArgSpace,
|
||||||
|
ArrayRef<ParmVarDecl *> Args,
|
||||||
|
SourceLocation EndLoc);
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3994,7 +3994,7 @@ bool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
|
||||||
// The first two arguments (self and _cmd) are pointers; account for
|
// The first two arguments (self and _cmd) are pointers; account for
|
||||||
// their size.
|
// their size.
|
||||||
CharUnits ParmOffset = 2 * PtrSize;
|
CharUnits ParmOffset = 2 * PtrSize;
|
||||||
for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
|
for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(),
|
||||||
E = Decl->sel_param_end(); PI != E; ++PI) {
|
E = Decl->sel_param_end(); PI != E; ++PI) {
|
||||||
QualType PType = (*PI)->getType();
|
QualType PType = (*PI)->getType();
|
||||||
CharUnits sz = getObjCEncodingTypeSize(PType);
|
CharUnits sz = getObjCEncodingTypeSize(PType);
|
||||||
|
@ -4011,9 +4011,9 @@ bool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
|
||||||
|
|
||||||
// Argument types.
|
// Argument types.
|
||||||
ParmOffset = 2 * PtrSize;
|
ParmOffset = 2 * PtrSize;
|
||||||
for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
|
for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(),
|
||||||
E = Decl->sel_param_end(); PI != E; ++PI) {
|
E = Decl->sel_param_end(); PI != E; ++PI) {
|
||||||
ParmVarDecl *PVDecl = *PI;
|
const ParmVarDecl *PVDecl = *PI;
|
||||||
QualType PType = PVDecl->getOriginalType();
|
QualType PType = PVDecl->getOriginalType();
|
||||||
if (const ArrayType *AT =
|
if (const ArrayType *AT =
|
||||||
dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) {
|
dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) {
|
||||||
|
|
|
@ -2923,7 +2923,6 @@ Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
|
||||||
= ObjCMethodDecl::Create(Importer.getToContext(),
|
= ObjCMethodDecl::Create(Importer.getToContext(),
|
||||||
Loc,
|
Loc,
|
||||||
Importer.Import(D->getLocEnd()),
|
Importer.Import(D->getLocEnd()),
|
||||||
/*FIXME:*/ ArrayRef<SourceLocation>(),
|
|
||||||
Name.getObjCSelector(),
|
Name.getObjCSelector(),
|
||||||
ResultTy, ResultTInfo, DC,
|
ResultTy, ResultTInfo, DC,
|
||||||
D->isInstanceMethod(),
|
D->isInstanceMethod(),
|
||||||
|
@ -2955,8 +2954,9 @@ Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
|
||||||
ToParams[I]->setOwningFunction(ToMethod);
|
ToParams[I]->setOwningFunction(ToMethod);
|
||||||
ToMethod->addDecl(ToParams[I]);
|
ToMethod->addDecl(ToParams[I]);
|
||||||
}
|
}
|
||||||
ToMethod->setMethodParams(Importer.getToContext(),
|
SmallVector<SourceLocation, 12> SelLocs;
|
||||||
ToParams.data(), ToParams.size());
|
D->getSelectorLocs(SelLocs);
|
||||||
|
ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs);
|
||||||
|
|
||||||
ToMethod->setLexicalDeclContext(LexicalDC);
|
ToMethod->setLexicalDeclContext(LexicalDC);
|
||||||
Importer.Imported(D, ToMethod);
|
Importer.Imported(D, ToMethod);
|
||||||
|
|
|
@ -332,7 +332,6 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
|
||||||
ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
|
ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
|
||||||
SourceLocation beginLoc,
|
SourceLocation beginLoc,
|
||||||
SourceLocation endLoc,
|
SourceLocation endLoc,
|
||||||
ArrayRef<SourceLocation> SelLocs,
|
|
||||||
Selector SelInfo, QualType T,
|
Selector SelInfo, QualType T,
|
||||||
TypeSourceInfo *ResultTInfo,
|
TypeSourceInfo *ResultTInfo,
|
||||||
DeclContext *contextDecl,
|
DeclContext *contextDecl,
|
||||||
|
@ -352,6 +351,42 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
|
||||||
HasRelatedResultType);
|
HasRelatedResultType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
|
||||||
|
ArrayRef<ParmVarDecl*> Params,
|
||||||
|
ArrayRef<SourceLocation> SelLocs) {
|
||||||
|
ParamsAndSelLocs = 0;
|
||||||
|
NumParams = Params.size();
|
||||||
|
if (Params.empty() && SelLocs.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned Size = sizeof(ParmVarDecl *) * NumParams +
|
||||||
|
sizeof(SourceLocation) * SelLocs.size();
|
||||||
|
ParamsAndSelLocs = C.Allocate(Size);
|
||||||
|
std::copy(Params.begin(), Params.end(), getParams());
|
||||||
|
std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjCMethodDecl::getSelectorLocs(
|
||||||
|
SmallVectorImpl<SourceLocation> &SelLocs) const {
|
||||||
|
for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i)
|
||||||
|
SelLocs.push_back(getSelectorLoc(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjCMethodDecl::setMethodParams(ASTContext &C,
|
||||||
|
ArrayRef<ParmVarDecl*> Params,
|
||||||
|
ArrayRef<SourceLocation> SelLocs) {
|
||||||
|
assert((!SelLocs.empty() || isImplicit()) &&
|
||||||
|
"No selector locs for non-implicit method");
|
||||||
|
if (isImplicit())
|
||||||
|
return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
|
||||||
|
|
||||||
|
SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, EndLoc);
|
||||||
|
if (SelLocsKind != SelLoc_NonStandard)
|
||||||
|
return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
|
||||||
|
|
||||||
|
setParamsAndSelLocs(C, Params, SelLocs);
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief A definition will return its interface declaration.
|
/// \brief A definition will return its interface declaration.
|
||||||
/// An interface declaration will return its definition.
|
/// An interface declaration will return its definition.
|
||||||
/// Otherwise it will return itself.
|
/// Otherwise it will return itself.
|
||||||
|
|
|
@ -52,6 +52,12 @@ SourceLocation getArgLoc<Expr>(Expr *Arg) {
|
||||||
return Arg->getLocStart();
|
return Arg->getLocStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) {
|
||||||
|
// -1 to point to left paren of the method parameter's type.
|
||||||
|
return Arg->getLocStart().getLocWithOffset(-1);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
|
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
|
||||||
return Index < Args.size() ? getArgLoc(Args[Index]) : SourceLocation();
|
return Index < Args.size() ? getArgLoc(Args[Index]) : SourceLocation();
|
||||||
|
@ -100,3 +106,20 @@ SourceLocation clang::getStandardSelectorLoc(unsigned Index,
|
||||||
return getStandardSelLoc(Index, Sel, WithArgSpace,
|
return getStandardSelLoc(Index, Sel, WithArgSpace,
|
||||||
getArgLoc(Index, Args), EndLoc);
|
getArgLoc(Index, Args), EndLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectorLocationsKind
|
||||||
|
clang::hasStandardSelectorLocs(Selector Sel,
|
||||||
|
ArrayRef<SourceLocation> SelLocs,
|
||||||
|
ArrayRef<ParmVarDecl *> Args,
|
||||||
|
SourceLocation EndLoc) {
|
||||||
|
return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
|
||||||
|
Selector Sel,
|
||||||
|
bool WithArgSpace,
|
||||||
|
ArrayRef<ParmVarDecl *> Args,
|
||||||
|
SourceLocation EndLoc) {
|
||||||
|
return getStandardSelLoc(Index, Sel, WithArgSpace,
|
||||||
|
getArgLoc(Index, Args), EndLoc);
|
||||||
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) {
|
||||||
ArgTys.push_back(Context.getCanonicalParamType(MD->getSelfDecl()->getType()));
|
ArgTys.push_back(Context.getCanonicalParamType(MD->getSelfDecl()->getType()));
|
||||||
ArgTys.push_back(Context.getCanonicalParamType(Context.getObjCSelType()));
|
ArgTys.push_back(Context.getCanonicalParamType(Context.getObjCSelType()));
|
||||||
// FIXME: Kill copy?
|
// FIXME: Kill copy?
|
||||||
for (ObjCMethodDecl::param_iterator i = MD->param_begin(),
|
for (ObjCMethodDecl::param_const_iterator i = MD->param_begin(),
|
||||||
e = MD->param_end(); i != e; ++i) {
|
e = MD->param_end(); i != e; ++i) {
|
||||||
ArgTys.push_back(Context.getCanonicalParamType((*i)->getType()));
|
ArgTys.push_back(Context.getCanonicalParamType((*i)->getType()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1660,7 +1660,7 @@ llvm::DIType CGDebugInfo::getOrCreateFunctionType(const Decl * D, QualType FnTyp
|
||||||
// "cmd" pointer is always second argument.
|
// "cmd" pointer is always second argument.
|
||||||
Elts.push_back(getOrCreateType(OMethod->getCmdDecl()->getType(), F));
|
Elts.push_back(getOrCreateType(OMethod->getCmdDecl()->getType(), F));
|
||||||
// Get rest of the arguments.
|
// Get rest of the arguments.
|
||||||
for (ObjCMethodDecl::param_iterator PI = OMethod->param_begin(),
|
for (ObjCMethodDecl::param_const_iterator PI = OMethod->param_begin(),
|
||||||
PE = OMethod->param_end(); PI != PE; ++PI)
|
PE = OMethod->param_end(); PI != PE; ++PI)
|
||||||
Elts.push_back(getOrCreateType((*PI)->getType(), F));
|
Elts.push_back(getOrCreateType((*PI)->getType(), F));
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
|
||||||
args.push_back(OMD->getSelfDecl());
|
args.push_back(OMD->getSelfDecl());
|
||||||
args.push_back(OMD->getCmdDecl());
|
args.push_back(OMD->getCmdDecl());
|
||||||
|
|
||||||
for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
|
for (ObjCMethodDecl::param_const_iterator PI = OMD->param_begin(),
|
||||||
E = OMD->param_end(); PI != E; ++PI)
|
E = OMD->param_end(); PI != E; ++PI)
|
||||||
args.push_back(*PI);
|
args.push_back(*PI);
|
||||||
|
|
||||||
|
|
|
@ -2134,7 +2134,6 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) {
|
||||||
Selector cxxSelector = getContext().Selectors.getSelector(0, &II);
|
Selector cxxSelector = getContext().Selectors.getSelector(0, &II);
|
||||||
ObjCMethodDecl *DTORMethod =
|
ObjCMethodDecl *DTORMethod =
|
||||||
ObjCMethodDecl::Create(getContext(), D->getLocation(), D->getLocation(),
|
ObjCMethodDecl::Create(getContext(), D->getLocation(), D->getLocation(),
|
||||||
ArrayRef<SourceLocation>(),
|
|
||||||
cxxSelector, getContext().VoidTy, 0, D,
|
cxxSelector, getContext().VoidTy, 0, D,
|
||||||
/*isInstance=*/true, /*isVariadic=*/false,
|
/*isInstance=*/true, /*isVariadic=*/false,
|
||||||
/*isSynthesized=*/true, /*isImplicitlyDeclared=*/true,
|
/*isSynthesized=*/true, /*isImplicitlyDeclared=*/true,
|
||||||
|
@ -2155,7 +2154,6 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) {
|
||||||
ObjCMethodDecl *CTORMethod = ObjCMethodDecl::Create(getContext(),
|
ObjCMethodDecl *CTORMethod = ObjCMethodDecl::Create(getContext(),
|
||||||
D->getLocation(),
|
D->getLocation(),
|
||||||
D->getLocation(),
|
D->getLocation(),
|
||||||
ArrayRef<SourceLocation>(),
|
|
||||||
cxxSelector,
|
cxxSelector,
|
||||||
getContext().getObjCIdType(), 0,
|
getContext().getObjCIdType(), 0,
|
||||||
D, /*isInstance=*/true,
|
D, /*isInstance=*/true,
|
||||||
|
|
|
@ -2003,7 +2003,8 @@ void Sema::mergeObjCMethodDecls(ObjCMethodDecl *newMethod,
|
||||||
mergeDeclAttributes(newMethod, oldMethod, Context, mergeDeprecation);
|
mergeDeclAttributes(newMethod, oldMethod, Context, mergeDeprecation);
|
||||||
|
|
||||||
// Merge attributes from the parameters.
|
// Merge attributes from the parameters.
|
||||||
for (ObjCMethodDecl::param_iterator oi = oldMethod->param_begin(),
|
ObjCMethodDecl::param_const_iterator oi = oldMethod->param_begin();
|
||||||
|
for (ObjCMethodDecl::param_iterator
|
||||||
ni = newMethod->param_begin(), ne = newMethod->param_end();
|
ni = newMethod->param_begin(), ne = newMethod->param_end();
|
||||||
ni != ne; ++ni, ++oi)
|
ni != ne; ++ni, ++oi)
|
||||||
mergeParamDeclAttributes(*ni, *oi, Context);
|
mergeParamDeclAttributes(*ni, *oi, Context);
|
||||||
|
|
|
@ -171,10 +171,11 @@ void Sema::CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
|
||||||
Diag(Overridden->getLocation(), diag::note_previous_decl)
|
Diag(Overridden->getLocation(), diag::note_previous_decl)
|
||||||
<< "method";
|
<< "method";
|
||||||
}
|
}
|
||||||
for (ObjCMethodDecl::param_iterator oi = Overridden->param_begin(),
|
ObjCMethodDecl::param_const_iterator oi = Overridden->param_begin();
|
||||||
ni = NewMethod->param_begin(), ne = NewMethod->param_end();
|
for (ObjCMethodDecl::param_iterator
|
||||||
|
ni = NewMethod->param_begin(), ne = NewMethod->param_end();
|
||||||
ni != ne; ++ni, ++oi) {
|
ni != ne; ++ni, ++oi) {
|
||||||
ParmVarDecl *oldDecl = (*oi);
|
const ParmVarDecl *oldDecl = (*oi);
|
||||||
ParmVarDecl *newDecl = (*ni);
|
ParmVarDecl *newDecl = (*ni);
|
||||||
if (newDecl->hasAttr<NSConsumedAttr>() !=
|
if (newDecl->hasAttr<NSConsumedAttr>() !=
|
||||||
oldDecl->hasAttr<NSConsumedAttr>()) {
|
oldDecl->hasAttr<NSConsumedAttr>()) {
|
||||||
|
@ -1860,12 +1861,12 @@ bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *left,
|
||||||
!= right->hasAttr<NSConsumesSelfAttr>()))
|
!= right->hasAttr<NSConsumesSelfAttr>()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ObjCMethodDecl::param_iterator
|
ObjCMethodDecl::param_const_iterator
|
||||||
li = left->param_begin(), le = left->param_end(), ri = right->param_begin();
|
li = left->param_begin(), le = left->param_end(), ri = right->param_begin();
|
||||||
|
|
||||||
for (; li != le; ++li, ++ri) {
|
for (; li != le; ++li, ++ri) {
|
||||||
assert(ri != right->param_end() && "Param mismatch");
|
assert(ri != right->param_end() && "Param mismatch");
|
||||||
ParmVarDecl *lparm = *li, *rparm = *ri;
|
const ParmVarDecl *lparm = *li, *rparm = *ri;
|
||||||
|
|
||||||
if (!matchTypes(Context, strategy, lparm->getType(), rparm->getType()))
|
if (!matchTypes(Context, strategy, lparm->getType(), rparm->getType()))
|
||||||
return false;
|
return false;
|
||||||
|
@ -2527,7 +2528,7 @@ Decl *Sema::ActOnMethodDeclaration(
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjCMethodDecl* ObjCMethod =
|
ObjCMethodDecl* ObjCMethod =
|
||||||
ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, SelectorLocs, Sel,
|
ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel,
|
||||||
resultDeclType,
|
resultDeclType,
|
||||||
ResultTInfo,
|
ResultTInfo,
|
||||||
CurContext,
|
CurContext,
|
||||||
|
@ -2610,7 +2611,7 @@ Decl *Sema::ActOnMethodDeclaration(
|
||||||
Params.push_back(Param);
|
Params.push_back(Param);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjCMethod->setMethodParams(Context, Params.data(), Params.size());
|
ObjCMethod->setMethodParams(Context, Params, SelectorLocs);
|
||||||
ObjCMethod->setObjCDeclQualifier(
|
ObjCMethod->setObjCDeclQualifier(
|
||||||
CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
|
CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
|
||||||
|
|
||||||
|
|
|
@ -7412,7 +7412,7 @@ void Sema::ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS,
|
||||||
// setter, RHS expression is being passed to the setter argument. So,
|
// setter, RHS expression is being passed to the setter argument. So,
|
||||||
// type conversion (and comparison) is RHS to setter's argument type.
|
// type conversion (and comparison) is RHS to setter's argument type.
|
||||||
if (const ObjCMethodDecl *SetterMD = PropRef->getImplicitPropertySetter()) {
|
if (const ObjCMethodDecl *SetterMD = PropRef->getImplicitPropertySetter()) {
|
||||||
ObjCMethodDecl::param_iterator P = SetterMD->param_begin();
|
ObjCMethodDecl::param_const_iterator P = SetterMD->param_begin();
|
||||||
LHSTy = (*P)->getType();
|
LHSTy = (*P)->getType();
|
||||||
Consumed = (getLangOptions().ObjCAutoRefCount &&
|
Consumed = (getLangOptions().ObjCAutoRefCount &&
|
||||||
(*P)->hasAttr<NSConsumedAttr>());
|
(*P)->hasAttr<NSConsumedAttr>());
|
||||||
|
@ -7431,7 +7431,7 @@ void Sema::ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS,
|
||||||
const ObjCMethodDecl *setter
|
const ObjCMethodDecl *setter
|
||||||
= PropRef->getExplicitProperty()->getSetterMethodDecl();
|
= PropRef->getExplicitProperty()->getSetterMethodDecl();
|
||||||
if (setter) {
|
if (setter) {
|
||||||
ObjCMethodDecl::param_iterator P = setter->param_begin();
|
ObjCMethodDecl::param_const_iterator P = setter->param_begin();
|
||||||
LHSTy = (*P)->getType();
|
LHSTy = (*P)->getType();
|
||||||
Consumed = (*P)->hasAttr<NSConsumedAttr>();
|
Consumed = (*P)->hasAttr<NSConsumedAttr>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1518,7 +1518,6 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
|
||||||
property->getLocation();
|
property->getLocation();
|
||||||
|
|
||||||
GetterMethod = ObjCMethodDecl::Create(Context, Loc, Loc,
|
GetterMethod = ObjCMethodDecl::Create(Context, Loc, Loc,
|
||||||
ArrayRef<SourceLocation>(),
|
|
||||||
property->getGetterName(),
|
property->getGetterName(),
|
||||||
property->getType(), 0, CD, /*isInstance=*/true,
|
property->getType(), 0, CD, /*isInstance=*/true,
|
||||||
/*isVariadic=*/false, /*isSynthesized=*/true,
|
/*isVariadic=*/false, /*isSynthesized=*/true,
|
||||||
|
@ -1556,7 +1555,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
|
||||||
property->getLocation();
|
property->getLocation();
|
||||||
|
|
||||||
SetterMethod =
|
SetterMethod =
|
||||||
ObjCMethodDecl::Create(Context, Loc, Loc, ArrayRef<SourceLocation>(),
|
ObjCMethodDecl::Create(Context, Loc, Loc,
|
||||||
property->getSetterName(), Context.VoidTy, 0,
|
property->getSetterName(), Context.VoidTy, 0,
|
||||||
CD, /*isInstance=*/true, /*isVariadic=*/false,
|
CD, /*isInstance=*/true, /*isVariadic=*/false,
|
||||||
/*isSynthesized=*/true,
|
/*isSynthesized=*/true,
|
||||||
|
@ -1577,7 +1576,8 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
|
||||||
SC_None,
|
SC_None,
|
||||||
SC_None,
|
SC_None,
|
||||||
0);
|
0);
|
||||||
SetterMethod->setMethodParams(Context, &Argument, 1);
|
SetterMethod->setMethodParams(Context, Argument,
|
||||||
|
ArrayRef<SourceLocation>());
|
||||||
|
|
||||||
AddPropertyAttrs(*this, SetterMethod, property);
|
AddPropertyAttrs(*this, SetterMethod, property);
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,15 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
|
||||||
Params.reserve(NumParams);
|
Params.reserve(NumParams);
|
||||||
for (unsigned I = 0; I != NumParams; ++I)
|
for (unsigned I = 0; I != NumParams; ++I)
|
||||||
Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
|
Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
|
||||||
MD->setMethodParams(Reader.getContext(), Params.data(), NumParams);
|
|
||||||
|
MD->SelLocsKind = Record[Idx++];
|
||||||
|
unsigned NumStoredSelLocs = Record[Idx++];
|
||||||
|
SmallVector<SourceLocation, 16> SelLocs;
|
||||||
|
SelLocs.reserve(NumStoredSelLocs);
|
||||||
|
for (unsigned i = 0; i != NumStoredSelLocs; ++i)
|
||||||
|
SelLocs.push_back(ReadSourceLocation(Record, Idx));
|
||||||
|
|
||||||
|
MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
|
void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
|
||||||
|
@ -1614,7 +1622,6 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
|
||||||
|
|
||||||
case DECL_OBJC_METHOD:
|
case DECL_OBJC_METHOD:
|
||||||
D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
|
D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
|
||||||
ArrayRef<SourceLocation>(),
|
|
||||||
Selector(), QualType(), 0, 0);
|
Selector(), QualType(), 0, 0);
|
||||||
break;
|
break;
|
||||||
case DECL_OBJC_INTERFACE:
|
case DECL_OBJC_INTERFACE:
|
||||||
|
|
|
@ -414,6 +414,14 @@ void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
|
||||||
for (ObjCMethodDecl::param_iterator P = D->param_begin(),
|
for (ObjCMethodDecl::param_iterator P = D->param_begin(),
|
||||||
PEnd = D->param_end(); P != PEnd; ++P)
|
PEnd = D->param_end(); P != PEnd; ++P)
|
||||||
Writer.AddDeclRef(*P, Record);
|
Writer.AddDeclRef(*P, Record);
|
||||||
|
|
||||||
|
Record.push_back(D->SelLocsKind);
|
||||||
|
unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
|
||||||
|
SourceLocation *SelLocs = D->getStoredSelLocs();
|
||||||
|
Record.push_back(NumStoredSelLocs);
|
||||||
|
for (unsigned i = 0; i != NumStoredSelLocs; ++i)
|
||||||
|
Writer.AddSourceLocation(SelLocs[i], Record);
|
||||||
|
|
||||||
Code = serialization::DECL_OBJC_METHOD;
|
Code = serialization::DECL_OBJC_METHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ void NSErrorMethodChecker::checkASTDecl(const ObjCMethodDecl *D,
|
||||||
II = &D->getASTContext().Idents.get("NSError");
|
II = &D->getASTContext().Idents.get("NSError");
|
||||||
|
|
||||||
bool hasNSError = false;
|
bool hasNSError = false;
|
||||||
for (ObjCMethodDecl::param_iterator
|
for (ObjCMethodDecl::param_const_iterator
|
||||||
I = D->param_begin(), E = D->param_end(); I != E; ++I) {
|
I = D->param_begin(), E = D->param_end(); I != E; ++I) {
|
||||||
if (IsNSError((*I)->getType(), II)) {
|
if (IsNSError((*I)->getType(), II)) {
|
||||||
hasNSError = true;
|
hasNSError = true;
|
||||||
|
|
|
@ -1198,7 +1198,8 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary *&Summ,
|
||||||
|
|
||||||
// Effects on the parameters.
|
// Effects on the parameters.
|
||||||
unsigned parm_idx = 0;
|
unsigned parm_idx = 0;
|
||||||
for (ObjCMethodDecl::param_iterator pi=MD->param_begin(), pe=MD->param_end();
|
for (ObjCMethodDecl::param_const_iterator
|
||||||
|
pi=MD->param_begin(), pe=MD->param_end();
|
||||||
pi != pe; ++pi, ++parm_idx) {
|
pi != pe; ++pi, ++parm_idx) {
|
||||||
const ParmVarDecl *pd = *pi;
|
const ParmVarDecl *pd = *pi;
|
||||||
if (pd->getAttr<NSConsumedAttr>()) {
|
if (pd->getAttr<NSConsumedAttr>()) {
|
||||||
|
@ -1244,9 +1245,9 @@ RetainSummaryManager::getCommonMethodSummary(const ObjCMethodDecl *MD,
|
||||||
// Delegates are a frequent form of false positives with the retain
|
// Delegates are a frequent form of false positives with the retain
|
||||||
// count checker.
|
// count checker.
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (ObjCMethodDecl::param_iterator I = MD->param_begin(),
|
for (ObjCMethodDecl::param_const_iterator I = MD->param_begin(),
|
||||||
E = MD->param_end(); I != E; ++I, ++i)
|
E = MD->param_end(); I != E; ++I, ++i)
|
||||||
if (ParmVarDecl *PD = *I) {
|
if (const ParmVarDecl *PD = *I) {
|
||||||
QualType Ty = Ctx.getCanonicalType(PD->getType());
|
QualType Ty = Ctx.getCanonicalType(PD->getType());
|
||||||
if (Ty.getLocalUnqualifiedType() == Ctx.VoidPtrTy)
|
if (Ty.getLocalUnqualifiedType() == Ctx.VoidPtrTy)
|
||||||
ScratchArgs = AF.add(ScratchArgs, i, StopTracking);
|
ScratchArgs = AF.add(ScratchArgs, i, StopTracking);
|
||||||
|
|
Loading…
Reference in New Issue