]> granicus.if.org Git - clang/commitdiff
Added missing IgnoreParens().
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Tue, 14 Dec 2010 22:11:44 +0000 (22:11 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Tue, 14 Dec 2010 22:11:44 +0000 (22:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121795 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/clang/AST/Type.h
include/clang/AST/TypeLoc.h
lib/AST/DeclPrinter.cpp
lib/AST/TypeLoc.cpp
lib/Checker/CheckSecuritySyntaxOnly.cpp
lib/Rewrite/RewriteObjC.cpp
lib/Sema/SemaCodeComplete.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaExceptionSpec.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
tools/libclang/CIndex.cpp

index 229119c78127eb17ac9b50176a1e0fbaa7927fe8..4c3a295ccbf94734bbf0650613e1e5fb08ed4410 100644 (file)
@@ -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
index 6f2e705953d965d005b75b825692bffc66726709..5b695d089129f3d2ff263702e73ad2e5ebb11425 100644 (file)
@@ -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);
 };
 
index 3eded8f7dc98a9d0609a0b62becbb117ffb0a4dc..95421a494ba0c45d8fe1760fc8dea36fb5360d91 100644 (file)
@@ -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;
index c987b9bb9b1f7ab0f4f0f71781f07f4fde308087..cde747d5075413e1c75c7f75ccff74a4d6de4747 100644 (file)
@@ -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;
index 0223240ce6e4d8c9457ace9df75ba1ce2940731b..6090fa5baf2f51b08100d8a0e77f717bdee45f1c 100644 (file)
@@ -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;
 
index 539ee49a6c4ed48e8f3ab0dbe4852683798693b7..7d060389e780c65d64014b07c640b6f90b0e3ad2 100644 (file)
@@ -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)) {
index 2394629be59b66afecab9e2c7dccaacaeef05729..76452a45168cd1f5a63c6305f35011f25dd96975 100644 (file)
@@ -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;
index 66e517008caf1d7e64b4df6e4559250cbdc45502..3506456eb756ae6e8274def443d5b37708e670f2 100644 (file)
@@ -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)) {
index 8a88ae5f571f6cb8756f43f60b3a9172f6a36624..3453528d8a4d3ae4e6142c026bcc22daa116d1d1 100644 (file)
@@ -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()
index d08e84dacd21dc22e5c88ce5c115b85ab3972f00..5d7993b1afbaa9dca60ef964e4e9b0823ee38d40 100644 (file)
@@ -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());
     }
index 862a242d51238839f594376373b3b58b8673b4ed..218a0b313d2d692124e2c403d8251504b305e609 100644 (file)
@@ -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 &&
index 65e61ed1745eff1c63f7d6f531e1425df9cb8984..fe9750108bf3097addc15f2b22e2ec7375c4c914 100644 (file)
@@ -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;
 
index 2f73991ec56dc0830dba1a20a0839a0a574ea00b..b6ef498874e4de3fc90432ec6017a425af396bbf 100644 (file)
@@ -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), 
index e8c1a745bfa323efe1e7f14f4b0a924127ab4ac5..c8dbf3b58880779ecb42a27d31490b90639f93b8 100644 (file)
@@ -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),