Skip to content

Commit

Permalink
Rename getResultType() on function and method declarations to getRetu…
Browse files Browse the repository at this point in the history
…rnType()

A return type is the declared or deduced part of the function type specified in
the declaration.

A result type is the (potentially adjusted) type of the value of an expression
that calls the function.

Rule of thumb:

  * Declarations have return types and parameters.
  * Expressions have result types and arguments.

llvm-svn: 200082
  • Loading branch information
atoker committed Jan 25, 2014
1 parent 68855fe commit 314cc81
Show file tree
Hide file tree
Showing 81 changed files with 650 additions and 726 deletions.
4 changes: 2 additions & 2 deletions clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);

/**
* \brief Retrieve the result type associated with a function type.
* \brief Retrieve the return type associated with a function type.
*
* If a non-function type is passed in, an invalid type is returned.
*/
Expand Down Expand Up @@ -2908,7 +2908,7 @@ CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);

/**
* \brief Retrieve the result type associated with a given cursor.
* \brief Retrieve the return type associated with a given cursor.
*
* This only returns a valid type if the cursor refers to a function or method.
*/
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/CanonicalType.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,21 +541,21 @@ struct CanProxyAdaptor<ExtVectorType> : public CanProxyBase<ExtVectorType> {

template<>
struct CanProxyAdaptor<FunctionType> : public CanProxyBase<FunctionType> {
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
};

template<>
struct CanProxyAdaptor<FunctionNoProtoType>
: public CanProxyBase<FunctionNoProtoType> {
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
};

template<>
struct CanProxyAdaptor<FunctionProtoType>
: public CanProxyBase<FunctionProtoType> {
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumParams)
CanQualType getParamType(unsigned i) const {
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/Comment.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,9 @@ struct DeclInfo {
/// that we consider a "function".
ArrayRef<const ParmVarDecl *> ParamVars;

/// Function result type if \c CommentDecl is something that we consider
/// Function return type if \c CommentDecl is something that we consider
/// a "function".
QualType ResultType;
QualType ReturnType;

/// Template parameters that can be referenced by \\tparam if \c CommentDecl is
/// a template (\c IsTemplateDecl or \c IsTemplatePartialSpecialization is
Expand Down
53 changes: 26 additions & 27 deletions clang/include/clang/AST/DataRecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,25 +866,24 @@ DEF_TRAVERSE_TYPE(ExtVectorType, {
TRY_TO(TraverseType(T->getElementType()));
})

DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
TRY_TO(TraverseType(T->getResultType()));
})
DEF_TRAVERSE_TYPE(FunctionNoProtoType,
{ TRY_TO(TraverseType(T->getReturnType())); })

DEF_TRAVERSE_TYPE(FunctionProtoType, {
TRY_TO(TraverseType(T->getResultType()));
TRY_TO(TraverseType(T->getReturnType()));

for (FunctionProtoType::param_type_iterator A = T->param_type_begin(),
AEnd = T->param_type_end();
A != AEnd; ++A) {
TRY_TO(TraverseType(*A));
}
for (FunctionProtoType::param_type_iterator A = T->param_type_begin(),
AEnd = T->param_type_end();
A != AEnd; ++A) {
TRY_TO(TraverseType(*A));
}

for (FunctionProtoType::exception_iterator E = T->exception_begin(),
EEnd = T->exception_end();
E != EEnd; ++E) {
TRY_TO(TraverseType(*E));
}
})
for (FunctionProtoType::exception_iterator E = T->exception_begin(),
EEnd = T->exception_end();
E != EEnd; ++E) {
TRY_TO(TraverseType(*E));
}
})

DEF_TRAVERSE_TYPE(UnresolvedUsingType, { })
DEF_TRAVERSE_TYPE(TypedefType, { })
Expand Down Expand Up @@ -1362,18 +1361,18 @@ DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
})

DEF_TRAVERSE_DECL(ObjCMethodDecl, {
if (D->getResultTypeSourceInfo()) {
TRY_TO(TraverseTypeLoc(D->getResultTypeSourceInfo()->getTypeLoc()));
}
for (ObjCMethodDecl::param_iterator
I = D->param_begin(), E = D->param_end(); I != E; ++I) {
TRY_TO(TraverseDecl(*I));
}
if (D->isThisDeclarationADefinition()) {
TRY_TO(TraverseStmt(D->getBody()));
}
return true;
})
if (D->getReturnTypeSourceInfo()) {
TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
}
for (ObjCMethodDecl::param_iterator I = D->param_begin(), E = D->param_end();
I != E; ++I) {
TRY_TO(TraverseDecl(*I));
}
if (D->isThisDeclarationADefinition()) {
TRY_TO(TraverseStmt(D->getBody()));
}
return true;
})

DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
// FIXME: implement
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1868,8 +1868,8 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext,
/// arguments (in C++).
unsigned getMinRequiredArguments() const;

QualType getResultType() const {
return getType()->getAs<FunctionType>()->getResultType();
QualType getReturnType() const {
return getType()->getAs<FunctionType>()->getReturnType();
}

/// \brief Determine the type of an expression that calls this function.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ class CXXConversionDecl : public CXXMethodDecl {

/// \brief Returns the type that this conversion function is converting to.
QualType getConversionType() const {
return getType()->getAs<FunctionType>()->getResultType();
return getType()->getAs<FunctionType>()->getReturnType();
}

/// \brief Determine whether this conversion function is a conversion from
Expand Down
71 changes: 30 additions & 41 deletions clang/include/clang/AST/DeclObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
/// \brief Indicates if the method was a definition but its body was skipped.
unsigned HasSkippedBody : 1;

// Result type of this method.
// Return type of this method.
QualType MethodDeclType;

// Type source information for the result type.
TypeSourceInfo *ResultTInfo;
// Type source information for the return type.
TypeSourceInfo *ReturnTInfo;

/// \brief Array of ParmVarDecls for the formal parameters of this method
/// and optionally followed by selector locations.
Expand Down Expand Up @@ -224,27 +224,22 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
ArrayRef<SourceLocation> SelLocs);

ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
Selector SelInfo, QualType T,
TypeSourceInfo *ResultTInfo,
DeclContext *contextDecl,
bool isInstance = true,
bool isVariadic = false,
bool isPropertyAccessor = false,
bool isImplicitlyDeclared = false,
bool isDefined = false,
Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
DeclContext *contextDecl, bool isInstance = true,
bool isVariadic = false, bool isPropertyAccessor = false,
bool isImplicitlyDeclared = false, bool isDefined = false,
ImplementationControl impControl = None,
bool HasRelatedResultType = false)
: NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
IsInstance(isInstance), IsVariadic(isVariadic),
IsPropertyAccessor(isPropertyAccessor),
IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0),
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
RelatedResultType(HasRelatedResultType),
SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
MethodDeclType(T), ResultTInfo(ResultTInfo),
ParamsAndSelLocs(0), NumParams(0),
DeclEndLoc(endLoc), Body(), SelfDecl(0), CmdDecl(0) {
: NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
IsInstance(isInstance), IsVariadic(isVariadic),
IsPropertyAccessor(isPropertyAccessor), IsDefined(isDefined),
IsRedeclaration(0), HasRedeclaration(0), DeclImplementation(impControl),
objcDeclQualifier(OBJC_TQ_None),
RelatedResultType(HasRelatedResultType),
SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
MethodDeclType(T), ReturnTInfo(ReturnTInfo), ParamsAndSelLocs(0),
NumParams(0), DeclEndLoc(endLoc), Body(), SelfDecl(0), CmdDecl(0) {
setImplicit(isImplicitlyDeclared);
}

Expand All @@ -254,20 +249,14 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
virtual ObjCMethodDecl *getNextRedeclaration();

public:
static ObjCMethodDecl *Create(ASTContext &C,
SourceLocation beginLoc,
SourceLocation endLoc,
Selector SelInfo,
QualType T,
TypeSourceInfo *ResultTInfo,
DeclContext *contextDecl,
bool isInstance = true,
bool isVariadic = false,
bool isPropertyAccessor = false,
bool isImplicitlyDeclared = false,
bool isDefined = false,
ImplementationControl impControl = None,
bool HasRelatedResultType = false);
static ObjCMethodDecl *
Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
DeclContext *contextDecl, bool isInstance = true,
bool isVariadic = false, bool isPropertyAccessor = false,
bool isImplicitlyDeclared = false, bool isDefined = false,
ImplementationControl impControl = None,
bool HasRelatedResultType = false);

static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);

Expand Down Expand Up @@ -337,17 +326,17 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {

Selector getSelector() const { return getDeclName().getObjCSelector(); }

QualType getResultType() const { return MethodDeclType; }
void setResultType(QualType T) { MethodDeclType = T; }
QualType getReturnType() const { return MethodDeclType; }
void setReturnType(QualType T) { MethodDeclType = T; }

/// \brief Determine the type of an expression that sends a message to this
/// function.
QualType getSendResultType() const {
return getResultType().getNonLValueExprType(getASTContext());
return getReturnType().getNonLValueExprType(getASTContext());
}

TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
TypeSourceInfo *getReturnTypeSourceInfo() const { return ReturnTInfo; }
void setReturnTypeSourceInfo(TypeSourceInfo *TInfo) { ReturnTInfo = TInfo; }

// Iterator access to formal parameters.
unsigned param_size() const { return NumParams; }
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/ExprObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,13 @@ class ObjCPropertyRefExpr : public Expr {
if (isExplicitProperty()) {
const ObjCPropertyDecl *PDecl = getExplicitProperty();
if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl())
ResultType = Getter->getResultType();
ResultType = Getter->getReturnType();
else
ResultType = PDecl->getType();
} else {
const ObjCMethodDecl *Getter = getImplicitPropertyGetter();
if (Getter)
ResultType = Getter->getResultType(); // with reference!
ResultType = Getter->getReturnType(); // with reference!
}
return ResultType;
}
Expand Down
53 changes: 26 additions & 27 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,25 +947,24 @@ DEF_TRAVERSE_TYPE(ExtVectorType, {
TRY_TO(TraverseType(T->getElementType()));
})

DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
TRY_TO(TraverseType(T->getResultType()));
})
DEF_TRAVERSE_TYPE(FunctionNoProtoType,
{ TRY_TO(TraverseType(T->getReturnType())); })

DEF_TRAVERSE_TYPE(FunctionProtoType, {
TRY_TO(TraverseType(T->getResultType()));
TRY_TO(TraverseType(T->getReturnType()));

for (FunctionProtoType::param_type_iterator A = T->param_type_begin(),
AEnd = T->param_type_end();
A != AEnd; ++A) {
TRY_TO(TraverseType(*A));
}
for (FunctionProtoType::param_type_iterator A = T->param_type_begin(),
AEnd = T->param_type_end();
A != AEnd; ++A) {
TRY_TO(TraverseType(*A));
}

for (FunctionProtoType::exception_iterator E = T->exception_begin(),
EEnd = T->exception_end();
E != EEnd; ++E) {
TRY_TO(TraverseType(*E));
}
})
for (FunctionProtoType::exception_iterator E = T->exception_begin(),
EEnd = T->exception_end();
E != EEnd; ++E) {
TRY_TO(TraverseType(*E));
}
})

DEF_TRAVERSE_TYPE(UnresolvedUsingType, { })
DEF_TRAVERSE_TYPE(TypedefType, { })
Expand Down Expand Up @@ -1449,18 +1448,18 @@ DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
})

DEF_TRAVERSE_DECL(ObjCMethodDecl, {
if (D->getResultTypeSourceInfo()) {
TRY_TO(TraverseTypeLoc(D->getResultTypeSourceInfo()->getTypeLoc()));
}
for (ObjCMethodDecl::param_iterator
I = D->param_begin(), E = D->param_end(); I != E; ++I) {
TRY_TO(TraverseDecl(*I));
}
if (D->isThisDeclarationADefinition()) {
TRY_TO(TraverseStmt(D->getBody()));
}
return true;
})
if (D->getReturnTypeSourceInfo()) {
TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
}
for (ObjCMethodDecl::param_iterator I = D->param_begin(), E = D->param_end();
I != E; ++I) {
TRY_TO(TraverseDecl(*I));
}
if (D->isThisDeclarationADefinition()) {
TRY_TO(TraverseStmt(D->getBody()));
}
return true;
})

DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
// FIXME: implement
Expand Down
7 changes: 3 additions & 4 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -2779,8 +2779,7 @@ class FunctionType : public Type {
unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }

public:

QualType getResultType() const { return ResultType; }
QualType getReturnType() const { return ResultType; }

bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
Expand All @@ -2797,7 +2796,7 @@ class FunctionType : public Type {
/// \brief Determine the type of an expression that calls a function of
/// this type.
QualType getCallResultType(ASTContext &Context) const {
return getResultType().getNonLValueExprType(Context);
return getReturnType().getNonLValueExprType(Context);
}

static StringRef getNameForCallConv(CallingConv CC);
Expand Down Expand Up @@ -2826,7 +2825,7 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
QualType desugar() const { return QualType(this, 0); }

void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, getResultType(), getExtInfo());
Profile(ID, getReturnType(), getExtInfo());
}
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
ExtInfo Info) {
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 @@ -1251,7 +1251,7 @@ class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
return llvm::alignOf<ParmVarDecl*>();
}

QualType getInnerType() const { return getTypePtr()->getResultType(); }
QualType getInnerType() const { return getTypePtr()->getReturnType(); }
};

class FunctionProtoTypeLoc :
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ AST_MATCHER_P(FunctionDecl, parameterCountIs, unsigned, N) {
/// matches int f() { return 1; }
AST_MATCHER_P(FunctionDecl, returns,
internal::Matcher<QualType>, InnerMatcher) {
return InnerMatcher.matches(Node.getResultType(), Finder, Builder);
return InnerMatcher.matches(Node.getReturnType(), Finder, Builder);
}

/// \brief Matches extern "C" function declarations.
Expand Down
Loading

0 comments on commit 314cc81

Please sign in to comment.