blob: 558718c0d94dcb2be1dd03e57050268fcdde5dbd [file] [log] [blame]
Douglas Gregord2baafd2008-10-21 16:13:35 +00001//===--- 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
20namespace 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)
Douglas Gregor2aecd1f2008-10-29 02:00:59 +000041 ICK_Derived_To_Base, ///< Derived-to-base (C++ [over.best.ics][)
Douglas Gregord2baafd2008-10-21 16:13:35 +000042 ICK_Num_Conversion_Kinds ///< The number of conversion kinds
43 };
44
45 /// ImplicitConversionCategory - The category of an implicit
46 /// conversion kind. The enumerator values match with Table 9 of
47 /// (C++ 13.3.3.1.1) and are listed such that better conversion
48 /// categories have smaller values.
49 enum ImplicitConversionCategory {
50 ICC_Identity = 0, ///< Identity
51 ICC_Lvalue_Transformation, ///< Lvalue transformation
52 ICC_Qualification_Adjustment, ///< Qualification adjustment
53 ICC_Promotion, ///< Promotion
54 ICC_Conversion ///< Conversion
55 };
56
57 ImplicitConversionCategory
58 GetConversionCategory(ImplicitConversionKind Kind);
59
60 /// ImplicitConversionRank - The rank of an implicit conversion
61 /// kind. The enumerator values match with Table 9 of (C++
62 /// 13.3.3.1.1) and are listed such that better conversion ranks
63 /// have smaller values.
64 enum ImplicitConversionRank {
65 ICR_Exact_Match = 0, ///< Exact Match
66 ICR_Promotion, ///< Promotion
67 ICR_Conversion ///< Conversion
68 };
69
70 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
71
72 /// StandardConversionSequence - represents a standard conversion
73 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
74 /// contains between zero and three conversions. If a particular
75 /// conversion is not needed, it will be set to the identity conversion
76 /// (ICK_Identity). Note that the three conversions are
77 /// specified as separate members (rather than in an array) so that
78 /// we can keep the size of a standard conversion sequence to a
79 /// single word.
80 struct StandardConversionSequence {
81 /// First -- The first conversion can be an lvalue-to-rvalue
82 /// conversion, array-to-pointer conversion, or
83 /// function-to-pointer conversion.
84 ImplicitConversionKind First : 8;
85
86 /// Second - The second conversion can be an integral promotion,
87 /// floating point promotion, integral conversion, floating point
88 /// conversion, floating-integral conversion, pointer conversion,
89 /// pointer-to-member conversion, or boolean conversion.
90 ImplicitConversionKind Second : 8;
91
92 /// Third - The third conversion can be a qualification conversion.
93 ImplicitConversionKind Third : 8;
94
Douglas Gregor2aecd1f2008-10-29 02:00:59 +000095 /// Deprecated - Whether this the deprecated conversion of a
96 /// string literal to a pointer to non-const character data
97 /// (C++ 4.2p2).
Douglas Gregord2baafd2008-10-21 16:13:35 +000098 bool Deprecated : 1;
99
100 /// FromType - The type that this conversion is converting
Douglas Gregor14046502008-10-23 00:40:37 +0000101 /// from. This is an opaque pointer that can be translated into a
102 /// QualType.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000103 void *FromTypePtr;
104
105 /// ToType - The type that this conversion is converting to. This
Douglas Gregor14046502008-10-23 00:40:37 +0000106 /// is an opaque pointer that can be translated into a QualType.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000107 void *ToTypePtr;
108
109 ImplicitConversionRank getRank() const;
110 bool isPointerConversionToBool() const;
Douglas Gregor14046502008-10-23 00:40:37 +0000111 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
Douglas Gregord2baafd2008-10-21 16:13:35 +0000112 void DebugPrint() const;
113 };
114
115 /// UserDefinedConversionSequence - Represents a user-defined
116 /// conversion sequence (C++ 13.3.3.1.2).
117 struct UserDefinedConversionSequence {
118 /// Before - Represents the standard conversion that occurs before
119 /// the actual user-defined conversion. (C++ 13.3.3.1.2p1):
120 ///
121 /// If the user-defined conversion is specified by a constructor
122 /// (12.3.1), the initial standard conversion sequence converts
123 /// the source type to the type required by the argument of the
124 /// constructor. If the user-defined conversion is specified by
125 /// a conversion function (12.3.2), the initial standard
126 /// conversion sequence converts the source type to the implicit
127 /// object parameter of the conversion function.
128 StandardConversionSequence Before;
129
130 /// After - Represents the standard conversion that occurs after
131 /// the actual user-defined conversion.
132 StandardConversionSequence After;
133
134 /// ConversionFunction - The function that will perform the
135 /// user-defined conversion.
136 FunctionDecl* ConversionFunction;
137
138 void DebugPrint() const;
139 };
140
141 /// ImplicitConversionSequence - Represents an implicit conversion
142 /// sequence, which may be a standard conversion sequence
143 // (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
144 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
145 struct ImplicitConversionSequence {
146 /// Kind - The kind of implicit conversion sequence. BadConversion
147 /// specifies that there is no conversion from the source type to
148 /// the target type. The enumerator values are ordered such that
149 /// better implicit conversions have smaller values.
150 enum Kind {
151 StandardConversion = 0,
152 UserDefinedConversion,
153 EllipsisConversion,
154 BadConversion
155 };
156
157 /// ConversionKind - The kind of implicit conversion sequence.
Douglas Gregor2aecd1f2008-10-29 02:00:59 +0000158 /// As usual, we use "unsigned" here because VC++ makes enum bitfields
159 /// signed.
160 unsigned ConversionKind : 2;
161
162 /// ReferenceBinding - True when this is a reference binding
163 /// (C++ [over.ics.ref]).
164 bool ReferenceBinding : 1;
165
166 /// DirectBinding - True when this is a reference binding that is a
167 /// direct binding (C++ [dcl.init.ref]).
168 bool DirectBinding : 1;
Douglas Gregord2baafd2008-10-21 16:13:35 +0000169
170 union {
171 /// When ConversionKind == StandardConversion, provides the
172 /// details of the standard conversion sequence.
173 StandardConversionSequence Standard;
174
175 /// When ConversionKind == UserDefinedConversion, provides the
176 /// details of the user-defined conversion sequence.
177 UserDefinedConversionSequence UserDefined;
178 };
179
180 // The result of a comparison between implicit conversion
181 // sequences. Use Sema::CompareImplicitConversionSequences to
182 // actually perform the comparison.
183 enum CompareKind {
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000184 Better = -1,
185 Indistinguishable = 0,
186 Worse = 1
Douglas Gregord2baafd2008-10-21 16:13:35 +0000187 };
188
189 void DebugPrint() const;
190 };
191
192 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
193 struct OverloadCandidate {
194 /// Function - The actual function that this candidate represents.
195 FunctionDecl *Function;
196
197 /// Conversions - The conversion sequences used to convert the
198 /// function arguments to the function parameters.
199 llvm::SmallVector<ImplicitConversionSequence, 4> Conversions;
200
201 /// Viable - True to indicate that this overload candidate is viable.
202 bool Viable;
203 };
204
205 /// OverloadCandidateSet - A set of overload candidates, used in C++
206 /// overload resolution (C++ 13.3).
207 typedef llvm::SmallVector<OverloadCandidate, 4> OverloadCandidateSet;
208} // end namespace clang
209
210#endif // LLVM_CLANG_SEMA_OVERLOAD_H