blob: c3fa425be7b21123eb3e976f692577df53a6a7fd [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
117 ImplicitConversionRank getRank() const;
118 bool isPointerConversionToBool() const;
Douglas Gregor14046502008-10-23 00:40:37 +0000119 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
Douglas Gregord2baafd2008-10-21 16:13:35 +0000120 void DebugPrint() const;
121 };
122
123 /// UserDefinedConversionSequence - Represents a user-defined
124 /// conversion sequence (C++ 13.3.3.1.2).
125 struct UserDefinedConversionSequence {
126 /// Before - Represents the standard conversion that occurs before
127 /// the actual user-defined conversion. (C++ 13.3.3.1.2p1):
128 ///
129 /// If the user-defined conversion is specified by a constructor
130 /// (12.3.1), the initial standard conversion sequence converts
131 /// the source type to the type required by the argument of the
132 /// constructor. If the user-defined conversion is specified by
133 /// a conversion function (12.3.2), the initial standard
134 /// conversion sequence converts the source type to the implicit
135 /// object parameter of the conversion function.
136 StandardConversionSequence Before;
137
138 /// After - Represents the standard conversion that occurs after
139 /// the actual user-defined conversion.
140 StandardConversionSequence After;
141
142 /// ConversionFunction - The function that will perform the
143 /// user-defined conversion.
144 FunctionDecl* ConversionFunction;
145
146 void DebugPrint() const;
147 };
148
149 /// ImplicitConversionSequence - Represents an implicit conversion
150 /// sequence, which may be a standard conversion sequence
151 // (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
152 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
153 struct ImplicitConversionSequence {
154 /// Kind - The kind of implicit conversion sequence. BadConversion
155 /// specifies that there is no conversion from the source type to
156 /// the target type. The enumerator values are ordered such that
157 /// better implicit conversions have smaller values.
158 enum Kind {
159 StandardConversion = 0,
160 UserDefinedConversion,
161 EllipsisConversion,
162 BadConversion
163 };
164
165 /// ConversionKind - The kind of implicit conversion sequence.
Douglas Gregor0e343382008-10-29 14:50:44 +0000166 Kind ConversionKind;
Douglas Gregord2baafd2008-10-21 16:13:35 +0000167
168 union {
169 /// When ConversionKind == StandardConversion, provides the
170 /// details of the standard conversion sequence.
171 StandardConversionSequence Standard;
172
173 /// When ConversionKind == UserDefinedConversion, provides the
174 /// details of the user-defined conversion sequence.
175 UserDefinedConversionSequence UserDefined;
176 };
177
178 // The result of a comparison between implicit conversion
179 // sequences. Use Sema::CompareImplicitConversionSequences to
180 // actually perform the comparison.
181 enum CompareKind {
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000182 Better = -1,
183 Indistinguishable = 0,
184 Worse = 1
Douglas Gregord2baafd2008-10-21 16:13:35 +0000185 };
186
187 void DebugPrint() const;
188 };
189
190 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
191 struct OverloadCandidate {
192 /// Function - The actual function that this candidate represents.
193 FunctionDecl *Function;
194
195 /// Conversions - The conversion sequences used to convert the
196 /// function arguments to the function parameters.
197 llvm::SmallVector<ImplicitConversionSequence, 4> Conversions;
198
199 /// Viable - True to indicate that this overload candidate is viable.
200 bool Viable;
201 };
202
203 /// OverloadCandidateSet - A set of overload candidates, used in C++
204 /// overload resolution (C++ 13.3).
205 typedef llvm::SmallVector<OverloadCandidate, 4> OverloadCandidateSet;
206} // end namespace clang
207
208#endif // LLVM_CLANG_SEMA_OVERLOAD_H