diff options
| author | John McCall <rjmccall@apple.com> | 2016-03-01 06:27:40 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2016-03-01 06:27:40 +0000 |
| commit | 65a6fe0c665ad16f068f7c5d3d584075f74aaf1f (patch) | |
| tree | 510f2e00fac83326db1456f5ab86f7c8f9dcc8e1 | |
| parent | 1d1493219c3de5befde52930c3bbb0143eecda26 (diff) | |
| download | bcm5719-llvm-65a6fe0c665ad16f068f7c5d3d584075f74aaf1f.tar.gz bcm5719-llvm-65a6fe0c665ad16f068f7c5d3d584075f74aaf1f.zip | |
Better comments for ExtParameterInfo.
llvm-svn: 262308
| -rw-r--r-- | clang/include/clang/AST/Type.h | 24 | ||||
| -rw-r--r-- | clang/include/clang/Sema/Sema.h | 11 |
2 files changed, 33 insertions, 2 deletions
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index d6e30e4f068..464d85255ce 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -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; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 8ff47e93ce0..563eea0eb1a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -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(); } }; |

