blob: 2fd6b1fb3e573544f91e807fa6ea72d4dc50cc73 [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
Douglas Gregor0e343382008-10-29 14:50:44 +0000100 /// ReferenceBinding - True when this is a reference binding
101 /// (C++ [over.ics.ref]).
102 bool ReferenceBinding : 1;
103
104 /// DirectBinding - True when this is a reference binding that is a
105 /// direct binding (C++ [dcl.init.ref]).
106 bool DirectBinding : 1;
107
Douglas Gregord2baafd2008-10-21 16:13:35 +0000108 /// FromType - The type that this conversion is converting
Douglas Gregor14046502008-10-23 00:40:37 +0000109 /// from. This is an opaque pointer that can be translated into a
110 /// QualType.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000111 void *FromTypePtr;
112
113 /// ToType - The type that this conversion is converting to. This
Douglas Gregor14046502008-10-23 00:40:37 +0000114 /// is an opaque pointer that can be translated into a QualType.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000115 void *ToTypePtr;
116
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000117 void setAsIdentityConversion();
Douglas Gregord2baafd2008-10-21 16:13:35 +0000118 ImplicitConversionRank getRank() const;
119 bool isPointerConversionToBool() const;
Douglas Gregor14046502008-10-23 00:40:37 +0000120 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
Douglas Gregord2baafd2008-10-21 16:13:35 +0000121 void DebugPrint() const;
122 };
123
124 /// UserDefinedConversionSequence - Represents a user-defined
125 /// conversion sequence (C++ 13.3.3.1.2).
126 struct UserDefinedConversionSequence {
127 /// Before - Represents the standard conversion that occurs before
128 /// the actual user-defined conversion. (C++ 13.3.3.1.2p1):
129 ///
130 /// If the user-defined conversion is specified by a constructor
131 /// (12.3.1), the initial standard conversion sequence converts
132 /// the source type to the type required by the argument of the
133 /// constructor. If the user-defined conversion is specified by
134 /// a conversion function (12.3.2), the initial standard
135 /// conversion sequence converts the source type to the implicit
136 /// object parameter of the conversion function.
137 StandardConversionSequence Before;
138
139 /// After - Represents the standard conversion that occurs after
140 /// the actual user-defined conversion.
141 StandardConversionSequence After;
142
143 /// ConversionFunction - The function that will perform the
144 /// user-defined conversion.
145 FunctionDecl* ConversionFunction;
146
147 void DebugPrint() const;
148 };
149
150 /// ImplicitConversionSequence - Represents an implicit conversion
151 /// sequence, which may be a standard conversion sequence
152 // (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
153 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
154 struct ImplicitConversionSequence {
155 /// Kind - The kind of implicit conversion sequence. BadConversion
156 /// specifies that there is no conversion from the source type to
157 /// the target type. The enumerator values are ordered such that
158 /// better implicit conversions have smaller values.
159 enum Kind {
160 StandardConversion = 0,
161 UserDefinedConversion,
162 EllipsisConversion,
163 BadConversion
164 };
165
166 /// ConversionKind - The kind of implicit conversion sequence.
Douglas Gregor0e343382008-10-29 14:50:44 +0000167 Kind ConversionKind;
Douglas Gregord2baafd2008-10-21 16:13:35 +0000168
169 union {
170 /// When ConversionKind == StandardConversion, provides the
171 /// details of the standard conversion sequence.
172 StandardConversionSequence Standard;
173
174 /// When ConversionKind == UserDefinedConversion, provides the
175 /// details of the user-defined conversion sequence.
176 UserDefinedConversionSequence UserDefined;
177 };
178
179 // The result of a comparison between implicit conversion
180 // sequences. Use Sema::CompareImplicitConversionSequences to
181 // actually perform the comparison.
182 enum CompareKind {
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000183 Better = -1,
184 Indistinguishable = 0,
185 Worse = 1
Douglas Gregord2baafd2008-10-21 16:13:35 +0000186 };
187
188 void DebugPrint() const;
189 };
190
191 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
192 struct OverloadCandidate {
193 /// Function - The actual function that this candidate represents.
194 FunctionDecl *Function;
195
196 /// Conversions - The conversion sequences used to convert the
197 /// function arguments to the function parameters.
198 llvm::SmallVector<ImplicitConversionSequence, 4> Conversions;
199
200 /// Viable - True to indicate that this overload candidate is viable.
201 bool Viable;
202 };
203
204 /// OverloadCandidateSet - A set of overload candidates, used in C++
205 /// overload resolution (C++ 13.3).
206 typedef llvm::SmallVector<OverloadCandidate, 4> OverloadCandidateSet;
207} // end namespace clang
208
209#endif // LLVM_CLANG_SEMA_OVERLOAD_H