Skip to content

Commit

Permalink
Rename FunctionProtoType accessors from 'arguments' to 'parameters'
Browse files Browse the repository at this point in the history
Fix a perennial source of confusion in the clang type system: Declarations and
function prototypes have parameters to which arguments are supplied, so calling
these 'arguments' was a stretch even in C mode, let alone C++ where default
arguments, templates and overloading make the distinction important to get
right.

Readability win across the board, especially in the casting, ADL and
overloading implementations which make a lot more sense at a glance now.

Will keep an eye on the builders and update dependent projects shortly.

No functional change.

llvm-svn: 199686
  • Loading branch information
atoker committed Jan 20, 2014
1 parent 8ff1610 commit 9cacbab
Show file tree
Hide file tree
Showing 52 changed files with 451 additions and 438 deletions.
6 changes: 3 additions & 3 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2017,9 +2017,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
bool Unqualified = false, bool BlockReturnType = false);
QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
bool Unqualified = false);
QualType mergeFunctionArgumentTypes(QualType, QualType,
bool OfBlockPointer=false,
bool Unqualified = false);
QualType mergeFunctionParameterTypes(QualType, QualType,
bool OfBlockPointer = false,
bool Unqualified = false);
QualType mergeTransparentUnionType(QualType, QualType,
bool OfBlockPointer=false,
bool Unqualified = false);
Expand Down
18 changes: 9 additions & 9 deletions clang/include/clang/AST/CanonicalType.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,23 +557,23 @@ struct CanProxyAdaptor<FunctionProtoType>
: public CanProxyBase<FunctionProtoType> {
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumArgs)
CanQualType getArgType(unsigned i) const {
return CanQualType::CreateUnsafe(this->getTypePtr()->getArgType(i));
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumParams)
CanQualType getParamType(unsigned i) const {
return CanQualType::CreateUnsafe(this->getTypePtr()->getParamType(i));
}

LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getTypeQuals)

typedef CanTypeIterator<FunctionProtoType::arg_type_iterator>
arg_type_iterator;
typedef CanTypeIterator<FunctionProtoType::param_type_iterator>
param_type_iterator;

