| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 1 | //===--- Overload.h - C++ Overloading ---------------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This file defines the data structures and types used in C++ | 
|  | 11 | // overload resolution. | 
|  | 12 | // | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
|  | 15 | #ifndef LLVM_CLANG_SEMA_OVERLOAD_H | 
|  | 16 | #define LLVM_CLANG_SEMA_OVERLOAD_H | 
|  | 17 |  | 
|  | 18 | #include "llvm/ADT/SmallVector.h" | 
|  | 19 |  | 
|  | 20 | namespace clang { | 
| Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 21 | class CXXConstructorDecl; | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 22 | class FunctionDecl; | 
|  | 23 |  | 
|  | 24 | /// ImplicitConversionKind - The kind of implicit conversion used to | 
|  | 25 | /// convert an argument to a parameter's type. The enumerator values | 
|  | 26 | /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that | 
|  | 27 | /// better conversion kinds have smaller values. | 
|  | 28 | enum ImplicitConversionKind { | 
| Douglas Gregor | f9201e0 | 2009-02-11 23:02:49 +0000 | [diff] [blame] | 29 | ICK_Identity = 0,          ///< Identity conversion (no conversion) | 
|  | 30 | ICK_Lvalue_To_Rvalue,      ///< Lvalue-to-rvalue conversion (C++ 4.1) | 
|  | 31 | ICK_Array_To_Pointer,      ///< Array-to-pointer conversion (C++ 4.2) | 
|  | 32 | ICK_Function_To_Pointer,   ///< Function-to-pointer (C++ 4.3) | 
| Douglas Gregor | 43c79c2 | 2009-12-09 00:47:37 +0000 | [diff] [blame^] | 33 | ICK_NoReturn_Adjustment,   ///< Removal of noreturn from a type (Clang) | 
| Douglas Gregor | f9201e0 | 2009-02-11 23:02:49 +0000 | [diff] [blame] | 34 | ICK_Qualification,         ///< Qualification conversions (C++ 4.4) | 
|  | 35 | ICK_Integral_Promotion,    ///< Integral promotions (C++ 4.5) | 
|  | 36 | ICK_Floating_Promotion,    ///< Floating point promotions (C++ 4.6) | 
| Douglas Gregor | 5cdf821 | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 37 | ICK_Complex_Promotion,     ///< Complex promotions (Clang extension) | 
| Douglas Gregor | f9201e0 | 2009-02-11 23:02:49 +0000 | [diff] [blame] | 38 | ICK_Integral_Conversion,   ///< Integral conversions (C++ 4.7) | 
|  | 39 | ICK_Floating_Conversion,   ///< Floating point conversions (C++ 4.8) | 
| Douglas Gregor | 5cdf821 | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 40 | ICK_Complex_Conversion,    ///< Complex conversions (C99 6.3.1.6) | 
| Douglas Gregor | f9201e0 | 2009-02-11 23:02:49 +0000 | [diff] [blame] | 41 | ICK_Floating_Integral,     ///< Floating-integral conversions (C++ 4.9) | 
| Douglas Gregor | 5cdf821 | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 42 | ICK_Complex_Real,          ///< Complex-real conversions (C99 6.3.1.7) | 
| Douglas Gregor | f9201e0 | 2009-02-11 23:02:49 +0000 | [diff] [blame] | 43 | ICK_Pointer_Conversion,    ///< Pointer conversions (C++ 4.10) | 
|  | 44 | ICK_Pointer_Member,        ///< Pointer-to-member conversions (C++ 4.11) | 
|  | 45 | ICK_Boolean_Conversion,    ///< Boolean conversions (C++ 4.12) | 
|  | 46 | ICK_Compatible_Conversion, ///< Conversions between compatible types in C99 | 
|  | 47 | ICK_Derived_To_Base,       ///< Derived-to-base (C++ [over.best.ics]) | 
|  | 48 | ICK_Num_Conversion_Kinds   ///< The number of conversion kinds | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 49 | }; | 
|  | 50 |  | 
|  | 51 | /// ImplicitConversionCategory - The category of an implicit | 
|  | 52 | /// conversion kind. The enumerator values match with Table 9 of | 
|  | 53 | /// (C++ 13.3.3.1.1) and are listed such that better conversion | 
|  | 54 | /// categories have smaller values. | 
|  | 55 | enum ImplicitConversionCategory { | 
|  | 56 | ICC_Identity = 0,              ///< Identity | 
|  | 57 | ICC_Lvalue_Transformation,     ///< Lvalue transformation | 
|  | 58 | ICC_Qualification_Adjustment,  ///< Qualification adjustment | 
|  | 59 | ICC_Promotion,                 ///< Promotion | 
|  | 60 | ICC_Conversion                 ///< Conversion | 
|  | 61 | }; | 
|  | 62 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | ImplicitConversionCategory | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 64 | GetConversionCategory(ImplicitConversionKind Kind); | 
|  | 65 |  | 
|  | 66 | /// ImplicitConversionRank - The rank of an implicit conversion | 
|  | 67 | /// kind. The enumerator values match with Table 9 of (C++ | 
|  | 68 | /// 13.3.3.1.1) and are listed such that better conversion ranks | 
|  | 69 | /// have smaller values. | 
|  | 70 | enum ImplicitConversionRank { | 
|  | 71 | ICR_Exact_Match = 0, ///< Exact Match | 
|  | 72 | ICR_Promotion,       ///< Promotion | 
|  | 73 | ICR_Conversion       ///< Conversion | 
|  | 74 | }; | 
|  | 75 |  | 
|  | 76 | ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind); | 
|  | 77 |  | 
|  | 78 | /// StandardConversionSequence - represents a standard conversion | 
|  | 79 | /// sequence (C++ 13.3.3.1.1). A standard conversion sequence | 
|  | 80 | /// contains between zero and three conversions. If a particular | 
|  | 81 | /// conversion is not needed, it will be set to the identity conversion | 
|  | 82 | /// (ICK_Identity). Note that the three conversions are | 
|  | 83 | /// specified as separate members (rather than in an array) so that | 
|  | 84 | /// we can keep the size of a standard conversion sequence to a | 
|  | 85 | /// single word. | 
|  | 86 | struct StandardConversionSequence { | 
|  | 87 | /// First -- The first conversion can be an lvalue-to-rvalue | 
|  | 88 | /// conversion, array-to-pointer conversion, or | 
|  | 89 | /// function-to-pointer conversion. | 
|  | 90 | ImplicitConversionKind First : 8; | 
|  | 91 |  | 
|  | 92 | /// Second - The second conversion can be an integral promotion, | 
|  | 93 | /// floating point promotion, integral conversion, floating point | 
|  | 94 | /// conversion, floating-integral conversion, pointer conversion, | 
|  | 95 | /// pointer-to-member conversion, or boolean conversion. | 
|  | 96 | ImplicitConversionKind Second : 8; | 
|  | 97 |  | 
|  | 98 | /// Third - The third conversion can be a qualification conversion. | 
|  | 99 | ImplicitConversionKind Third : 8; | 
|  | 100 |  | 
| Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 101 | /// Deprecated - Whether this the deprecated conversion of a | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | /// string literal to a pointer to non-const character data | 
| Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 103 | /// (C++ 4.2p2). | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 104 | bool Deprecated : 1; | 
|  | 105 |  | 
| Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 106 | /// IncompatibleObjC - Whether this is an Objective-C conversion | 
|  | 107 | /// that we should warn about (if we actually use it). | 
|  | 108 | bool IncompatibleObjC : 1; | 
|  | 109 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | /// ReferenceBinding - True when this is a reference binding | 
| Douglas Gregor | f70bdb9 | 2008-10-29 14:50:44 +0000 | [diff] [blame] | 111 | /// (C++ [over.ics.ref]). | 
|  | 112 | bool ReferenceBinding : 1; | 
|  | 113 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | /// DirectBinding - True when this is a reference binding that is a | 
| Douglas Gregor | f70bdb9 | 2008-10-29 14:50:44 +0000 | [diff] [blame] | 115 | /// direct binding (C++ [dcl.init.ref]). | 
|  | 116 | bool DirectBinding : 1; | 
|  | 117 |  | 
| Sebastian Redl | a984580 | 2009-03-29 15:27:50 +0000 | [diff] [blame] | 118 | /// RRefBinding - True when this is a reference binding of an rvalue | 
|  | 119 | /// reference to an rvalue (C++0x [over.ics.rank]p3b4). | 
|  | 120 | bool RRefBinding : 1; | 
|  | 121 |  | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 122 | /// FromType - The type that this conversion is converting | 
| Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 123 | /// from. This is an opaque pointer that can be translated into a | 
|  | 124 | /// QualType. | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 125 | void *FromTypePtr; | 
|  | 126 |  | 
|  | 127 | /// ToType - The type that this conversion is converting to. This | 
| Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 128 | /// is an opaque pointer that can be translated into a QualType. | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 129 | void *ToTypePtr; | 
|  | 130 |  | 
| Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 131 | /// CopyConstructor - The copy constructor that is used to perform | 
|  | 132 | /// this conversion, when the conversion is actually just the | 
|  | 133 | /// initialization of an object via copy constructor. Such | 
|  | 134 | /// conversions are either identity conversions or derived-to-base | 
|  | 135 | /// conversions. | 
|  | 136 | CXXConstructorDecl *CopyConstructor; | 
|  | 137 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | void setAsIdentityConversion(); | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 139 | ImplicitConversionRank getRank() const; | 
|  | 140 | bool isPointerConversionToBool() const; | 
| Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 141 | bool isPointerConversionToVoidPointer(ASTContext& Context) const; | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 142 | void DebugPrint() const; | 
|  | 143 | }; | 
|  | 144 |  | 
|  | 145 | /// UserDefinedConversionSequence - Represents a user-defined | 
|  | 146 | /// conversion sequence (C++ 13.3.3.1.2). | 
|  | 147 | struct UserDefinedConversionSequence { | 
|  | 148 | /// Before - Represents the standard conversion that occurs before | 
|  | 149 | /// the actual user-defined conversion. (C++ 13.3.3.1.2p1): | 
|  | 150 | /// | 
|  | 151 | ///   If the user-defined conversion is specified by a constructor | 
|  | 152 | ///   (12.3.1), the initial standard conversion sequence converts | 
|  | 153 | ///   the source type to the type required by the argument of the | 
|  | 154 | ///   constructor. If the user-defined conversion is specified by | 
|  | 155 | ///   a conversion function (12.3.2), the initial standard | 
|  | 156 | ///   conversion sequence converts the source type to the implicit | 
|  | 157 | ///   object parameter of the conversion function. | 
|  | 158 | StandardConversionSequence Before; | 
|  | 159 |  | 
| Fariborz Jahanian | 966256a | 2009-11-06 00:23:08 +0000 | [diff] [blame] | 160 | /// EllipsisConversion - When this is true, it means user-defined | 
|  | 161 | /// conversion sequence starts with a ... (elipsis) conversion, instead of | 
|  | 162 | /// a standard conversion. In this case, 'Before' field must be ignored. | 
|  | 163 | // FIXME. I much rather put this as the first field. But there seems to be | 
|  | 164 | // a gcc code gen. bug which causes a crash in a test. Putting it here seems | 
|  | 165 | // to work around the crash. | 
|  | 166 | bool EllipsisConversion : 1; | 
|  | 167 |  | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 168 | /// After - Represents the standard conversion that occurs after | 
|  | 169 | /// the actual user-defined conversion. | 
|  | 170 | StandardConversionSequence After; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 |  | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 172 | /// ConversionFunction - The function that will perform the | 
|  | 173 | /// user-defined conversion. | 
|  | 174 | FunctionDecl* ConversionFunction; | 
|  | 175 |  | 
|  | 176 | void DebugPrint() const; | 
|  | 177 | }; | 
|  | 178 |  | 
|  | 179 | /// ImplicitConversionSequence - Represents an implicit conversion | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | /// sequence, which may be a standard conversion sequence | 
| Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 181 | /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2), | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 182 | /// or an ellipsis conversion sequence (C++ 13.3.3.1.3). | 
|  | 183 | struct ImplicitConversionSequence { | 
|  | 184 | /// Kind - The kind of implicit conversion sequence. BadConversion | 
|  | 185 | /// specifies that there is no conversion from the source type to | 
|  | 186 | /// the target type. The enumerator values are ordered such that | 
|  | 187 | /// better implicit conversions have smaller values. | 
|  | 188 | enum Kind { | 
|  | 189 | StandardConversion = 0, | 
|  | 190 | UserDefinedConversion, | 
|  | 191 | EllipsisConversion, | 
|  | 192 | BadConversion | 
|  | 193 | }; | 
|  | 194 |  | 
|  | 195 | /// ConversionKind - The kind of implicit conversion sequence. | 
| Douglas Gregor | f70bdb9 | 2008-10-29 14:50:44 +0000 | [diff] [blame] | 196 | Kind ConversionKind; | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 197 |  | 
|  | 198 | union { | 
|  | 199 | /// When ConversionKind == StandardConversion, provides the | 
|  | 200 | /// details of the standard conversion sequence. | 
|  | 201 | StandardConversionSequence Standard; | 
|  | 202 |  | 
|  | 203 | /// When ConversionKind == UserDefinedConversion, provides the | 
|  | 204 | /// details of the user-defined conversion sequence. | 
|  | 205 | UserDefinedConversionSequence UserDefined; | 
|  | 206 | }; | 
| Fariborz Jahanian | b1663d0 | 2009-09-23 00:58:07 +0000 | [diff] [blame] | 207 |  | 
|  | 208 | /// When ConversionKind == BadConversion due to multiple conversion | 
|  | 209 | /// functions, this will list those functions. | 
|  | 210 | llvm::SmallVector<FunctionDecl*, 4> ConversionFunctionSet; | 
|  | 211 |  | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 212 | // The result of a comparison between implicit conversion | 
|  | 213 | // sequences. Use Sema::CompareImplicitConversionSequences to | 
|  | 214 | // actually perform the comparison. | 
|  | 215 | enum CompareKind { | 
| Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 216 | Better = -1, | 
|  | 217 | Indistinguishable = 0, | 
|  | 218 | Worse = 1 | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 219 | }; | 
|  | 220 |  | 
|  | 221 | void DebugPrint() const; | 
|  | 222 | }; | 
|  | 223 |  | 
|  | 224 | /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). | 
|  | 225 | struct OverloadCandidate { | 
| Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 226 | /// Function - The actual function that this candidate | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 227 | /// represents. When NULL, this is a built-in candidate | 
|  | 228 | /// (C++ [over.oper]) or a surrogate for a conversion to a | 
| Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 229 | /// function pointer or reference (C++ [over.call.object]). | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 230 | FunctionDecl *Function; | 
| Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 231 |  | 
| Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 232 | // BuiltinTypes - Provides the return and parameter types of a | 
|  | 233 | // built-in overload candidate. Only valid when Function is NULL. | 
|  | 234 | struct { | 
|  | 235 | QualType ResultTy; | 
|  | 236 | QualType ParamTypes[3]; | 
|  | 237 | } BuiltinTypes; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 238 |  | 
| Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 239 | /// Surrogate - The conversion function for which this candidate | 
|  | 240 | /// is a surrogate, but only if IsSurrogate is true. | 
|  | 241 | CXXConversionDecl *Surrogate; | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 242 |  | 
|  | 243 | /// Conversions - The conversion sequences used to convert the | 
|  | 244 | /// function arguments to the function parameters. | 
|  | 245 | llvm::SmallVector<ImplicitConversionSequence, 4> Conversions; | 
|  | 246 |  | 
|  | 247 | /// Viable - True to indicate that this overload candidate is viable. | 
|  | 248 | bool Viable; | 
| Douglas Gregor | f1991ea | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 249 |  | 
| Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 250 | /// IsSurrogate - True to indicate that this candidate is a | 
|  | 251 | /// surrogate for a conversion to a function pointer or reference | 
|  | 252 | /// (C++ [over.call.object]). | 
|  | 253 | bool IsSurrogate; | 
|  | 254 |  | 
| Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 255 | /// IgnoreObjectArgument - True to indicate that the first | 
|  | 256 | /// argument's conversion, which for this function represents the | 
|  | 257 | /// implicit object argument, should be ignored. This will be true | 
|  | 258 | /// when the candidate is a static member function (where the | 
|  | 259 | /// implicit object argument is just a placeholder) or a | 
|  | 260 | /// non-static member function when the call doesn't have an | 
|  | 261 | /// object argument. | 
|  | 262 | bool IgnoreObjectArgument; | 
|  | 263 |  | 
| Douglas Gregor | f1991ea | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 264 | /// FinalConversion - For a conversion function (where Function is | 
|  | 265 | /// a CXXConversionDecl), the standard conversion that occurs | 
|  | 266 | /// after the call to the overload candidate to convert the result | 
|  | 267 | /// of calling the conversion function to the required type. | 
|  | 268 | StandardConversionSequence FinalConversion; | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 269 | }; | 
|  | 270 |  | 
|  | 271 | /// OverloadCandidateSet - A set of overload candidates, used in C++ | 
|  | 272 | /// overload resolution (C++ 13.3). | 
| Douglas Gregor | 3f39602 | 2009-09-28 04:47:19 +0000 | [diff] [blame] | 273 | class OverloadCandidateSet : public llvm::SmallVector<OverloadCandidate, 16> { | 
|  | 274 | llvm::SmallPtrSet<Decl *, 16> Functions; | 
|  | 275 |  | 
|  | 276 | public: | 
|  | 277 | /// \brief Determine when this overload candidate will be new to the | 
|  | 278 | /// overload set. | 
|  | 279 | bool isNewCandidate(Decl *F) { | 
|  | 280 | return Functions.insert(F->getCanonicalDecl()); | 
|  | 281 | } | 
|  | 282 | }; | 
| Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 283 | } // end namespace clang | 
|  | 284 |  | 
|  | 285 | #endif // LLVM_CLANG_SEMA_OVERLOAD_H |