diff options
author | Abramo Bagnara <abramo.bagnara@gmail.com> | 2010-12-14 22:11:44 +0000 |
---|---|---|
committer | Abramo Bagnara <abramo.bagnara@gmail.com> | 2010-12-14 22:11:44 +0000 |
commit | 723df245307a530da5433dfb43accf187dc3e243 (patch) | |
tree | 54bc41314c4898d2d1f156fbf627a159eb38e56d | |
parent | 8786da77984e81d48e0e1b2bd339809b1efc19f3 (diff) |
Added missing IgnoreParens().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121795 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Type.h | 4 | ||||
-rw-r--r-- | include/clang/AST/TypeLoc.h | 7 | ||||
-rw-r--r-- | lib/AST/DeclPrinter.cpp | 12 | ||||
-rw-r--r-- | lib/AST/TypeLoc.cpp | 3 | ||||
-rw-r--r-- | lib/Checker/CheckSecuritySyntaxOnly.cpp | 18 | ||||
-rw-r--r-- | lib/Rewrite/RewriteObjC.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExceptionSpec.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 2 |
14 files changed, 47 insertions, 32 deletions
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 229119c781..4c3a295ccb 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -694,7 +694,9 @@ public: /// 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 diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 6f2e705953..5b695d0891 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -115,7 +115,11 @@ public: /// \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. @@ -146,6 +150,7 @@ private: 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); }; diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 3eded8f7dc..95421a494b 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -366,9 +366,15 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { 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); @@ -487,7 +493,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { else AFT->getResultType().getAsStringInternal(Proto, Policy); } else { - D->getType().getAsStringInternal(Proto, Policy); + Ty.getAsStringInternal(Proto, Policy); } Out << Proto; diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index c987b9bb9b..cde747d507 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -230,8 +230,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const { 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; diff --git a/lib/Checker/CheckSecuritySyntaxOnly.cpp b/lib/Checker/CheckSecuritySyntaxOnly.cpp index 0223240ce6..6090fa5baf 100644 --- a/lib/Checker/CheckSecuritySyntaxOnly.cpp +++ b/lib/Checker/CheckSecuritySyntaxOnly.cpp @@ -242,7 +242,8 @@ void WalkAST::CheckCall_gets(const CallExpr *CE, const FunctionDecl *FD) { 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; @@ -276,7 +277,8 @@ void WalkAST::CheckCall_getpw(const CallExpr *CE, const FunctionDecl *FD) { 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; @@ -314,7 +316,8 @@ void WalkAST::CheckCall_mktemp(const CallExpr *CE, const FunctionDecl *FD) { 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; @@ -369,7 +372,8 @@ void WalkAST::CheckCall_rand(const CallExpr *CE, const FunctionDecl *FD) { 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; @@ -410,7 +414,8 @@ void WalkAST::CheckCall_random(const CallExpr *CE, const FunctionDecl *FD) { 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; @@ -457,7 +462,8 @@ void WalkAST::CheckUncheckedReturnValue(CallExpr *CE) { 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; diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index 539ee49a6c..7d060389e7 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -472,7 +472,8 @@ namespace { 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)) { diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 2394629be5..76452a4516 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -1918,10 +1918,7 @@ static std::string FormatFunctionParameter(ASTContext &Context, // 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; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 66e517008c..3506456eb7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3761,7 +3761,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // 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 @@ -4283,7 +4283,7 @@ void Sema::CheckMain(FunctionDecl* FD) { 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)) { diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 8a88ae5f57..3453528d8a 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2170,7 +2170,7 @@ static void HandleGlobalAttr(Decl *d, const AttributeList &Attr, Sema &S) { 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() diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index d08e84dacd..5d7993b1af 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -81,7 +81,6 @@ bool Sema::CheckSpecifiedExceptionType(QualType T, const SourceRange &Range) { /// 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>()) @@ -89,7 +88,6 @@ bool Sema::CheckDistantExceptionSpec(QualType T) { else return false; - T = T.IgnoreParens(); const FunctionProtoType *FnT = T->getAs<FunctionProtoType>(); if (!FnT) return false; @@ -198,7 +196,7 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { 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()); } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 862a242d51..218a0b313d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8240,8 +8240,9 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { // 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 && diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 65e61ed174..fe9750108b 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -990,7 +990,7 @@ static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { if (T->getType()->isDependentType() || T->getType()->isVariablyModifiedType()) return true; - TypeLoc TL = T->getTypeLoc(); + TypeLoc TL = T->getTypeLoc().IgnoreParens(); if (!isa<FunctionProtoTypeLoc>(TL)) return false; diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 2f73991ec5..b6ef498874 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1264,16 +1264,16 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, 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), diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index e8c1a745bf..c8dbf3b588 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -693,7 +693,7 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) { 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), |