arg_type_iterator arg_type_begin() const {
return arg_type_iterator(this->getTypePtr()->arg_type_begin());
param_type_iterator param_type_begin() const {
return param_type_iterator(this->getTypePtr()->param_type_begin());
}

arg_type_iterator arg_type_end() const {
return arg_type_iterator(this->getTypePtr()->arg_type_end());
param_type_iterator param_type_end() const {
return param_type_iterator(this->getTypePtr()->param_type_end());
}

// Note: canonical function types never have exception specifications
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/AST/DataRecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
DEF_TRAVERSE_TYPE(FunctionProtoType, {
TRY_TO(TraverseType(T->getResultType()));

for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(),
AEnd = T->arg_type_end();
for (FunctionProtoType::param_type_iterator A = T->param_type_begin(),
AEnd = T->param_type_end();
A != AEnd; ++A) {
TRY_TO(TraverseType(*A));
}
Expand Down Expand Up @@ -1106,8 +1106,8 @@ DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
if (TL.getArg(I)) {
TRY_TO(TraverseDecl(TL.getArg(I)));
} else if (I < T->getNumArgs()) {
TRY_TO(TraverseType(T->getArgType(I)));
} else if (I < T->getNumParams()) {
TRY_TO(TraverseType(T->getParamType(I)));
}
}

Expand Down
14 changes: 11 additions & 3 deletions clang/include/clang/AST/DeclObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,23 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
// Iterator access to parameter types.
typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
arg_type_iterator;
param_type_iterator;

arg_type_iterator arg_type_begin() const {
param_type_iterator arg_type_begin() const {
return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
}
arg_type_iterator arg_type_end() const {
param_type_iterator arg_type_end() const {
return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
}

// FunctionProtoType adapters.
param_type_iterator param_type_begin() const {
return arg_type_begin();
}
param_type_iterator param_type_end() const {
return arg_type_end();
}

/// createImplicitParams - Used to lazily create the self and cmd
/// implict parameters. This must be called prior to using getSelfDecl()
/// or getCmdDecl(). The call is ignored if the implicit paramters
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
DEF_TRAVERSE_TYPE(FunctionProtoType, {
TRY_TO(TraverseType(T->getResultType()));

for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(),
AEnd = T->arg_type_end();
for (FunctionProtoType::param_type_iterator A = T->param_type_begin(),
AEnd = T->param_type_end();
A != AEnd; ++A) {
TRY_TO(TraverseType(*A));
}
Expand Down Expand Up @@ -1187,8 +1187,8 @@ DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
if (TL.getArg(I)) {
TRY_TO(TraverseDecl(TL.getArg(I)));
} else if (I < T->getNumArgs()) {
TRY_TO(TraverseType(T->getArgType(I)));
} else if (I < T->getNumParams()) {
TRY_TO(TraverseType(T->getParamType(I)));
}
}

Expand Down
52 changes: 26 additions & 26 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -2933,11 +2933,11 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {

friend class ASTContext; // ASTContext creates these.

const bool *getConsumedArgsBuffer() const {
assert(hasAnyConsumedArgs());
const bool *getConsumedParamsBuffer() const {
assert(hasAnyConsumedParams());

// Find the end of the exceptions.
Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end());
Expr *const *eh_end = reinterpret_cast<Expr *const *>(param_type_end());
if (getExceptionSpecType() != EST_ComputedNoexcept)
eh_end += NumExceptions;
else
Expand All @@ -2947,13 +2947,13 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
}

public:
unsigned getNumArgs() const { return NumArgs; }
QualType getArgType(unsigned i) const {
assert(i < NumArgs && "Invalid argument number!");
return arg_type_begin()[i];
unsigned getNumParams() const { return NumArgs; }
QualType getParamType(unsigned i) const {
assert(i < NumArgs && "Invalid parameter index");
return param_type_begin()[i];
}
ArrayRef<QualType> getArgTypes() const {
return ArrayRef<QualType>(arg_type_begin(), arg_type_end());
ArrayRef<QualType> getParamTypes() const {
return ArrayRef<QualType>(param_type_begin(), param_type_end());
}

ExtProtoInfo getExtProtoInfo() const {
Expand All @@ -2975,8 +2975,8 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
} else if (EPI.ExceptionSpecType == EST_Unevaluated) {
EPI.ExceptionSpecDecl = getExceptionSpecDecl();
}
if (hasAnyConsumedArgs())
EPI.ConsumedArguments = getConsumedArgsBuffer();
if (hasAnyConsumedParams())
EPI.ConsumedArguments = getConsumedParamsBuffer();
return EPI;
}

Expand Down Expand Up @@ -3015,7 +3015,7 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
if (getExceptionSpecType() != EST_ComputedNoexcept)
return 0;
// NoexceptExpr sits where the arguments end.
return *reinterpret_cast<Expr *const *>(arg_type_end());
return *reinterpret_cast<Expr *const *>(param_type_end());
}
/// \brief If this function type has an exception specification which hasn't
/// been determined yet (either because it has not been evaluated or because
Expand All @@ -3025,7 +3025,7 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
if (getExceptionSpecType() != EST_Uninstantiated &&
getExceptionSpecType() != EST_Unevaluated)
return 0;
return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[0];
return reinterpret_cast<FunctionDecl *const *>(param_type_end())[0];
}
/// \brief If this function type has an uninstantiated exception
/// specification, this is the function whose exception specification
Expand All @@ -3034,7 +3034,7 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
FunctionDecl *getExceptionSpecTemplate() const {
if (getExceptionSpecType() != EST_Uninstantiated)
return 0;
return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[1];
return reinterpret_cast<FunctionDecl *const *>(param_type_end())[1];
}
/// \brief Determine whether this function type has a non-throwing exception
/// specification. If this depends on template arguments, returns
Expand All @@ -3061,30 +3061,30 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
return static_cast<RefQualifierKind>(RefQualifier);
}

typedef const QualType *arg_type_iterator;
arg_type_iterator arg_type_begin() const {
typedef const QualType *param_type_iterator;
param_type_iterator param_type_begin() const {
return reinterpret_cast<const QualType *>(this+1);
}
arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
param_type_iterator param_type_end() const {
return param_type_begin() + NumArgs;
}

typedef const QualType *exception_iterator;
exception_iterator exception_begin() const {
// exceptions begin where arguments end
return arg_type_end();
return param_type_end();
}
exception_iterator exception_end() const {
if (getExceptionSpecType() != EST_Dynamic)
return exception_begin();
return exception_begin() + NumExceptions;
}

bool hasAnyConsumedArgs() const {
return HasAnyConsumedArgs;
}
bool isArgConsumed(unsigned I) const {
assert(I < getNumArgs() && "argument index out of range!");
if (hasAnyConsumedArgs())
return getConsumedArgsBuffer()[I];
bool hasAnyConsumedParams() const { return HasAnyConsumedArgs; }
bool isParamConsumed(unsigned I) const {
assert(I < getNumParams() && "parameter index out of range");
if (hasAnyConsumedParams())
return getConsumedParamsBuffer()[I];
return false;
}

Expand All @@ -3100,7 +3100,7 @@ class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {

void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
arg_type_iterator ArgTys, unsigned NumArgs,
param_type_iterator ArgTys, unsigned NumArgs,
const ExtProtoInfo &EPI, const ASTContext &Context);
};

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/TypeLoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
unsigned getNumArgs() const {
if (isa<FunctionNoProtoType>(getTypePtr()))
return 0;
return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
return cast<FunctionProtoType>(getTypePtr())->getNumParams();
}
ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CodeGen/CGFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class RequiredArgs {
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
unsigned additional) {
if (!prototype->isVariadic()) return All;
return RequiredArgs(prototype->getNumArgs() + additional);
return RequiredArgs(prototype->getNumParams() + additional);
}

static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
Expand Down
12 changes: 5 additions & 7 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1954,9 +1954,9 @@ class Sema {
QualType &ConvertedType);
bool IsBlockPointerConversion(QualType FromType, QualType ToType,
QualType& ConvertedType);
bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
const FunctionProtoType *NewType,
unsigned *ArgPos = 0);
bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
const FunctionProtoType *NewType,
unsigned *ArgPos = 0);
void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
QualType FromType, QualType ToType);

Expand Down Expand Up @@ -7825,10 +7825,8 @@ class Sema {
SourceLocation Loc);

void checkCall(NamedDecl *FDecl, ArrayRef<const Expr *> Args,
unsigned NumProtoArgs, bool IsMemberFunction,
SourceLocation Loc, SourceRange Range,
VariadicCallType CallType);

unsigned NumParams, bool IsMemberFunction, SourceLocation Loc,
SourceRange Range, VariadicCallType CallType);

bool CheckObjCString(Expr *Arg);

Expand Down
Loading

0 comments on commit 9cacbab

Please sign in to comment.