/// IgnoreParens - Returns the specified type after dropping any
/// outer-level parentheses.
QualType IgnoreParens() const {
- return QualType::IgnoreParens(*this);
+ if (isa<ParenType>(*this))
+ return QualType::IgnoreParens(*this);
+ return *this;
}
/// operator==/!= - Indicate whether the specified types and qualifiers are
/// \brief Skips past any qualifiers, if this is qualified.
UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
- TypeLoc IgnoreParens() const;
+ TypeLoc IgnoreParens() const {
+ if (isa<ParenTypeLoc>(this))
+ return IgnoreParensImpl(*this);
+ return *this;
+ }
/// \brief Initializes this to state that every location in this
/// type is the given location.
static void initializeImpl(TypeLoc TL, SourceLocation Loc);
static void initializeFullCopyImpl(TypeLoc TL, TypeLoc Other);
static TypeLoc getNextTypeLocImpl(TypeLoc TL);
+ static TypeLoc IgnoreParensImpl(TypeLoc TL);
static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
};
PrintingPolicy SubPolicy(Policy);
SubPolicy.SuppressSpecifiers = false;
std::string Proto = D->getNameInfo().getAsString();
- if (isa<FunctionType>(D->getType().getTypePtr())) {
- const FunctionType *AFT = D->getType()->getAs<FunctionType>();
+ QualType Ty = D->getType();
+ while (ParenType* PT = dyn_cast<ParenType>(Ty)) {
+ Proto = '(' + Proto + ')';
+ Ty = PT->getInnerType();
+ }
+
+ if (isa<FunctionType>(Ty)) {
+ const FunctionType *AFT = Ty->getAs<FunctionType>();
const FunctionProtoType *FT = 0;
if (D->hasWrittenPrototype())
FT = dyn_cast<FunctionProtoType>(AFT);
else
AFT->getResultType().getAsStringInternal(Proto, Policy);
} else {
- D->getType().getAsStringInternal(Proto, Policy);
+ Ty.getAsStringInternal(Proto, Policy);
}
Out << Proto;
return TST_unspecified;
}
-TypeLoc TypeLoc::IgnoreParens() const {
- TypeLoc TL = *this;
+TypeLoc TypeLoc::IgnoreParensImpl(TypeLoc TL) {
while (ParenTypeLoc* PTL = dyn_cast<ParenTypeLoc>(&TL))
TL = PTL->getInnerLoc();
return TL;
if (FD->getIdentifier() != GetIdentifier(II_gets, "gets"))
return;
- const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FD->getType());
+ const FunctionProtoType *FPT
+ = dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FPT)
return;
if (FD->getIdentifier() != GetIdentifier(II_getpw, "getpw"))
return;
- const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FD->getType());
+ const FunctionProtoType *FPT
+ = dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FPT)
return;
if (FD->getIdentifier() != GetIdentifier(II_mktemp, "mktemp"))
return;
- const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FD->getType());
+ const FunctionProtoType *FPT
+ = dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if(!FPT)
return;
if (identifierid >= num_rands)
return;
- const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FD->getType());
+ const FunctionProtoType *FTP
+ = dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FTP)
return;
if (FD->getIdentifier() != GetIdentifier(II_random, "random"))
return;
- const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FD->getType());
+ const FunctionProtoType *FTP
+ = dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FTP)
return;
if (identifierid >= num_setids)
return;
- const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FD->getType());
+ const FunctionProtoType *FTP
+ = dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FTP)
return;
void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType,
NamedDecl *D) {
- if (FunctionProtoType *fproto = dyn_cast<FunctionProtoType>(funcType)) {
+ if (FunctionProtoType *fproto
+ = dyn_cast<FunctionProtoType>(funcType.IgnoreParens())) {
for (FunctionProtoType::arg_type_iterator I = fproto->arg_type_begin(),
E = fproto->arg_type_end(); I && (I != E); ++I)
if (isTopLevelBlockPointerType(*I)) {
// then we're done.
if (BlockPointerTypeLoc *BlockPtr
= dyn_cast<BlockPointerTypeLoc>(&TL)) {
- TL = BlockPtr->getPointeeLoc();
- // Skip any paren typeloc.
- while (ParenTypeLoc *ParenPtr = dyn_cast<ParenTypeLoc>(&TL))
- TL = ParenPtr->getInnerLoc();
+ TL = BlockPtr->getPointeeLoc().IgnoreParens();
Block = dyn_cast<FunctionProtoTypeLoc>(&TL);
}
break;
// Copy the parameter declarations from the declarator D to the function
// declaration NewFD, if they are available. First scavenge them into Params.
llvm::SmallVector<ParmVarDecl*, 16> Params;
- if (D.getNumTypeObjects() > 0) {
+ if (D.isFunctionDeclarator()) {
DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
// Check for C99 6.7.5.3p10 - foo(void) is a non-varargs
if (!Context.hasSameUnqualifiedType(FT->getResultType(), Context.IntTy)) {
TypeSourceInfo *TSI = FD->getTypeSourceInfo();
- TypeLoc TL = TSI->getTypeLoc();
+ TypeLoc TL = TSI->getTypeLoc().IgnoreParens();
const SemaDiagnosticBuilder& D = Diag(FD->getTypeSpecStartLoc(),
diag::err_main_returns_nonint);
if (FunctionTypeLoc* PTL = dyn_cast<FunctionTypeLoc>(&TL)) {
FunctionDecl *FD = cast<FunctionDecl>(d);
if (!FD->getResultType()->isVoidType()) {
- TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
+ TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc().IgnoreParens();
if (FunctionTypeLoc* FTL = dyn_cast<FunctionTypeLoc>(&TL)) {
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
<< FD->getType()
/// to member to a function with an exception specification. This means that
/// it is invalid to add another level of indirection.
bool Sema::CheckDistantExceptionSpec(QualType T) {
- T = T.IgnoreParens();
if (const PointerType *PT = T->getAs<PointerType>())
T = PT->getPointeeType();
else if (const MemberPointerType *PT = T->getAs<MemberPointerType>())
else
return false;
- T = T.IgnoreParens();
const FunctionProtoType *FnT = T->getAs<FunctionProtoType>();
if (!FnT)
return false;
SourceLocation AfterParenLoc;
if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) {
- TypeLoc TL = TSInfo->getTypeLoc();
+ TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
if (const FunctionTypeLoc *FTLoc = dyn_cast<FunctionTypeLoc>(&TL))
AfterParenLoc = PP.getLocForEndOfToken(FTLoc->getRParenLoc());
}
// Push block parameters from the declarator if we had them.
llvm::SmallVector<ParmVarDecl*, 8> Params;
- if (isa<FunctionProtoType>(T)) {
- FunctionProtoTypeLoc TL = cast<FunctionProtoTypeLoc>(Sig->getTypeLoc());
+ if (isa<FunctionProtoType>(T.IgnoreParens())) {
+ FunctionProtoTypeLoc TL
+ = cast<FunctionProtoTypeLoc>(Sig->getTypeLoc().IgnoreParens());
for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
ParmVarDecl *Param = TL.getArg(I);
if (Param->getIdentifier() == 0 &&
if (T->getType()->isDependentType() || T->getType()->isVariablyModifiedType())
return true;
- TypeLoc TL = T->getTypeLoc();
+ TypeLoc TL = T->getTypeLoc().IgnoreParens();
if (!isa<FunctionProtoTypeLoc>(TL))
return false;
return 0;
QualType T = TInfo->getType();
- // \brief If the type of this function is not *directly* a function
- // type, then we're instantiating the a function that was declared
- // via a typedef, e.g.,
+ // \brief If the type of this function, after ignoring parentheses,
+ // is not *directly* a function type, then we're instantiating a function
+ // that was declared via a typedef, e.g.,
//
// typedef int functype(int, int);
// functype func;
//
// In this case, we'll just go instantiate the ParmVarDecls that we
// synthesized in the method declaration.
- if (!isa<FunctionProtoType>(T)) {
+ if (!isa<FunctionProtoType>(T.IgnoreParens())) {
assert(!Params.size() && "Instantiating type could not yield parameters");
for (unsigned I = 0, N = D->getNumParams(); I != N; ++I) {
ParmVarDecl *P = SemaRef.SubstParmVarDecl(D->getParamDecl(I),
if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) {
// Visit the function declaration's syntactic components in the order
// written. This requires a bit of work.
- TypeLoc TL = TSInfo->getTypeLoc();
+ TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL);
// If we have a function declared directly (without the use of a typedef),