Skip to content
Snippets Groups Projects
Commit b5b9d9e3 authored by Bruno Cardoso Lopes's avatar Bruno Cardoso Lopes
Browse files

[Sema][Comments] Factor out function type loc logic. NFCI

This is in prepatation for @param TypeAliasTemplate support.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279691 91177308-0d34-0410-b5e6-96231b3b80d8
parent 483d651d
No related branches found
No related tags found
No related merge requests found
......@@ -113,6 +113,65 @@ bool ParagraphComment::isWhitespaceNoCache() const {
return true;
}
static TypeLoc lookThroughTypedefOrTypeAliasLocs(TypeLoc &SrcTL) {
TypeLoc TL = SrcTL.IgnoreParens();
// Look through qualified types.
if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>())
return QualifiedTL.getUnqualifiedLoc();
// Look through pointer types.
if (PointerTypeLoc PointerTL = TL.getAs<PointerTypeLoc>())
return PointerTL.getPointeeLoc().getUnqualifiedLoc();
// Look through reference types.
if (ReferenceTypeLoc ReferenceTL = TL.getAs<ReferenceTypeLoc>())
return ReferenceTL.getPointeeLoc().getUnqualifiedLoc();
// Look through adjusted types.
if (AdjustedTypeLoc ATL = TL.getAs<AdjustedTypeLoc>())
return ATL.getOriginalLoc();
if (BlockPointerTypeLoc BlockPointerTL = TL.getAs<BlockPointerTypeLoc>())
return BlockPointerTL.getPointeeLoc().getUnqualifiedLoc();
if (MemberPointerTypeLoc MemberPointerTL = TL.getAs<MemberPointerTypeLoc>())
return MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();
if (ElaboratedTypeLoc ETL = TL.getAs<ElaboratedTypeLoc>())
return ETL.getNamedTypeLoc();
return TL;
}
static bool getFunctionTypeLoc(TypeLoc TL, FunctionTypeLoc &ResFTL) {
TypeLoc PrevTL;
while (PrevTL != TL) {
PrevTL = TL;
TL = lookThroughTypedefOrTypeAliasLocs(TL);
}
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
ResFTL = FTL;
return true;
}
if (TemplateSpecializationTypeLoc STL =
TL.getAs<TemplateSpecializationTypeLoc>()) {
// If we have a typedef to a template specialization with exactly one
// template argument of a function type, this looks like std::function,
// boost::function, or other function wrapper. Treat these typedefs as
// functions.
if (STL.getNumArgs() != 1)
return false;
TemplateArgumentLoc MaybeFunction = STL.getArgLoc(0);
if (MaybeFunction.getArgument().getKind() != TemplateArgument::Type)
return false;
TypeSourceInfo *MaybeFunctionTSI = MaybeFunction.getTypeSourceInfo();
TypeLoc TL = MaybeFunctionTSI->getTypeLoc().getUnqualifiedLoc();
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
ResFTL = FTL;
return true;
}
}
return false;
}
const char *ParamCommandComment::getDirectionAsString(PassDirection D) {
switch (D) {
case ParamCommandComment::In:
......@@ -238,70 +297,11 @@ void DeclInfo::fill() {
if (!TSI)
break;
TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
while (true) {
TL = TL.IgnoreParens();
// Look through qualified types.
if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>()) {
TL = QualifiedTL.getUnqualifiedLoc();
continue;
}
// Look through pointer types.
if (PointerTypeLoc PointerTL = TL.getAs<PointerTypeLoc>()) {
TL = PointerTL.getPointeeLoc().getUnqualifiedLoc();
continue;
}
// Look through reference types.
if (ReferenceTypeLoc ReferenceTL = TL.getAs<ReferenceTypeLoc>()) {
TL = ReferenceTL.getPointeeLoc().getUnqualifiedLoc();
continue;
}
// Look through adjusted types.
if (AdjustedTypeLoc ATL = TL.getAs<AdjustedTypeLoc>()) {
TL = ATL.getOriginalLoc();
continue;
}
if (BlockPointerTypeLoc BlockPointerTL =
TL.getAs<BlockPointerTypeLoc>()) {
TL = BlockPointerTL.getPointeeLoc().getUnqualifiedLoc();
continue;
}
if (MemberPointerTypeLoc MemberPointerTL =
TL.getAs<MemberPointerTypeLoc>()) {
TL = MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();
continue;
}
if (ElaboratedTypeLoc ETL = TL.getAs<ElaboratedTypeLoc>()) {
TL = ETL.getNamedTypeLoc();
continue;
}
// Is this a typedef for a function type?
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
Kind = FunctionKind;
ParamVars = FTL.getParams();
ReturnType = FTL.getReturnLoc().getType();
break;
}
if (TemplateSpecializationTypeLoc STL =
TL.getAs<TemplateSpecializationTypeLoc>()) {
// If we have a typedef to a template specialization with exactly one
// template argument of a function type, this looks like std::function,
// boost::function, or other function wrapper. Treat these typedefs as
// functions.
if (STL.getNumArgs() != 1)
break;
TemplateArgumentLoc MaybeFunction = STL.getArgLoc(0);
if (MaybeFunction.getArgument().getKind() != TemplateArgument::Type)
break;
TypeSourceInfo *MaybeFunctionTSI = MaybeFunction.getTypeSourceInfo();
TypeLoc TL = MaybeFunctionTSI->getTypeLoc().getUnqualifiedLoc();
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
Kind = FunctionKind;
ParamVars = FTL.getParams();
ReturnType = FTL.getReturnLoc().getType();
}
break;
}
break;
FunctionTypeLoc FTL;
if (getFunctionTypeLoc(TL, FTL)) {
Kind = FunctionKind;
ParamVars = FTL.getParams();
ReturnType = FTL.getReturnLoc().getType();
}
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment