r199466 - Add ArrayRef<> interface to get the parameters of a FunctionDecl/ObjCMethodDecl.

Ted Kremenek kremenek at apple.com
Thu Jan 16 22:24:50 PST 2014


Author: kremenek
Date: Fri Jan 17 00:24:50 2014
New Revision: 199466

URL: http://llvm.org/viewvc/llvm-project?rev=199466&view=rev
Log:
Add ArrayRef<> interface to get the parameters of a FunctionDecl/ObjCMethodDecl.

This is an alternate interface to the separate iterator interfaces
provided by FunctionDecl and ObjCMethodDecl, which precede ArrayRef.

Providing this new interface is more convenient for some uses, and
likely the old interfaces should be removed.  I have not undertaken
that effort in this change because this API introduction may
solicit commentary and that was a larger change than I wanted
to introduce all at once to serve a direct purpose.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclObjC.h

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=199466&r1=199465&r2=199466&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Jan 17 00:24:50 2014
@@ -1851,6 +1851,12 @@ public:
     setParams(getASTContext(), NewParamInfo);
   }
 
+  // ArrayRef iterface to parameters.
+  // FIXME: Should one day replace iterator interface.
+  ArrayRef<ParmVarDecl*> parameters() const {
+    return llvm::makeArrayRef(ParamInfo, getNumParams());
+  }
+
   const ArrayRef<NamedDecl *> &getDeclsInPrototypeScope() const {
     return DeclsInPrototypeScope;
   }

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=199466&r1=199465&r2=199466&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Jan 17 00:24:50 2014
@@ -314,8 +314,7 @@ public:
     if (hasStandardSelLocs())
       return getStandardSelectorLoc(Index, getSelector(),
                                    getSelLocsKind() == SelLoc_StandardWithSpace,
-                      llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
-                                         NumParams),
+                                    parameters(),
                                    DeclEndLoc);
     return getStoredSelLocs()[Index];
   }
@@ -364,6 +363,13 @@ public:
     return param_begin() + getSelector().getNumArgs();
   }
 
+  // ArrayRef access to formal parameters.  This should eventually
+  // replace the iterator interface above.
+  ArrayRef<ParmVarDecl*> parameters() const {
+    return llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
+                              NumParams);
+  }
+
   /// \brief Sets the method's parameters and selector source locations.
   /// If the method is implicit (not coming from source) \p SelLocs is
   /// ignored.





More information about the cfe-commits mailing list