Douglas Gregor | d2baafd | 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 { |
| 21 | class FunctionDecl; |
| 22 | |
| 23 | /// ImplicitConversionKind - The kind of implicit conversion used to |
| 24 | /// convert an argument to a parameter's type. The enumerator values |
| 25 | /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that |
| 26 | /// better conversion kinds have smaller values. |
| 27 | enum ImplicitConversionKind { |
| 28 | ICK_Identity = 0, ///< Identity conversion (no conversion) |
| 29 | ICK_Lvalue_To_Rvalue, ///< Lvalue-to-rvalue conversion (C++ 4.1) |
| 30 | ICK_Array_To_Pointer, ///< Array-to-pointer conversion (C++ 4.2) |
| 31 | ICK_Function_To_Pointer, ///< Function-to-pointer (C++ 4.3) |
| 32 | ICK_Qualification, ///< Qualification conversions (C++ 4.4) |
| 33 | ICK_Integral_Promotion, ///< Integral promotions (C++ 4.5) |
| 34 | ICK_Floating_Promotion, ///< Floating point promotions (C++ 4.6) |
| 35 | ICK_Integral_Conversion, ///< Integral conversions (C++ 4.7) |
| 36 | ICK_Floating_Conversion, ///< Floating point conversions (C++ 4.8) |
| 37 | ICK_Floating_Integral, ///< Floating-integral conversions (C++ 4.9) |
| 38 | ICK_Pointer_Conversion, ///< Pointer conversions (C++ 4.10) |
| 39 | ICK_Pointer_Member, ///< Pointer-to-member conversions (C++ 4.11) |
| 40 | ICK_Boolean_Conversion, ///< Boolean conversions (C++ 4.12) |
| 41 | ICK_Num_Conversion_Kinds ///< The number of conversion kinds |
| 42 | }; |
| 43 | |
| 44 | /// ImplicitConversionCategory - The category of an implicit |
| 45 | /// conversion kind. The enumerator values match with Table 9 of |
| 46 | /// (C++ 13.3.3.1.1) and are listed such that better conversion |
| 47 | /// categories have smaller values. |
| 48 | enum ImplicitConversionCategory { |
| 49 | ICC_Identity = 0, ///< Identity |
| 50 | ICC_Lvalue_Transformation, ///< Lvalue transformation |
| 51 | ICC_Qualification_Adjustment, ///< Qualification adjustment |
| 52 | ICC_Promotion, ///< Promotion |
| 53 | ICC_Conversion ///< Conversion |
| 54 | }; |
| 55 | |
| 56 | ImplicitConversionCategory |
| 57 | GetConversionCategory(ImplicitConversionKind Kind); |
| 58 | |
| 59 | /// ImplicitConversionRank - The rank of an implicit conversion |
| 60 | /// kind. The enumerator values match with Table 9 of (C++ |
| 61 | /// 13.3.3.1.1) and are listed such that better conversion ranks |
| 62 | /// have smaller values. |
| 63 | enum ImplicitConversionRank { |
| 64 | ICR_Exact_Match = 0, ///< Exact Match |
| 65 | ICR_Promotion, ///< Promotion |
| 66 | ICR_Conversion ///< Conversion |
| 67 | }; |
| 68 | |
| 69 | ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind); |
| 70 | |
| 71 | /// StandardConversionSequence - represents a standard conversion |
| 72 | /// sequence (C++ 13.3.3.1.1). A standard conversion sequence |
| 73 | /// contains between zero and three conversions. If a particular |
| 74 | /// conversion is not needed, it will be set to the identity conversion |
| 75 | /// (ICK_Identity). Note that the three conversions are |
| 76 | /// specified as separate members (rather than in an array) so that |
| 77 | /// we can keep the size of a standard conversion sequence to a |
| 78 | /// single word. |
| 79 | struct StandardConversionSequence { |
| 80 | /// First -- The first conversion can be an lvalue-to-rvalue |
| 81 | /// conversion, array-to-pointer conversion, or |
| 82 | /// function-to-pointer conversion. |
| 83 | ImplicitConversionKind First : 8; |
| 84 | |
| 85 | /// Second - The second conversion can be an integral promotion, |
| 86 | /// floating point promotion, integral conversion, floating point |
| 87 | /// conversion, floating-integral conversion, pointer conversion, |
| 88 | /// pointer-to-member conversion, or boolean conversion. |
| 89 | ImplicitConversionKind Second : 8; |
| 90 | |
| 91 | /// Third - The third conversion can be a qualification conversion. |
| 92 | ImplicitConversionKind Third : 8; |
| 93 | |
| 94 | /// Deprecated - Whether this is a deprecated conversion, such as |
| 95 | /// converting a string literal to a pointer to non-const |
| 96 | /// character data (C++ 4.2p2). |
| 97 | bool Deprecated : 1; |
| 98 | |
| 99 | /// FromType - The type that this conversion is converting |
Douglas Gregor | 1404650 | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 100 | /// from. This is an opaque pointer that can be translated into a |
| 101 | /// QualType. |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 102 | void *FromTypePtr; |
| 103 | |
| 104 | /// ToType - The type that this conversion is converting to. This |
Douglas Gregor | 1404650 | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 105 | /// is an opaque pointer that can be translated into a QualType. |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 106 | void *ToTypePtr; |
| 107 | |
| 108 | ImplicitConversionRank getRank() const; |
| 109 | bool isPointerConversionToBool() const; |
Douglas Gregor | 1404650 | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 110 | bool isPointerConversionToVoidPointer(ASTContext& Context) const; |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 111 | void DebugPrint() const; |
| 112 | }; |
| 113 | |
| 114 | /// UserDefinedConversionSequence - Represents a user-defined |
| 115 | /// conversion sequence (C++ 13.3.3.1.2). |
| 116 | struct UserDefinedConversionSequence { |
| 117 | /// Before - Represents the standard conversion that occurs before |
| 118 | /// the actual user-defined conversion. (C++ 13.3.3.1.2p1): |
| 119 | /// |
| 120 | /// If the user-defined conversion is specified by a constructor |
| 121 | /// (12.3.1), the initial standard conversion sequence converts |
| 122 | /// the source type to the type required by the argument of the |
| 123 | /// constructor. If the user-defined conversion is specified by |
| 124 | /// a conversion function (12.3.2), the initial standard |
| 125 | /// conversion sequence converts the source type to the implicit |
| 126 | /// object parameter of the conversion function. |
| 127 | StandardConversionSequence Before; |
| 128 | |
| 129 | /// After - Represents the standard conversion that occurs after |
| 130 | /// the actual user-defined conversion. |
| 131 | StandardConversionSequence After; |
| 132 | |
| 133 | /// ConversionFunction - The function that will perform the |
| 134 | /// user-defined conversion. |
| 135 | FunctionDecl* ConversionFunction; |
| 136 | |
| 137 | void DebugPrint() const; |
| 138 | }; |
| 139 | |
| 140 | /// ImplicitConversionSequence - Represents an implicit conversion |
| 141 | /// sequence, which may be a standard conversion sequence |
| 142 | // (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2), |
| 143 | /// or an ellipsis conversion sequence (C++ 13.3.3.1.3). |
| 144 | struct ImplicitConversionSequence { |
| 145 | /// Kind - The kind of implicit conversion sequence. BadConversion |
| 146 | /// specifies that there is no conversion from the source type to |
| 147 | /// the target type. The enumerator values are ordered such that |
| 148 | /// better implicit conversions have smaller values. |
| 149 | enum Kind { |
| 150 | StandardConversion = 0, |
| 151 | UserDefinedConversion, |
| 152 | EllipsisConversion, |
| 153 | BadConversion |
| 154 | }; |
| 155 | |
| 156 | /// ConversionKind - The kind of implicit conversion sequence. |
| 157 | Kind ConversionKind; |
| 158 | |
| 159 | union { |
| 160 | /// When ConversionKind == StandardConversion, provides the |
| 161 | /// details of the standard conversion sequence. |
| 162 | StandardConversionSequence Standard; |
| 163 | |
| 164 | /// When ConversionKind == UserDefinedConversion, provides the |
| 165 | /// details of the user-defined conversion sequence. |
| 166 | UserDefinedConversionSequence UserDefined; |
| 167 | }; |
| 168 | |
| 169 | // The result of a comparison between implicit conversion |
| 170 | // sequences. Use Sema::CompareImplicitConversionSequences to |
| 171 | // actually perform the comparison. |
| 172 | enum CompareKind { |
Douglas Gregor | ccc0ccc | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 173 | Better = -1, |
| 174 | Indistinguishable = 0, |
| 175 | Worse = 1 |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | void DebugPrint() const; |
| 179 | }; |
| 180 | |
| 181 | /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). |
| 182 | struct OverloadCandidate { |
| 183 | /// Function - The actual function that this candidate represents. |
| 184 | FunctionDecl *Function; |
| 185 | |
| 186 | /// Conversions - The conversion sequences used to convert the |
| 187 | /// function arguments to the function parameters. |
| 188 | llvm::SmallVector<ImplicitConversionSequence, 4> Conversions; |
| 189 | |
| 190 | /// Viable - True to indicate that this overload candidate is viable. |
| 191 | bool Viable; |
| 192 | }; |
| 193 | |
| 194 | /// OverloadCandidateSet - A set of overload candidates, used in C++ |
| 195 | /// overload resolution (C++ 13.3). |
| 196 | typedef llvm::SmallVector<OverloadCandidate, 4> OverloadCandidateSet; |
| 197 | } // end namespace clang |
| 198 | |
| 199 | #endif // LLVM_CLANG_SEMA_OVERLOAD_H |