r262308 - Better comments for ExtParameterInfo.

John McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 29 22:27:40 PST 2016


Author: rjmccall
Date: Tue Mar  1 00:27:40 2016
New Revision: 262308

URL: http://llvm.org/viewvc/llvm-project?rev=262308&view=rev
Log:
Better comments for ExtParameterInfo.

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/include/clang/Sema/Sema.h

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=262308&r1=262307&r2=262308&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Mar  1 00:27:40 2016
@@ -3040,6 +3040,25 @@ public:
 /// type.
 class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
 public:
+  /// Interesting information about a specific parameter that can't simply
+  /// be reflected in parameter's type.
+  ///
+  /// It makes sense to model language features this way when there's some
+  /// sort of parameter-specific override (such as an attribute) that
+  /// affects how the function is called.  For example, the ARC ns_consumed
+  /// attribute changes whether a parameter is passed at +0 (the default)
+  /// or +1 (ns_consumed).  This must be reflected in the function type,
+  /// but isn't really a change to the parameter type.
+  ///
+  /// One serious disadvantage of modelling language features this way is
+  /// that they generally do not work with language features that attempt
+  /// to destructure types.  For example, template argument deduction will
+  /// not be able to match a parameter declared as
+  ///   T (*)(U)
+  /// against an argument of type
+  ///   void (*)(__attribute__((ns_consumed)) id)
+  /// because the substitution of T=void, U=id into the former will
+  /// not produce the latter.
   class ExtParameterInfo {
     enum {
       IsConsumed      = 0x01,
@@ -3349,12 +3368,17 @@ public:
     return exception_begin() + NumExceptions;
   }
 
+  /// Is there any interesting extra information for any of the parameters
+  /// of this function type?
   bool hasExtParameterInfos() const { return HasExtParameterInfos; }
   ArrayRef<ExtParameterInfo> getExtParameterInfos() const {
     assert(hasExtParameterInfos());
     return ArrayRef<ExtParameterInfo>(getExtParameterInfosBuffer(),
                                       getNumParams());
   }
+  /// Return a pointer to the beginning of the array of extra parameter
+  /// information, if present, or else null if none of the parameters
+  /// carry it.  This is equivalent to getExtProtoInfo().ExtParameterInfos.
   const ExtParameterInfo *getExtParameterInfosOrNull() const {
     if (!hasExtParameterInfos())
       return nullptr;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=262308&r1=262307&r2=262308&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Mar  1 00:27:40 2016
@@ -6982,11 +6982,14 @@ public:
     SavedPendingLocalImplicitInstantiations;
   };
 
+  /// A helper class for building up ExtParameterInfos.
   class ExtParameterInfoBuilder {
-    SmallVector<FunctionProtoType::ExtParameterInfo, 4> Infos;
+    SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos;
     bool HasInteresting = false;
 
   public:
+    /// Set the ExtParameterInfo for the parameter at the given index,
+    /// 
     void set(unsigned index, FunctionProtoType::ExtParameterInfo info) {
       assert(Infos.size() <= index);
       Infos.resize(index);
@@ -6996,9 +6999,13 @@ public:
         HasInteresting = (info != FunctionProtoType::ExtParameterInfo());
     }
 
+    /// Return a pointer (suitable for setting in an ExtProtoInfo) to the
+    /// ExtParameterInfo array we've built up.
     const FunctionProtoType::ExtParameterInfo *
     getPointerOrNull(unsigned numParams) {
-      return (HasInteresting ? Infos.data() : nullptr);
+      if (!HasInteresting) return nullptr;
+      Infos.resize(numParams);
+      return Infos.data();
     }
   };
 




More information about the cfe-commits mailing list