File: | tools/clang/lib/AST/Expr.cpp |
Warning: | line 3208, column 24 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// | |||
2 | // | |||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
4 | // See https://llvm.org/LICENSE.txt for license information. | |||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This file implements the Expr class and subclasses. | |||
10 | // | |||
11 | //===----------------------------------------------------------------------===// | |||
12 | ||||
13 | #include "clang/AST/Expr.h" | |||
14 | #include "clang/AST/APValue.h" | |||
15 | #include "clang/AST/ASTContext.h" | |||
16 | #include "clang/AST/Attr.h" | |||
17 | #include "clang/AST/DeclCXX.h" | |||
18 | #include "clang/AST/DeclObjC.h" | |||
19 | #include "clang/AST/DeclTemplate.h" | |||
20 | #include "clang/AST/EvaluatedExprVisitor.h" | |||
21 | #include "clang/AST/ExprCXX.h" | |||
22 | #include "clang/AST/Mangle.h" | |||
23 | #include "clang/AST/RecordLayout.h" | |||
24 | #include "clang/AST/StmtVisitor.h" | |||
25 | #include "clang/Basic/Builtins.h" | |||
26 | #include "clang/Basic/CharInfo.h" | |||
27 | #include "clang/Basic/SourceManager.h" | |||
28 | #include "clang/Basic/TargetInfo.h" | |||
29 | #include "clang/Lex/Lexer.h" | |||
30 | #include "clang/Lex/LiteralSupport.h" | |||
31 | #include "llvm/Support/ErrorHandling.h" | |||
32 | #include "llvm/Support/raw_ostream.h" | |||
33 | #include <algorithm> | |||
34 | #include <cstring> | |||
35 | using namespace clang; | |||
36 | ||||
37 | const Expr *Expr::getBestDynamicClassTypeExpr() const { | |||
38 | const Expr *E = this; | |||
39 | while (true) { | |||
40 | E = E->ignoreParenBaseCasts(); | |||
41 | ||||
42 | // Follow the RHS of a comma operator. | |||
43 | if (auto *BO = dyn_cast<BinaryOperator>(E)) { | |||
44 | if (BO->getOpcode() == BO_Comma) { | |||
45 | E = BO->getRHS(); | |||
46 | continue; | |||
47 | } | |||
48 | } | |||
49 | ||||
50 | // Step into initializer for materialized temporaries. | |||
51 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) { | |||
52 | E = MTE->GetTemporaryExpr(); | |||
53 | continue; | |||
54 | } | |||
55 | ||||
56 | break; | |||
57 | } | |||
58 | ||||
59 | return E; | |||
60 | } | |||
61 | ||||
62 | const CXXRecordDecl *Expr::getBestDynamicClassType() const { | |||
63 | const Expr *E = getBestDynamicClassTypeExpr(); | |||
64 | QualType DerivedType = E->getType(); | |||
65 | if (const PointerType *PTy = DerivedType->getAs<PointerType>()) | |||
66 | DerivedType = PTy->getPointeeType(); | |||
67 | ||||
68 | if (DerivedType->isDependentType()) | |||
69 | return nullptr; | |||
70 | ||||
71 | const RecordType *Ty = DerivedType->castAs<RecordType>(); | |||
72 | Decl *D = Ty->getDecl(); | |||
73 | return cast<CXXRecordDecl>(D); | |||
74 | } | |||
75 | ||||
76 | const Expr *Expr::skipRValueSubobjectAdjustments( | |||
77 | SmallVectorImpl<const Expr *> &CommaLHSs, | |||
78 | SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { | |||
79 | const Expr *E = this; | |||
80 | while (true) { | |||
81 | E = E->IgnoreParens(); | |||
82 | ||||
83 | if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { | |||
84 | if ((CE->getCastKind() == CK_DerivedToBase || | |||
85 | CE->getCastKind() == CK_UncheckedDerivedToBase) && | |||
86 | E->getType()->isRecordType()) { | |||
87 | E = CE->getSubExpr(); | |||
88 | CXXRecordDecl *Derived | |||
89 | = cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl()); | |||
90 | Adjustments.push_back(SubobjectAdjustment(CE, Derived)); | |||
91 | continue; | |||
92 | } | |||
93 | ||||
94 | if (CE->getCastKind() == CK_NoOp) { | |||
95 | E = CE->getSubExpr(); | |||
96 | continue; | |||
97 | } | |||
98 | } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { | |||
99 | if (!ME->isArrow()) { | |||
100 | assert(ME->getBase()->getType()->isRecordType())((ME->getBase()->getType()->isRecordType()) ? static_cast <void> (0) : __assert_fail ("ME->getBase()->getType()->isRecordType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 100, __PRETTY_FUNCTION__)); | |||
101 | if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) { | |||
102 | if (!Field->isBitField() && !Field->getType()->isReferenceType()) { | |||
103 | E = ME->getBase(); | |||
104 | Adjustments.push_back(SubobjectAdjustment(Field)); | |||
105 | continue; | |||
106 | } | |||
107 | } | |||
108 | } | |||
109 | } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { | |||
110 | if (BO->getOpcode() == BO_PtrMemD) { | |||
111 | assert(BO->getRHS()->isRValue())((BO->getRHS()->isRValue()) ? static_cast<void> ( 0) : __assert_fail ("BO->getRHS()->isRValue()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 111, __PRETTY_FUNCTION__)); | |||
112 | E = BO->getLHS(); | |||
113 | const MemberPointerType *MPT = | |||
114 | BO->getRHS()->getType()->getAs<MemberPointerType>(); | |||
115 | Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); | |||
116 | continue; | |||
117 | } else if (BO->getOpcode() == BO_Comma) { | |||
118 | CommaLHSs.push_back(BO->getLHS()); | |||
119 | E = BO->getRHS(); | |||
120 | continue; | |||
121 | } | |||
122 | } | |||
123 | ||||
124 | // Nothing changed. | |||
125 | break; | |||
126 | } | |||
127 | return E; | |||
128 | } | |||
129 | ||||
130 | /// isKnownToHaveBooleanValue - Return true if this is an integer expression | |||
131 | /// that is known to return 0 or 1. This happens for _Bool/bool expressions | |||
132 | /// but also int expressions which are produced by things like comparisons in | |||
133 | /// C. | |||
134 | bool Expr::isKnownToHaveBooleanValue() const { | |||
135 | const Expr *E = IgnoreParens(); | |||
136 | ||||
137 | // If this value has _Bool type, it is obvious 0/1. | |||
138 | if (E->getType()->isBooleanType()) return true; | |||
139 | // If this is a non-scalar-integer type, we don't care enough to try. | |||
140 | if (!E->getType()->isIntegralOrEnumerationType()) return false; | |||
141 | ||||
142 | if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { | |||
143 | switch (UO->getOpcode()) { | |||
144 | case UO_Plus: | |||
145 | return UO->getSubExpr()->isKnownToHaveBooleanValue(); | |||
146 | case UO_LNot: | |||
147 | return true; | |||
148 | default: | |||
149 | return false; | |||
150 | } | |||
151 | } | |||
152 | ||||
153 | // Only look through implicit casts. If the user writes | |||
154 | // '(int) (a && b)' treat it as an arbitrary int. | |||
155 | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) | |||
156 | return CE->getSubExpr()->isKnownToHaveBooleanValue(); | |||
157 | ||||
158 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { | |||
159 | switch (BO->getOpcode()) { | |||
160 | default: return false; | |||
161 | case BO_LT: // Relational operators. | |||
162 | case BO_GT: | |||
163 | case BO_LE: | |||
164 | case BO_GE: | |||
165 | case BO_EQ: // Equality operators. | |||
166 | case BO_NE: | |||
167 | case BO_LAnd: // AND operator. | |||
168 | case BO_LOr: // Logical OR operator. | |||
169 | return true; | |||
170 | ||||
171 | case BO_And: // Bitwise AND operator. | |||
172 | case BO_Xor: // Bitwise XOR operator. | |||
173 | case BO_Or: // Bitwise OR operator. | |||
174 | // Handle things like (x==2)|(y==12). | |||
175 | return BO->getLHS()->isKnownToHaveBooleanValue() && | |||
176 | BO->getRHS()->isKnownToHaveBooleanValue(); | |||
177 | ||||
178 | case BO_Comma: | |||
179 | case BO_Assign: | |||
180 | return BO->getRHS()->isKnownToHaveBooleanValue(); | |||
181 | } | |||
182 | } | |||
183 | ||||
184 | if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) | |||
185 | return CO->getTrueExpr()->isKnownToHaveBooleanValue() && | |||
186 | CO->getFalseExpr()->isKnownToHaveBooleanValue(); | |||
187 | ||||
188 | if (isa<ObjCBoolLiteralExpr>(E)) | |||
189 | return true; | |||
190 | ||||
191 | if (const auto *OVE = dyn_cast<OpaqueValueExpr>(E)) | |||
192 | return OVE->getSourceExpr()->isKnownToHaveBooleanValue(); | |||
193 | ||||
194 | return false; | |||
195 | } | |||
196 | ||||
197 | // Amusing macro metaprogramming hack: check whether a class provides | |||
198 | // a more specific implementation of getExprLoc(). | |||
199 | // | |||
200 | // See also Stmt.cpp:{getBeginLoc(),getEndLoc()}. | |||
201 | namespace { | |||
202 | /// This implementation is used when a class provides a custom | |||
203 | /// implementation of getExprLoc. | |||
204 | template <class E, class T> | |||
205 | SourceLocation getExprLocImpl(const Expr *expr, | |||
206 | SourceLocation (T::*v)() const) { | |||
207 | return static_cast<const E*>(expr)->getExprLoc(); | |||
208 | } | |||
209 | ||||
210 | /// This implementation is used when a class doesn't provide | |||
211 | /// a custom implementation of getExprLoc. Overload resolution | |||
212 | /// should pick it over the implementation above because it's | |||
213 | /// more specialized according to function template partial ordering. | |||
214 | template <class E> | |||
215 | SourceLocation getExprLocImpl(const Expr *expr, | |||
216 | SourceLocation (Expr::*v)() const) { | |||
217 | return static_cast<const E *>(expr)->getBeginLoc(); | |||
218 | } | |||
219 | } | |||
220 | ||||
221 | SourceLocation Expr::getExprLoc() const { | |||
222 | switch (getStmtClass()) { | |||
223 | case Stmt::NoStmtClass: llvm_unreachable("statement without class")::llvm::llvm_unreachable_internal("statement without class", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 223); | |||
224 | #define ABSTRACT_STMT(type) | |||
225 | #define STMT(type, base) \ | |||
226 | case Stmt::type##Class: break; | |||
227 | #define EXPR(type, base) \ | |||
228 | case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); | |||
229 | #include "clang/AST/StmtNodes.inc" | |||
230 | } | |||
231 | llvm_unreachable("unknown expression kind")::llvm::llvm_unreachable_internal("unknown expression kind", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 231); | |||
232 | } | |||
233 | ||||
234 | //===----------------------------------------------------------------------===// | |||
235 | // Primary Expressions. | |||
236 | //===----------------------------------------------------------------------===// | |||
237 | ||||
238 | static void AssertResultStorageKind(ConstantExpr::ResultStorageKind Kind) { | |||
239 | assert((Kind == ConstantExpr::RSK_APValue ||(((Kind == ConstantExpr::RSK_APValue || Kind == ConstantExpr:: RSK_Int64 || Kind == ConstantExpr::RSK_None) && "Invalid StorageKind Value" ) ? static_cast<void> (0) : __assert_fail ("(Kind == ConstantExpr::RSK_APValue || Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) && \"Invalid StorageKind Value\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 241, __PRETTY_FUNCTION__)) | |||
240 | Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) &&(((Kind == ConstantExpr::RSK_APValue || Kind == ConstantExpr:: RSK_Int64 || Kind == ConstantExpr::RSK_None) && "Invalid StorageKind Value" ) ? static_cast<void> (0) : __assert_fail ("(Kind == ConstantExpr::RSK_APValue || Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) && \"Invalid StorageKind Value\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 241, __PRETTY_FUNCTION__)) | |||
241 | "Invalid StorageKind Value")(((Kind == ConstantExpr::RSK_APValue || Kind == ConstantExpr:: RSK_Int64 || Kind == ConstantExpr::RSK_None) && "Invalid StorageKind Value" ) ? static_cast<void> (0) : __assert_fail ("(Kind == ConstantExpr::RSK_APValue || Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) && \"Invalid StorageKind Value\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 241, __PRETTY_FUNCTION__)); | |||
242 | } | |||
243 | ||||
244 | ConstantExpr::ResultStorageKind | |||
245 | ConstantExpr::getStorageKind(const APValue &Value) { | |||
246 | switch (Value.getKind()) { | |||
247 | case APValue::None: | |||
248 | case APValue::Indeterminate: | |||
249 | return ConstantExpr::RSK_None; | |||
250 | case APValue::Int: | |||
251 | if (!Value.getInt().needsCleanup()) | |||
252 | return ConstantExpr::RSK_Int64; | |||
253 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | |||
254 | default: | |||
255 | return ConstantExpr::RSK_APValue; | |||
256 | } | |||
257 | } | |||
258 | ||||
259 | ConstantExpr::ResultStorageKind | |||
260 | ConstantExpr::getStorageKind(const Type *T, const ASTContext &Context) { | |||
261 | if (T->isIntegralOrEnumerationType() && Context.getTypeInfo(T).Width <= 64) | |||
262 | return ConstantExpr::RSK_Int64; | |||
263 | return ConstantExpr::RSK_APValue; | |||
264 | } | |||
265 | ||||
266 | void ConstantExpr::DefaultInit(ResultStorageKind StorageKind) { | |||
267 | ConstantExprBits.ResultKind = StorageKind; | |||
268 | ConstantExprBits.APValueKind = APValue::None; | |||
269 | ConstantExprBits.HasCleanup = false; | |||
270 | if (StorageKind == ConstantExpr::RSK_APValue) | |||
271 | ::new (getTrailingObjects<APValue>()) APValue(); | |||
272 | } | |||
273 | ||||
274 | ConstantExpr::ConstantExpr(Expr *subexpr, ResultStorageKind StorageKind) | |||
275 | : FullExpr(ConstantExprClass, subexpr) { | |||
276 | DefaultInit(StorageKind); | |||
277 | } | |||
278 | ||||
279 | ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E, | |||
280 | ResultStorageKind StorageKind) { | |||
281 | assert(!isa<ConstantExpr>(E))((!isa<ConstantExpr>(E)) ? static_cast<void> (0) : __assert_fail ("!isa<ConstantExpr>(E)", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 281, __PRETTY_FUNCTION__)); | |||
282 | AssertResultStorageKind(StorageKind); | |||
283 | unsigned Size = totalSizeToAlloc<APValue, uint64_t>( | |||
284 | StorageKind == ConstantExpr::RSK_APValue, | |||
285 | StorageKind == ConstantExpr::RSK_Int64); | |||
286 | void *Mem = Context.Allocate(Size, alignof(ConstantExpr)); | |||
287 | ConstantExpr *Self = new (Mem) ConstantExpr(E, StorageKind); | |||
288 | return Self; | |||
289 | } | |||
290 | ||||
291 | ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E, | |||
292 | const APValue &Result) { | |||
293 | ResultStorageKind StorageKind = getStorageKind(Result); | |||
294 | ConstantExpr *Self = Create(Context, E, StorageKind); | |||
295 | Self->SetResult(Result, Context); | |||
296 | return Self; | |||
297 | } | |||
298 | ||||
299 | ConstantExpr::ConstantExpr(ResultStorageKind StorageKind, EmptyShell Empty) | |||
300 | : FullExpr(ConstantExprClass, Empty) { | |||
301 | DefaultInit(StorageKind); | |||
302 | } | |||
303 | ||||
304 | ConstantExpr *ConstantExpr::CreateEmpty(const ASTContext &Context, | |||
305 | ResultStorageKind StorageKind, | |||
306 | EmptyShell Empty) { | |||
307 | AssertResultStorageKind(StorageKind); | |||
308 | unsigned Size = totalSizeToAlloc<APValue, uint64_t>( | |||
309 | StorageKind == ConstantExpr::RSK_APValue, | |||
310 | StorageKind == ConstantExpr::RSK_Int64); | |||
311 | void *Mem = Context.Allocate(Size, alignof(ConstantExpr)); | |||
312 | ConstantExpr *Self = new (Mem) ConstantExpr(StorageKind, Empty); | |||
313 | return Self; | |||
314 | } | |||
315 | ||||
316 | void ConstantExpr::MoveIntoResult(APValue &Value, const ASTContext &Context) { | |||
317 | assert(getStorageKind(Value) == ConstantExprBits.ResultKind &&((getStorageKind(Value) == ConstantExprBits.ResultKind && "Invalid storage for this value kind") ? static_cast<void > (0) : __assert_fail ("getStorageKind(Value) == ConstantExprBits.ResultKind && \"Invalid storage for this value kind\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 318, __PRETTY_FUNCTION__)) | |||
318 | "Invalid storage for this value kind")((getStorageKind(Value) == ConstantExprBits.ResultKind && "Invalid storage for this value kind") ? static_cast<void > (0) : __assert_fail ("getStorageKind(Value) == ConstantExprBits.ResultKind && \"Invalid storage for this value kind\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 318, __PRETTY_FUNCTION__)); | |||
319 | ConstantExprBits.APValueKind = Value.getKind(); | |||
320 | switch (ConstantExprBits.ResultKind) { | |||
321 | case RSK_None: | |||
322 | return; | |||
323 | case RSK_Int64: | |||
324 | Int64Result() = *Value.getInt().getRawData(); | |||
325 | ConstantExprBits.BitWidth = Value.getInt().getBitWidth(); | |||
326 | ConstantExprBits.IsUnsigned = Value.getInt().isUnsigned(); | |||
327 | return; | |||
328 | case RSK_APValue: | |||
329 | if (!ConstantExprBits.HasCleanup && Value.needsCleanup()) { | |||
330 | ConstantExprBits.HasCleanup = true; | |||
331 | Context.addDestruction(&APValueResult()); | |||
332 | } | |||
333 | APValueResult() = std::move(Value); | |||
334 | return; | |||
335 | } | |||
336 | llvm_unreachable("Invalid ResultKind Bits")::llvm::llvm_unreachable_internal("Invalid ResultKind Bits", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 336); | |||
337 | } | |||
338 | ||||
339 | llvm::APSInt ConstantExpr::getResultAsAPSInt() const { | |||
340 | switch (ConstantExprBits.ResultKind) { | |||
341 | case ConstantExpr::RSK_APValue: | |||
342 | return APValueResult().getInt(); | |||
343 | case ConstantExpr::RSK_Int64: | |||
344 | return llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()), | |||
345 | ConstantExprBits.IsUnsigned); | |||
346 | default: | |||
347 | llvm_unreachable("invalid Accessor")::llvm::llvm_unreachable_internal("invalid Accessor", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 347); | |||
348 | } | |||
349 | } | |||
350 | ||||
351 | APValue ConstantExpr::getAPValueResult() const { | |||
352 | switch (ConstantExprBits.ResultKind) { | |||
353 | case ConstantExpr::RSK_APValue: | |||
354 | return APValueResult(); | |||
355 | case ConstantExpr::RSK_Int64: | |||
356 | return APValue( | |||
357 | llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()), | |||
358 | ConstantExprBits.IsUnsigned)); | |||
359 | case ConstantExpr::RSK_None: | |||
360 | return APValue(); | |||
361 | } | |||
362 | llvm_unreachable("invalid ResultKind")::llvm::llvm_unreachable_internal("invalid ResultKind", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 362); | |||
363 | } | |||
364 | ||||
365 | /// Compute the type-, value-, and instantiation-dependence of a | |||
366 | /// declaration reference | |||
367 | /// based on the declaration being referenced. | |||
368 | static void computeDeclRefDependence(const ASTContext &Ctx, NamedDecl *D, | |||
369 | QualType T, bool &TypeDependent, | |||
370 | bool &ValueDependent, | |||
371 | bool &InstantiationDependent) { | |||
372 | TypeDependent = false; | |||
373 | ValueDependent = false; | |||
374 | InstantiationDependent = false; | |||
375 | ||||
376 | // (TD) C++ [temp.dep.expr]p3: | |||
377 | // An id-expression is type-dependent if it contains: | |||
378 | // | |||
379 | // and | |||
380 | // | |||
381 | // (VD) C++ [temp.dep.constexpr]p2: | |||
382 | // An identifier is value-dependent if it is: | |||
383 | ||||
384 | // (TD) - an identifier that was declared with dependent type | |||
385 | // (VD) - a name declared with a dependent type, | |||
386 | if (T->isDependentType()) { | |||
387 | TypeDependent = true; | |||
388 | ValueDependent = true; | |||
389 | InstantiationDependent = true; | |||
390 | return; | |||
391 | } else if (T->isInstantiationDependentType()) { | |||
392 | InstantiationDependent = true; | |||
393 | } | |||
394 | ||||
395 | // (TD) - a conversion-function-id that specifies a dependent type | |||
396 | if (D->getDeclName().getNameKind() | |||
397 | == DeclarationName::CXXConversionFunctionName) { | |||
398 | QualType T = D->getDeclName().getCXXNameType(); | |||
399 | if (T->isDependentType()) { | |||
400 | TypeDependent = true; | |||
401 | ValueDependent = true; | |||
402 | InstantiationDependent = true; | |||
403 | return; | |||
404 | } | |||
405 | ||||
406 | if (T->isInstantiationDependentType()) | |||
407 | InstantiationDependent = true; | |||
408 | } | |||
409 | ||||
410 | // (VD) - the name of a non-type template parameter, | |||
411 | if (isa<NonTypeTemplateParmDecl>(D)) { | |||
412 | ValueDependent = true; | |||
413 | InstantiationDependent = true; | |||
414 | return; | |||
415 | } | |||
416 | ||||
417 | // (VD) - a constant with integral or enumeration type and is | |||
418 | // initialized with an expression that is value-dependent. | |||
419 | // (VD) - a constant with literal type and is initialized with an | |||
420 | // expression that is value-dependent [C++11]. | |||
421 | // (VD) - FIXME: Missing from the standard: | |||
422 | // - an entity with reference type and is initialized with an | |||
423 | // expression that is value-dependent [C++11] | |||
424 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) { | |||
425 | if ((Ctx.getLangOpts().CPlusPlus11 ? | |||
426 | Var->getType()->isLiteralType(Ctx) : | |||
427 | Var->getType()->isIntegralOrEnumerationType()) && | |||
428 | (Var->getType().isConstQualified() || | |||
429 | Var->getType()->isReferenceType())) { | |||
430 | if (const Expr *Init = Var->getAnyInitializer()) | |||
431 | if (Init->isValueDependent()) { | |||
432 | ValueDependent = true; | |||
433 | InstantiationDependent = true; | |||
434 | } | |||
435 | } | |||
436 | ||||
437 | // (VD) - FIXME: Missing from the standard: | |||
438 | // - a member function or a static data member of the current | |||
439 | // instantiation | |||
440 | if (Var->isStaticDataMember() && | |||
441 | Var->getDeclContext()->isDependentContext()) { | |||
442 | ValueDependent = true; | |||
443 | InstantiationDependent = true; | |||
444 | TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo(); | |||
445 | if (TInfo->getType()->isIncompleteArrayType()) | |||
446 | TypeDependent = true; | |||
447 | } | |||
448 | ||||
449 | return; | |||
450 | } | |||
451 | ||||
452 | // (VD) - FIXME: Missing from the standard: | |||
453 | // - a member function or a static data member of the current | |||
454 | // instantiation | |||
455 | if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { | |||
456 | ValueDependent = true; | |||
457 | InstantiationDependent = true; | |||
458 | } | |||
459 | } | |||
460 | ||||
461 | void DeclRefExpr::computeDependence(const ASTContext &Ctx) { | |||
462 | bool TypeDependent = false; | |||
463 | bool ValueDependent = false; | |||
464 | bool InstantiationDependent = false; | |||
465 | computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent, | |||
466 | ValueDependent, InstantiationDependent); | |||
467 | ||||
468 | ExprBits.TypeDependent |= TypeDependent; | |||
469 | ExprBits.ValueDependent |= ValueDependent; | |||
470 | ExprBits.InstantiationDependent |= InstantiationDependent; | |||
471 | ||||
472 | // Is the declaration a parameter pack? | |||
473 | if (getDecl()->isParameterPack()) | |||
474 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
475 | } | |||
476 | ||||
477 | DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, ValueDecl *D, | |||
478 | bool RefersToEnclosingVariableOrCapture, QualType T, | |||
479 | ExprValueKind VK, SourceLocation L, | |||
480 | const DeclarationNameLoc &LocInfo, | |||
481 | NonOdrUseReason NOUR) | |||
482 | : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), | |||
483 | D(D), DNLoc(LocInfo) { | |||
484 | DeclRefExprBits.HasQualifier = false; | |||
485 | DeclRefExprBits.HasTemplateKWAndArgsInfo = false; | |||
486 | DeclRefExprBits.HasFoundDecl = false; | |||
487 | DeclRefExprBits.HadMultipleCandidates = false; | |||
488 | DeclRefExprBits.RefersToEnclosingVariableOrCapture = | |||
489 | RefersToEnclosingVariableOrCapture; | |||
490 | DeclRefExprBits.NonOdrUseReason = NOUR; | |||
491 | DeclRefExprBits.Loc = L; | |||
492 | computeDependence(Ctx); | |||
493 | } | |||
494 | ||||
495 | DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, | |||
496 | NestedNameSpecifierLoc QualifierLoc, | |||
497 | SourceLocation TemplateKWLoc, ValueDecl *D, | |||
498 | bool RefersToEnclosingVariableOrCapture, | |||
499 | const DeclarationNameInfo &NameInfo, NamedDecl *FoundD, | |||
500 | const TemplateArgumentListInfo *TemplateArgs, | |||
501 | QualType T, ExprValueKind VK, NonOdrUseReason NOUR) | |||
502 | : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), | |||
503 | D(D), DNLoc(NameInfo.getInfo()) { | |||
504 | DeclRefExprBits.Loc = NameInfo.getLoc(); | |||
505 | DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; | |||
506 | if (QualifierLoc) { | |||
507 | new (getTrailingObjects<NestedNameSpecifierLoc>()) | |||
508 | NestedNameSpecifierLoc(QualifierLoc); | |||
509 | auto *NNS = QualifierLoc.getNestedNameSpecifier(); | |||
510 | if (NNS->isInstantiationDependent()) | |||
511 | ExprBits.InstantiationDependent = true; | |||
512 | if (NNS->containsUnexpandedParameterPack()) | |||
513 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
514 | } | |||
515 | DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; | |||
516 | if (FoundD) | |||
517 | *getTrailingObjects<NamedDecl *>() = FoundD; | |||
518 | DeclRefExprBits.HasTemplateKWAndArgsInfo | |||
519 | = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0; | |||
520 | DeclRefExprBits.RefersToEnclosingVariableOrCapture = | |||
521 | RefersToEnclosingVariableOrCapture; | |||
522 | DeclRefExprBits.NonOdrUseReason = NOUR; | |||
523 | if (TemplateArgs) { | |||
524 | bool Dependent = false; | |||
525 | bool InstantiationDependent = false; | |||
526 | bool ContainsUnexpandedParameterPack = false; | |||
527 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( | |||
528 | TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(), | |||
529 | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); | |||
530 | assert(!Dependent && "built a DeclRefExpr with dependent template args")((!Dependent && "built a DeclRefExpr with dependent template args" ) ? static_cast<void> (0) : __assert_fail ("!Dependent && \"built a DeclRefExpr with dependent template args\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 530, __PRETTY_FUNCTION__)); | |||
531 | ExprBits.InstantiationDependent |= InstantiationDependent; | |||
532 | ExprBits.ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack; | |||
533 | } else if (TemplateKWLoc.isValid()) { | |||
534 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( | |||
535 | TemplateKWLoc); | |||
536 | } | |||
537 | DeclRefExprBits.HadMultipleCandidates = 0; | |||
538 | ||||
539 | computeDependence(Ctx); | |||
540 | } | |||
541 | ||||
542 | DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, | |||
543 | NestedNameSpecifierLoc QualifierLoc, | |||
544 | SourceLocation TemplateKWLoc, ValueDecl *D, | |||
545 | bool RefersToEnclosingVariableOrCapture, | |||
546 | SourceLocation NameLoc, QualType T, | |||
547 | ExprValueKind VK, NamedDecl *FoundD, | |||
548 | const TemplateArgumentListInfo *TemplateArgs, | |||
549 | NonOdrUseReason NOUR) { | |||
550 | return Create(Context, QualifierLoc, TemplateKWLoc, D, | |||
551 | RefersToEnclosingVariableOrCapture, | |||
552 | DeclarationNameInfo(D->getDeclName(), NameLoc), | |||
553 | T, VK, FoundD, TemplateArgs, NOUR); | |||
554 | } | |||
555 | ||||
556 | DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, | |||
557 | NestedNameSpecifierLoc QualifierLoc, | |||
558 | SourceLocation TemplateKWLoc, ValueDecl *D, | |||
559 | bool RefersToEnclosingVariableOrCapture, | |||
560 | const DeclarationNameInfo &NameInfo, | |||
561 | QualType T, ExprValueKind VK, | |||
562 | NamedDecl *FoundD, | |||
563 | const TemplateArgumentListInfo *TemplateArgs, | |||
564 | NonOdrUseReason NOUR) { | |||
565 | // Filter out cases where the found Decl is the same as the value refenenced. | |||
566 | if (D == FoundD) | |||
567 | FoundD = nullptr; | |||
568 | ||||
569 | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); | |||
570 | std::size_t Size = | |||
571 | totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *, | |||
572 | ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( | |||
573 | QualifierLoc ? 1 : 0, FoundD ? 1 : 0, | |||
574 | HasTemplateKWAndArgsInfo ? 1 : 0, | |||
575 | TemplateArgs ? TemplateArgs->size() : 0); | |||
576 | ||||
577 | void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); | |||
578 | return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, | |||
579 | RefersToEnclosingVariableOrCapture, NameInfo, | |||
580 | FoundD, TemplateArgs, T, VK, NOUR); | |||
581 | } | |||
582 | ||||
583 | DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext &Context, | |||
584 | bool HasQualifier, | |||
585 | bool HasFoundDecl, | |||
586 | bool HasTemplateKWAndArgsInfo, | |||
587 | unsigned NumTemplateArgs) { | |||
588 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo)((NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo) ? static_cast <void> (0) : __assert_fail ("NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 588, __PRETTY_FUNCTION__)); | |||
589 | std::size_t Size = | |||
590 | totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *, | |||
591 | ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( | |||
592 | HasQualifier ? 1 : 0, HasFoundDecl ? 1 : 0, HasTemplateKWAndArgsInfo, | |||
593 | NumTemplateArgs); | |||
594 | void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); | |||
595 | return new (Mem) DeclRefExpr(EmptyShell()); | |||
596 | } | |||
597 | ||||
598 | SourceLocation DeclRefExpr::getBeginLoc() const { | |||
599 | if (hasQualifier()) | |||
600 | return getQualifierLoc().getBeginLoc(); | |||
601 | return getNameInfo().getBeginLoc(); | |||
602 | } | |||
603 | SourceLocation DeclRefExpr::getEndLoc() const { | |||
604 | if (hasExplicitTemplateArgs()) | |||
605 | return getRAngleLoc(); | |||
606 | return getNameInfo().getEndLoc(); | |||
607 | } | |||
608 | ||||
609 | PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK, | |||
610 | StringLiteral *SL) | |||
611 | : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary, | |||
612 | FNTy->isDependentType(), FNTy->isDependentType(), | |||
613 | FNTy->isInstantiationDependentType(), | |||
614 | /*ContainsUnexpandedParameterPack=*/false) { | |||
615 | PredefinedExprBits.Kind = IK; | |||
616 | assert((getIdentKind() == IK) &&(((getIdentKind() == IK) && "IdentKind do not fit in PredefinedExprBitfields!" ) ? static_cast<void> (0) : __assert_fail ("(getIdentKind() == IK) && \"IdentKind do not fit in PredefinedExprBitfields!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 617, __PRETTY_FUNCTION__)) | |||
617 | "IdentKind do not fit in PredefinedExprBitfields!")(((getIdentKind() == IK) && "IdentKind do not fit in PredefinedExprBitfields!" ) ? static_cast<void> (0) : __assert_fail ("(getIdentKind() == IK) && \"IdentKind do not fit in PredefinedExprBitfields!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 617, __PRETTY_FUNCTION__)); | |||
618 | bool HasFunctionName = SL != nullptr; | |||
619 | PredefinedExprBits.HasFunctionName = HasFunctionName; | |||
620 | PredefinedExprBits.Loc = L; | |||
621 | if (HasFunctionName) | |||
622 | setFunctionName(SL); | |||
623 | } | |||
624 | ||||
625 | PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName) | |||
626 | : Expr(PredefinedExprClass, Empty) { | |||
627 | PredefinedExprBits.HasFunctionName = HasFunctionName; | |||
628 | } | |||
629 | ||||
630 | PredefinedExpr *PredefinedExpr::Create(const ASTContext &Ctx, SourceLocation L, | |||
631 | QualType FNTy, IdentKind IK, | |||
632 | StringLiteral *SL) { | |||
633 | bool HasFunctionName = SL != nullptr; | |||
634 | void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName), | |||
635 | alignof(PredefinedExpr)); | |||
636 | return new (Mem) PredefinedExpr(L, FNTy, IK, SL); | |||
637 | } | |||
638 | ||||
639 | PredefinedExpr *PredefinedExpr::CreateEmpty(const ASTContext &Ctx, | |||
640 | bool HasFunctionName) { | |||
641 | void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName), | |||
642 | alignof(PredefinedExpr)); | |||
643 | return new (Mem) PredefinedExpr(EmptyShell(), HasFunctionName); | |||
644 | } | |||
645 | ||||
646 | StringRef PredefinedExpr::getIdentKindName(PredefinedExpr::IdentKind IK) { | |||
647 | switch (IK) { | |||
648 | case Func: | |||
649 | return "__func__"; | |||
650 | case Function: | |||
651 | return "__FUNCTION__"; | |||
652 | case FuncDName: | |||
653 | return "__FUNCDNAME__"; | |||
654 | case LFunction: | |||
655 | return "L__FUNCTION__"; | |||
656 | case PrettyFunction: | |||
657 | return "__PRETTY_FUNCTION__"; | |||
658 | case FuncSig: | |||
659 | return "__FUNCSIG__"; | |||
660 | case LFuncSig: | |||
661 | return "L__FUNCSIG__"; | |||
662 | case PrettyFunctionNoVirtual: | |||
663 | break; | |||
664 | } | |||
665 | llvm_unreachable("Unknown ident kind for PredefinedExpr")::llvm::llvm_unreachable_internal("Unknown ident kind for PredefinedExpr" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 665); | |||
666 | } | |||
667 | ||||
668 | // FIXME: Maybe this should use DeclPrinter with a special "print predefined | |||
669 | // expr" policy instead. | |||
670 | std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { | |||
671 | ASTContext &Context = CurrentDecl->getASTContext(); | |||
672 | ||||
673 | if (IK == PredefinedExpr::FuncDName) { | |||
674 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) { | |||
675 | std::unique_ptr<MangleContext> MC; | |||
676 | MC.reset(Context.createMangleContext()); | |||
677 | ||||
678 | if (MC->shouldMangleDeclName(ND)) { | |||
679 | SmallString<256> Buffer; | |||
680 | llvm::raw_svector_ostream Out(Buffer); | |||
681 | if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND)) | |||
682 | MC->mangleCXXCtor(CD, Ctor_Base, Out); | |||
683 | else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND)) | |||
684 | MC->mangleCXXDtor(DD, Dtor_Base, Out); | |||
685 | else | |||
686 | MC->mangleName(ND, Out); | |||
687 | ||||
688 | if (!Buffer.empty() && Buffer.front() == '\01') | |||
689 | return Buffer.substr(1); | |||
690 | return Buffer.str(); | |||
691 | } else | |||
692 | return ND->getIdentifier()->getName(); | |||
693 | } | |||
694 | return ""; | |||
695 | } | |||
696 | if (isa<BlockDecl>(CurrentDecl)) { | |||
697 | // For blocks we only emit something if it is enclosed in a function | |||
698 | // For top-level block we'd like to include the name of variable, but we | |||
699 | // don't have it at this point. | |||
700 | auto DC = CurrentDecl->getDeclContext(); | |||
701 | if (DC->isFileContext()) | |||
702 | return ""; | |||
703 | ||||
704 | SmallString<256> Buffer; | |||
705 | llvm::raw_svector_ostream Out(Buffer); | |||
706 | if (auto *DCBlock = dyn_cast<BlockDecl>(DC)) | |||
707 | // For nested blocks, propagate up to the parent. | |||
708 | Out << ComputeName(IK, DCBlock); | |||
709 | else if (auto *DCDecl = dyn_cast<Decl>(DC)) | |||
710 | Out << ComputeName(IK, DCDecl) << "_block_invoke"; | |||
711 | return Out.str(); | |||
712 | } | |||
713 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { | |||
714 | if (IK != PrettyFunction && IK != PrettyFunctionNoVirtual && | |||
715 | IK != FuncSig && IK != LFuncSig) | |||
716 | return FD->getNameAsString(); | |||
717 | ||||
718 | SmallString<256> Name; | |||
719 | llvm::raw_svector_ostream Out(Name); | |||
720 | ||||
721 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { | |||
722 | if (MD->isVirtual() && IK != PrettyFunctionNoVirtual) | |||
723 | Out << "virtual "; | |||
724 | if (MD->isStatic()) | |||
725 | Out << "static "; | |||
726 | } | |||
727 | ||||
728 | PrintingPolicy Policy(Context.getLangOpts()); | |||
729 | std::string Proto; | |||
730 | llvm::raw_string_ostream POut(Proto); | |||
731 | ||||
732 | const FunctionDecl *Decl = FD; | |||
733 | if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) | |||
734 | Decl = Pattern; | |||
735 | const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); | |||
736 | const FunctionProtoType *FT = nullptr; | |||
737 | if (FD->hasWrittenPrototype()) | |||
738 | FT = dyn_cast<FunctionProtoType>(AFT); | |||
739 | ||||
740 | if (IK == FuncSig || IK == LFuncSig) { | |||
741 | switch (AFT->getCallConv()) { | |||
742 | case CC_C: POut << "__cdecl "; break; | |||
743 | case CC_X86StdCall: POut << "__stdcall "; break; | |||
744 | case CC_X86FastCall: POut << "__fastcall "; break; | |||
745 | case CC_X86ThisCall: POut << "__thiscall "; break; | |||
746 | case CC_X86VectorCall: POut << "__vectorcall "; break; | |||
747 | case CC_X86RegCall: POut << "__regcall "; break; | |||
748 | // Only bother printing the conventions that MSVC knows about. | |||
749 | default: break; | |||
750 | } | |||
751 | } | |||
752 | ||||
753 | FD->printQualifiedName(POut, Policy); | |||
754 | ||||
755 | POut << "("; | |||
756 | if (FT) { | |||
757 | for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) { | |||
758 | if (i) POut << ", "; | |||
759 | POut << Decl->getParamDecl(i)->getType().stream(Policy); | |||
760 | } | |||
761 | ||||
762 | if (FT->isVariadic()) { | |||
763 | if (FD->getNumParams()) POut << ", "; | |||
764 | POut << "..."; | |||
765 | } else if ((IK == FuncSig || IK == LFuncSig || | |||
766 | !Context.getLangOpts().CPlusPlus) && | |||
767 | !Decl->getNumParams()) { | |||
768 | POut << "void"; | |||
769 | } | |||
770 | } | |||
771 | POut << ")"; | |||
772 | ||||
773 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { | |||
774 | assert(FT && "We must have a written prototype in this case.")((FT && "We must have a written prototype in this case." ) ? static_cast<void> (0) : __assert_fail ("FT && \"We must have a written prototype in this case.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 774, __PRETTY_FUNCTION__)); | |||
775 | if (FT->isConst()) | |||
776 | POut << " const"; | |||
777 | if (FT->isVolatile()) | |||
778 | POut << " volatile"; | |||
779 | RefQualifierKind Ref = MD->getRefQualifier(); | |||
780 | if (Ref == RQ_LValue) | |||
781 | POut << " &"; | |||
782 | else if (Ref == RQ_RValue) | |||
783 | POut << " &&"; | |||
784 | } | |||
785 | ||||
786 | typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; | |||
787 | SpecsTy Specs; | |||
788 | const DeclContext *Ctx = FD->getDeclContext(); | |||
789 | while (Ctx && isa<NamedDecl>(Ctx)) { | |||
790 | const ClassTemplateSpecializationDecl *Spec | |||
791 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); | |||
792 | if (Spec && !Spec->isExplicitSpecialization()) | |||
793 | Specs.push_back(Spec); | |||
794 | Ctx = Ctx->getParent(); | |||
795 | } | |||
796 | ||||
797 | std::string TemplateParams; | |||
798 | llvm::raw_string_ostream TOut(TemplateParams); | |||
799 | for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend(); | |||
800 | I != E; ++I) { | |||
801 | const TemplateParameterList *Params | |||
802 | = (*I)->getSpecializedTemplate()->getTemplateParameters(); | |||
803 | const TemplateArgumentList &Args = (*I)->getTemplateArgs(); | |||
804 | assert(Params->size() == Args.size())((Params->size() == Args.size()) ? static_cast<void> (0) : __assert_fail ("Params->size() == Args.size()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 804, __PRETTY_FUNCTION__)); | |||
805 | for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) { | |||
806 | StringRef Param = Params->getParam(i)->getName(); | |||
807 | if (Param.empty()) continue; | |||
808 | TOut << Param << " = "; | |||
809 | Args.get(i).print(Policy, TOut); | |||
810 | TOut << ", "; | |||
811 | } | |||
812 | } | |||
813 | ||||
814 | FunctionTemplateSpecializationInfo *FSI | |||
815 | = FD->getTemplateSpecializationInfo(); | |||
816 | if (FSI && !FSI->isExplicitSpecialization()) { | |||
817 | const TemplateParameterList* Params | |||
818 | = FSI->getTemplate()->getTemplateParameters(); | |||
819 | const TemplateArgumentList* Args = FSI->TemplateArguments; | |||
820 | assert(Params->size() == Args->size())((Params->size() == Args->size()) ? static_cast<void > (0) : __assert_fail ("Params->size() == Args->size()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 820, __PRETTY_FUNCTION__)); | |||
821 | for (unsigned i = 0, e = Params->size(); i != e; ++i) { | |||
822 | StringRef Param = Params->getParam(i)->getName(); | |||
823 | if (Param.empty()) continue; | |||
824 | TOut << Param << " = "; | |||
825 | Args->get(i).print(Policy, TOut); | |||
826 | TOut << ", "; | |||
827 | } | |||
828 | } | |||
829 | ||||
830 | TOut.flush(); | |||
831 | if (!TemplateParams.empty()) { | |||
832 | // remove the trailing comma and space | |||
833 | TemplateParams.resize(TemplateParams.size() - 2); | |||
834 | POut << " [" << TemplateParams << "]"; | |||
835 | } | |||
836 | ||||
837 | POut.flush(); | |||
838 | ||||
839 | // Print "auto" for all deduced return types. This includes C++1y return | |||
840 | // type deduction and lambdas. For trailing return types resolve the | |||
841 | // decltype expression. Otherwise print the real type when this is | |||
842 | // not a constructor or destructor. | |||
843 | if (isa<CXXMethodDecl>(FD) && | |||
844 | cast<CXXMethodDecl>(FD)->getParent()->isLambda()) | |||
845 | Proto = "auto " + Proto; | |||
846 | else if (FT && FT->getReturnType()->getAs<DecltypeType>()) | |||
847 | FT->getReturnType() | |||
848 | ->getAs<DecltypeType>() | |||
849 | ->getUnderlyingType() | |||
850 | .getAsStringInternal(Proto, Policy); | |||
851 | else if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) | |||
852 | AFT->getReturnType().getAsStringInternal(Proto, Policy); | |||
853 | ||||
854 | Out << Proto; | |||
855 | ||||
856 | return Name.str().str(); | |||
857 | } | |||
858 | if (const CapturedDecl *CD = dyn_cast<CapturedDecl>(CurrentDecl)) { | |||
859 | for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent()) | |||
860 | // Skip to its enclosing function or method, but not its enclosing | |||
861 | // CapturedDecl. | |||
862 | if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) { | |||
863 | const Decl *D = Decl::castFromDeclContext(DC); | |||
864 | return ComputeName(IK, D); | |||
865 | } | |||
866 | llvm_unreachable("CapturedDecl not inside a function or method")::llvm::llvm_unreachable_internal("CapturedDecl not inside a function or method" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 866); | |||
867 | } | |||
868 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { | |||
869 | SmallString<256> Name; | |||
870 | llvm::raw_svector_ostream Out(Name); | |||
871 | Out << (MD->isInstanceMethod() ? '-' : '+'); | |||
872 | Out << '['; | |||
873 | ||||
874 | // For incorrect code, there might not be an ObjCInterfaceDecl. Do | |||
875 | // a null check to avoid a crash. | |||
876 | if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) | |||
877 | Out << *ID; | |||
878 | ||||
879 | if (const ObjCCategoryImplDecl *CID = | |||
880 | dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) | |||
881 | Out << '(' << *CID << ')'; | |||
882 | ||||
883 | Out << ' '; | |||
884 | MD->getSelector().print(Out); | |||
885 | Out << ']'; | |||
886 | ||||
887 | return Name.str().str(); | |||
888 | } | |||
889 | if (isa<TranslationUnitDecl>(CurrentDecl) && IK == PrettyFunction) { | |||
890 | // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. | |||
891 | return "top level"; | |||
892 | } | |||
893 | return ""; | |||
894 | } | |||
895 | ||||
896 | void APNumericStorage::setIntValue(const ASTContext &C, | |||
897 | const llvm::APInt &Val) { | |||
898 | if (hasAllocation()) | |||
899 | C.Deallocate(pVal); | |||
900 | ||||
901 | BitWidth = Val.getBitWidth(); | |||
902 | unsigned NumWords = Val.getNumWords(); | |||
903 | const uint64_t* Words = Val.getRawData(); | |||
904 | if (NumWords > 1) { | |||
905 | pVal = new (C) uint64_t[NumWords]; | |||
906 | std::copy(Words, Words + NumWords, pVal); | |||
907 | } else if (NumWords == 1) | |||
908 | VAL = Words[0]; | |||
909 | else | |||
910 | VAL = 0; | |||
911 | } | |||
912 | ||||
913 | IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V, | |||
914 | QualType type, SourceLocation l) | |||
915 | : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, | |||
916 | false, false), | |||
917 | Loc(l) { | |||
918 | assert(type->isIntegerType() && "Illegal type in IntegerLiteral")((type->isIntegerType() && "Illegal type in IntegerLiteral" ) ? static_cast<void> (0) : __assert_fail ("type->isIntegerType() && \"Illegal type in IntegerLiteral\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 918, __PRETTY_FUNCTION__)); | |||
919 | assert(V.getBitWidth() == C.getIntWidth(type) &&((V.getBitWidth() == C.getIntWidth(type) && "Integer type is not the correct size for constant." ) ? static_cast<void> (0) : __assert_fail ("V.getBitWidth() == C.getIntWidth(type) && \"Integer type is not the correct size for constant.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 920, __PRETTY_FUNCTION__)) | |||
920 | "Integer type is not the correct size for constant.")((V.getBitWidth() == C.getIntWidth(type) && "Integer type is not the correct size for constant." ) ? static_cast<void> (0) : __assert_fail ("V.getBitWidth() == C.getIntWidth(type) && \"Integer type is not the correct size for constant.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 920, __PRETTY_FUNCTION__)); | |||
921 | setValue(C, V); | |||
922 | } | |||
923 | ||||
924 | IntegerLiteral * | |||
925 | IntegerLiteral::Create(const ASTContext &C, const llvm::APInt &V, | |||
926 | QualType type, SourceLocation l) { | |||
927 | return new (C) IntegerLiteral(C, V, type, l); | |||
928 | } | |||
929 | ||||
930 | IntegerLiteral * | |||
931 | IntegerLiteral::Create(const ASTContext &C, EmptyShell Empty) { | |||
932 | return new (C) IntegerLiteral(Empty); | |||
933 | } | |||
934 | ||||
935 | FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, | |||
936 | QualType type, SourceLocation l, | |||
937 | unsigned Scale) | |||
938 | : Expr(FixedPointLiteralClass, type, VK_RValue, OK_Ordinary, false, false, | |||
939 | false, false), | |||
940 | Loc(l), Scale(Scale) { | |||
941 | assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral")((type->isFixedPointType() && "Illegal type in FixedPointLiteral" ) ? static_cast<void> (0) : __assert_fail ("type->isFixedPointType() && \"Illegal type in FixedPointLiteral\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 941, __PRETTY_FUNCTION__)); | |||
942 | assert(V.getBitWidth() == C.getTypeInfo(type).Width &&((V.getBitWidth() == C.getTypeInfo(type).Width && "Fixed point type is not the correct size for constant." ) ? static_cast<void> (0) : __assert_fail ("V.getBitWidth() == C.getTypeInfo(type).Width && \"Fixed point type is not the correct size for constant.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 943, __PRETTY_FUNCTION__)) | |||
943 | "Fixed point type is not the correct size for constant.")((V.getBitWidth() == C.getTypeInfo(type).Width && "Fixed point type is not the correct size for constant." ) ? static_cast<void> (0) : __assert_fail ("V.getBitWidth() == C.getTypeInfo(type).Width && \"Fixed point type is not the correct size for constant.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 943, __PRETTY_FUNCTION__)); | |||
944 | setValue(C, V); | |||
945 | } | |||
946 | ||||
947 | FixedPointLiteral *FixedPointLiteral::CreateFromRawInt(const ASTContext &C, | |||
948 | const llvm::APInt &V, | |||
949 | QualType type, | |||
950 | SourceLocation l, | |||
951 | unsigned Scale) { | |||
952 | return new (C) FixedPointLiteral(C, V, type, l, Scale); | |||
953 | } | |||
954 | ||||
955 | std::string FixedPointLiteral::getValueAsString(unsigned Radix) const { | |||
956 | // Currently the longest decimal number that can be printed is the max for an | |||
957 | // unsigned long _Accum: 4294967295.99999999976716935634613037109375 | |||
958 | // which is 43 characters. | |||
959 | SmallString<64> S; | |||
960 | FixedPointValueToString( | |||
961 | S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale); | |||
962 | return S.str(); | |||
963 | } | |||
964 | ||||
965 | FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, | |||
966 | bool isexact, QualType Type, SourceLocation L) | |||
967 | : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, | |||
968 | false, false), Loc(L) { | |||
969 | setSemantics(V.getSemantics()); | |||
970 | FloatingLiteralBits.IsExact = isexact; | |||
971 | setValue(C, V); | |||
972 | } | |||
973 | ||||
974 | FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty) | |||
975 | : Expr(FloatingLiteralClass, Empty) { | |||
976 | setRawSemantics(llvm::APFloatBase::S_IEEEhalf); | |||
977 | FloatingLiteralBits.IsExact = false; | |||
978 | } | |||
979 | ||||
980 | FloatingLiteral * | |||
981 | FloatingLiteral::Create(const ASTContext &C, const llvm::APFloat &V, | |||
982 | bool isexact, QualType Type, SourceLocation L) { | |||
983 | return new (C) FloatingLiteral(C, V, isexact, Type, L); | |||
984 | } | |||
985 | ||||
986 | FloatingLiteral * | |||
987 | FloatingLiteral::Create(const ASTContext &C, EmptyShell Empty) { | |||
988 | return new (C) FloatingLiteral(C, Empty); | |||
989 | } | |||
990 | ||||
991 | /// getValueAsApproximateDouble - This returns the value as an inaccurate | |||
992 | /// double. Note that this may cause loss of precision, but is useful for | |||
993 | /// debugging dumps, etc. | |||
994 | double FloatingLiteral::getValueAsApproximateDouble() const { | |||
995 | llvm::APFloat V = getValue(); | |||
996 | bool ignored; | |||
997 | V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, | |||
998 | &ignored); | |||
999 | return V.convertToDouble(); | |||
1000 | } | |||
1001 | ||||
1002 | unsigned StringLiteral::mapCharByteWidth(TargetInfo const &Target, | |||
1003 | StringKind SK) { | |||
1004 | unsigned CharByteWidth = 0; | |||
1005 | switch (SK) { | |||
1006 | case Ascii: | |||
1007 | case UTF8: | |||
1008 | CharByteWidth = Target.getCharWidth(); | |||
1009 | break; | |||
1010 | case Wide: | |||
1011 | CharByteWidth = Target.getWCharWidth(); | |||
1012 | break; | |||
1013 | case UTF16: | |||
1014 | CharByteWidth = Target.getChar16Width(); | |||
1015 | break; | |||
1016 | case UTF32: | |||
1017 | CharByteWidth = Target.getChar32Width(); | |||
1018 | break; | |||
1019 | } | |||
1020 | assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple")(((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple" ) ? static_cast<void> (0) : __assert_fail ("(CharByteWidth & 7) == 0 && \"Assumes character size is byte multiple\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1020, __PRETTY_FUNCTION__)); | |||
1021 | CharByteWidth /= 8; | |||
1022 | assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&(((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) && "The only supported character byte widths are 1,2 and 4!" ) ? static_cast<void> (0) : __assert_fail ("(CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) && \"The only supported character byte widths are 1,2 and 4!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1023, __PRETTY_FUNCTION__)) | |||
1023 | "The only supported character byte widths are 1,2 and 4!")(((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) && "The only supported character byte widths are 1,2 and 4!" ) ? static_cast<void> (0) : __assert_fail ("(CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) && \"The only supported character byte widths are 1,2 and 4!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1023, __PRETTY_FUNCTION__)); | |||
1024 | return CharByteWidth; | |||
1025 | } | |||
1026 | ||||
1027 | StringLiteral::StringLiteral(const ASTContext &Ctx, StringRef Str, | |||
1028 | StringKind Kind, bool Pascal, QualType Ty, | |||
1029 | const SourceLocation *Loc, | |||
1030 | unsigned NumConcatenated) | |||
1031 | : Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, | |||
1032 | false) { | |||
1033 | assert(Ctx.getAsConstantArrayType(Ty) &&((Ctx.getAsConstantArrayType(Ty) && "StringLiteral must be of constant array type!" ) ? static_cast<void> (0) : __assert_fail ("Ctx.getAsConstantArrayType(Ty) && \"StringLiteral must be of constant array type!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1034, __PRETTY_FUNCTION__)) | |||
1034 | "StringLiteral must be of constant array type!")((Ctx.getAsConstantArrayType(Ty) && "StringLiteral must be of constant array type!" ) ? static_cast<void> (0) : __assert_fail ("Ctx.getAsConstantArrayType(Ty) && \"StringLiteral must be of constant array type!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1034, __PRETTY_FUNCTION__)); | |||
1035 | unsigned CharByteWidth = mapCharByteWidth(Ctx.getTargetInfo(), Kind); | |||
1036 | unsigned ByteLength = Str.size(); | |||
1037 | assert((ByteLength % CharByteWidth == 0) &&(((ByteLength % CharByteWidth == 0) && "The size of the data must be a multiple of CharByteWidth!" ) ? static_cast<void> (0) : __assert_fail ("(ByteLength % CharByteWidth == 0) && \"The size of the data must be a multiple of CharByteWidth!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1038, __PRETTY_FUNCTION__)) | |||
1038 | "The size of the data must be a multiple of CharByteWidth!")(((ByteLength % CharByteWidth == 0) && "The size of the data must be a multiple of CharByteWidth!" ) ? static_cast<void> (0) : __assert_fail ("(ByteLength % CharByteWidth == 0) && \"The size of the data must be a multiple of CharByteWidth!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1038, __PRETTY_FUNCTION__)); | |||
1039 | ||||
1040 | // Avoid the expensive division. The compiler should be able to figure it | |||
1041 | // out by itself. However as of clang 7, even with the appropriate | |||
1042 | // llvm_unreachable added just here, it is not able to do so. | |||
1043 | unsigned Length; | |||
1044 | switch (CharByteWidth) { | |||
1045 | case 1: | |||
1046 | Length = ByteLength; | |||
1047 | break; | |||
1048 | case 2: | |||
1049 | Length = ByteLength / 2; | |||
1050 | break; | |||
1051 | case 4: | |||
1052 | Length = ByteLength / 4; | |||
1053 | break; | |||
1054 | default: | |||
1055 | llvm_unreachable("Unsupported character width!")::llvm::llvm_unreachable_internal("Unsupported character width!" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1055); | |||
1056 | } | |||
1057 | ||||
1058 | StringLiteralBits.Kind = Kind; | |||
1059 | StringLiteralBits.CharByteWidth = CharByteWidth; | |||
1060 | StringLiteralBits.IsPascal = Pascal; | |||
1061 | StringLiteralBits.NumConcatenated = NumConcatenated; | |||
1062 | *getTrailingObjects<unsigned>() = Length; | |||
1063 | ||||
1064 | // Initialize the trailing array of SourceLocation. | |||
1065 | // This is safe since SourceLocation is POD-like. | |||
1066 | std::memcpy(getTrailingObjects<SourceLocation>(), Loc, | |||
1067 | NumConcatenated * sizeof(SourceLocation)); | |||
1068 | ||||
1069 | // Initialize the trailing array of char holding the string data. | |||
1070 | std::memcpy(getTrailingObjects<char>(), Str.data(), ByteLength); | |||
1071 | } | |||
1072 | ||||
1073 | StringLiteral::StringLiteral(EmptyShell Empty, unsigned NumConcatenated, | |||
1074 | unsigned Length, unsigned CharByteWidth) | |||
1075 | : Expr(StringLiteralClass, Empty) { | |||
1076 | StringLiteralBits.CharByteWidth = CharByteWidth; | |||
1077 | StringLiteralBits.NumConcatenated = NumConcatenated; | |||
1078 | *getTrailingObjects<unsigned>() = Length; | |||
1079 | } | |||
1080 | ||||
1081 | StringLiteral *StringLiteral::Create(const ASTContext &Ctx, StringRef Str, | |||
1082 | StringKind Kind, bool Pascal, QualType Ty, | |||
1083 | const SourceLocation *Loc, | |||
1084 | unsigned NumConcatenated) { | |||
1085 | void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>( | |||
1086 | 1, NumConcatenated, Str.size()), | |||
1087 | alignof(StringLiteral)); | |||
1088 | return new (Mem) | |||
1089 | StringLiteral(Ctx, Str, Kind, Pascal, Ty, Loc, NumConcatenated); | |||
1090 | } | |||
1091 | ||||
1092 | StringLiteral *StringLiteral::CreateEmpty(const ASTContext &Ctx, | |||
1093 | unsigned NumConcatenated, | |||
1094 | unsigned Length, | |||
1095 | unsigned CharByteWidth) { | |||
1096 | void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>( | |||
1097 | 1, NumConcatenated, Length * CharByteWidth), | |||
1098 | alignof(StringLiteral)); | |||
1099 | return new (Mem) | |||
1100 | StringLiteral(EmptyShell(), NumConcatenated, Length, CharByteWidth); | |||
1101 | } | |||
1102 | ||||
1103 | void StringLiteral::outputString(raw_ostream &OS) const { | |||
1104 | switch (getKind()) { | |||
1105 | case Ascii: break; // no prefix. | |||
1106 | case Wide: OS << 'L'; break; | |||
1107 | case UTF8: OS << "u8"; break; | |||
1108 | case UTF16: OS << 'u'; break; | |||
1109 | case UTF32: OS << 'U'; break; | |||
1110 | } | |||
1111 | OS << '"'; | |||
1112 | static const char Hex[] = "0123456789ABCDEF"; | |||
1113 | ||||
1114 | unsigned LastSlashX = getLength(); | |||
1115 | for (unsigned I = 0, N = getLength(); I != N; ++I) { | |||
1116 | switch (uint32_t Char = getCodeUnit(I)) { | |||
1117 | default: | |||
1118 | // FIXME: Convert UTF-8 back to codepoints before rendering. | |||
1119 | ||||
1120 | // Convert UTF-16 surrogate pairs back to codepoints before rendering. | |||
1121 | // Leave invalid surrogates alone; we'll use \x for those. | |||
1122 | if (getKind() == UTF16 && I != N - 1 && Char >= 0xd800 && | |||
1123 | Char <= 0xdbff) { | |||
1124 | uint32_t Trail = getCodeUnit(I + 1); | |||
1125 | if (Trail >= 0xdc00 && Trail <= 0xdfff) { | |||
1126 | Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00); | |||
1127 | ++I; | |||
1128 | } | |||
1129 | } | |||
1130 | ||||
1131 | if (Char > 0xff) { | |||
1132 | // If this is a wide string, output characters over 0xff using \x | |||
1133 | // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a | |||
1134 | // codepoint: use \x escapes for invalid codepoints. | |||
1135 | if (getKind() == Wide || | |||
1136 | (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) { | |||
1137 | // FIXME: Is this the best way to print wchar_t? | |||
1138 | OS << "\\x"; | |||
1139 | int Shift = 28; | |||
1140 | while ((Char >> Shift) == 0) | |||
1141 | Shift -= 4; | |||
1142 | for (/**/; Shift >= 0; Shift -= 4) | |||
1143 | OS << Hex[(Char >> Shift) & 15]; | |||
1144 | LastSlashX = I; | |||
1145 | break; | |||
1146 | } | |||
1147 | ||||
1148 | if (Char > 0xffff) | |||
1149 | OS << "\\U00" | |||
1150 | << Hex[(Char >> 20) & 15] | |||
1151 | << Hex[(Char >> 16) & 15]; | |||
1152 | else | |||
1153 | OS << "\\u"; | |||
1154 | OS << Hex[(Char >> 12) & 15] | |||
1155 | << Hex[(Char >> 8) & 15] | |||
1156 | << Hex[(Char >> 4) & 15] | |||
1157 | << Hex[(Char >> 0) & 15]; | |||
1158 | break; | |||
1159 | } | |||
1160 | ||||
1161 | // If we used \x... for the previous character, and this character is a | |||
1162 | // hexadecimal digit, prevent it being slurped as part of the \x. | |||
1163 | if (LastSlashX + 1 == I) { | |||
1164 | switch (Char) { | |||
1165 | case '0': case '1': case '2': case '3': case '4': | |||
1166 | case '5': case '6': case '7': case '8': case '9': | |||
1167 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | |||
1168 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |||
1169 | OS << "\"\""; | |||
1170 | } | |||
1171 | } | |||
1172 | ||||
1173 | assert(Char <= 0xff &&((Char <= 0xff && "Characters above 0xff should already have been handled." ) ? static_cast<void> (0) : __assert_fail ("Char <= 0xff && \"Characters above 0xff should already have been handled.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1174, __PRETTY_FUNCTION__)) | |||
1174 | "Characters above 0xff should already have been handled.")((Char <= 0xff && "Characters above 0xff should already have been handled." ) ? static_cast<void> (0) : __assert_fail ("Char <= 0xff && \"Characters above 0xff should already have been handled.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1174, __PRETTY_FUNCTION__)); | |||
1175 | ||||
1176 | if (isPrintable(Char)) | |||
1177 | OS << (char)Char; | |||
1178 | else // Output anything hard as an octal escape. | |||
1179 | OS << '\\' | |||
1180 | << (char)('0' + ((Char >> 6) & 7)) | |||
1181 | << (char)('0' + ((Char >> 3) & 7)) | |||
1182 | << (char)('0' + ((Char >> 0) & 7)); | |||
1183 | break; | |||
1184 | // Handle some common non-printable cases to make dumps prettier. | |||
1185 | case '\\': OS << "\\\\"; break; | |||
1186 | case '"': OS << "\\\""; break; | |||
1187 | case '\a': OS << "\\a"; break; | |||
1188 | case '\b': OS << "\\b"; break; | |||
1189 | case '\f': OS << "\\f"; break; | |||
1190 | case '\n': OS << "\\n"; break; | |||
1191 | case '\r': OS << "\\r"; break; | |||
1192 | case '\t': OS << "\\t"; break; | |||
1193 | case '\v': OS << "\\v"; break; | |||
1194 | } | |||
1195 | } | |||
1196 | OS << '"'; | |||
1197 | } | |||
1198 | ||||
1199 | /// getLocationOfByte - Return a source location that points to the specified | |||
1200 | /// byte of this string literal. | |||
1201 | /// | |||
1202 | /// Strings are amazingly complex. They can be formed from multiple tokens and | |||
1203 | /// can have escape sequences in them in addition to the usual trigraph and | |||
1204 | /// escaped newline business. This routine handles this complexity. | |||
1205 | /// | |||
1206 | /// The *StartToken sets the first token to be searched in this function and | |||
1207 | /// the *StartTokenByteOffset is the byte offset of the first token. Before | |||
1208 | /// returning, it updates the *StartToken to the TokNo of the token being found | |||
1209 | /// and sets *StartTokenByteOffset to the byte offset of the token in the | |||
1210 | /// string. | |||
1211 | /// Using these two parameters can reduce the time complexity from O(n^2) to | |||
1212 | /// O(n) if one wants to get the location of byte for all the tokens in a | |||
1213 | /// string. | |||
1214 | /// | |||
1215 | SourceLocation | |||
1216 | StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM, | |||
1217 | const LangOptions &Features, | |||
1218 | const TargetInfo &Target, unsigned *StartToken, | |||
1219 | unsigned *StartTokenByteOffset) const { | |||
1220 | assert((getKind() == StringLiteral::Ascii ||(((getKind() == StringLiteral::Ascii || getKind() == StringLiteral ::UTF8) && "Only narrow string literals are currently supported" ) ? static_cast<void> (0) : __assert_fail ("(getKind() == StringLiteral::Ascii || getKind() == StringLiteral::UTF8) && \"Only narrow string literals are currently supported\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1222, __PRETTY_FUNCTION__)) | |||
1221 | getKind() == StringLiteral::UTF8) &&(((getKind() == StringLiteral::Ascii || getKind() == StringLiteral ::UTF8) && "Only narrow string literals are currently supported" ) ? static_cast<void> (0) : __assert_fail ("(getKind() == StringLiteral::Ascii || getKind() == StringLiteral::UTF8) && \"Only narrow string literals are currently supported\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1222, __PRETTY_FUNCTION__)) | |||
1222 | "Only narrow string literals are currently supported")(((getKind() == StringLiteral::Ascii || getKind() == StringLiteral ::UTF8) && "Only narrow string literals are currently supported" ) ? static_cast<void> (0) : __assert_fail ("(getKind() == StringLiteral::Ascii || getKind() == StringLiteral::UTF8) && \"Only narrow string literals are currently supported\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1222, __PRETTY_FUNCTION__)); | |||
1223 | ||||
1224 | // Loop over all of the tokens in this string until we find the one that | |||
1225 | // contains the byte we're looking for. | |||
1226 | unsigned TokNo = 0; | |||
1227 | unsigned StringOffset = 0; | |||
1228 | if (StartToken) | |||
1229 | TokNo = *StartToken; | |||
1230 | if (StartTokenByteOffset) { | |||
1231 | StringOffset = *StartTokenByteOffset; | |||
1232 | ByteNo -= StringOffset; | |||
1233 | } | |||
1234 | while (1) { | |||
1235 | assert(TokNo < getNumConcatenated() && "Invalid byte number!")((TokNo < getNumConcatenated() && "Invalid byte number!" ) ? static_cast<void> (0) : __assert_fail ("TokNo < getNumConcatenated() && \"Invalid byte number!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1235, __PRETTY_FUNCTION__)); | |||
1236 | SourceLocation StrTokLoc = getStrTokenLoc(TokNo); | |||
1237 | ||||
1238 | // Get the spelling of the string so that we can get the data that makes up | |||
1239 | // the string literal, not the identifier for the macro it is potentially | |||
1240 | // expanded through. | |||
1241 | SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); | |||
1242 | ||||
1243 | // Re-lex the token to get its length and original spelling. | |||
1244 | std::pair<FileID, unsigned> LocInfo = | |||
1245 | SM.getDecomposedLoc(StrTokSpellingLoc); | |||
1246 | bool Invalid = false; | |||
1247 | StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); | |||
1248 | if (Invalid) { | |||
1249 | if (StartTokenByteOffset != nullptr) | |||
1250 | *StartTokenByteOffset = StringOffset; | |||
1251 | if (StartToken != nullptr) | |||
1252 | *StartToken = TokNo; | |||
1253 | return StrTokSpellingLoc; | |||
1254 | } | |||
1255 | ||||
1256 | const char *StrData = Buffer.data()+LocInfo.second; | |||
1257 | ||||
1258 | // Create a lexer starting at the beginning of this token. | |||
1259 | Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, | |||
1260 | Buffer.begin(), StrData, Buffer.end()); | |||
1261 | Token TheTok; | |||
1262 | TheLexer.LexFromRawLexer(TheTok); | |||
1263 | ||||
1264 | // Use the StringLiteralParser to compute the length of the string in bytes. | |||
1265 | StringLiteralParser SLP(TheTok, SM, Features, Target); | |||
1266 | unsigned TokNumBytes = SLP.GetStringLength(); | |||
1267 | ||||
1268 | // If the byte is in this token, return the location of the byte. | |||
1269 | if (ByteNo < TokNumBytes || | |||
1270 | (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { | |||
1271 | unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); | |||
1272 | ||||
1273 | // Now that we know the offset of the token in the spelling, use the | |||
1274 | // preprocessor to get the offset in the original source. | |||
1275 | if (StartTokenByteOffset != nullptr) | |||
1276 | *StartTokenByteOffset = StringOffset; | |||
1277 | if (StartToken != nullptr) | |||
1278 | *StartToken = TokNo; | |||
1279 | return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); | |||
1280 | } | |||
1281 | ||||
1282 | // Move to the next string token. | |||
1283 | StringOffset += TokNumBytes; | |||
1284 | ++TokNo; | |||
1285 | ByteNo -= TokNumBytes; | |||
1286 | } | |||
1287 | } | |||
1288 | ||||
1289 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it | |||
1290 | /// corresponds to, e.g. "sizeof" or "[pre]++". | |||
1291 | StringRef UnaryOperator::getOpcodeStr(Opcode Op) { | |||
1292 | switch (Op) { | |||
1293 | #define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling; | |||
1294 | #include "clang/AST/OperationKinds.def" | |||
1295 | } | |||
1296 | llvm_unreachable("Unknown unary operator")::llvm::llvm_unreachable_internal("Unknown unary operator", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1296); | |||
1297 | } | |||
1298 | ||||
1299 | UnaryOperatorKind | |||
1300 | UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { | |||
1301 | switch (OO) { | |||
1302 | default: llvm_unreachable("No unary operator for overloaded function")::llvm::llvm_unreachable_internal("No unary operator for overloaded function" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1302); | |||
1303 | case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; | |||
1304 | case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; | |||
1305 | case OO_Amp: return UO_AddrOf; | |||
1306 | case OO_Star: return UO_Deref; | |||
1307 | case OO_Plus: return UO_Plus; | |||
1308 | case OO_Minus: return UO_Minus; | |||
1309 | case OO_Tilde: return UO_Not; | |||
1310 | case OO_Exclaim: return UO_LNot; | |||
1311 | case OO_Coawait: return UO_Coawait; | |||
1312 | } | |||
1313 | } | |||
1314 | ||||
1315 | OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { | |||
1316 | switch (Opc) { | |||
1317 | case UO_PostInc: case UO_PreInc: return OO_PlusPlus; | |||
1318 | case UO_PostDec: case UO_PreDec: return OO_MinusMinus; | |||
1319 | case UO_AddrOf: return OO_Amp; | |||
1320 | case UO_Deref: return OO_Star; | |||
1321 | case UO_Plus: return OO_Plus; | |||
1322 | case UO_Minus: return OO_Minus; | |||
1323 | case UO_Not: return OO_Tilde; | |||
1324 | case UO_LNot: return OO_Exclaim; | |||
1325 | case UO_Coawait: return OO_Coawait; | |||
1326 | default: return OO_None; | |||
1327 | } | |||
1328 | } | |||
1329 | ||||
1330 | ||||
1331 | //===----------------------------------------------------------------------===// | |||
1332 | // Postfix Operators. | |||
1333 | //===----------------------------------------------------------------------===// | |||
1334 | ||||
1335 | CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs, | |||
1336 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, | |||
1337 | SourceLocation RParenLoc, unsigned MinNumArgs, | |||
1338 | ADLCallKind UsesADL) | |||
1339 | : Expr(SC, Ty, VK, OK_Ordinary, Fn->isTypeDependent(), | |||
1340 | Fn->isValueDependent(), Fn->isInstantiationDependent(), | |||
1341 | Fn->containsUnexpandedParameterPack()), | |||
1342 | RParenLoc(RParenLoc) { | |||
1343 | NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); | |||
1344 | unsigned NumPreArgs = PreArgs.size(); | |||
1345 | CallExprBits.NumPreArgs = NumPreArgs; | |||
1346 | assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!")(((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!" ) ? static_cast<void> (0) : __assert_fail ("(NumPreArgs == getNumPreArgs()) && \"NumPreArgs overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1346, __PRETTY_FUNCTION__)); | |||
1347 | ||||
1348 | unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC); | |||
1349 | CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects; | |||
1350 | assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&(((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects ) && "OffsetToTrailingObjects overflow!") ? static_cast <void> (0) : __assert_fail ("(CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && \"OffsetToTrailingObjects overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1351, __PRETTY_FUNCTION__)) | |||
1351 | "OffsetToTrailingObjects overflow!")(((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects ) && "OffsetToTrailingObjects overflow!") ? static_cast <void> (0) : __assert_fail ("(CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && \"OffsetToTrailingObjects overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1351, __PRETTY_FUNCTION__)); | |||
1352 | ||||
1353 | CallExprBits.UsesADL = static_cast<bool>(UsesADL); | |||
1354 | ||||
1355 | setCallee(Fn); | |||
1356 | for (unsigned I = 0; I != NumPreArgs; ++I) { | |||
1357 | updateDependenciesFromArg(PreArgs[I]); | |||
1358 | setPreArg(I, PreArgs[I]); | |||
1359 | } | |||
1360 | for (unsigned I = 0; I != Args.size(); ++I) { | |||
1361 | updateDependenciesFromArg(Args[I]); | |||
1362 | setArg(I, Args[I]); | |||
1363 | } | |||
1364 | for (unsigned I = Args.size(); I != NumArgs; ++I) { | |||
1365 | setArg(I, nullptr); | |||
1366 | } | |||
1367 | } | |||
1368 | ||||
1369 | CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs, | |||
1370 | EmptyShell Empty) | |||
1371 | : Expr(SC, Empty), NumArgs(NumArgs) { | |||
1372 | CallExprBits.NumPreArgs = NumPreArgs; | |||
1373 | assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!")(((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!" ) ? static_cast<void> (0) : __assert_fail ("(NumPreArgs == getNumPreArgs()) && \"NumPreArgs overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1373, __PRETTY_FUNCTION__)); | |||
1374 | ||||
1375 | unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC); | |||
1376 | CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects; | |||
1377 | assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&(((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects ) && "OffsetToTrailingObjects overflow!") ? static_cast <void> (0) : __assert_fail ("(CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && \"OffsetToTrailingObjects overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1378, __PRETTY_FUNCTION__)) | |||
1378 | "OffsetToTrailingObjects overflow!")(((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects ) && "OffsetToTrailingObjects overflow!") ? static_cast <void> (0) : __assert_fail ("(CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && \"OffsetToTrailingObjects overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1378, __PRETTY_FUNCTION__)); | |||
1379 | } | |||
1380 | ||||
1381 | CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn, | |||
1382 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, | |||
1383 | SourceLocation RParenLoc, unsigned MinNumArgs, | |||
1384 | ADLCallKind UsesADL) { | |||
1385 | unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); | |||
1386 | unsigned SizeOfTrailingObjects = | |||
1387 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); | |||
1388 | void *Mem = | |||
1389 | Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr)); | |||
1390 | return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, | |||
1391 | RParenLoc, MinNumArgs, UsesADL); | |||
1392 | } | |||
1393 | ||||
1394 | CallExpr *CallExpr::CreateTemporary(void *Mem, Expr *Fn, QualType Ty, | |||
1395 | ExprValueKind VK, SourceLocation RParenLoc, | |||
1396 | ADLCallKind UsesADL) { | |||
1397 | assert(!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) &&((!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr )) && "Misaligned memory in CallExpr::CreateTemporary!" ) ? static_cast<void> (0) : __assert_fail ("!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) && \"Misaligned memory in CallExpr::CreateTemporary!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1398, __PRETTY_FUNCTION__)) | |||
1398 | "Misaligned memory in CallExpr::CreateTemporary!")((!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr )) && "Misaligned memory in CallExpr::CreateTemporary!" ) ? static_cast<void> (0) : __assert_fail ("!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) && \"Misaligned memory in CallExpr::CreateTemporary!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1398, __PRETTY_FUNCTION__)); | |||
1399 | return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty, | |||
1400 | VK, RParenLoc, /*MinNumArgs=*/0, UsesADL); | |||
1401 | } | |||
1402 | ||||
1403 | CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, | |||
1404 | EmptyShell Empty) { | |||
1405 | unsigned SizeOfTrailingObjects = | |||
1406 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); | |||
1407 | void *Mem = | |||
1408 | Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr)); | |||
1409 | return new (Mem) CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, Empty); | |||
1410 | } | |||
1411 | ||||
1412 | unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) { | |||
1413 | switch (SC) { | |||
1414 | case CallExprClass: | |||
1415 | return sizeof(CallExpr); | |||
1416 | case CXXOperatorCallExprClass: | |||
1417 | return sizeof(CXXOperatorCallExpr); | |||
1418 | case CXXMemberCallExprClass: | |||
1419 | return sizeof(CXXMemberCallExpr); | |||
1420 | case UserDefinedLiteralClass: | |||
1421 | return sizeof(UserDefinedLiteral); | |||
1422 | case CUDAKernelCallExprClass: | |||
1423 | return sizeof(CUDAKernelCallExpr); | |||
1424 | default: | |||
1425 | llvm_unreachable("unexpected class deriving from CallExpr!")::llvm::llvm_unreachable_internal("unexpected class deriving from CallExpr!" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1425); | |||
1426 | } | |||
1427 | } | |||
1428 | ||||
1429 | void CallExpr::updateDependenciesFromArg(Expr *Arg) { | |||
1430 | if (Arg->isTypeDependent()) | |||
1431 | ExprBits.TypeDependent = true; | |||
1432 | if (Arg->isValueDependent()) | |||
1433 | ExprBits.ValueDependent = true; | |||
1434 | if (Arg->isInstantiationDependent()) | |||
1435 | ExprBits.InstantiationDependent = true; | |||
1436 | if (Arg->containsUnexpandedParameterPack()) | |||
1437 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
1438 | } | |||
1439 | ||||
1440 | Decl *Expr::getReferencedDeclOfCallee() { | |||
1441 | Expr *CEE = IgnoreParenImpCasts(); | |||
1442 | ||||
1443 | while (SubstNonTypeTemplateParmExpr *NTTP | |||
1444 | = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { | |||
1445 | CEE = NTTP->getReplacement()->IgnoreParenCasts(); | |||
1446 | } | |||
1447 | ||||
1448 | // If we're calling a dereference, look at the pointer instead. | |||
1449 | if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { | |||
1450 | if (BO->isPtrMemOp()) | |||
1451 | CEE = BO->getRHS()->IgnoreParenCasts(); | |||
1452 | } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { | |||
1453 | if (UO->getOpcode() == UO_Deref) | |||
1454 | CEE = UO->getSubExpr()->IgnoreParenCasts(); | |||
1455 | } | |||
1456 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) | |||
1457 | return DRE->getDecl(); | |||
1458 | if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) | |||
1459 | return ME->getMemberDecl(); | |||
1460 | if (auto *BE = dyn_cast<BlockExpr>(CEE)) | |||
1461 | return BE->getBlockDecl(); | |||
1462 | ||||
1463 | return nullptr; | |||
1464 | } | |||
1465 | ||||
1466 | /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID. If | |||
1467 | /// not, return 0. | |||
1468 | unsigned CallExpr::getBuiltinCallee() const { | |||
1469 | // All simple function calls (e.g. func()) are implicitly cast to pointer to | |||
1470 | // function. As a result, we try and obtain the DeclRefExpr from the | |||
1471 | // ImplicitCastExpr. | |||
1472 | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); | |||
1473 | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). | |||
1474 | return 0; | |||
1475 | ||||
1476 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); | |||
1477 | if (!DRE) | |||
1478 | return 0; | |||
1479 | ||||
1480 | const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); | |||
1481 | if (!FDecl) | |||
1482 | return 0; | |||
1483 | ||||
1484 | if (!FDecl->getIdentifier()) | |||
1485 | return 0; | |||
1486 | ||||
1487 | return FDecl->getBuiltinID(); | |||
1488 | } | |||
1489 | ||||
1490 | bool CallExpr::isUnevaluatedBuiltinCall(const ASTContext &Ctx) const { | |||
1491 | if (unsigned BI = getBuiltinCallee()) | |||
1492 | return Ctx.BuiltinInfo.isUnevaluated(BI); | |||
1493 | return false; | |||
1494 | } | |||
1495 | ||||
1496 | QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const { | |||
1497 | const Expr *Callee = getCallee(); | |||
1498 | QualType CalleeType = Callee->getType(); | |||
1499 | if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) { | |||
1500 | CalleeType = FnTypePtr->getPointeeType(); | |||
1501 | } else if (const auto *BPT = CalleeType->getAs<BlockPointerType>()) { | |||
1502 | CalleeType = BPT->getPointeeType(); | |||
1503 | } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) { | |||
1504 | if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens())) | |||
1505 | return Ctx.VoidTy; | |||
1506 | ||||
1507 | // This should never be overloaded and so should never return null. | |||
1508 | CalleeType = Expr::findBoundMemberType(Callee); | |||
1509 | } | |||
1510 | ||||
1511 | const FunctionType *FnType = CalleeType->castAs<FunctionType>(); | |||
1512 | return FnType->getReturnType(); | |||
1513 | } | |||
1514 | ||||
1515 | const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { | |||
1516 | // If the return type is a struct, union, or enum that is marked nodiscard, | |||
1517 | // then return the return type attribute. | |||
1518 | if (const TagDecl *TD = getCallReturnType(Ctx)->getAsTagDecl()) | |||
1519 | if (const auto *A = TD->getAttr<WarnUnusedResultAttr>()) | |||
1520 | return A; | |||
1521 | ||||
1522 | // Otherwise, see if the callee is marked nodiscard and return that attribute | |||
1523 | // instead. | |||
1524 | const Decl *D = getCalleeDecl(); | |||
1525 | return D ? D->getAttr<WarnUnusedResultAttr>() : nullptr; | |||
1526 | } | |||
1527 | ||||
1528 | SourceLocation CallExpr::getBeginLoc() const { | |||
1529 | if (isa<CXXOperatorCallExpr>(this)) | |||
1530 | return cast<CXXOperatorCallExpr>(this)->getBeginLoc(); | |||
1531 | ||||
1532 | SourceLocation begin = getCallee()->getBeginLoc(); | |||
1533 | if (begin.isInvalid() && getNumArgs() > 0 && getArg(0)) | |||
1534 | begin = getArg(0)->getBeginLoc(); | |||
1535 | return begin; | |||
1536 | } | |||
1537 | SourceLocation CallExpr::getEndLoc() const { | |||
1538 | if (isa<CXXOperatorCallExpr>(this)) | |||
1539 | return cast<CXXOperatorCallExpr>(this)->getEndLoc(); | |||
1540 | ||||
1541 | SourceLocation end = getRParenLoc(); | |||
1542 | if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1)) | |||
1543 | end = getArg(getNumArgs() - 1)->getEndLoc(); | |||
1544 | return end; | |||
1545 | } | |||
1546 | ||||
1547 | OffsetOfExpr *OffsetOfExpr::Create(const ASTContext &C, QualType type, | |||
1548 | SourceLocation OperatorLoc, | |||
1549 | TypeSourceInfo *tsi, | |||
1550 | ArrayRef<OffsetOfNode> comps, | |||
1551 | ArrayRef<Expr*> exprs, | |||
1552 | SourceLocation RParenLoc) { | |||
1553 | void *Mem = C.Allocate( | |||
1554 | totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size())); | |||
1555 | ||||
1556 | return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, | |||
1557 | RParenLoc); | |||
1558 | } | |||
1559 | ||||
1560 | OffsetOfExpr *OffsetOfExpr::CreateEmpty(const ASTContext &C, | |||
1561 | unsigned numComps, unsigned numExprs) { | |||
1562 | void *Mem = | |||
1563 | C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs)); | |||
1564 | return new (Mem) OffsetOfExpr(numComps, numExprs); | |||
1565 | } | |||
1566 | ||||
1567 | OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type, | |||
1568 | SourceLocation OperatorLoc, TypeSourceInfo *tsi, | |||
1569 | ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, | |||
1570 | SourceLocation RParenLoc) | |||
1571 | : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, | |||
1572 | /*TypeDependent=*/false, | |||
1573 | /*ValueDependent=*/tsi->getType()->isDependentType(), | |||
1574 | tsi->getType()->isInstantiationDependentType(), | |||
1575 | tsi->getType()->containsUnexpandedParameterPack()), | |||
1576 | OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), | |||
1577 | NumComps(comps.size()), NumExprs(exprs.size()) | |||
1578 | { | |||
1579 | for (unsigned i = 0; i != comps.size(); ++i) { | |||
1580 | setComponent(i, comps[i]); | |||
1581 | } | |||
1582 | ||||
1583 | for (unsigned i = 0; i != exprs.size(); ++i) { | |||
1584 | if (exprs[i]->isTypeDependent() || exprs[i]->isValueDependent()) | |||
1585 | ExprBits.ValueDependent = true; | |||
1586 | if (exprs[i]->containsUnexpandedParameterPack()) | |||
1587 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
1588 | ||||
1589 | setIndexExpr(i, exprs[i]); | |||
1590 | } | |||
1591 | } | |||
1592 | ||||
1593 | IdentifierInfo *OffsetOfNode::getFieldName() const { | |||
1594 | assert(getKind() == Field || getKind() == Identifier)((getKind() == Field || getKind() == Identifier) ? static_cast <void> (0) : __assert_fail ("getKind() == Field || getKind() == Identifier" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1594, __PRETTY_FUNCTION__)); | |||
1595 | if (getKind() == Field) | |||
1596 | return getField()->getIdentifier(); | |||
1597 | ||||
1598 | return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); | |||
1599 | } | |||
1600 | ||||
1601 | UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr( | |||
1602 | UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType, | |||
1603 | SourceLocation op, SourceLocation rp) | |||
1604 | : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, | |||
1605 | false, // Never type-dependent (C++ [temp.dep.expr]p3). | |||
1606 | // Value-dependent if the argument is type-dependent. | |||
1607 | E->isTypeDependent(), E->isInstantiationDependent(), | |||
1608 | E->containsUnexpandedParameterPack()), | |||
1609 | OpLoc(op), RParenLoc(rp) { | |||
1610 | UnaryExprOrTypeTraitExprBits.Kind = ExprKind; | |||
1611 | UnaryExprOrTypeTraitExprBits.IsType = false; | |||
1612 | Argument.Ex = E; | |||
1613 | ||||
1614 | // Check to see if we are in the situation where alignof(decl) should be | |||
1615 | // dependent because decl's alignment is dependent. | |||
1616 | if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) { | |||
1617 | if (!isValueDependent() || !isInstantiationDependent()) { | |||
1618 | E = E->IgnoreParens(); | |||
1619 | ||||
1620 | const ValueDecl *D = nullptr; | |||
1621 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) | |||
1622 | D = DRE->getDecl(); | |||
1623 | else if (const auto *ME = dyn_cast<MemberExpr>(E)) | |||
1624 | D = ME->getMemberDecl(); | |||
1625 | ||||
1626 | if (D) { | |||
1627 | for (const auto *I : D->specific_attrs<AlignedAttr>()) { | |||
1628 | if (I->isAlignmentDependent()) { | |||
1629 | setValueDependent(true); | |||
1630 | setInstantiationDependent(true); | |||
1631 | break; | |||
1632 | } | |||
1633 | } | |||
1634 | } | |||
1635 | } | |||
1636 | } | |||
1637 | } | |||
1638 | ||||
1639 | MemberExpr::MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc, | |||
1640 | ValueDecl *MemberDecl, | |||
1641 | const DeclarationNameInfo &NameInfo, QualType T, | |||
1642 | ExprValueKind VK, ExprObjectKind OK, | |||
1643 | NonOdrUseReason NOUR) | |||
1644 | : Expr(MemberExprClass, T, VK, OK, Base->isTypeDependent(), | |||
1645 | Base->isValueDependent(), Base->isInstantiationDependent(), | |||
1646 | Base->containsUnexpandedParameterPack()), | |||
1647 | Base(Base), MemberDecl(MemberDecl), MemberDNLoc(NameInfo.getInfo()), | |||
1648 | MemberLoc(NameInfo.getLoc()) { | |||
1649 | assert(!NameInfo.getName() ||((!NameInfo.getName() || MemberDecl->getDeclName() == NameInfo .getName()) ? static_cast<void> (0) : __assert_fail ("!NameInfo.getName() || MemberDecl->getDeclName() == NameInfo.getName()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1650, __PRETTY_FUNCTION__)) | |||
1650 | MemberDecl->getDeclName() == NameInfo.getName())((!NameInfo.getName() || MemberDecl->getDeclName() == NameInfo .getName()) ? static_cast<void> (0) : __assert_fail ("!NameInfo.getName() || MemberDecl->getDeclName() == NameInfo.getName()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1650, __PRETTY_FUNCTION__)); | |||
1651 | MemberExprBits.IsArrow = IsArrow; | |||
1652 | MemberExprBits.HasQualifierOrFoundDecl = false; | |||
1653 | MemberExprBits.HasTemplateKWAndArgsInfo = false; | |||
1654 | MemberExprBits.HadMultipleCandidates = false; | |||
1655 | MemberExprBits.NonOdrUseReason = NOUR; | |||
1656 | MemberExprBits.OperatorLoc = OperatorLoc; | |||
1657 | } | |||
1658 | ||||
1659 | MemberExpr *MemberExpr::Create( | |||
1660 | const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, | |||
1661 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, | |||
1662 | ValueDecl *MemberDecl, DeclAccessPair FoundDecl, | |||
1663 | DeclarationNameInfo NameInfo, const TemplateArgumentListInfo *TemplateArgs, | |||
1664 | QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR) { | |||
1665 | bool HasQualOrFound = QualifierLoc || FoundDecl.getDecl() != MemberDecl || | |||
1666 | FoundDecl.getAccess() != MemberDecl->getAccess(); | |||
1667 | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); | |||
1668 | std::size_t Size = | |||
1669 | totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo, | |||
1670 | TemplateArgumentLoc>( | |||
1671 | HasQualOrFound ? 1 : 0, HasTemplateKWAndArgsInfo ? 1 : 0, | |||
1672 | TemplateArgs ? TemplateArgs->size() : 0); | |||
1673 | ||||
1674 | void *Mem = C.Allocate(Size, alignof(MemberExpr)); | |||
1675 | MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl, | |||
1676 | NameInfo, T, VK, OK, NOUR); | |||
1677 | ||||
1678 | if (HasQualOrFound) { | |||
1679 | // FIXME: Wrong. We should be looking at the member declaration we found. | |||
1680 | if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { | |||
1681 | E->setValueDependent(true); | |||
1682 | E->setTypeDependent(true); | |||
1683 | E->setInstantiationDependent(true); | |||
1684 | } | |||
1685 | else if (QualifierLoc && | |||
1686 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) | |||
1687 | E->setInstantiationDependent(true); | |||
1688 | ||||
1689 | E->MemberExprBits.HasQualifierOrFoundDecl = true; | |||
1690 | ||||
1691 | MemberExprNameQualifier *NQ = | |||
1692 | E->getTrailingObjects<MemberExprNameQualifier>(); | |||
1693 | NQ->QualifierLoc = QualifierLoc; | |||
1694 | NQ->FoundDecl = FoundDecl; | |||
1695 | } | |||
1696 | ||||
1697 | E->MemberExprBits.HasTemplateKWAndArgsInfo = | |||
1698 | TemplateArgs || TemplateKWLoc.isValid(); | |||
1699 | ||||
1700 | if (TemplateArgs) { | |||
1701 | bool Dependent = false; | |||
1702 | bool InstantiationDependent = false; | |||
1703 | bool ContainsUnexpandedParameterPack = false; | |||
1704 | E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( | |||
1705 | TemplateKWLoc, *TemplateArgs, | |||
1706 | E->getTrailingObjects<TemplateArgumentLoc>(), Dependent, | |||
1707 | InstantiationDependent, ContainsUnexpandedParameterPack); | |||
1708 | if (InstantiationDependent) | |||
1709 | E->setInstantiationDependent(true); | |||
1710 | } else if (TemplateKWLoc.isValid()) { | |||
1711 | E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( | |||
1712 | TemplateKWLoc); | |||
1713 | } | |||
1714 | ||||
1715 | return E; | |||
1716 | } | |||
1717 | ||||
1718 | MemberExpr *MemberExpr::CreateEmpty(const ASTContext &Context, | |||
1719 | bool HasQualifier, bool HasFoundDecl, | |||
1720 | bool HasTemplateKWAndArgsInfo, | |||
1721 | unsigned NumTemplateArgs) { | |||
1722 | assert((!NumTemplateArgs || HasTemplateKWAndArgsInfo) &&(((!NumTemplateArgs || HasTemplateKWAndArgsInfo) && "template args but no template arg info?" ) ? static_cast<void> (0) : __assert_fail ("(!NumTemplateArgs || HasTemplateKWAndArgsInfo) && \"template args but no template arg info?\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1723, __PRETTY_FUNCTION__)) | |||
1723 | "template args but no template arg info?")(((!NumTemplateArgs || HasTemplateKWAndArgsInfo) && "template args but no template arg info?" ) ? static_cast<void> (0) : __assert_fail ("(!NumTemplateArgs || HasTemplateKWAndArgsInfo) && \"template args but no template arg info?\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1723, __PRETTY_FUNCTION__)); | |||
1724 | bool HasQualOrFound = HasQualifier || HasFoundDecl; | |||
1725 | std::size_t Size = | |||
1726 | totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo, | |||
1727 | TemplateArgumentLoc>(HasQualOrFound ? 1 : 0, | |||
1728 | HasTemplateKWAndArgsInfo ? 1 : 0, | |||
1729 | NumTemplateArgs); | |||
1730 | void *Mem = Context.Allocate(Size, alignof(MemberExpr)); | |||
1731 | return new (Mem) MemberExpr(EmptyShell()); | |||
1732 | } | |||
1733 | ||||
1734 | SourceLocation MemberExpr::getBeginLoc() const { | |||
1735 | if (isImplicitAccess()) { | |||
1736 | if (hasQualifier()) | |||
1737 | return getQualifierLoc().getBeginLoc(); | |||
1738 | return MemberLoc; | |||
1739 | } | |||
1740 | ||||
1741 | // FIXME: We don't want this to happen. Rather, we should be able to | |||
1742 | // detect all kinds of implicit accesses more cleanly. | |||
1743 | SourceLocation BaseStartLoc = getBase()->getBeginLoc(); | |||
1744 | if (BaseStartLoc.isValid()) | |||
1745 | return BaseStartLoc; | |||
1746 | return MemberLoc; | |||
1747 | } | |||
1748 | SourceLocation MemberExpr::getEndLoc() const { | |||
1749 | SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); | |||
1750 | if (hasExplicitTemplateArgs()) | |||
1751 | EndLoc = getRAngleLoc(); | |||
1752 | else if (EndLoc.isInvalid()) | |||
1753 | EndLoc = getBase()->getEndLoc(); | |||
1754 | return EndLoc; | |||
1755 | } | |||
1756 | ||||
1757 | bool CastExpr::CastConsistency() const { | |||
1758 | switch (getCastKind()) { | |||
1759 | case CK_DerivedToBase: | |||
1760 | case CK_UncheckedDerivedToBase: | |||
1761 | case CK_DerivedToBaseMemberPointer: | |||
1762 | case CK_BaseToDerived: | |||
1763 | case CK_BaseToDerivedMemberPointer: | |||
1764 | assert(!path_empty() && "Cast kind should have a base path!")((!path_empty() && "Cast kind should have a base path!" ) ? static_cast<void> (0) : __assert_fail ("!path_empty() && \"Cast kind should have a base path!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1764, __PRETTY_FUNCTION__)); | |||
1765 | break; | |||
1766 | ||||
1767 | case CK_CPointerToObjCPointerCast: | |||
1768 | assert(getType()->isObjCObjectPointerType())((getType()->isObjCObjectPointerType()) ? static_cast<void > (0) : __assert_fail ("getType()->isObjCObjectPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1768, __PRETTY_FUNCTION__)); | |||
1769 | assert(getSubExpr()->getType()->isPointerType())((getSubExpr()->getType()->isPointerType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1769, __PRETTY_FUNCTION__)); | |||
1770 | goto CheckNoBasePath; | |||
1771 | ||||
1772 | case CK_BlockPointerToObjCPointerCast: | |||
1773 | assert(getType()->isObjCObjectPointerType())((getType()->isObjCObjectPointerType()) ? static_cast<void > (0) : __assert_fail ("getType()->isObjCObjectPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1773, __PRETTY_FUNCTION__)); | |||
1774 | assert(getSubExpr()->getType()->isBlockPointerType())((getSubExpr()->getType()->isBlockPointerType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1774, __PRETTY_FUNCTION__)); | |||
1775 | goto CheckNoBasePath; | |||
1776 | ||||
1777 | case CK_ReinterpretMemberPointer: | |||
1778 | assert(getType()->isMemberPointerType())((getType()->isMemberPointerType()) ? static_cast<void> (0) : __assert_fail ("getType()->isMemberPointerType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1778, __PRETTY_FUNCTION__)); | |||
1779 | assert(getSubExpr()->getType()->isMemberPointerType())((getSubExpr()->getType()->isMemberPointerType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isMemberPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1779, __PRETTY_FUNCTION__)); | |||
1780 | goto CheckNoBasePath; | |||
1781 | ||||
1782 | case CK_BitCast: | |||
1783 | // Arbitrary casts to C pointer types count as bitcasts. | |||
1784 | // Otherwise, we should only have block and ObjC pointer casts | |||
1785 | // here if they stay within the type kind. | |||
1786 | if (!getType()->isPointerType()) { | |||
1787 | assert(getType()->isObjCObjectPointerType() ==((getType()->isObjCObjectPointerType() == getSubExpr()-> getType()->isObjCObjectPointerType()) ? static_cast<void > (0) : __assert_fail ("getType()->isObjCObjectPointerType() == getSubExpr()->getType()->isObjCObjectPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1788, __PRETTY_FUNCTION__)) | |||
1788 | getSubExpr()->getType()->isObjCObjectPointerType())((getType()->isObjCObjectPointerType() == getSubExpr()-> getType()->isObjCObjectPointerType()) ? static_cast<void > (0) : __assert_fail ("getType()->isObjCObjectPointerType() == getSubExpr()->getType()->isObjCObjectPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1788, __PRETTY_FUNCTION__)); | |||
1789 | assert(getType()->isBlockPointerType() ==((getType()->isBlockPointerType() == getSubExpr()->getType ()->isBlockPointerType()) ? static_cast<void> (0) : __assert_fail ("getType()->isBlockPointerType() == getSubExpr()->getType()->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1790, __PRETTY_FUNCTION__)) | |||
1790 | getSubExpr()->getType()->isBlockPointerType())((getType()->isBlockPointerType() == getSubExpr()->getType ()->isBlockPointerType()) ? static_cast<void> (0) : __assert_fail ("getType()->isBlockPointerType() == getSubExpr()->getType()->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1790, __PRETTY_FUNCTION__)); | |||
1791 | } | |||
1792 | goto CheckNoBasePath; | |||
1793 | ||||
1794 | case CK_AnyPointerToBlockPointerCast: | |||
1795 | assert(getType()->isBlockPointerType())((getType()->isBlockPointerType()) ? static_cast<void> (0) : __assert_fail ("getType()->isBlockPointerType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1795, __PRETTY_FUNCTION__)); | |||
1796 | assert(getSubExpr()->getType()->isAnyPointerType() &&((getSubExpr()->getType()->isAnyPointerType() && !getSubExpr()->getType()->isBlockPointerType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isAnyPointerType() && !getSubExpr()->getType()->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1797, __PRETTY_FUNCTION__)) | |||
1797 | !getSubExpr()->getType()->isBlockPointerType())((getSubExpr()->getType()->isAnyPointerType() && !getSubExpr()->getType()->isBlockPointerType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isAnyPointerType() && !getSubExpr()->getType()->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1797, __PRETTY_FUNCTION__)); | |||
1798 | goto CheckNoBasePath; | |||
1799 | ||||
1800 | case CK_CopyAndAutoreleaseBlockObject: | |||
1801 | assert(getType()->isBlockPointerType())((getType()->isBlockPointerType()) ? static_cast<void> (0) : __assert_fail ("getType()->isBlockPointerType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1801, __PRETTY_FUNCTION__)); | |||
1802 | assert(getSubExpr()->getType()->isBlockPointerType())((getSubExpr()->getType()->isBlockPointerType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1802, __PRETTY_FUNCTION__)); | |||
1803 | goto CheckNoBasePath; | |||
1804 | ||||
1805 | case CK_FunctionToPointerDecay: | |||
1806 | assert(getType()->isPointerType())((getType()->isPointerType()) ? static_cast<void> (0 ) : __assert_fail ("getType()->isPointerType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1806, __PRETTY_FUNCTION__)); | |||
1807 | assert(getSubExpr()->getType()->isFunctionType())((getSubExpr()->getType()->isFunctionType()) ? static_cast <void> (0) : __assert_fail ("getSubExpr()->getType()->isFunctionType()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1807, __PRETTY_FUNCTION__)); | |||
1808 | goto CheckNoBasePath; | |||
1809 | ||||
1810 | case CK_AddressSpaceConversion: { | |||
1811 | auto Ty = getType(); | |||
1812 | auto SETy = getSubExpr()->getType(); | |||
1813 | assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy))((getValueKindForType(Ty) == Expr::getValueKindForType(SETy)) ? static_cast<void> (0) : __assert_fail ("getValueKindForType(Ty) == Expr::getValueKindForType(SETy)" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1813, __PRETTY_FUNCTION__)); | |||
1814 | if (/*isRValue()*/ !Ty->getPointeeType().isNull()) { | |||
1815 | Ty = Ty->getPointeeType(); | |||
1816 | SETy = SETy->getPointeeType(); | |||
1817 | } | |||
1818 | assert(!Ty.isNull() && !SETy.isNull() &&((!Ty.isNull() && !SETy.isNull() && Ty.getAddressSpace () != SETy.getAddressSpace()) ? static_cast<void> (0) : __assert_fail ("!Ty.isNull() && !SETy.isNull() && Ty.getAddressSpace() != SETy.getAddressSpace()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1819, __PRETTY_FUNCTION__)) | |||
1819 | Ty.getAddressSpace() != SETy.getAddressSpace())((!Ty.isNull() && !SETy.isNull() && Ty.getAddressSpace () != SETy.getAddressSpace()) ? static_cast<void> (0) : __assert_fail ("!Ty.isNull() && !SETy.isNull() && Ty.getAddressSpace() != SETy.getAddressSpace()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1819, __PRETTY_FUNCTION__)); | |||
1820 | goto CheckNoBasePath; | |||
1821 | } | |||
1822 | // These should not have an inheritance path. | |||
1823 | case CK_Dynamic: | |||
1824 | case CK_ToUnion: | |||
1825 | case CK_ArrayToPointerDecay: | |||
1826 | case CK_NullToMemberPointer: | |||
1827 | case CK_NullToPointer: | |||
1828 | case CK_ConstructorConversion: | |||
1829 | case CK_IntegralToPointer: | |||
1830 | case CK_PointerToIntegral: | |||
1831 | case CK_ToVoid: | |||
1832 | case CK_VectorSplat: | |||
1833 | case CK_IntegralCast: | |||
1834 | case CK_BooleanToSignedIntegral: | |||
1835 | case CK_IntegralToFloating: | |||
1836 | case CK_FloatingToIntegral: | |||
1837 | case CK_FloatingCast: | |||
1838 | case CK_ObjCObjectLValueCast: | |||
1839 | case CK_FloatingRealToComplex: | |||
1840 | case CK_FloatingComplexToReal: | |||
1841 | case CK_FloatingComplexCast: | |||
1842 | case CK_FloatingComplexToIntegralComplex: | |||
1843 | case CK_IntegralRealToComplex: | |||
1844 | case CK_IntegralComplexToReal: | |||
1845 | case CK_IntegralComplexCast: | |||
1846 | case CK_IntegralComplexToFloatingComplex: | |||
1847 | case CK_ARCProduceObject: | |||
1848 | case CK_ARCConsumeObject: | |||
1849 | case CK_ARCReclaimReturnedObject: | |||
1850 | case CK_ARCExtendBlockObject: | |||
1851 | case CK_ZeroToOCLOpaqueType: | |||
1852 | case CK_IntToOCLSampler: | |||
1853 | case CK_FixedPointCast: | |||
1854 | case CK_FixedPointToIntegral: | |||
1855 | case CK_IntegralToFixedPoint: | |||
1856 | assert(!getType()->isBooleanType() && "unheralded conversion to bool")((!getType()->isBooleanType() && "unheralded conversion to bool" ) ? static_cast<void> (0) : __assert_fail ("!getType()->isBooleanType() && \"unheralded conversion to bool\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1856, __PRETTY_FUNCTION__)); | |||
1857 | goto CheckNoBasePath; | |||
1858 | ||||
1859 | case CK_Dependent: | |||
1860 | case CK_LValueToRValue: | |||
1861 | case CK_NoOp: | |||
1862 | case CK_AtomicToNonAtomic: | |||
1863 | case CK_NonAtomicToAtomic: | |||
1864 | case CK_PointerToBoolean: | |||
1865 | case CK_IntegralToBoolean: | |||
1866 | case CK_FloatingToBoolean: | |||
1867 | case CK_MemberPointerToBoolean: | |||
1868 | case CK_FloatingComplexToBoolean: | |||
1869 | case CK_IntegralComplexToBoolean: | |||
1870 | case CK_LValueBitCast: // -> bool& | |||
1871 | case CK_LValueToRValueBitCast: | |||
1872 | case CK_UserDefinedConversion: // operator bool() | |||
1873 | case CK_BuiltinFnToFnPtr: | |||
1874 | case CK_FixedPointToBoolean: | |||
1875 | CheckNoBasePath: | |||
1876 | assert(path_empty() && "Cast kind should not have a base path!")((path_empty() && "Cast kind should not have a base path!" ) ? static_cast<void> (0) : __assert_fail ("path_empty() && \"Cast kind should not have a base path!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1876, __PRETTY_FUNCTION__)); | |||
1877 | break; | |||
1878 | } | |||
1879 | return true; | |||
1880 | } | |||
1881 | ||||
1882 | const char *CastExpr::getCastKindName(CastKind CK) { | |||
1883 | switch (CK) { | |||
1884 | #define CAST_OPERATION(Name) case CK_##Name: return #Name; | |||
1885 | #include "clang/AST/OperationKinds.def" | |||
1886 | } | |||
1887 | llvm_unreachable("Unhandled cast kind!")::llvm::llvm_unreachable_internal("Unhandled cast kind!", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1887); | |||
1888 | } | |||
1889 | ||||
1890 | namespace { | |||
1891 | const Expr *skipImplicitTemporary(const Expr *E) { | |||
1892 | // Skip through reference binding to temporary. | |||
1893 | if (auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
1894 | E = Materialize->GetTemporaryExpr(); | |||
1895 | ||||
1896 | // Skip any temporary bindings; they're implicit. | |||
1897 | if (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) | |||
1898 | E = Binder->getSubExpr(); | |||
1899 | ||||
1900 | return E; | |||
1901 | } | |||
1902 | } | |||
1903 | ||||
1904 | Expr *CastExpr::getSubExprAsWritten() { | |||
1905 | const Expr *SubExpr = nullptr; | |||
1906 | const CastExpr *E = this; | |||
1907 | do { | |||
1908 | SubExpr = skipImplicitTemporary(E->getSubExpr()); | |||
1909 | ||||
1910 | // Conversions by constructor and conversion functions have a | |||
1911 | // subexpression describing the call; strip it off. | |||
1912 | if (E->getCastKind() == CK_ConstructorConversion) | |||
1913 | SubExpr = | |||
1914 | skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr)->getArg(0)); | |||
1915 | else if (E->getCastKind() == CK_UserDefinedConversion) { | |||
1916 | assert((isa<CXXMemberCallExpr>(SubExpr) ||(((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr> (SubExpr)) && "Unexpected SubExpr for CK_UserDefinedConversion." ) ? static_cast<void> (0) : __assert_fail ("(isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) && \"Unexpected SubExpr for CK_UserDefinedConversion.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1918, __PRETTY_FUNCTION__)) | |||
1917 | isa<BlockExpr>(SubExpr)) &&(((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr> (SubExpr)) && "Unexpected SubExpr for CK_UserDefinedConversion." ) ? static_cast<void> (0) : __assert_fail ("(isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) && \"Unexpected SubExpr for CK_UserDefinedConversion.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1918, __PRETTY_FUNCTION__)) | |||
1918 | "Unexpected SubExpr for CK_UserDefinedConversion.")(((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr> (SubExpr)) && "Unexpected SubExpr for CK_UserDefinedConversion." ) ? static_cast<void> (0) : __assert_fail ("(isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) && \"Unexpected SubExpr for CK_UserDefinedConversion.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1918, __PRETTY_FUNCTION__)); | |||
1919 | if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr)) | |||
1920 | SubExpr = MCE->getImplicitObjectArgument(); | |||
1921 | } | |||
1922 | ||||
1923 | // If the subexpression we're left with is an implicit cast, look | |||
1924 | // through that, too. | |||
1925 | } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); | |||
1926 | ||||
1927 | return const_cast<Expr*>(SubExpr); | |||
1928 | } | |||
1929 | ||||
1930 | NamedDecl *CastExpr::getConversionFunction() const { | |||
1931 | const Expr *SubExpr = nullptr; | |||
1932 | ||||
1933 | for (const CastExpr *E = this; E; E = dyn_cast<ImplicitCastExpr>(SubExpr)) { | |||
1934 | SubExpr = skipImplicitTemporary(E->getSubExpr()); | |||
1935 | ||||
1936 | if (E->getCastKind() == CK_ConstructorConversion) | |||
1937 | return cast<CXXConstructExpr>(SubExpr)->getConstructor(); | |||
1938 | ||||
1939 | if (E->getCastKind() == CK_UserDefinedConversion) { | |||
1940 | if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr)) | |||
1941 | return MCE->getMethodDecl(); | |||
1942 | } | |||
1943 | } | |||
1944 | ||||
1945 | return nullptr; | |||
1946 | } | |||
1947 | ||||
1948 | CXXBaseSpecifier **CastExpr::path_buffer() { | |||
1949 | switch (getStmtClass()) { | |||
1950 | #define ABSTRACT_STMT(x) | |||
1951 | #define CASTEXPR(Type, Base) \ | |||
1952 | case Stmt::Type##Class: \ | |||
1953 | return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>(); | |||
1954 | #define STMT(Type, Base) | |||
1955 | #include "clang/AST/StmtNodes.inc" | |||
1956 | default: | |||
1957 | llvm_unreachable("non-cast expressions not possible here")::llvm::llvm_unreachable_internal("non-cast expressions not possible here" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1957); | |||
1958 | } | |||
1959 | } | |||
1960 | ||||
1961 | const FieldDecl *CastExpr::getTargetFieldForToUnionCast(QualType unionType, | |||
1962 | QualType opType) { | |||
1963 | auto RD = unionType->castAs<RecordType>()->getDecl(); | |||
1964 | return getTargetFieldForToUnionCast(RD, opType); | |||
1965 | } | |||
1966 | ||||
1967 | const FieldDecl *CastExpr::getTargetFieldForToUnionCast(const RecordDecl *RD, | |||
1968 | QualType OpType) { | |||
1969 | auto &Ctx = RD->getASTContext(); | |||
1970 | RecordDecl::field_iterator Field, FieldEnd; | |||
1971 | for (Field = RD->field_begin(), FieldEnd = RD->field_end(); | |||
1972 | Field != FieldEnd; ++Field) { | |||
1973 | if (Ctx.hasSameUnqualifiedType(Field->getType(), OpType) && | |||
1974 | !Field->isUnnamedBitfield()) { | |||
1975 | return *Field; | |||
1976 | } | |||
1977 | } | |||
1978 | return nullptr; | |||
1979 | } | |||
1980 | ||||
1981 | ImplicitCastExpr *ImplicitCastExpr::Create(const ASTContext &C, QualType T, | |||
1982 | CastKind Kind, Expr *Operand, | |||
1983 | const CXXCastPath *BasePath, | |||
1984 | ExprValueKind VK) { | |||
1985 | unsigned PathSize = (BasePath ? BasePath->size() : 0); | |||
1986 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); | |||
1987 | // Per C++ [conv.lval]p3, lvalue-to-rvalue conversions on class and | |||
1988 | // std::nullptr_t have special semantics not captured by CK_LValueToRValue. | |||
1989 | assert((Kind != CK_LValueToRValue ||(((Kind != CK_LValueToRValue || !(T->isNullPtrType() || T-> getAsCXXRecordDecl())) && "invalid type for lvalue-to-rvalue conversion" ) ? static_cast<void> (0) : __assert_fail ("(Kind != CK_LValueToRValue || !(T->isNullPtrType() || T->getAsCXXRecordDecl())) && \"invalid type for lvalue-to-rvalue conversion\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1991, __PRETTY_FUNCTION__)) | |||
1990 | !(T->isNullPtrType() || T->getAsCXXRecordDecl())) &&(((Kind != CK_LValueToRValue || !(T->isNullPtrType() || T-> getAsCXXRecordDecl())) && "invalid type for lvalue-to-rvalue conversion" ) ? static_cast<void> (0) : __assert_fail ("(Kind != CK_LValueToRValue || !(T->isNullPtrType() || T->getAsCXXRecordDecl())) && \"invalid type for lvalue-to-rvalue conversion\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1991, __PRETTY_FUNCTION__)) | |||
1991 | "invalid type for lvalue-to-rvalue conversion")(((Kind != CK_LValueToRValue || !(T->isNullPtrType() || T-> getAsCXXRecordDecl())) && "invalid type for lvalue-to-rvalue conversion" ) ? static_cast<void> (0) : __assert_fail ("(Kind != CK_LValueToRValue || !(T->isNullPtrType() || T->getAsCXXRecordDecl())) && \"invalid type for lvalue-to-rvalue conversion\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 1991, __PRETTY_FUNCTION__)); | |||
1992 | ImplicitCastExpr *E = | |||
1993 | new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); | |||
1994 | if (PathSize) | |||
1995 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), | |||
1996 | E->getTrailingObjects<CXXBaseSpecifier *>()); | |||
1997 | return E; | |||
1998 | } | |||
1999 | ||||
2000 | ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(const ASTContext &C, | |||
2001 | unsigned PathSize) { | |||
2002 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); | |||
2003 | return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); | |||
2004 | } | |||
2005 | ||||
2006 | ||||
2007 | CStyleCastExpr *CStyleCastExpr::Create(const ASTContext &C, QualType T, | |||
2008 | ExprValueKind VK, CastKind K, Expr *Op, | |||
2009 | const CXXCastPath *BasePath, | |||
2010 | TypeSourceInfo *WrittenTy, | |||
2011 | SourceLocation L, SourceLocation R) { | |||
2012 | unsigned PathSize = (BasePath ? BasePath->size() : 0); | |||
2013 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); | |||
2014 | CStyleCastExpr *E = | |||
2015 | new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); | |||
2016 | if (PathSize) | |||
2017 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), | |||
2018 | E->getTrailingObjects<CXXBaseSpecifier *>()); | |||
2019 | return E; | |||
2020 | } | |||
2021 | ||||
2022 | CStyleCastExpr *CStyleCastExpr::CreateEmpty(const ASTContext &C, | |||
2023 | unsigned PathSize) { | |||
2024 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); | |||
2025 | return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); | |||
2026 | } | |||
2027 | ||||
2028 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it | |||
2029 | /// corresponds to, e.g. "<<=". | |||
2030 | StringRef BinaryOperator::getOpcodeStr(Opcode Op) { | |||
2031 | switch (Op) { | |||
2032 | #define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling; | |||
2033 | #include "clang/AST/OperationKinds.def" | |||
2034 | } | |||
2035 | llvm_unreachable("Invalid OpCode!")::llvm::llvm_unreachable_internal("Invalid OpCode!", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2035); | |||
2036 | } | |||
2037 | ||||
2038 | BinaryOperatorKind | |||
2039 | BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { | |||
2040 | switch (OO) { | |||
2041 | default: llvm_unreachable("Not an overloadable binary operator")::llvm::llvm_unreachable_internal("Not an overloadable binary operator" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2041); | |||
2042 | case OO_Plus: return BO_Add; | |||
2043 | case OO_Minus: return BO_Sub; | |||
2044 | case OO_Star: return BO_Mul; | |||
2045 | case OO_Slash: return BO_Div; | |||
2046 | case OO_Percent: return BO_Rem; | |||
2047 | case OO_Caret: return BO_Xor; | |||
2048 | case OO_Amp: return BO_And; | |||
2049 | case OO_Pipe: return BO_Or; | |||
2050 | case OO_Equal: return BO_Assign; | |||
2051 | case OO_Spaceship: return BO_Cmp; | |||
2052 | case OO_Less: return BO_LT; | |||
2053 | case OO_Greater: return BO_GT; | |||
2054 | case OO_PlusEqual: return BO_AddAssign; | |||
2055 | case OO_MinusEqual: return BO_SubAssign; | |||
2056 | case OO_StarEqual: return BO_MulAssign; | |||
2057 | case OO_SlashEqual: return BO_DivAssign; | |||
2058 | case OO_PercentEqual: return BO_RemAssign; | |||
2059 | case OO_CaretEqual: return BO_XorAssign; | |||
2060 | case OO_AmpEqual: return BO_AndAssign; | |||
2061 | case OO_PipeEqual: return BO_OrAssign; | |||
2062 | case OO_LessLess: return BO_Shl; | |||
2063 | case OO_GreaterGreater: return BO_Shr; | |||
2064 | case OO_LessLessEqual: return BO_ShlAssign; | |||
2065 | case OO_GreaterGreaterEqual: return BO_ShrAssign; | |||
2066 | case OO_EqualEqual: return BO_EQ; | |||
2067 | case OO_ExclaimEqual: return BO_NE; | |||
2068 | case OO_LessEqual: return BO_LE; | |||
2069 | case OO_GreaterEqual: return BO_GE; | |||
2070 | case OO_AmpAmp: return BO_LAnd; | |||
2071 | case OO_PipePipe: return BO_LOr; | |||
2072 | case OO_Comma: return BO_Comma; | |||
2073 | case OO_ArrowStar: return BO_PtrMemI; | |||
2074 | } | |||
2075 | } | |||
2076 | ||||
2077 | OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { | |||
2078 | static const OverloadedOperatorKind OverOps[] = { | |||
2079 | /* .* Cannot be overloaded */OO_None, OO_ArrowStar, | |||
2080 | OO_Star, OO_Slash, OO_Percent, | |||
2081 | OO_Plus, OO_Minus, | |||
2082 | OO_LessLess, OO_GreaterGreater, | |||
2083 | OO_Spaceship, | |||
2084 | OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, | |||
2085 | OO_EqualEqual, OO_ExclaimEqual, | |||
2086 | OO_Amp, | |||
2087 | OO_Caret, | |||
2088 | OO_Pipe, | |||
2089 | OO_AmpAmp, | |||
2090 | OO_PipePipe, | |||
2091 | OO_Equal, OO_StarEqual, | |||
2092 | OO_SlashEqual, OO_PercentEqual, | |||
2093 | OO_PlusEqual, OO_MinusEqual, | |||
2094 | OO_LessLessEqual, OO_GreaterGreaterEqual, | |||
2095 | OO_AmpEqual, OO_CaretEqual, | |||
2096 | OO_PipeEqual, | |||
2097 | OO_Comma | |||
2098 | }; | |||
2099 | return OverOps[Opc]; | |||
2100 | } | |||
2101 | ||||
2102 | bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, | |||
2103 | Opcode Opc, | |||
2104 | Expr *LHS, Expr *RHS) { | |||
2105 | if (Opc != BO_Add) | |||
2106 | return false; | |||
2107 | ||||
2108 | // Check that we have one pointer and one integer operand. | |||
2109 | Expr *PExp; | |||
2110 | if (LHS->getType()->isPointerType()) { | |||
2111 | if (!RHS->getType()->isIntegerType()) | |||
2112 | return false; | |||
2113 | PExp = LHS; | |||
2114 | } else if (RHS->getType()->isPointerType()) { | |||
2115 | if (!LHS->getType()->isIntegerType()) | |||
2116 | return false; | |||
2117 | PExp = RHS; | |||
2118 | } else { | |||
2119 | return false; | |||
2120 | } | |||
2121 | ||||
2122 | // Check that the pointer is a nullptr. | |||
2123 | if (!PExp->IgnoreParenCasts() | |||
2124 | ->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull)) | |||
2125 | return false; | |||
2126 | ||||
2127 | // Check that the pointee type is char-sized. | |||
2128 | const PointerType *PTy = PExp->getType()->getAs<PointerType>(); | |||
2129 | if (!PTy || !PTy->getPointeeType()->isCharType()) | |||
2130 | return false; | |||
2131 | ||||
2132 | return true; | |||
2133 | } | |||
2134 | ||||
2135 | static QualType getDecayedSourceLocExprType(const ASTContext &Ctx, | |||
2136 | SourceLocExpr::IdentKind Kind) { | |||
2137 | switch (Kind) { | |||
2138 | case SourceLocExpr::File: | |||
2139 | case SourceLocExpr::Function: { | |||
2140 | QualType ArrTy = Ctx.getStringLiteralArrayType(Ctx.CharTy, 0); | |||
2141 | return Ctx.getPointerType(ArrTy->getAsArrayTypeUnsafe()->getElementType()); | |||
2142 | } | |||
2143 | case SourceLocExpr::Line: | |||
2144 | case SourceLocExpr::Column: | |||
2145 | return Ctx.UnsignedIntTy; | |||
2146 | } | |||
2147 | llvm_unreachable("unhandled case")::llvm::llvm_unreachable_internal("unhandled case", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2147); | |||
2148 | } | |||
2149 | ||||
2150 | SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, IdentKind Kind, | |||
2151 | SourceLocation BLoc, SourceLocation RParenLoc, | |||
2152 | DeclContext *ParentContext) | |||
2153 | : Expr(SourceLocExprClass, getDecayedSourceLocExprType(Ctx, Kind), | |||
2154 | VK_RValue, OK_Ordinary, false, false, false, false), | |||
2155 | BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) { | |||
2156 | SourceLocExprBits.Kind = Kind; | |||
2157 | } | |||
2158 | ||||
2159 | StringRef SourceLocExpr::getBuiltinStr() const { | |||
2160 | switch (getIdentKind()) { | |||
2161 | case File: | |||
2162 | return "__builtin_FILE"; | |||
2163 | case Function: | |||
2164 | return "__builtin_FUNCTION"; | |||
2165 | case Line: | |||
2166 | return "__builtin_LINE"; | |||
2167 | case Column: | |||
2168 | return "__builtin_COLUMN"; | |||
2169 | } | |||
2170 | llvm_unreachable("unexpected IdentKind!")::llvm::llvm_unreachable_internal("unexpected IdentKind!", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2170); | |||
2171 | } | |||
2172 | ||||
2173 | APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, | |||
2174 | const Expr *DefaultExpr) const { | |||
2175 | SourceLocation Loc; | |||
2176 | const DeclContext *Context; | |||
2177 | ||||
2178 | std::tie(Loc, | |||
2179 | Context) = [&]() -> std::pair<SourceLocation, const DeclContext *> { | |||
2180 | if (auto *DIE = dyn_cast_or_null<CXXDefaultInitExpr>(DefaultExpr)) | |||
2181 | return {DIE->getUsedLocation(), DIE->getUsedContext()}; | |||
2182 | if (auto *DAE = dyn_cast_or_null<CXXDefaultArgExpr>(DefaultExpr)) | |||
2183 | return {DAE->getUsedLocation(), DAE->getUsedContext()}; | |||
2184 | return {this->getLocation(), this->getParentContext()}; | |||
2185 | }(); | |||
2186 | ||||
2187 | PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc( | |||
2188 | Ctx.getSourceManager().getExpansionRange(Loc).getEnd()); | |||
2189 | ||||
2190 | auto MakeStringLiteral = [&](StringRef Tmp) { | |||
2191 | using LValuePathEntry = APValue::LValuePathEntry; | |||
2192 | StringLiteral *Res = Ctx.getPredefinedStringLiteralFromCache(Tmp); | |||
2193 | // Decay the string to a pointer to the first character. | |||
2194 | LValuePathEntry Path[1] = {LValuePathEntry::ArrayIndex(0)}; | |||
2195 | return APValue(Res, CharUnits::Zero(), Path, /*OnePastTheEnd=*/false); | |||
2196 | }; | |||
2197 | ||||
2198 | switch (getIdentKind()) { | |||
2199 | case SourceLocExpr::File: | |||
2200 | return MakeStringLiteral(PLoc.getFilename()); | |||
2201 | case SourceLocExpr::Function: { | |||
2202 | const Decl *CurDecl = dyn_cast_or_null<Decl>(Context); | |||
2203 | return MakeStringLiteral( | |||
2204 | CurDecl ? PredefinedExpr::ComputeName(PredefinedExpr::Function, CurDecl) | |||
2205 | : std::string("")); | |||
2206 | } | |||
2207 | case SourceLocExpr::Line: | |||
2208 | case SourceLocExpr::Column: { | |||
2209 | llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy), | |||
2210 | /*isUnsigned=*/true); | |||
2211 | IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine() | |||
2212 | : PLoc.getColumn(); | |||
2213 | return APValue(IntVal); | |||
2214 | } | |||
2215 | } | |||
2216 | llvm_unreachable("unhandled case")::llvm::llvm_unreachable_internal("unhandled case", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2216); | |||
2217 | } | |||
2218 | ||||
2219 | InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, | |||
2220 | ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) | |||
2221 | : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, | |||
2222 | false, false), | |||
2223 | InitExprs(C, initExprs.size()), | |||
2224 | LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(nullptr, true) | |||
2225 | { | |||
2226 | sawArrayRangeDesignator(false); | |||
2227 | for (unsigned I = 0; I != initExprs.size(); ++I) { | |||
2228 | if (initExprs[I]->isTypeDependent()) | |||
2229 | ExprBits.TypeDependent = true; | |||
2230 | if (initExprs[I]->isValueDependent()) | |||
2231 | ExprBits.ValueDependent = true; | |||
2232 | if (initExprs[I]->isInstantiationDependent()) | |||
2233 | ExprBits.InstantiationDependent = true; | |||
2234 | if (initExprs[I]->containsUnexpandedParameterPack()) | |||
2235 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
2236 | } | |||
2237 | ||||
2238 | InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); | |||
2239 | } | |||
2240 | ||||
2241 | void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) { | |||
2242 | if (NumInits > InitExprs.size()) | |||
2243 | InitExprs.reserve(C, NumInits); | |||
2244 | } | |||
2245 | ||||
2246 | void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) { | |||
2247 | InitExprs.resize(C, NumInits, nullptr); | |||
2248 | } | |||
2249 | ||||
2250 | Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) { | |||
2251 | if (Init >= InitExprs.size()) { | |||
2252 | InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr); | |||
2253 | setInit(Init, expr); | |||
2254 | return nullptr; | |||
2255 | } | |||
2256 | ||||
2257 | Expr *Result = cast_or_null<Expr>(InitExprs[Init]); | |||
2258 | setInit(Init, expr); | |||
2259 | return Result; | |||
2260 | } | |||
2261 | ||||
2262 | void InitListExpr::setArrayFiller(Expr *filler) { | |||
2263 | assert(!hasArrayFiller() && "Filler already set!")((!hasArrayFiller() && "Filler already set!") ? static_cast <void> (0) : __assert_fail ("!hasArrayFiller() && \"Filler already set!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2263, __PRETTY_FUNCTION__)); | |||
2264 | ArrayFillerOrUnionFieldInit = filler; | |||
2265 | // Fill out any "holes" in the array due to designated initializers. | |||
2266 | Expr **inits = getInits(); | |||
2267 | for (unsigned i = 0, e = getNumInits(); i != e; ++i) | |||
2268 | if (inits[i] == nullptr) | |||
2269 | inits[i] = filler; | |||
2270 | } | |||
2271 | ||||
2272 | bool InitListExpr::isStringLiteralInit() const { | |||
2273 | if (getNumInits() != 1) | |||
2274 | return false; | |||
2275 | const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); | |||
2276 | if (!AT || !AT->getElementType()->isIntegerType()) | |||
2277 | return false; | |||
2278 | // It is possible for getInit() to return null. | |||
2279 | const Expr *Init = getInit(0); | |||
2280 | if (!Init) | |||
2281 | return false; | |||
2282 | Init = Init->IgnoreParens(); | |||
2283 | return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); | |||
2284 | } | |||
2285 | ||||
2286 | bool InitListExpr::isTransparent() const { | |||
2287 | assert(isSemanticForm() && "syntactic form never semantically transparent")((isSemanticForm() && "syntactic form never semantically transparent" ) ? static_cast<void> (0) : __assert_fail ("isSemanticForm() && \"syntactic form never semantically transparent\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2287, __PRETTY_FUNCTION__)); | |||
2288 | ||||
2289 | // A glvalue InitListExpr is always just sugar. | |||
2290 | if (isGLValue()) { | |||
2291 | assert(getNumInits() == 1 && "multiple inits in glvalue init list")((getNumInits() == 1 && "multiple inits in glvalue init list" ) ? static_cast<void> (0) : __assert_fail ("getNumInits() == 1 && \"multiple inits in glvalue init list\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2291, __PRETTY_FUNCTION__)); | |||
2292 | return true; | |||
2293 | } | |||
2294 | ||||
2295 | // Otherwise, we're sugar if and only if we have exactly one initializer that | |||
2296 | // is of the same type. | |||
2297 | if (getNumInits() != 1 || !getInit(0)) | |||
2298 | return false; | |||
2299 | ||||
2300 | // Don't confuse aggregate initialization of a struct X { X &x; }; with a | |||
2301 | // transparent struct copy. | |||
2302 | if (!getInit(0)->isRValue() && getType()->isRecordType()) | |||
2303 | return false; | |||
2304 | ||||
2305 | return getType().getCanonicalType() == | |||
2306 | getInit(0)->getType().getCanonicalType(); | |||
2307 | } | |||
2308 | ||||
2309 | bool InitListExpr::isIdiomaticZeroInitializer(const LangOptions &LangOpts) const { | |||
2310 | assert(isSyntacticForm() && "only test syntactic form as zero initializer")((isSyntacticForm() && "only test syntactic form as zero initializer" ) ? static_cast<void> (0) : __assert_fail ("isSyntacticForm() && \"only test syntactic form as zero initializer\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2310, __PRETTY_FUNCTION__)); | |||
2311 | ||||
2312 | if (LangOpts.CPlusPlus || getNumInits() != 1 || !getInit(0)) { | |||
2313 | return false; | |||
2314 | } | |||
2315 | ||||
2316 | const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(getInit(0)->IgnoreImplicit()); | |||
2317 | return Lit && Lit->getValue() == 0; | |||
2318 | } | |||
2319 | ||||
2320 | SourceLocation InitListExpr::getBeginLoc() const { | |||
2321 | if (InitListExpr *SyntacticForm = getSyntacticForm()) | |||
2322 | return SyntacticForm->getBeginLoc(); | |||
2323 | SourceLocation Beg = LBraceLoc; | |||
2324 | if (Beg.isInvalid()) { | |||
2325 | // Find the first non-null initializer. | |||
2326 | for (InitExprsTy::const_iterator I = InitExprs.begin(), | |||
2327 | E = InitExprs.end(); | |||
2328 | I != E; ++I) { | |||
2329 | if (Stmt *S = *I) { | |||
2330 | Beg = S->getBeginLoc(); | |||
2331 | break; | |||
2332 | } | |||
2333 | } | |||
2334 | } | |||
2335 | return Beg; | |||
2336 | } | |||
2337 | ||||
2338 | SourceLocation InitListExpr::getEndLoc() const { | |||
2339 | if (InitListExpr *SyntacticForm = getSyntacticForm()) | |||
2340 | return SyntacticForm->getEndLoc(); | |||
2341 | SourceLocation End = RBraceLoc; | |||
2342 | if (End.isInvalid()) { | |||
2343 | // Find the first non-null initializer from the end. | |||
2344 | for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), | |||
2345 | E = InitExprs.rend(); | |||
2346 | I != E; ++I) { | |||
2347 | if (Stmt *S = *I) { | |||
2348 | End = S->getEndLoc(); | |||
2349 | break; | |||
2350 | } | |||
2351 | } | |||
2352 | } | |||
2353 | return End; | |||
2354 | } | |||
2355 | ||||
2356 | /// getFunctionType - Return the underlying function type for this block. | |||
2357 | /// | |||
2358 | const FunctionProtoType *BlockExpr::getFunctionType() const { | |||
2359 | // The block pointer is never sugared, but the function type might be. | |||
2360 | return cast<BlockPointerType>(getType()) | |||
2361 | ->getPointeeType()->castAs<FunctionProtoType>(); | |||
2362 | } | |||
2363 | ||||
2364 | SourceLocation BlockExpr::getCaretLocation() const { | |||
2365 | return TheBlock->getCaretLocation(); | |||
2366 | } | |||
2367 | const Stmt *BlockExpr::getBody() const { | |||
2368 | return TheBlock->getBody(); | |||
2369 | } | |||
2370 | Stmt *BlockExpr::getBody() { | |||
2371 | return TheBlock->getBody(); | |||
2372 | } | |||
2373 | ||||
2374 | ||||
2375 | //===----------------------------------------------------------------------===// | |||
2376 | // Generic Expression Routines | |||
2377 | //===----------------------------------------------------------------------===// | |||
2378 | ||||
2379 | /// isUnusedResultAWarning - Return true if this immediate expression should | |||
2380 | /// be warned about if the result is unused. If so, fill in Loc and Ranges | |||
2381 | /// with location to warn on and the source range[s] to report with the | |||
2382 | /// warning. | |||
2383 | bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, | |||
2384 | SourceRange &R1, SourceRange &R2, | |||
2385 | ASTContext &Ctx) const { | |||
2386 | // Don't warn if the expr is type dependent. The type could end up | |||
2387 | // instantiating to void. | |||
2388 | if (isTypeDependent()) | |||
2389 | return false; | |||
2390 | ||||
2391 | switch (getStmtClass()) { | |||
2392 | default: | |||
2393 | if (getType()->isVoidType()) | |||
2394 | return false; | |||
2395 | WarnE = this; | |||
2396 | Loc = getExprLoc(); | |||
2397 | R1 = getSourceRange(); | |||
2398 | return true; | |||
2399 | case ParenExprClass: | |||
2400 | return cast<ParenExpr>(this)->getSubExpr()-> | |||
2401 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2402 | case GenericSelectionExprClass: | |||
2403 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> | |||
2404 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2405 | case CoawaitExprClass: | |||
2406 | case CoyieldExprClass: | |||
2407 | return cast<CoroutineSuspendExpr>(this)->getResumeExpr()-> | |||
2408 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2409 | case ChooseExprClass: | |||
2410 | return cast<ChooseExpr>(this)->getChosenSubExpr()-> | |||
2411 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2412 | case UnaryOperatorClass: { | |||
2413 | const UnaryOperator *UO = cast<UnaryOperator>(this); | |||
2414 | ||||
2415 | switch (UO->getOpcode()) { | |||
2416 | case UO_Plus: | |||
2417 | case UO_Minus: | |||
2418 | case UO_AddrOf: | |||
2419 | case UO_Not: | |||
2420 | case UO_LNot: | |||
2421 | case UO_Deref: | |||
2422 | break; | |||
2423 | case UO_Coawait: | |||
2424 | // This is just the 'operator co_await' call inside the guts of a | |||
2425 | // dependent co_await call. | |||
2426 | case UO_PostInc: | |||
2427 | case UO_PostDec: | |||
2428 | case UO_PreInc: | |||
2429 | case UO_PreDec: // ++/-- | |||
2430 | return false; // Not a warning. | |||
2431 | case UO_Real: | |||
2432 | case UO_Imag: | |||
2433 | // accessing a piece of a volatile complex is a side-effect. | |||
2434 | if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) | |||
2435 | .isVolatileQualified()) | |||
2436 | return false; | |||
2437 | break; | |||
2438 | case UO_Extension: | |||
2439 | return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2440 | } | |||
2441 | WarnE = this; | |||
2442 | Loc = UO->getOperatorLoc(); | |||
2443 | R1 = UO->getSubExpr()->getSourceRange(); | |||
2444 | return true; | |||
2445 | } | |||
2446 | case BinaryOperatorClass: { | |||
2447 | const BinaryOperator *BO = cast<BinaryOperator>(this); | |||
2448 | switch (BO->getOpcode()) { | |||
2449 | default: | |||
2450 | break; | |||
2451 | // Consider the RHS of comma for side effects. LHS was checked by | |||
2452 | // Sema::CheckCommaOperands. | |||
2453 | case BO_Comma: | |||
2454 | // ((foo = <blah>), 0) is an idiom for hiding the result (and | |||
2455 | // lvalue-ness) of an assignment written in a macro. | |||
2456 | if (IntegerLiteral *IE = | |||
2457 | dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) | |||
2458 | if (IE->getValue() == 0) | |||
2459 | return false; | |||
2460 | return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2461 | // Consider '||', '&&' to have side effects if the LHS or RHS does. | |||
2462 | case BO_LAnd: | |||
2463 | case BO_LOr: | |||
2464 | if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || | |||
2465 | !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) | |||
2466 | return false; | |||
2467 | break; | |||
2468 | } | |||
2469 | if (BO->isAssignmentOp()) | |||
2470 | return false; | |||
2471 | WarnE = this; | |||
2472 | Loc = BO->getOperatorLoc(); | |||
2473 | R1 = BO->getLHS()->getSourceRange(); | |||
2474 | R2 = BO->getRHS()->getSourceRange(); | |||
2475 | return true; | |||
2476 | } | |||
2477 | case CompoundAssignOperatorClass: | |||
2478 | case VAArgExprClass: | |||
2479 | case AtomicExprClass: | |||
2480 | return false; | |||
2481 | ||||
2482 | case ConditionalOperatorClass: { | |||
2483 | // If only one of the LHS or RHS is a warning, the operator might | |||
2484 | // be being used for control flow. Only warn if both the LHS and | |||
2485 | // RHS are warnings. | |||
2486 | const auto *Exp = cast<ConditionalOperator>(this); | |||
2487 | return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) && | |||
2488 | Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2489 | } | |||
2490 | case BinaryConditionalOperatorClass: { | |||
2491 | const auto *Exp = cast<BinaryConditionalOperator>(this); | |||
2492 | return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2493 | } | |||
2494 | ||||
2495 | case MemberExprClass: | |||
2496 | WarnE = this; | |||
2497 | Loc = cast<MemberExpr>(this)->getMemberLoc(); | |||
2498 | R1 = SourceRange(Loc, Loc); | |||
2499 | R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); | |||
2500 | return true; | |||
2501 | ||||
2502 | case ArraySubscriptExprClass: | |||
2503 | WarnE = this; | |||
2504 | Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); | |||
2505 | R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); | |||
2506 | R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); | |||
2507 | return true; | |||
2508 | ||||
2509 | case CXXOperatorCallExprClass: { | |||
2510 | // Warn about operator ==,!=,<,>,<=, and >= even when user-defined operator | |||
2511 | // overloads as there is no reasonable way to define these such that they | |||
2512 | // have non-trivial, desirable side-effects. See the -Wunused-comparison | |||
2513 | // warning: operators == and != are commonly typo'ed, and so warning on them | |||
2514 | // provides additional value as well. If this list is updated, | |||
2515 | // DiagnoseUnusedComparison should be as well. | |||
2516 | const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); | |||
2517 | switch (Op->getOperator()) { | |||
2518 | default: | |||
2519 | break; | |||
2520 | case OO_EqualEqual: | |||
2521 | case OO_ExclaimEqual: | |||
2522 | case OO_Less: | |||
2523 | case OO_Greater: | |||
2524 | case OO_GreaterEqual: | |||
2525 | case OO_LessEqual: | |||
2526 | if (Op->getCallReturnType(Ctx)->isReferenceType() || | |||
2527 | Op->getCallReturnType(Ctx)->isVoidType()) | |||
2528 | break; | |||
2529 | WarnE = this; | |||
2530 | Loc = Op->getOperatorLoc(); | |||
2531 | R1 = Op->getSourceRange(); | |||
2532 | return true; | |||
2533 | } | |||
2534 | ||||
2535 | // Fallthrough for generic call handling. | |||
2536 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | |||
2537 | } | |||
2538 | case CallExprClass: | |||
2539 | case CXXMemberCallExprClass: | |||
2540 | case UserDefinedLiteralClass: { | |||
2541 | // If this is a direct call, get the callee. | |||
2542 | const CallExpr *CE = cast<CallExpr>(this); | |||
2543 | if (const Decl *FD = CE->getCalleeDecl()) { | |||
2544 | // If the callee has attribute pure, const, or warn_unused_result, warn | |||
2545 | // about it. void foo() { strlen("bar"); } should warn. | |||
2546 | // | |||
2547 | // Note: If new cases are added here, DiagnoseUnusedExprResult should be | |||
2548 | // updated to match for QoI. | |||
2549 | if (CE->hasUnusedResultAttr(Ctx) || | |||
2550 | FD->hasAttr<PureAttr>() || FD->hasAttr<ConstAttr>()) { | |||
2551 | WarnE = this; | |||
2552 | Loc = CE->getCallee()->getBeginLoc(); | |||
2553 | R1 = CE->getCallee()->getSourceRange(); | |||
2554 | ||||
2555 | if (unsigned NumArgs = CE->getNumArgs()) | |||
2556 | R2 = SourceRange(CE->getArg(0)->getBeginLoc(), | |||
2557 | CE->getArg(NumArgs - 1)->getEndLoc()); | |||
2558 | return true; | |||
2559 | } | |||
2560 | } | |||
2561 | return false; | |||
2562 | } | |||
2563 | ||||
2564 | // If we don't know precisely what we're looking at, let's not warn. | |||
2565 | case UnresolvedLookupExprClass: | |||
2566 | case CXXUnresolvedConstructExprClass: | |||
2567 | return false; | |||
2568 | ||||
2569 | case CXXTemporaryObjectExprClass: | |||
2570 | case CXXConstructExprClass: { | |||
2571 | if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) { | |||
2572 | const auto *WarnURAttr = Type->getAttr<WarnUnusedResultAttr>(); | |||
2573 | if (Type->hasAttr<WarnUnusedAttr>() || | |||
2574 | (WarnURAttr && WarnURAttr->IsCXX11NoDiscard())) { | |||
2575 | WarnE = this; | |||
2576 | Loc = getBeginLoc(); | |||
2577 | R1 = getSourceRange(); | |||
2578 | return true; | |||
2579 | } | |||
2580 | } | |||
2581 | ||||
2582 | const auto *CE = cast<CXXConstructExpr>(this); | |||
2583 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) { | |||
2584 | const auto *WarnURAttr = Ctor->getAttr<WarnUnusedResultAttr>(); | |||
2585 | if (WarnURAttr && WarnURAttr->IsCXX11NoDiscard()) { | |||
2586 | WarnE = this; | |||
2587 | Loc = getBeginLoc(); | |||
2588 | R1 = getSourceRange(); | |||
2589 | ||||
2590 | if (unsigned NumArgs = CE->getNumArgs()) | |||
2591 | R2 = SourceRange(CE->getArg(0)->getBeginLoc(), | |||
2592 | CE->getArg(NumArgs - 1)->getEndLoc()); | |||
2593 | return true; | |||
2594 | } | |||
2595 | } | |||
2596 | ||||
2597 | return false; | |||
2598 | } | |||
2599 | ||||
2600 | case ObjCMessageExprClass: { | |||
2601 | const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); | |||
2602 | if (Ctx.getLangOpts().ObjCAutoRefCount && | |||
2603 | ME->isInstanceMessage() && | |||
2604 | !ME->getType()->isVoidType() && | |||
2605 | ME->getMethodFamily() == OMF_init) { | |||
2606 | WarnE = this; | |||
2607 | Loc = getExprLoc(); | |||
2608 | R1 = ME->getSourceRange(); | |||
2609 | return true; | |||
2610 | } | |||
2611 | ||||
2612 | if (const ObjCMethodDecl *MD = ME->getMethodDecl()) | |||
2613 | if (MD->hasAttr<WarnUnusedResultAttr>()) { | |||
2614 | WarnE = this; | |||
2615 | Loc = getExprLoc(); | |||
2616 | return true; | |||
2617 | } | |||
2618 | ||||
2619 | return false; | |||
2620 | } | |||
2621 | ||||
2622 | case ObjCPropertyRefExprClass: | |||
2623 | WarnE = this; | |||
2624 | Loc = getExprLoc(); | |||
2625 | R1 = getSourceRange(); | |||
2626 | return true; | |||
2627 | ||||
2628 | case PseudoObjectExprClass: { | |||
2629 | const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); | |||
2630 | ||||
2631 | // Only complain about things that have the form of a getter. | |||
2632 | if (isa<UnaryOperator>(PO->getSyntacticForm()) || | |||
2633 | isa<BinaryOperator>(PO->getSyntacticForm())) | |||
2634 | return false; | |||
2635 | ||||
2636 | WarnE = this; | |||
2637 | Loc = getExprLoc(); | |||
2638 | R1 = getSourceRange(); | |||
2639 | return true; | |||
2640 | } | |||
2641 | ||||
2642 | case StmtExprClass: { | |||
2643 | // Statement exprs don't logically have side effects themselves, but are | |||
2644 | // sometimes used in macros in ways that give them a type that is unused. | |||
2645 | // For example ({ blah; foo(); }) will end up with a type if foo has a type. | |||
2646 | // however, if the result of the stmt expr is dead, we don't want to emit a | |||
2647 | // warning. | |||
2648 | const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); | |||
2649 | if (!CS->body_empty()) { | |||
2650 | if (const Expr *E = dyn_cast<Expr>(CS->body_back())) | |||
2651 | return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2652 | if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) | |||
2653 | if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) | |||
2654 | return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2655 | } | |||
2656 | ||||
2657 | if (getType()->isVoidType()) | |||
2658 | return false; | |||
2659 | WarnE = this; | |||
2660 | Loc = cast<StmtExpr>(this)->getLParenLoc(); | |||
2661 | R1 = getSourceRange(); | |||
2662 | return true; | |||
2663 | } | |||
2664 | case CXXFunctionalCastExprClass: | |||
2665 | case CStyleCastExprClass: { | |||
2666 | // Ignore an explicit cast to void unless the operand is a non-trivial | |||
2667 | // volatile lvalue. | |||
2668 | const CastExpr *CE = cast<CastExpr>(this); | |||
2669 | if (CE->getCastKind() == CK_ToVoid) { | |||
2670 | if (CE->getSubExpr()->isGLValue() && | |||
2671 | CE->getSubExpr()->getType().isVolatileQualified()) { | |||
2672 | const DeclRefExpr *DRE = | |||
2673 | dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); | |||
2674 | if (!(DRE && isa<VarDecl>(DRE->getDecl()) && | |||
2675 | cast<VarDecl>(DRE->getDecl())->hasLocalStorage()) && | |||
2676 | !isa<CallExpr>(CE->getSubExpr()->IgnoreParens())) { | |||
2677 | return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, | |||
2678 | R1, R2, Ctx); | |||
2679 | } | |||
2680 | } | |||
2681 | return false; | |||
2682 | } | |||
2683 | ||||
2684 | // If this is a cast to a constructor conversion, check the operand. | |||
2685 | // Otherwise, the result of the cast is unused. | |||
2686 | if (CE->getCastKind() == CK_ConstructorConversion) | |||
2687 | return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2688 | ||||
2689 | WarnE = this; | |||
2690 | if (const CXXFunctionalCastExpr *CXXCE = | |||
2691 | dyn_cast<CXXFunctionalCastExpr>(this)) { | |||
2692 | Loc = CXXCE->getBeginLoc(); | |||
2693 | R1 = CXXCE->getSubExpr()->getSourceRange(); | |||
2694 | } else { | |||
2695 | const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); | |||
2696 | Loc = CStyleCE->getLParenLoc(); | |||
2697 | R1 = CStyleCE->getSubExpr()->getSourceRange(); | |||
2698 | } | |||
2699 | return true; | |||
2700 | } | |||
2701 | case ImplicitCastExprClass: { | |||
2702 | const CastExpr *ICE = cast<ImplicitCastExpr>(this); | |||
2703 | ||||
2704 | // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. | |||
2705 | if (ICE->getCastKind() == CK_LValueToRValue && | |||
2706 | ICE->getSubExpr()->getType().isVolatileQualified()) | |||
2707 | return false; | |||
2708 | ||||
2709 | return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2710 | } | |||
2711 | case CXXDefaultArgExprClass: | |||
2712 | return (cast<CXXDefaultArgExpr>(this) | |||
2713 | ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); | |||
2714 | case CXXDefaultInitExprClass: | |||
2715 | return (cast<CXXDefaultInitExpr>(this) | |||
2716 | ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); | |||
2717 | ||||
2718 | case CXXNewExprClass: | |||
2719 | // FIXME: In theory, there might be new expressions that don't have side | |||
2720 | // effects (e.g. a placement new with an uninitialized POD). | |||
2721 | case CXXDeleteExprClass: | |||
2722 | return false; | |||
2723 | case MaterializeTemporaryExprClass: | |||
2724 | return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() | |||
2725 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2726 | case CXXBindTemporaryExprClass: | |||
2727 | return cast<CXXBindTemporaryExpr>(this)->getSubExpr() | |||
2728 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2729 | case ExprWithCleanupsClass: | |||
2730 | return cast<ExprWithCleanups>(this)->getSubExpr() | |||
2731 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); | |||
2732 | } | |||
2733 | } | |||
2734 | ||||
2735 | /// isOBJCGCCandidate - Check if an expression is objc gc'able. | |||
2736 | /// returns true, if it is; false otherwise. | |||
2737 | bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { | |||
2738 | const Expr *E = IgnoreParens(); | |||
2739 | switch (E->getStmtClass()) { | |||
2740 | default: | |||
2741 | return false; | |||
2742 | case ObjCIvarRefExprClass: | |||
2743 | return true; | |||
2744 | case Expr::UnaryOperatorClass: | |||
2745 | return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); | |||
2746 | case ImplicitCastExprClass: | |||
2747 | return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); | |||
2748 | case MaterializeTemporaryExprClass: | |||
2749 | return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() | |||
2750 | ->isOBJCGCCandidate(Ctx); | |||
2751 | case CStyleCastExprClass: | |||
2752 | return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); | |||
2753 | case DeclRefExprClass: { | |||
2754 | const Decl *D = cast<DeclRefExpr>(E)->getDecl(); | |||
2755 | ||||
2756 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { | |||
2757 | if (VD->hasGlobalStorage()) | |||
2758 | return true; | |||
2759 | QualType T = VD->getType(); | |||
2760 | // dereferencing to a pointer is always a gc'able candidate, | |||
2761 | // unless it is __weak. | |||
2762 | return T->isPointerType() && | |||
2763 | (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); | |||
2764 | } | |||
2765 | return false; | |||
2766 | } | |||
2767 | case MemberExprClass: { | |||
2768 | const MemberExpr *M = cast<MemberExpr>(E); | |||
2769 | return M->getBase()->isOBJCGCCandidate(Ctx); | |||
2770 | } | |||
2771 | case ArraySubscriptExprClass: | |||
2772 | return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); | |||
2773 | } | |||
2774 | } | |||
2775 | ||||
2776 | bool Expr::isBoundMemberFunction(ASTContext &Ctx) const { | |||
2777 | if (isTypeDependent()) | |||
2778 | return false; | |||
2779 | return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; | |||
2780 | } | |||
2781 | ||||
2782 | QualType Expr::findBoundMemberType(const Expr *expr) { | |||
2783 | assert(expr->hasPlaceholderType(BuiltinType::BoundMember))((expr->hasPlaceholderType(BuiltinType::BoundMember)) ? static_cast <void> (0) : __assert_fail ("expr->hasPlaceholderType(BuiltinType::BoundMember)" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2783, __PRETTY_FUNCTION__)); | |||
2784 | ||||
2785 | // Bound member expressions are always one of these possibilities: | |||
2786 | // x->m x.m x->*y x.*y | |||
2787 | // (possibly parenthesized) | |||
2788 | ||||
2789 | expr = expr->IgnoreParens(); | |||
2790 | if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { | |||
2791 | assert(isa<CXXMethodDecl>(mem->getMemberDecl()))((isa<CXXMethodDecl>(mem->getMemberDecl())) ? static_cast <void> (0) : __assert_fail ("isa<CXXMethodDecl>(mem->getMemberDecl())" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2791, __PRETTY_FUNCTION__)); | |||
2792 | return mem->getMemberDecl()->getType(); | |||
2793 | } | |||
2794 | ||||
2795 | if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { | |||
2796 | QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() | |||
2797 | ->getPointeeType(); | |||
2798 | assert(type->isFunctionType())((type->isFunctionType()) ? static_cast<void> (0) : __assert_fail ("type->isFunctionType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2798, __PRETTY_FUNCTION__)); | |||
2799 | return type; | |||
2800 | } | |||
2801 | ||||
2802 | assert(isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr))((isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr >(expr)) ? static_cast<void> (0) : __assert_fail ("isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr)" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 2802, __PRETTY_FUNCTION__)); | |||
2803 | return QualType(); | |||
2804 | } | |||
2805 | ||||
2806 | static Expr *IgnoreImpCastsSingleStep(Expr *E) { | |||
2807 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) | |||
2808 | return ICE->getSubExpr(); | |||
2809 | ||||
2810 | if (auto *FE = dyn_cast<FullExpr>(E)) | |||
2811 | return FE->getSubExpr(); | |||
2812 | ||||
2813 | return E; | |||
2814 | } | |||
2815 | ||||
2816 | static Expr *IgnoreImpCastsExtraSingleStep(Expr *E) { | |||
2817 | // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in | |||
2818 | // addition to what IgnoreImpCasts() skips to account for the current | |||
2819 | // behaviour of IgnoreParenImpCasts(). | |||
2820 | Expr *SubE = IgnoreImpCastsSingleStep(E); | |||
2821 | if (SubE != E) | |||
2822 | return SubE; | |||
2823 | ||||
2824 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
2825 | return MTE->GetTemporaryExpr(); | |||
2826 | ||||
2827 | if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) | |||
2828 | return NTTP->getReplacement(); | |||
2829 | ||||
2830 | return E; | |||
2831 | } | |||
2832 | ||||
2833 | static Expr *IgnoreCastsSingleStep(Expr *E) { | |||
2834 | if (auto *CE = dyn_cast<CastExpr>(E)) | |||
2835 | return CE->getSubExpr(); | |||
2836 | ||||
2837 | if (auto *FE = dyn_cast<FullExpr>(E)) | |||
2838 | return FE->getSubExpr(); | |||
2839 | ||||
2840 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
2841 | return MTE->GetTemporaryExpr(); | |||
2842 | ||||
2843 | if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) | |||
2844 | return NTTP->getReplacement(); | |||
2845 | ||||
2846 | return E; | |||
2847 | } | |||
2848 | ||||
2849 | static Expr *IgnoreLValueCastsSingleStep(Expr *E) { | |||
2850 | // Skip what IgnoreCastsSingleStep skips, except that only | |||
2851 | // lvalue-to-rvalue casts are skipped. | |||
2852 | if (auto *CE = dyn_cast<CastExpr>(E)) | |||
2853 | if (CE->getCastKind() != CK_LValueToRValue) | |||
2854 | return E; | |||
2855 | ||||
2856 | return IgnoreCastsSingleStep(E); | |||
2857 | } | |||
2858 | ||||
2859 | static Expr *IgnoreBaseCastsSingleStep(Expr *E) { | |||
2860 | if (auto *CE = dyn_cast<CastExpr>(E)) | |||
2861 | if (CE->getCastKind() == CK_DerivedToBase || | |||
2862 | CE->getCastKind() == CK_UncheckedDerivedToBase || | |||
2863 | CE->getCastKind() == CK_NoOp) | |||
2864 | return CE->getSubExpr(); | |||
2865 | ||||
2866 | return E; | |||
2867 | } | |||
2868 | ||||
2869 | static Expr *IgnoreImplicitSingleStep(Expr *E) { | |||
2870 | Expr *SubE = IgnoreImpCastsSingleStep(E); | |||
2871 | if (SubE != E) | |||
2872 | return SubE; | |||
2873 | ||||
2874 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
2875 | return MTE->GetTemporaryExpr(); | |||
2876 | ||||
2877 | if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E)) | |||
2878 | return BTE->getSubExpr(); | |||
2879 | ||||
2880 | return E; | |||
2881 | } | |||
2882 | ||||
2883 | static Expr *IgnoreParensSingleStep(Expr *E) { | |||
2884 | if (auto *PE = dyn_cast<ParenExpr>(E)) | |||
2885 | return PE->getSubExpr(); | |||
2886 | ||||
2887 | if (auto *UO = dyn_cast<UnaryOperator>(E)) { | |||
2888 | if (UO->getOpcode() == UO_Extension) | |||
2889 | return UO->getSubExpr(); | |||
2890 | } | |||
2891 | ||||
2892 | else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) { | |||
2893 | if (!GSE->isResultDependent()) | |||
2894 | return GSE->getResultExpr(); | |||
2895 | } | |||
2896 | ||||
2897 | else if (auto *CE = dyn_cast<ChooseExpr>(E)) { | |||
2898 | if (!CE->isConditionDependent()) | |||
2899 | return CE->getChosenSubExpr(); | |||
2900 | } | |||
2901 | ||||
2902 | else if (auto *CE = dyn_cast<ConstantExpr>(E)) | |||
2903 | return CE->getSubExpr(); | |||
2904 | ||||
2905 | return E; | |||
2906 | } | |||
2907 | ||||
2908 | static Expr *IgnoreNoopCastsSingleStep(const ASTContext &Ctx, Expr *E) { | |||
2909 | if (auto *CE = dyn_cast<CastExpr>(E)) { | |||
2910 | // We ignore integer <-> casts that are of the same width, ptr<->ptr and | |||
2911 | // ptr<->int casts of the same width. We also ignore all identity casts. | |||
2912 | Expr *SubExpr = CE->getSubExpr(); | |||
2913 | bool IsIdentityCast = | |||
2914 | Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType()); | |||
2915 | bool IsSameWidthCast = | |||
2916 | (E->getType()->isPointerType() || E->getType()->isIntegralType(Ctx)) && | |||
2917 | (SubExpr->getType()->isPointerType() || | |||
2918 | SubExpr->getType()->isIntegralType(Ctx)) && | |||
2919 | (Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SubExpr->getType())); | |||
2920 | ||||
2921 | if (IsIdentityCast || IsSameWidthCast) | |||
2922 | return SubExpr; | |||
2923 | } | |||
2924 | ||||
2925 | else if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) | |||
2926 | return NTTP->getReplacement(); | |||
2927 | ||||
2928 | return E; | |||
2929 | } | |||
2930 | ||||
2931 | static Expr *IgnoreExprNodesImpl(Expr *E) { return E; } | |||
2932 | template <typename FnTy, typename... FnTys> | |||
2933 | static Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | |||
2934 | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | |||
2935 | } | |||
2936 | ||||
2937 | /// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, | |||
2938 | /// Recursively apply each of the functions to E until reaching a fixed point. | |||
2939 | /// Note that a null E is valid; in this case nothing is done. | |||
2940 | template <typename... FnTys> | |||
2941 | static Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { | |||
2942 | Expr *LastE = nullptr; | |||
2943 | while (E != LastE) { | |||
2944 | LastE = E; | |||
2945 | E = IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); | |||
2946 | } | |||
2947 | return E; | |||
2948 | } | |||
2949 | ||||
2950 | Expr *Expr::IgnoreImpCasts() { | |||
2951 | return IgnoreExprNodes(this, IgnoreImpCastsSingleStep); | |||
2952 | } | |||
2953 | ||||
2954 | Expr *Expr::IgnoreCasts() { | |||
2955 | return IgnoreExprNodes(this, IgnoreCastsSingleStep); | |||
2956 | } | |||
2957 | ||||
2958 | Expr *Expr::IgnoreImplicit() { | |||
2959 | return IgnoreExprNodes(this, IgnoreImplicitSingleStep); | |||
2960 | } | |||
2961 | ||||
2962 | Expr *Expr::IgnoreParens() { | |||
2963 | return IgnoreExprNodes(this, IgnoreParensSingleStep); | |||
2964 | } | |||
2965 | ||||
2966 | Expr *Expr::IgnoreParenImpCasts() { | |||
2967 | return IgnoreExprNodes(this, IgnoreParensSingleStep, | |||
2968 | IgnoreImpCastsExtraSingleStep); | |||
2969 | } | |||
2970 | ||||
2971 | Expr *Expr::IgnoreParenCasts() { | |||
2972 | return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreCastsSingleStep); | |||
2973 | } | |||
2974 | ||||
2975 | Expr *Expr::IgnoreConversionOperator() { | |||
2976 | if (auto *MCE = dyn_cast<CXXMemberCallExpr>(this)) { | |||
2977 | if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) | |||
2978 | return MCE->getImplicitObjectArgument(); | |||
2979 | } | |||
2980 | return this; | |||
2981 | } | |||
2982 | ||||
2983 | Expr *Expr::IgnoreParenLValueCasts() { | |||
2984 | return IgnoreExprNodes(this, IgnoreParensSingleStep, | |||
2985 | IgnoreLValueCastsSingleStep); | |||
2986 | } | |||
2987 | ||||
2988 | Expr *Expr::ignoreParenBaseCasts() { | |||
2989 | return IgnoreExprNodes(this, IgnoreParensSingleStep, | |||
2990 | IgnoreBaseCastsSingleStep); | |||
2991 | } | |||
2992 | ||||
2993 | Expr *Expr::IgnoreParenNoopCasts(const ASTContext &Ctx) { | |||
2994 | return IgnoreExprNodes(this, IgnoreParensSingleStep, [&Ctx](Expr *E) { | |||
2995 | return IgnoreNoopCastsSingleStep(Ctx, E); | |||
2996 | }); | |||
2997 | } | |||
2998 | ||||
2999 | bool Expr::isDefaultArgument() const { | |||
3000 | const Expr *E = this; | |||
3001 | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
3002 | E = M->GetTemporaryExpr(); | |||
3003 | ||||
3004 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) | |||
3005 | E = ICE->getSubExprAsWritten(); | |||
3006 | ||||
3007 | return isa<CXXDefaultArgExpr>(E); | |||
3008 | } | |||
3009 | ||||
3010 | /// Skip over any no-op casts and any temporary-binding | |||
3011 | /// expressions. | |||
3012 | static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { | |||
3013 | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
3014 | E = M->GetTemporaryExpr(); | |||
3015 | ||||
3016 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | |||
3017 | if (ICE->getCastKind() == CK_NoOp) | |||
3018 | E = ICE->getSubExpr(); | |||
3019 | else | |||
3020 | break; | |||
3021 | } | |||
3022 | ||||
3023 | while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) | |||
3024 | E = BE->getSubExpr(); | |||
3025 | ||||
3026 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | |||
3027 | if (ICE->getCastKind() == CK_NoOp) | |||
3028 | E = ICE->getSubExpr(); | |||
3029 | else | |||
3030 | break; | |||
3031 | } | |||
3032 | ||||
3033 | return E->IgnoreParens(); | |||
3034 | } | |||
3035 | ||||
3036 | /// isTemporaryObject - Determines if this expression produces a | |||
3037 | /// temporary of the given class type. | |||
3038 | bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { | |||
3039 | if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) | |||
3040 | return false; | |||
3041 | ||||
3042 | const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); | |||
3043 | ||||
3044 | // Temporaries are by definition pr-values of class type. | |||
3045 | if (!E->Classify(C).isPRValue()) { | |||
3046 | // In this context, property reference is a message call and is pr-value. | |||
3047 | if (!isa<ObjCPropertyRefExpr>(E)) | |||
3048 | return false; | |||
3049 | } | |||
3050 | ||||
3051 | // Black-list a few cases which yield pr-values of class type that don't | |||
3052 | // refer to temporaries of that type: | |||
3053 | ||||
3054 | // - implicit derived-to-base conversions | |||
3055 | if (isa<ImplicitCastExpr>(E)) { | |||
3056 | switch (cast<ImplicitCastExpr>(E)->getCastKind()) { | |||
3057 | case CK_DerivedToBase: | |||
3058 | case CK_UncheckedDerivedToBase: | |||
3059 | return false; | |||
3060 | default: | |||
3061 | break; | |||
3062 | } | |||
3063 | } | |||
3064 | ||||
3065 | // - member expressions (all) | |||
3066 | if (isa<MemberExpr>(E)) | |||
3067 | return false; | |||
3068 | ||||
3069 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) | |||
3070 | if (BO->isPtrMemOp()) | |||
3071 | return false; | |||
3072 | ||||
3073 | // - opaque values (all) | |||
3074 | if (isa<OpaqueValueExpr>(E)) | |||
3075 | return false; | |||
3076 | ||||
3077 | return true; | |||
3078 | } | |||
3079 | ||||
3080 | bool Expr::isImplicitCXXThis() const { | |||
3081 | const Expr *E = this; | |||
3082 | ||||
3083 | // Strip away parentheses and casts we don't care about. | |||
3084 | while (true) { | |||
3085 | if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { | |||
3086 | E = Paren->getSubExpr(); | |||
3087 | continue; | |||
3088 | } | |||
3089 | ||||
3090 | if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | |||
3091 | if (ICE->getCastKind() == CK_NoOp || | |||
3092 | ICE->getCastKind() == CK_LValueToRValue || | |||
3093 | ICE->getCastKind() == CK_DerivedToBase || | |||
3094 | ICE->getCastKind() == CK_UncheckedDerivedToBase) { | |||
3095 | E = ICE->getSubExpr(); | |||
3096 | continue; | |||
3097 | } | |||
3098 | } | |||
3099 | ||||
3100 | if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { | |||
3101 | if (UnOp->getOpcode() == UO_Extension) { | |||
3102 | E = UnOp->getSubExpr(); | |||
3103 | continue; | |||
3104 | } | |||
3105 | } | |||
3106 | ||||
3107 | if (const MaterializeTemporaryExpr *M | |||
3108 | = dyn_cast<MaterializeTemporaryExpr>(E)) { | |||
3109 | E = M->GetTemporaryExpr(); | |||
3110 | continue; | |||
3111 | } | |||
3112 | ||||
3113 | break; | |||
3114 | } | |||
3115 | ||||
3116 | if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) | |||
3117 | return This->isImplicit(); | |||
3118 | ||||
3119 | return false; | |||
3120 | } | |||
3121 | ||||
3122 | /// hasAnyTypeDependentArguments - Determines if any of the expressions | |||
3123 | /// in Exprs is type-dependent. | |||
3124 | bool Expr::hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs) { | |||
3125 | for (unsigned I = 0; I < Exprs.size(); ++I) | |||
3126 | if (Exprs[I]->isTypeDependent()) | |||
3127 | return true; | |||
3128 | ||||
3129 | return false; | |||
3130 | } | |||
3131 | ||||
3132 | bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef, | |||
3133 | const Expr **Culprit) const { | |||
3134 | assert(!isValueDependent() &&((!isValueDependent() && "Expression evaluator can't be called on a dependent expression." ) ? static_cast<void> (0) : __assert_fail ("!isValueDependent() && \"Expression evaluator can't be called on a dependent expression.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3135, __PRETTY_FUNCTION__)) | |||
| ||||
3135 | "Expression evaluator can't be called on a dependent expression.")((!isValueDependent() && "Expression evaluator can't be called on a dependent expression." ) ? static_cast<void> (0) : __assert_fail ("!isValueDependent() && \"Expression evaluator can't be called on a dependent expression.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3135, __PRETTY_FUNCTION__)); | |||
3136 | ||||
3137 | // This function is attempting whether an expression is an initializer | |||
3138 | // which can be evaluated at compile-time. It very closely parallels | |||
3139 | // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it | |||
3140 | // will lead to unexpected results. Like ConstExprEmitter, it falls back | |||
3141 | // to isEvaluatable most of the time. | |||
3142 | // | |||
3143 | // If we ever capture reference-binding directly in the AST, we can | |||
3144 | // kill the second parameter. | |||
3145 | ||||
3146 | if (IsForRef) { | |||
3147 | EvalResult Result; | |||
3148 | if (EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects) | |||
3149 | return true; | |||
3150 | if (Culprit) | |||
3151 | *Culprit = this; | |||
3152 | return false; | |||
3153 | } | |||
3154 | ||||
3155 | switch (getStmtClass()) { | |||
3156 | default: break; | |||
3157 | case StringLiteralClass: | |||
3158 | case ObjCEncodeExprClass: | |||
3159 | return true; | |||
3160 | case CXXTemporaryObjectExprClass: | |||
3161 | case CXXConstructExprClass: { | |||
3162 | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); | |||
3163 | ||||
3164 | if (CE->getConstructor()->isTrivial() && | |||
3165 | CE->getConstructor()->getParent()->hasTrivialDestructor()) { | |||
3166 | // Trivial default constructor | |||
3167 | if (!CE->getNumArgs()) return true; | |||
3168 | ||||
3169 | // Trivial copy constructor | |||
3170 | assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument")((CE->getNumArgs() == 1 && "trivial ctor with > 1 argument" ) ? static_cast<void> (0) : __assert_fail ("CE->getNumArgs() == 1 && \"trivial ctor with > 1 argument\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3170, __PRETTY_FUNCTION__)); | |||
3171 | return CE->getArg(0)->isConstantInitializer(Ctx, false, Culprit); | |||
3172 | } | |||
3173 | ||||
3174 | break; | |||
3175 | } | |||
3176 | case ConstantExprClass: { | |||
3177 | // FIXME: We should be able to return "true" here, but it can lead to extra | |||
3178 | // error messages. E.g. in Sema/array-init.c. | |||
3179 | const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr(); | |||
3180 | return Exp->isConstantInitializer(Ctx, false, Culprit); | |||
3181 | } | |||
3182 | case CompoundLiteralExprClass: { | |||
3183 | // This handles gcc's extension that allows global initializers like | |||
3184 | // "struct x {int x;} x = (struct x) {};". | |||
3185 | // FIXME: This accepts other cases it shouldn't! | |||
3186 | const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); | |||
3187 | return Exp->isConstantInitializer(Ctx, false, Culprit); | |||
3188 | } | |||
3189 | case DesignatedInitUpdateExprClass: { | |||
3190 | const DesignatedInitUpdateExpr *DIUE = cast<DesignatedInitUpdateExpr>(this); | |||
3191 | return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) && | |||
3192 | DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit); | |||
3193 | } | |||
3194 | case InitListExprClass: { | |||
3195 | const InitListExpr *ILE = cast<InitListExpr>(this); | |||
3196 | assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form")((ILE->isSemanticForm() && "InitListExpr must be in semantic form" ) ? static_cast<void> (0) : __assert_fail ("ILE->isSemanticForm() && \"InitListExpr must be in semantic form\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3196, __PRETTY_FUNCTION__)); | |||
3197 | if (ILE->getType()->isArrayType()) { | |||
3198 | unsigned numInits = ILE->getNumInits(); | |||
3199 | for (unsigned i = 0; i < numInits; i++) { | |||
3200 | if (!ILE->getInit(i)->isConstantInitializer(Ctx, false, Culprit)) | |||
3201 | return false; | |||
3202 | } | |||
3203 | return true; | |||
3204 | } | |||
3205 | ||||
3206 | if (ILE->getType()->isRecordType()) { | |||
3207 | unsigned ElementNo = 0; | |||
3208 | RecordDecl *RD = ILE->getType()->getAs<RecordType>()->getDecl(); | |||
| ||||
3209 | for (const auto *Field : RD->fields()) { | |||
3210 | // If this is a union, skip all the fields that aren't being initialized. | |||
3211 | if (RD->isUnion() && ILE->getInitializedFieldInUnion() != Field) | |||
3212 | continue; | |||
3213 | ||||
3214 | // Don't emit anonymous bitfields, they just affect layout. | |||
3215 | if (Field->isUnnamedBitfield()) | |||
3216 | continue; | |||
3217 | ||||
3218 | if (ElementNo < ILE->getNumInits()) { | |||
3219 | const Expr *Elt = ILE->getInit(ElementNo++); | |||
3220 | if (Field->isBitField()) { | |||
3221 | // Bitfields have to evaluate to an integer. | |||
3222 | EvalResult Result; | |||
3223 | if (!Elt->EvaluateAsInt(Result, Ctx)) { | |||
3224 | if (Culprit) | |||
3225 | *Culprit = Elt; | |||
3226 | return false; | |||
3227 | } | |||
3228 | } else { | |||
3229 | bool RefType = Field->getType()->isReferenceType(); | |||
3230 | if (!Elt->isConstantInitializer(Ctx, RefType, Culprit)) | |||
3231 | return false; | |||
3232 | } | |||
3233 | } | |||
3234 | } | |||
3235 | return true; | |||
3236 | } | |||
3237 | ||||
3238 | break; | |||
3239 | } | |||
3240 | case ImplicitValueInitExprClass: | |||
3241 | case NoInitExprClass: | |||
3242 | return true; | |||
3243 | case ParenExprClass: | |||
3244 | return cast<ParenExpr>(this)->getSubExpr() | |||
3245 | ->isConstantInitializer(Ctx, IsForRef, Culprit); | |||
3246 | case GenericSelectionExprClass: | |||
3247 | return cast<GenericSelectionExpr>(this)->getResultExpr() | |||
3248 | ->isConstantInitializer(Ctx, IsForRef, Culprit); | |||
3249 | case ChooseExprClass: | |||
3250 | if (cast<ChooseExpr>(this)->isConditionDependent()) { | |||
3251 | if (Culprit) | |||
3252 | *Culprit = this; | |||
3253 | return false; | |||
3254 | } | |||
3255 | return cast<ChooseExpr>(this)->getChosenSubExpr() | |||
3256 | ->isConstantInitializer(Ctx, IsForRef, Culprit); | |||
3257 | case UnaryOperatorClass: { | |||
3258 | const UnaryOperator* Exp = cast<UnaryOperator>(this); | |||
3259 | if (Exp->getOpcode() == UO_Extension) | |||
3260 | return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); | |||
3261 | break; | |||
3262 | } | |||
3263 | case CXXFunctionalCastExprClass: | |||
3264 | case CXXStaticCastExprClass: | |||
3265 | case ImplicitCastExprClass: | |||
3266 | case CStyleCastExprClass: | |||
3267 | case ObjCBridgedCastExprClass: | |||
3268 | case CXXDynamicCastExprClass: | |||
3269 | case CXXReinterpretCastExprClass: | |||
3270 | case CXXConstCastExprClass: { | |||
3271 | const CastExpr *CE = cast<CastExpr>(this); | |||
3272 | ||||
3273 | // Handle misc casts we want to ignore. | |||
3274 | if (CE->getCastKind() == CK_NoOp || | |||
3275 | CE->getCastKind() == CK_LValueToRValue || | |||
3276 | CE->getCastKind() == CK_ToUnion || | |||
3277 | CE->getCastKind() == CK_ConstructorConversion || | |||
3278 | CE->getCastKind() == CK_NonAtomicToAtomic || | |||
3279 | CE->getCastKind() == CK_AtomicToNonAtomic || | |||
3280 | CE->getCastKind() == CK_IntToOCLSampler) | |||
3281 | return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); | |||
3282 | ||||
3283 | break; | |||
3284 | } | |||
3285 | case MaterializeTemporaryExprClass: | |||
3286 | return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() | |||
3287 | ->isConstantInitializer(Ctx, false, Culprit); | |||
3288 | ||||
3289 | case SubstNonTypeTemplateParmExprClass: | |||
3290 | return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement() | |||
3291 | ->isConstantInitializer(Ctx, false, Culprit); | |||
3292 | case CXXDefaultArgExprClass: | |||
3293 | return cast<CXXDefaultArgExpr>(this)->getExpr() | |||
3294 | ->isConstantInitializer(Ctx, false, Culprit); | |||
3295 | case CXXDefaultInitExprClass: | |||
3296 | return cast<CXXDefaultInitExpr>(this)->getExpr() | |||
3297 | ->isConstantInitializer(Ctx, false, Culprit); | |||
3298 | } | |||
3299 | // Allow certain forms of UB in constant initializers: signed integer | |||
3300 | // overflow and floating-point division by zero. We'll give a warning on | |||
3301 | // these, but they're common enough that we have to accept them. | |||
3302 | if (isEvaluatable(Ctx, SE_AllowUndefinedBehavior)) | |||
3303 | return true; | |||
3304 | if (Culprit) | |||
3305 | *Culprit = this; | |||
3306 | return false; | |||
3307 | } | |||
3308 | ||||
3309 | bool CallExpr::isBuiltinAssumeFalse(const ASTContext &Ctx) const { | |||
3310 | const FunctionDecl* FD = getDirectCallee(); | |||
3311 | if (!FD || (FD->getBuiltinID() != Builtin::BI__assume && | |||
3312 | FD->getBuiltinID() != Builtin::BI__builtin_assume)) | |||
3313 | return false; | |||
3314 | ||||
3315 | const Expr* Arg = getArg(0); | |||
3316 | bool ArgVal; | |||
3317 | return !Arg->isValueDependent() && | |||
3318 | Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && !ArgVal; | |||
3319 | } | |||
3320 | ||||
3321 | namespace { | |||
3322 | /// Look for any side effects within a Stmt. | |||
3323 | class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> { | |||
3324 | typedef ConstEvaluatedExprVisitor<SideEffectFinder> Inherited; | |||
3325 | const bool IncludePossibleEffects; | |||
3326 | bool HasSideEffects; | |||
3327 | ||||
3328 | public: | |||
3329 | explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible) | |||
3330 | : Inherited(Context), | |||
3331 | IncludePossibleEffects(IncludePossible), HasSideEffects(false) { } | |||
3332 | ||||
3333 | bool hasSideEffects() const { return HasSideEffects; } | |||
3334 | ||||
3335 | void VisitExpr(const Expr *E) { | |||
3336 | if (!HasSideEffects && | |||
3337 | E->HasSideEffects(Context, IncludePossibleEffects)) | |||
3338 | HasSideEffects = true; | |||
3339 | } | |||
3340 | }; | |||
3341 | } | |||
3342 | ||||
3343 | bool Expr::HasSideEffects(const ASTContext &Ctx, | |||
3344 | bool IncludePossibleEffects) const { | |||
3345 | // In circumstances where we care about definite side effects instead of | |||
3346 | // potential side effects, we want to ignore expressions that are part of a | |||
3347 | // macro expansion as a potential side effect. | |||
3348 | if (!IncludePossibleEffects && getExprLoc().isMacroID()) | |||
3349 | return false; | |||
3350 | ||||
3351 | if (isInstantiationDependent()) | |||
3352 | return IncludePossibleEffects; | |||
3353 | ||||
3354 | switch (getStmtClass()) { | |||
3355 | case NoStmtClass: | |||
3356 | #define ABSTRACT_STMT(Type) | |||
3357 | #define STMT(Type, Base) case Type##Class: | |||
3358 | #define EXPR(Type, Base) | |||
3359 | #include "clang/AST/StmtNodes.inc" | |||
3360 | llvm_unreachable("unexpected Expr kind")::llvm::llvm_unreachable_internal("unexpected Expr kind", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3360); | |||
3361 | ||||
3362 | case DependentScopeDeclRefExprClass: | |||
3363 | case CXXUnresolvedConstructExprClass: | |||
3364 | case CXXDependentScopeMemberExprClass: | |||
3365 | case UnresolvedLookupExprClass: | |||
3366 | case UnresolvedMemberExprClass: | |||
3367 | case PackExpansionExprClass: | |||
3368 | case SubstNonTypeTemplateParmPackExprClass: | |||
3369 | case FunctionParmPackExprClass: | |||
3370 | case TypoExprClass: | |||
3371 | case CXXFoldExprClass: | |||
3372 | llvm_unreachable("shouldn't see dependent / unresolved nodes here")::llvm::llvm_unreachable_internal("shouldn't see dependent / unresolved nodes here" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3372); | |||
3373 | ||||
3374 | case DeclRefExprClass: | |||
3375 | case ObjCIvarRefExprClass: | |||
3376 | case PredefinedExprClass: | |||
3377 | case IntegerLiteralClass: | |||
3378 | case FixedPointLiteralClass: | |||
3379 | case FloatingLiteralClass: | |||
3380 | case ImaginaryLiteralClass: | |||
3381 | case StringLiteralClass: | |||
3382 | case CharacterLiteralClass: | |||
3383 | case OffsetOfExprClass: | |||
3384 | case ImplicitValueInitExprClass: | |||
3385 | case UnaryExprOrTypeTraitExprClass: | |||
3386 | case AddrLabelExprClass: | |||
3387 | case GNUNullExprClass: | |||
3388 | case ArrayInitIndexExprClass: | |||
3389 | case NoInitExprClass: | |||
3390 | case CXXBoolLiteralExprClass: | |||
3391 | case CXXNullPtrLiteralExprClass: | |||
3392 | case CXXThisExprClass: | |||
3393 | case CXXScalarValueInitExprClass: | |||
3394 | case TypeTraitExprClass: | |||
3395 | case ArrayTypeTraitExprClass: | |||
3396 | case ExpressionTraitExprClass: | |||
3397 | case CXXNoexceptExprClass: | |||
3398 | case SizeOfPackExprClass: | |||
3399 | case ObjCStringLiteralClass: | |||
3400 | case ObjCEncodeExprClass: | |||
3401 | case ObjCBoolLiteralExprClass: | |||
3402 | case ObjCAvailabilityCheckExprClass: | |||
3403 | case CXXUuidofExprClass: | |||
3404 | case OpaqueValueExprClass: | |||
3405 | case SourceLocExprClass: | |||
3406 | // These never have a side-effect. | |||
3407 | return false; | |||
3408 | ||||
3409 | case ConstantExprClass: | |||
3410 | // FIXME: Move this into the "return false;" block above. | |||
3411 | return cast<ConstantExpr>(this)->getSubExpr()->HasSideEffects( | |||
3412 | Ctx, IncludePossibleEffects); | |||
3413 | ||||
3414 | case CallExprClass: | |||
3415 | case CXXOperatorCallExprClass: | |||
3416 | case CXXMemberCallExprClass: | |||
3417 | case CUDAKernelCallExprClass: | |||
3418 | case UserDefinedLiteralClass: { | |||
3419 | // We don't know a call definitely has side effects, except for calls | |||
3420 | // to pure/const functions that definitely don't. | |||
3421 | // If the call itself is considered side-effect free, check the operands. | |||
3422 | const Decl *FD = cast<CallExpr>(this)->getCalleeDecl(); | |||
3423 | bool IsPure = FD && (FD->hasAttr<ConstAttr>() || FD->hasAttr<PureAttr>()); | |||
3424 | if (IsPure || !IncludePossibleEffects) | |||
3425 | break; | |||
3426 | return true; | |||
3427 | } | |||
3428 | ||||
3429 | case BlockExprClass: | |||
3430 | case CXXBindTemporaryExprClass: | |||
3431 | if (!IncludePossibleEffects) | |||
3432 | break; | |||
3433 | return true; | |||
3434 | ||||
3435 | case MSPropertyRefExprClass: | |||
3436 | case MSPropertySubscriptExprClass: | |||
3437 | case CompoundAssignOperatorClass: | |||
3438 | case VAArgExprClass: | |||
3439 | case AtomicExprClass: | |||
3440 | case CXXThrowExprClass: | |||
3441 | case CXXNewExprClass: | |||
3442 | case CXXDeleteExprClass: | |||
3443 | case CoawaitExprClass: | |||
3444 | case DependentCoawaitExprClass: | |||
3445 | case CoyieldExprClass: | |||
3446 | // These always have a side-effect. | |||
3447 | return true; | |||
3448 | ||||
3449 | case StmtExprClass: { | |||
3450 | // StmtExprs have a side-effect if any substatement does. | |||
3451 | SideEffectFinder Finder(Ctx, IncludePossibleEffects); | |||
3452 | Finder.Visit(cast<StmtExpr>(this)->getSubStmt()); | |||
3453 | return Finder.hasSideEffects(); | |||
3454 | } | |||
3455 | ||||
3456 | case ExprWithCleanupsClass: | |||
3457 | if (IncludePossibleEffects) | |||
3458 | if (cast<ExprWithCleanups>(this)->cleanupsHaveSideEffects()) | |||
3459 | return true; | |||
3460 | break; | |||
3461 | ||||
3462 | case ParenExprClass: | |||
3463 | case ArraySubscriptExprClass: | |||
3464 | case OMPArraySectionExprClass: | |||
3465 | case MemberExprClass: | |||
3466 | case ConditionalOperatorClass: | |||
3467 | case BinaryConditionalOperatorClass: | |||
3468 | case CompoundLiteralExprClass: | |||
3469 | case ExtVectorElementExprClass: | |||
3470 | case DesignatedInitExprClass: | |||
3471 | case DesignatedInitUpdateExprClass: | |||
3472 | case ArrayInitLoopExprClass: | |||
3473 | case ParenListExprClass: | |||
3474 | case CXXPseudoDestructorExprClass: | |||
3475 | case CXXStdInitializerListExprClass: | |||
3476 | case SubstNonTypeTemplateParmExprClass: | |||
3477 | case MaterializeTemporaryExprClass: | |||
3478 | case ShuffleVectorExprClass: | |||
3479 | case ConvertVectorExprClass: | |||
3480 | case AsTypeExprClass: | |||
3481 | // These have a side-effect if any subexpression does. | |||
3482 | break; | |||
3483 | ||||
3484 | case UnaryOperatorClass: | |||
3485 | if (cast<UnaryOperator>(this)->isIncrementDecrementOp()) | |||
3486 | return true; | |||
3487 | break; | |||
3488 | ||||
3489 | case BinaryOperatorClass: | |||
3490 | if (cast<BinaryOperator>(this)->isAssignmentOp()) | |||
3491 | return true; | |||
3492 | break; | |||
3493 | ||||
3494 | case InitListExprClass: | |||
3495 | // FIXME: The children for an InitListExpr doesn't include the array filler. | |||
3496 | if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller()) | |||
3497 | if (E->HasSideEffects(Ctx, IncludePossibleEffects)) | |||
3498 | return true; | |||
3499 | break; | |||
3500 | ||||
3501 | case GenericSelectionExprClass: | |||
3502 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> | |||
3503 | HasSideEffects(Ctx, IncludePossibleEffects); | |||
3504 | ||||
3505 | case ChooseExprClass: | |||
3506 | return cast<ChooseExpr>(this)->getChosenSubExpr()->HasSideEffects( | |||
3507 | Ctx, IncludePossibleEffects); | |||
3508 | ||||
3509 | case CXXDefaultArgExprClass: | |||
3510 | return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects( | |||
3511 | Ctx, IncludePossibleEffects); | |||
3512 | ||||
3513 | case CXXDefaultInitExprClass: { | |||
3514 | const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)->getField(); | |||
3515 | if (const Expr *E = FD->getInClassInitializer()) | |||
3516 | return E->HasSideEffects(Ctx, IncludePossibleEffects); | |||
3517 | // If we've not yet parsed the initializer, assume it has side-effects. | |||
3518 | return true; | |||
3519 | } | |||
3520 | ||||
3521 | case CXXDynamicCastExprClass: { | |||
3522 | // A dynamic_cast expression has side-effects if it can throw. | |||
3523 | const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this); | |||
3524 | if (DCE->getTypeAsWritten()->isReferenceType() && | |||
3525 | DCE->getCastKind() == CK_Dynamic) | |||
3526 | return true; | |||
3527 | } | |||
3528 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | |||
3529 | case ImplicitCastExprClass: | |||
3530 | case CStyleCastExprClass: | |||
3531 | case CXXStaticCastExprClass: | |||
3532 | case CXXReinterpretCastExprClass: | |||
3533 | case CXXConstCastExprClass: | |||
3534 | case CXXFunctionalCastExprClass: | |||
3535 | case BuiltinBitCastExprClass: { | |||
3536 | // While volatile reads are side-effecting in both C and C++, we treat them | |||
3537 | // as having possible (not definite) side-effects. This allows idiomatic | |||
3538 | // code to behave without warning, such as sizeof(*v) for a volatile- | |||
3539 | // qualified pointer. | |||
3540 | if (!IncludePossibleEffects) | |||
3541 | break; | |||
3542 | ||||
3543 | const CastExpr *CE = cast<CastExpr>(this); | |||
3544 | if (CE->getCastKind() == CK_LValueToRValue && | |||
3545 | CE->getSubExpr()->getType().isVolatileQualified()) | |||
3546 | return true; | |||
3547 | break; | |||
3548 | } | |||
3549 | ||||
3550 | case CXXTypeidExprClass: | |||
3551 | // typeid might throw if its subexpression is potentially-evaluated, so has | |||
3552 | // side-effects in that case whether or not its subexpression does. | |||
3553 | return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); | |||
3554 | ||||
3555 | case CXXConstructExprClass: | |||
3556 | case CXXTemporaryObjectExprClass: { | |||
3557 | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); | |||
3558 | if (!CE->getConstructor()->isTrivial() && IncludePossibleEffects) | |||
3559 | return true; | |||
3560 | // A trivial constructor does not add any side-effects of its own. Just look | |||
3561 | // at its arguments. | |||
3562 | break; | |||
3563 | } | |||
3564 | ||||
3565 | case CXXInheritedCtorInitExprClass: { | |||
3566 | const auto *ICIE = cast<CXXInheritedCtorInitExpr>(this); | |||
3567 | if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects) | |||
3568 | return true; | |||
3569 | break; | |||
3570 | } | |||
3571 | ||||
3572 | case LambdaExprClass: { | |||
3573 | const LambdaExpr *LE = cast<LambdaExpr>(this); | |||
3574 | for (Expr *E : LE->capture_inits()) | |||
3575 | if (E->HasSideEffects(Ctx, IncludePossibleEffects)) | |||
3576 | return true; | |||
3577 | return false; | |||
3578 | } | |||
3579 | ||||
3580 | case PseudoObjectExprClass: { | |||
3581 | // Only look for side-effects in the semantic form, and look past | |||
3582 | // OpaqueValueExpr bindings in that form. | |||
3583 | const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); | |||
3584 | for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), | |||
3585 | E = PO->semantics_end(); | |||
3586 | I != E; ++I) { | |||
3587 | const Expr *Subexpr = *I; | |||
3588 | if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr)) | |||
3589 | Subexpr = OVE->getSourceExpr(); | |||
3590 | if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects)) | |||
3591 | return true; | |||
3592 | } | |||
3593 | return false; | |||
3594 | } | |||
3595 | ||||
3596 | case ObjCBoxedExprClass: | |||
3597 | case ObjCArrayLiteralClass: | |||
3598 | case ObjCDictionaryLiteralClass: | |||
3599 | case ObjCSelectorExprClass: | |||
3600 | case ObjCProtocolExprClass: | |||
3601 | case ObjCIsaExprClass: | |||
3602 | case ObjCIndirectCopyRestoreExprClass: | |||
3603 | case ObjCSubscriptRefExprClass: | |||
3604 | case ObjCBridgedCastExprClass: | |||
3605 | case ObjCMessageExprClass: | |||
3606 | case ObjCPropertyRefExprClass: | |||
3607 | // FIXME: Classify these cases better. | |||
3608 | if (IncludePossibleEffects) | |||
3609 | return true; | |||
3610 | break; | |||
3611 | } | |||
3612 | ||||
3613 | // Recurse to children. | |||
3614 | for (const Stmt *SubStmt : children()) | |||
3615 | if (SubStmt && | |||
3616 | cast<Expr>(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects)) | |||
3617 | return true; | |||
3618 | ||||
3619 | return false; | |||
3620 | } | |||
3621 | ||||
3622 | namespace { | |||
3623 | /// Look for a call to a non-trivial function within an expression. | |||
3624 | class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder> | |||
3625 | { | |||
3626 | typedef ConstEvaluatedExprVisitor<NonTrivialCallFinder> Inherited; | |||
3627 | ||||
3628 | bool NonTrivial; | |||
3629 | ||||
3630 | public: | |||
3631 | explicit NonTrivialCallFinder(const ASTContext &Context) | |||
3632 | : Inherited(Context), NonTrivial(false) { } | |||
3633 | ||||
3634 | bool hasNonTrivialCall() const { return NonTrivial; } | |||
3635 | ||||
3636 | void VisitCallExpr(const CallExpr *E) { | |||
3637 | if (const CXXMethodDecl *Method | |||
3638 | = dyn_cast_or_null<const CXXMethodDecl>(E->getCalleeDecl())) { | |||
3639 | if (Method->isTrivial()) { | |||
3640 | // Recurse to children of the call. | |||
3641 | Inherited::VisitStmt(E); | |||
3642 | return; | |||
3643 | } | |||
3644 | } | |||
3645 | ||||
3646 | NonTrivial = true; | |||
3647 | } | |||
3648 | ||||
3649 | void VisitCXXConstructExpr(const CXXConstructExpr *E) { | |||
3650 | if (E->getConstructor()->isTrivial()) { | |||
3651 | // Recurse to children of the call. | |||
3652 | Inherited::VisitStmt(E); | |||
3653 | return; | |||
3654 | } | |||
3655 | ||||
3656 | NonTrivial = true; | |||
3657 | } | |||
3658 | ||||
3659 | void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) { | |||
3660 | if (E->getTemporary()->getDestructor()->isTrivial()) { | |||
3661 | Inherited::VisitStmt(E); | |||
3662 | return; | |||
3663 | } | |||
3664 | ||||
3665 | NonTrivial = true; | |||
3666 | } | |||
3667 | }; | |||
3668 | } | |||
3669 | ||||
3670 | bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const { | |||
3671 | NonTrivialCallFinder Finder(Ctx); | |||
3672 | Finder.Visit(this); | |||
3673 | return Finder.hasNonTrivialCall(); | |||
3674 | } | |||
3675 | ||||
3676 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null | |||
3677 | /// pointer constant or not, as well as the specific kind of constant detected. | |||
3678 | /// Null pointer constants can be integer constant expressions with the | |||
3679 | /// value zero, casts of zero to void*, nullptr (C++0X), or __null | |||
3680 | /// (a GNU extension). | |||
3681 | Expr::NullPointerConstantKind | |||
3682 | Expr::isNullPointerConstant(ASTContext &Ctx, | |||
3683 | NullPointerConstantValueDependence NPC) const { | |||
3684 | if (isValueDependent() && | |||
3685 | (!Ctx.getLangOpts().CPlusPlus11 || Ctx.getLangOpts().MSVCCompat)) { | |||
3686 | switch (NPC) { | |||
3687 | case NPC_NeverValueDependent: | |||
3688 | llvm_unreachable("Unexpected value dependent expression!")::llvm::llvm_unreachable_internal("Unexpected value dependent expression!" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3688); | |||
3689 | case NPC_ValueDependentIsNull: | |||
3690 | if (isTypeDependent() || getType()->isIntegralType(Ctx)) | |||
3691 | return NPCK_ZeroExpression; | |||
3692 | else | |||
3693 | return NPCK_NotNull; | |||
3694 | ||||
3695 | case NPC_ValueDependentIsNotNull: | |||
3696 | return NPCK_NotNull; | |||
3697 | } | |||
3698 | } | |||
3699 | ||||
3700 | // Strip off a cast to void*, if it exists. Except in C++. | |||
3701 | if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { | |||
3702 | if (!Ctx.getLangOpts().CPlusPlus) { | |||
3703 | // Check that it is a cast to void*. | |||
3704 | if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { | |||
3705 | QualType Pointee = PT->getPointeeType(); | |||
3706 | Qualifiers Qs = Pointee.getQualifiers(); | |||
3707 | // Only (void*)0 or equivalent are treated as nullptr. If pointee type | |||
3708 | // has non-default address space it is not treated as nullptr. | |||
3709 | // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr | |||
3710 | // since it cannot be assigned to a pointer to constant address space. | |||
3711 | if ((Ctx.getLangOpts().OpenCLVersion >= 200 && | |||
3712 | Pointee.getAddressSpace() == LangAS::opencl_generic) || | |||
3713 | (Ctx.getLangOpts().OpenCL && | |||
3714 | Ctx.getLangOpts().OpenCLVersion < 200 && | |||
3715 | Pointee.getAddressSpace() == LangAS::opencl_private)) | |||
3716 | Qs.removeAddressSpace(); | |||
3717 | ||||
3718 | if (Pointee->isVoidType() && Qs.empty() && // to void* | |||
3719 | CE->getSubExpr()->getType()->isIntegerType()) // from int | |||
3720 | return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); | |||
3721 | } | |||
3722 | } | |||
3723 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { | |||
3724 | // Ignore the ImplicitCastExpr type entirely. | |||
3725 | return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); | |||
3726 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { | |||
3727 | // Accept ((void*)0) as a null pointer constant, as many other | |||
3728 | // implementations do. | |||
3729 | return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); | |||
3730 | } else if (const GenericSelectionExpr *GE = | |||
3731 | dyn_cast<GenericSelectionExpr>(this)) { | |||
3732 | if (GE->isResultDependent()) | |||
3733 | return NPCK_NotNull; | |||
3734 | return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); | |||
3735 | } else if (const ChooseExpr *CE = dyn_cast<ChooseExpr>(this)) { | |||
3736 | if (CE->isConditionDependent()) | |||
3737 | return NPCK_NotNull; | |||
3738 | return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC); | |||
3739 | } else if (const CXXDefaultArgExpr *DefaultArg | |||
3740 | = dyn_cast<CXXDefaultArgExpr>(this)) { | |||
3741 | // See through default argument expressions. | |||
3742 | return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); | |||
3743 | } else if (const CXXDefaultInitExpr *DefaultInit | |||
3744 | = dyn_cast<CXXDefaultInitExpr>(this)) { | |||
3745 | // See through default initializer expressions. | |||
3746 | return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC); | |||
3747 | } else if (isa<GNUNullExpr>(this)) { | |||
3748 | // The GNU __null extension is always a null pointer constant. | |||
3749 | return NPCK_GNUNull; | |||
3750 | } else if (const MaterializeTemporaryExpr *M | |||
3751 | = dyn_cast<MaterializeTemporaryExpr>(this)) { | |||
3752 | return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); | |||
3753 | } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { | |||
3754 | if (const Expr *Source = OVE->getSourceExpr()) | |||
3755 | return Source->isNullPointerConstant(Ctx, NPC); | |||
3756 | } | |||
3757 | ||||
3758 | // C++11 nullptr_t is always a null pointer constant. | |||
3759 | if (getType()->isNullPtrType()) | |||
3760 | return NPCK_CXX11_nullptr; | |||
3761 | ||||
3762 | if (const RecordType *UT = getType()->getAsUnionType()) | |||
3763 | if (!Ctx.getLangOpts().CPlusPlus11 && | |||
3764 | UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) | |||
3765 | if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ | |||
3766 | const Expr *InitExpr = CLE->getInitializer(); | |||
3767 | if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) | |||
3768 | return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); | |||
3769 | } | |||
3770 | // This expression must be an integer type. | |||
3771 | if (!getType()->isIntegerType() || | |||
3772 | (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType())) | |||
3773 | return NPCK_NotNull; | |||
3774 | ||||
3775 | if (Ctx.getLangOpts().CPlusPlus11) { | |||
3776 | // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with | |||
3777 | // value zero or a prvalue of type std::nullptr_t. | |||
3778 | // Microsoft mode permits C++98 rules reflecting MSVC behavior. | |||
3779 | const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this); | |||
3780 | if (Lit && !Lit->getValue()) | |||
3781 | return NPCK_ZeroLiteral; | |||
3782 | else if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx)) | |||
3783 | return NPCK_NotNull; | |||
3784 | } else { | |||
3785 | // If we have an integer constant expression, we need to *evaluate* it and | |||
3786 | // test for the value 0. | |||
3787 | if (!isIntegerConstantExpr(Ctx)) | |||
3788 | return NPCK_NotNull; | |||
3789 | } | |||
3790 | ||||
3791 | if (EvaluateKnownConstInt(Ctx) != 0) | |||
3792 | return NPCK_NotNull; | |||
3793 | ||||
3794 | if (isa<IntegerLiteral>(this)) | |||
3795 | return NPCK_ZeroLiteral; | |||
3796 | return NPCK_ZeroExpression; | |||
3797 | } | |||
3798 | ||||
3799 | /// If this expression is an l-value for an Objective C | |||
3800 | /// property, find the underlying property reference expression. | |||
3801 | const ObjCPropertyRefExpr *Expr::getObjCProperty() const { | |||
3802 | const Expr *E = this; | |||
3803 | while (true) { | |||
3804 | assert((E->getValueKind() == VK_LValue &&(((E->getValueKind() == VK_LValue && E->getObjectKind () == OK_ObjCProperty) && "expression is not a property reference" ) ? static_cast<void> (0) : __assert_fail ("(E->getValueKind() == VK_LValue && E->getObjectKind() == OK_ObjCProperty) && \"expression is not a property reference\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3806, __PRETTY_FUNCTION__)) | |||
3805 | E->getObjectKind() == OK_ObjCProperty) &&(((E->getValueKind() == VK_LValue && E->getObjectKind () == OK_ObjCProperty) && "expression is not a property reference" ) ? static_cast<void> (0) : __assert_fail ("(E->getValueKind() == VK_LValue && E->getObjectKind() == OK_ObjCProperty) && \"expression is not a property reference\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3806, __PRETTY_FUNCTION__)) | |||
3806 | "expression is not a property reference")(((E->getValueKind() == VK_LValue && E->getObjectKind () == OK_ObjCProperty) && "expression is not a property reference" ) ? static_cast<void> (0) : __assert_fail ("(E->getValueKind() == VK_LValue && E->getObjectKind() == OK_ObjCProperty) && \"expression is not a property reference\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 3806, __PRETTY_FUNCTION__)); | |||
3807 | E = E->IgnoreParenCasts(); | |||
3808 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { | |||
3809 | if (BO->getOpcode() == BO_Comma) { | |||
3810 | E = BO->getRHS(); | |||
3811 | continue; | |||
3812 | } | |||
3813 | } | |||
3814 | ||||
3815 | break; | |||
3816 | } | |||
3817 | ||||
3818 | return cast<ObjCPropertyRefExpr>(E); | |||
3819 | } | |||
3820 | ||||
3821 | bool Expr::isObjCSelfExpr() const { | |||
3822 | const Expr *E = IgnoreParenImpCasts(); | |||
3823 | ||||
3824 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); | |||
3825 | if (!DRE) | |||
3826 | return false; | |||
3827 | ||||
3828 | const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); | |||
3829 | if (!Param) | |||
3830 | return false; | |||
3831 | ||||
3832 | const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); | |||
3833 | if (!M) | |||
3834 | return false; | |||
3835 | ||||
3836 | return M->getSelfDecl() == Param; | |||
3837 | } | |||
3838 | ||||
3839 | FieldDecl *Expr::getSourceBitField() { | |||
3840 | Expr *E = this->IgnoreParens(); | |||
3841 | ||||
3842 | while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | |||
3843 | if (ICE->getCastKind() == CK_LValueToRValue || | |||
3844 | (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) | |||
3845 | E = ICE->getSubExpr()->IgnoreParens(); | |||
3846 | else | |||
3847 | break; | |||
3848 | } | |||
3849 | ||||
3850 | if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) | |||
3851 | if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) | |||
3852 | if (Field->isBitField()) | |||
3853 | return Field; | |||
3854 | ||||
3855 | if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) { | |||
3856 | FieldDecl *Ivar = IvarRef->getDecl(); | |||
3857 | if (Ivar->isBitField()) | |||
3858 | return Ivar; | |||
3859 | } | |||
3860 | ||||
3861 | if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) { | |||
3862 | if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) | |||
3863 | if (Field->isBitField()) | |||
3864 | return Field; | |||
3865 | ||||
3866 | if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl())) | |||
3867 | if (Expr *E = BD->getBinding()) | |||
3868 | return E->getSourceBitField(); | |||
3869 | } | |||
3870 | ||||
3871 | if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { | |||
3872 | if (BinOp->isAssignmentOp() && BinOp->getLHS()) | |||
3873 | return BinOp->getLHS()->getSourceBitField(); | |||
3874 | ||||
3875 | if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) | |||
3876 | return BinOp->getRHS()->getSourceBitField(); | |||
3877 | } | |||
3878 | ||||
3879 | if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) | |||
3880 | if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp()) | |||
3881 | return UnOp->getSubExpr()->getSourceBitField(); | |||
3882 | ||||
3883 | return nullptr; | |||
3884 | } | |||
3885 | ||||
3886 | bool Expr::refersToVectorElement() const { | |||
3887 | // FIXME: Why do we not just look at the ObjectKind here? | |||
3888 | const Expr *E = this->IgnoreParens(); | |||
3889 | ||||
3890 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | |||
3891 | if (ICE->getValueKind() != VK_RValue && | |||
3892 | ICE->getCastKind() == CK_NoOp) | |||
3893 | E = ICE->getSubExpr()->IgnoreParens(); | |||
3894 | else | |||
3895 | break; | |||
3896 | } | |||
3897 | ||||
3898 | if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) | |||
3899 | return ASE->getBase()->getType()->isVectorType(); | |||
3900 | ||||
3901 | if (isa<ExtVectorElementExpr>(E)) | |||
3902 | return true; | |||
3903 | ||||
3904 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) | |||
3905 | if (auto *BD = dyn_cast<BindingDecl>(DRE->getDecl())) | |||
3906 | if (auto *E = BD->getBinding()) | |||
3907 | return E->refersToVectorElement(); | |||
3908 | ||||
3909 | return false; | |||
3910 | } | |||
3911 | ||||
3912 | bool Expr::refersToGlobalRegisterVar() const { | |||
3913 | const Expr *E = this->IgnoreParenImpCasts(); | |||
3914 | ||||
3915 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) | |||
3916 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) | |||
3917 | if (VD->getStorageClass() == SC_Register && | |||
3918 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl()) | |||
3919 | return true; | |||
3920 | ||||
3921 | return false; | |||
3922 | } | |||
3923 | ||||
3924 | bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) { | |||
3925 | E1 = E1->IgnoreParens(); | |||
3926 | E2 = E2->IgnoreParens(); | |||
3927 | ||||
3928 | if (E1->getStmtClass() != E2->getStmtClass()) | |||
3929 | return false; | |||
3930 | ||||
3931 | switch (E1->getStmtClass()) { | |||
3932 | default: | |||
3933 | return false; | |||
3934 | case CXXThisExprClass: | |||
3935 | return true; | |||
3936 | case DeclRefExprClass: { | |||
3937 | // DeclRefExpr without an ImplicitCastExpr can happen for integral | |||
3938 | // template parameters. | |||
3939 | const auto *DRE1 = cast<DeclRefExpr>(E1); | |||
3940 | const auto *DRE2 = cast<DeclRefExpr>(E2); | |||
3941 | return DRE1->isRValue() && DRE2->isRValue() && | |||
3942 | DRE1->getDecl() == DRE2->getDecl(); | |||
3943 | } | |||
3944 | case ImplicitCastExprClass: { | |||
3945 | // Peel off implicit casts. | |||
3946 | while (true) { | |||
3947 | const auto *ICE1 = dyn_cast<ImplicitCastExpr>(E1); | |||
3948 | const auto *ICE2 = dyn_cast<ImplicitCastExpr>(E2); | |||
3949 | if (!ICE1 || !ICE2) | |||
3950 | return false; | |||
3951 | if (ICE1->getCastKind() != ICE2->getCastKind()) | |||
3952 | return false; | |||
3953 | E1 = ICE1->getSubExpr()->IgnoreParens(); | |||
3954 | E2 = ICE2->getSubExpr()->IgnoreParens(); | |||
3955 | // The final cast must be one of these types. | |||
3956 | if (ICE1->getCastKind() == CK_LValueToRValue || | |||
3957 | ICE1->getCastKind() == CK_ArrayToPointerDecay || | |||
3958 | ICE1->getCastKind() == CK_FunctionToPointerDecay) { | |||
3959 | break; | |||
3960 | } | |||
3961 | } | |||
3962 | ||||
3963 | const auto *DRE1 = dyn_cast<DeclRefExpr>(E1); | |||
3964 | const auto *DRE2 = dyn_cast<DeclRefExpr>(E2); | |||
3965 | if (DRE1 && DRE2) | |||
3966 | return declaresSameEntity(DRE1->getDecl(), DRE2->getDecl()); | |||
3967 | ||||
3968 | const auto *Ivar1 = dyn_cast<ObjCIvarRefExpr>(E1); | |||
3969 | const auto *Ivar2 = dyn_cast<ObjCIvarRefExpr>(E2); | |||
3970 | if (Ivar1 && Ivar2) { | |||
3971 | return Ivar1->isFreeIvar() && Ivar2->isFreeIvar() && | |||
3972 | declaresSameEntity(Ivar1->getDecl(), Ivar2->getDecl()); | |||
3973 | } | |||
3974 | ||||
3975 | const auto *Array1 = dyn_cast<ArraySubscriptExpr>(E1); | |||
3976 | const auto *Array2 = dyn_cast<ArraySubscriptExpr>(E2); | |||
3977 | if (Array1 && Array2) { | |||
3978 | if (!isSameComparisonOperand(Array1->getBase(), Array2->getBase())) | |||
3979 | return false; | |||
3980 | ||||
3981 | auto Idx1 = Array1->getIdx(); | |||
3982 | auto Idx2 = Array2->getIdx(); | |||
3983 | const auto Integer1 = dyn_cast<IntegerLiteral>(Idx1); | |||
3984 | const auto Integer2 = dyn_cast<IntegerLiteral>(Idx2); | |||
3985 | if (Integer1 && Integer2) { | |||
3986 | if (!llvm::APInt::isSameValue(Integer1->getValue(), | |||
3987 | Integer2->getValue())) | |||
3988 | return false; | |||
3989 | } else { | |||
3990 | if (!isSameComparisonOperand(Idx1, Idx2)) | |||
3991 | return false; | |||
3992 | } | |||
3993 | ||||
3994 | return true; | |||
3995 | } | |||
3996 | ||||
3997 | // Walk the MemberExpr chain. | |||
3998 | while (isa<MemberExpr>(E1) && isa<MemberExpr>(E2)) { | |||
3999 | const auto *ME1 = cast<MemberExpr>(E1); | |||
4000 | const auto *ME2 = cast<MemberExpr>(E2); | |||
4001 | if (!declaresSameEntity(ME1->getMemberDecl(), ME2->getMemberDecl())) | |||
4002 | return false; | |||
4003 | if (const auto *D = dyn_cast<VarDecl>(ME1->getMemberDecl())) | |||
4004 | if (D->isStaticDataMember()) | |||
4005 | return true; | |||
4006 | E1 = ME1->getBase()->IgnoreParenImpCasts(); | |||
4007 | E2 = ME2->getBase()->IgnoreParenImpCasts(); | |||
4008 | } | |||
4009 | ||||
4010 | if (isa<CXXThisExpr>(E1) && isa<CXXThisExpr>(E2)) | |||
4011 | return true; | |||
4012 | ||||
4013 | // A static member variable can end the MemberExpr chain with either | |||
4014 | // a MemberExpr or a DeclRefExpr. | |||
4015 | auto getAnyDecl = [](const Expr *E) -> const ValueDecl * { | |||
4016 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) | |||
4017 | return DRE->getDecl(); | |||
4018 | if (const auto *ME = dyn_cast<MemberExpr>(E)) | |||
4019 | return ME->getMemberDecl(); | |||
4020 | return nullptr; | |||
4021 | }; | |||
4022 | ||||
4023 | const ValueDecl *VD1 = getAnyDecl(E1); | |||
4024 | const ValueDecl *VD2 = getAnyDecl(E2); | |||
4025 | return declaresSameEntity(VD1, VD2); | |||
4026 | } | |||
4027 | } | |||
4028 | } | |||
4029 | ||||
4030 | /// isArrow - Return true if the base expression is a pointer to vector, | |||
4031 | /// return false if the base expression is a vector. | |||
4032 | bool ExtVectorElementExpr::isArrow() const { | |||
4033 | return getBase()->getType()->isPointerType(); | |||
4034 | } | |||
4035 | ||||
4036 | unsigned ExtVectorElementExpr::getNumElements() const { | |||
4037 | if (const VectorType *VT = getType()->getAs<VectorType>()) | |||
4038 | return VT->getNumElements(); | |||
4039 | return 1; | |||
4040 | } | |||
4041 | ||||
4042 | /// containsDuplicateElements - Return true if any element access is repeated. | |||
4043 | bool ExtVectorElementExpr::containsDuplicateElements() const { | |||
4044 | // FIXME: Refactor this code to an accessor on the AST node which returns the | |||
4045 | // "type" of component access, and share with code below and in Sema. | |||
4046 | StringRef Comp = Accessor->getName(); | |||
4047 | ||||
4048 | // Halving swizzles do not contain duplicate elements. | |||
4049 | if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") | |||
4050 | return false; | |||
4051 | ||||
4052 | // Advance past s-char prefix on hex swizzles. | |||
4053 | if (Comp[0] == 's' || Comp[0] == 'S') | |||
4054 | Comp = Comp.substr(1); | |||
4055 | ||||
4056 | for (unsigned i = 0, e = Comp.size(); i != e; ++i) | |||
4057 | if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) | |||
4058 | return true; | |||
4059 | ||||
4060 | return false; | |||
4061 | } | |||
4062 | ||||
4063 | /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. | |||
4064 | void ExtVectorElementExpr::getEncodedElementAccess( | |||
4065 | SmallVectorImpl<uint32_t> &Elts) const { | |||
4066 | StringRef Comp = Accessor->getName(); | |||
4067 | bool isNumericAccessor = false; | |||
4068 | if (Comp[0] == 's' || Comp[0] == 'S') { | |||
4069 | Comp = Comp.substr(1); | |||
4070 | isNumericAccessor = true; | |||
4071 | } | |||
4072 | ||||
4073 | bool isHi = Comp == "hi"; | |||
4074 | bool isLo = Comp == "lo"; | |||
4075 | bool isEven = Comp == "even"; | |||
4076 | bool isOdd = Comp == "odd"; | |||
4077 | ||||
4078 | for (unsigned i = 0, e = getNumElements(); i != e; ++i) { | |||
4079 | uint64_t Index; | |||
4080 | ||||
4081 | if (isHi) | |||
4082 | Index = e + i; | |||
4083 | else if (isLo) | |||
4084 | Index = i; | |||
4085 | else if (isEven) | |||
4086 | Index = 2 * i; | |||
4087 | else if (isOdd) | |||
4088 | Index = 2 * i + 1; | |||
4089 | else | |||
4090 | Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor); | |||
4091 | ||||
4092 | Elts.push_back(Index); | |||
4093 | } | |||
4094 | } | |||
4095 | ||||
4096 | ShuffleVectorExpr::ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, | |||
4097 | QualType Type, SourceLocation BLoc, | |||
4098 | SourceLocation RP) | |||
4099 | : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, | |||
4100 | Type->isDependentType(), Type->isDependentType(), | |||
4101 | Type->isInstantiationDependentType(), | |||
4102 | Type->containsUnexpandedParameterPack()), | |||
4103 | BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) | |||
4104 | { | |||
4105 | SubExprs = new (C) Stmt*[args.size()]; | |||
4106 | for (unsigned i = 0; i != args.size(); i++) { | |||
4107 | if (args[i]->isTypeDependent()) | |||
4108 | ExprBits.TypeDependent = true; | |||
4109 | if (args[i]->isValueDependent()) | |||
4110 | ExprBits.ValueDependent = true; | |||
4111 | if (args[i]->isInstantiationDependent()) | |||
4112 | ExprBits.InstantiationDependent = true; | |||
4113 | if (args[i]->containsUnexpandedParameterPack()) | |||
4114 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
4115 | ||||
4116 | SubExprs[i] = args[i]; | |||
4117 | } | |||
4118 | } | |||
4119 | ||||
4120 | void ShuffleVectorExpr::setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs) { | |||
4121 | if (SubExprs) C.Deallocate(SubExprs); | |||
4122 | ||||
4123 | this->NumExprs = Exprs.size(); | |||
4124 | SubExprs = new (C) Stmt*[NumExprs]; | |||
4125 | memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size()); | |||
4126 | } | |||
4127 | ||||
4128 | GenericSelectionExpr::GenericSelectionExpr( | |||
4129 | const ASTContext &, SourceLocation GenericLoc, Expr *ControllingExpr, | |||
4130 | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, | |||
4131 | SourceLocation DefaultLoc, SourceLocation RParenLoc, | |||
4132 | bool ContainsUnexpandedParameterPack, unsigned ResultIndex) | |||
4133 | : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(), | |||
4134 | AssocExprs[ResultIndex]->getValueKind(), | |||
4135 | AssocExprs[ResultIndex]->getObjectKind(), | |||
4136 | AssocExprs[ResultIndex]->isTypeDependent(), | |||
4137 | AssocExprs[ResultIndex]->isValueDependent(), | |||
4138 | AssocExprs[ResultIndex]->isInstantiationDependent(), | |||
4139 | ContainsUnexpandedParameterPack), | |||
4140 | NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), | |||
4141 | DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { | |||
4142 | assert(AssocTypes.size() == AssocExprs.size() &&((AssocTypes.size() == AssocExprs.size() && "Must have the same number of association expressions" " and TypeSourceInfo!") ? static_cast<void> (0) : __assert_fail ("AssocTypes.size() == AssocExprs.size() && \"Must have the same number of association expressions\" \" and TypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4144, __PRETTY_FUNCTION__)) | |||
4143 | "Must have the same number of association expressions"((AssocTypes.size() == AssocExprs.size() && "Must have the same number of association expressions" " and TypeSourceInfo!") ? static_cast<void> (0) : __assert_fail ("AssocTypes.size() == AssocExprs.size() && \"Must have the same number of association expressions\" \" and TypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4144, __PRETTY_FUNCTION__)) | |||
4144 | " and TypeSourceInfo!")((AssocTypes.size() == AssocExprs.size() && "Must have the same number of association expressions" " and TypeSourceInfo!") ? static_cast<void> (0) : __assert_fail ("AssocTypes.size() == AssocExprs.size() && \"Must have the same number of association expressions\" \" and TypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4144, __PRETTY_FUNCTION__)); | |||
4145 | assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!")((ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!" ) ? static_cast<void> (0) : __assert_fail ("ResultIndex < NumAssocs && \"ResultIndex is out-of-bounds!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4145, __PRETTY_FUNCTION__)); | |||
4146 | ||||
4147 | GenericSelectionExprBits.GenericLoc = GenericLoc; | |||
4148 | getTrailingObjects<Stmt *>()[ControllingIndex] = ControllingExpr; | |||
4149 | std::copy(AssocExprs.begin(), AssocExprs.end(), | |||
4150 | getTrailingObjects<Stmt *>() + AssocExprStartIndex); | |||
4151 | std::copy(AssocTypes.begin(), AssocTypes.end(), | |||
4152 | getTrailingObjects<TypeSourceInfo *>()); | |||
4153 | } | |||
4154 | ||||
4155 | GenericSelectionExpr::GenericSelectionExpr( | |||
4156 | const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, | |||
4157 | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, | |||
4158 | SourceLocation DefaultLoc, SourceLocation RParenLoc, | |||
4159 | bool ContainsUnexpandedParameterPack) | |||
4160 | : Expr(GenericSelectionExprClass, Context.DependentTy, VK_RValue, | |||
4161 | OK_Ordinary, | |||
4162 | /*isTypeDependent=*/true, | |||
4163 | /*isValueDependent=*/true, | |||
4164 | /*isInstantiationDependent=*/true, ContainsUnexpandedParameterPack), | |||
4165 | NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex), | |||
4166 | DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { | |||
4167 | assert(AssocTypes.size() == AssocExprs.size() &&((AssocTypes.size() == AssocExprs.size() && "Must have the same number of association expressions" " and TypeSourceInfo!") ? static_cast<void> (0) : __assert_fail ("AssocTypes.size() == AssocExprs.size() && \"Must have the same number of association expressions\" \" and TypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4169, __PRETTY_FUNCTION__)) | |||
4168 | "Must have the same number of association expressions"((AssocTypes.size() == AssocExprs.size() && "Must have the same number of association expressions" " and TypeSourceInfo!") ? static_cast<void> (0) : __assert_fail ("AssocTypes.size() == AssocExprs.size() && \"Must have the same number of association expressions\" \" and TypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4169, __PRETTY_FUNCTION__)) | |||
4169 | " and TypeSourceInfo!")((AssocTypes.size() == AssocExprs.size() && "Must have the same number of association expressions" " and TypeSourceInfo!") ? static_cast<void> (0) : __assert_fail ("AssocTypes.size() == AssocExprs.size() && \"Must have the same number of association expressions\" \" and TypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4169, __PRETTY_FUNCTION__)); | |||
4170 | ||||
4171 | GenericSelectionExprBits.GenericLoc = GenericLoc; | |||
4172 | getTrailingObjects<Stmt *>()[ControllingIndex] = ControllingExpr; | |||
4173 | std::copy(AssocExprs.begin(), AssocExprs.end(), | |||
4174 | getTrailingObjects<Stmt *>() + AssocExprStartIndex); | |||
4175 | std::copy(AssocTypes.begin(), AssocTypes.end(), | |||
4176 | getTrailingObjects<TypeSourceInfo *>()); | |||
4177 | } | |||
4178 | ||||
4179 | GenericSelectionExpr::GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs) | |||
4180 | : Expr(GenericSelectionExprClass, Empty), NumAssocs(NumAssocs) {} | |||
4181 | ||||
4182 | GenericSelectionExpr *GenericSelectionExpr::Create( | |||
4183 | const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, | |||
4184 | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, | |||
4185 | SourceLocation DefaultLoc, SourceLocation RParenLoc, | |||
4186 | bool ContainsUnexpandedParameterPack, unsigned ResultIndex) { | |||
4187 | unsigned NumAssocs = AssocExprs.size(); | |||
4188 | void *Mem = Context.Allocate( | |||
4189 | totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs), | |||
4190 | alignof(GenericSelectionExpr)); | |||
4191 | return new (Mem) GenericSelectionExpr( | |||
4192 | Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc, | |||
4193 | RParenLoc, ContainsUnexpandedParameterPack, ResultIndex); | |||
4194 | } | |||
4195 | ||||
4196 | GenericSelectionExpr *GenericSelectionExpr::Create( | |||
4197 | const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, | |||
4198 | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, | |||
4199 | SourceLocation DefaultLoc, SourceLocation RParenLoc, | |||
4200 | bool ContainsUnexpandedParameterPack) { | |||
4201 | unsigned NumAssocs = AssocExprs.size(); | |||
4202 | void *Mem = Context.Allocate( | |||
4203 | totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs), | |||
4204 | alignof(GenericSelectionExpr)); | |||
4205 | return new (Mem) GenericSelectionExpr( | |||
4206 | Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc, | |||
4207 | RParenLoc, ContainsUnexpandedParameterPack); | |||
4208 | } | |||
4209 | ||||
4210 | GenericSelectionExpr * | |||
4211 | GenericSelectionExpr::CreateEmpty(const ASTContext &Context, | |||
4212 | unsigned NumAssocs) { | |||
4213 | void *Mem = Context.Allocate( | |||
4214 | totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs), | |||
4215 | alignof(GenericSelectionExpr)); | |||
4216 | return new (Mem) GenericSelectionExpr(EmptyShell(), NumAssocs); | |||
4217 | } | |||
4218 | ||||
4219 | //===----------------------------------------------------------------------===// | |||
4220 | // DesignatedInitExpr | |||
4221 | //===----------------------------------------------------------------------===// | |||
4222 | ||||
4223 | IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { | |||
4224 | assert(Kind == FieldDesignator && "Only valid on a field designator")((Kind == FieldDesignator && "Only valid on a field designator" ) ? static_cast<void> (0) : __assert_fail ("Kind == FieldDesignator && \"Only valid on a field designator\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4224, __PRETTY_FUNCTION__)); | |||
4225 | if (Field.NameOrField & 0x01) | |||
4226 | return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); | |||
4227 | else | |||
4228 | return getField()->getIdentifier(); | |||
4229 | } | |||
4230 | ||||
4231 | DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty, | |||
4232 | llvm::ArrayRef<Designator> Designators, | |||
4233 | SourceLocation EqualOrColonLoc, | |||
4234 | bool GNUSyntax, | |||
4235 | ArrayRef<Expr*> IndexExprs, | |||
4236 | Expr *Init) | |||
4237 | : Expr(DesignatedInitExprClass, Ty, | |||
4238 | Init->getValueKind(), Init->getObjectKind(), | |||
4239 | Init->isTypeDependent(), Init->isValueDependent(), | |||
4240 | Init->isInstantiationDependent(), | |||
4241 | Init->containsUnexpandedParameterPack()), | |||
4242 | EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), | |||
4243 | NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) { | |||
4244 | this->Designators = new (C) Designator[NumDesignators]; | |||
4245 | ||||
4246 | // Record the initializer itself. | |||
4247 | child_iterator Child = child_begin(); | |||
4248 | *Child++ = Init; | |||
4249 | ||||
4250 | // Copy the designators and their subexpressions, computing | |||
4251 | // value-dependence along the way. | |||
4252 | unsigned IndexIdx = 0; | |||
4253 | for (unsigned I = 0; I != NumDesignators; ++I) { | |||
4254 | this->Designators[I] = Designators[I]; | |||
4255 | ||||
4256 | if (this->Designators[I].isArrayDesignator()) { | |||
4257 | // Compute type- and value-dependence. | |||
4258 | Expr *Index = IndexExprs[IndexIdx]; | |||
4259 | if (Index->isTypeDependent() || Index->isValueDependent()) | |||
4260 | ExprBits.TypeDependent = ExprBits.ValueDependent = true; | |||
4261 | if (Index->isInstantiationDependent()) | |||
4262 | ExprBits.InstantiationDependent = true; | |||
4263 | // Propagate unexpanded parameter packs. | |||
4264 | if (Index->containsUnexpandedParameterPack()) | |||
4265 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
4266 | ||||
4267 | // Copy the index expressions into permanent storage. | |||
4268 | *Child++ = IndexExprs[IndexIdx++]; | |||
4269 | } else if (this->Designators[I].isArrayRangeDesignator()) { | |||
4270 | // Compute type- and value-dependence. | |||
4271 | Expr *Start = IndexExprs[IndexIdx]; | |||
4272 | Expr *End = IndexExprs[IndexIdx + 1]; | |||
4273 | if (Start->isTypeDependent() || Start->isValueDependent() || | |||
4274 | End->isTypeDependent() || End->isValueDependent()) { | |||
4275 | ExprBits.TypeDependent = ExprBits.ValueDependent = true; | |||
4276 | ExprBits.InstantiationDependent = true; | |||
4277 | } else if (Start->isInstantiationDependent() || | |||
4278 | End->isInstantiationDependent()) { | |||
4279 | ExprBits.InstantiationDependent = true; | |||
4280 | } | |||
4281 | ||||
4282 | // Propagate unexpanded parameter packs. | |||
4283 | if (Start->containsUnexpandedParameterPack() || | |||
4284 | End->containsUnexpandedParameterPack()) | |||
4285 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
4286 | ||||
4287 | // Copy the start/end expressions into permanent storage. | |||
4288 | *Child++ = IndexExprs[IndexIdx++]; | |||
4289 | *Child++ = IndexExprs[IndexIdx++]; | |||
4290 | } | |||
4291 | } | |||
4292 | ||||
4293 | assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions")((IndexIdx == IndexExprs.size() && "Wrong number of index expressions" ) ? static_cast<void> (0) : __assert_fail ("IndexIdx == IndexExprs.size() && \"Wrong number of index expressions\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4293, __PRETTY_FUNCTION__)); | |||
4294 | } | |||
4295 | ||||
4296 | DesignatedInitExpr * | |||
4297 | DesignatedInitExpr::Create(const ASTContext &C, | |||
4298 | llvm::ArrayRef<Designator> Designators, | |||
4299 | ArrayRef<Expr*> IndexExprs, | |||
4300 | SourceLocation ColonOrEqualLoc, | |||
4301 | bool UsesColonSyntax, Expr *Init) { | |||
4302 | void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1), | |||
4303 | alignof(DesignatedInitExpr)); | |||
4304 | return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators, | |||
4305 | ColonOrEqualLoc, UsesColonSyntax, | |||
4306 | IndexExprs, Init); | |||
4307 | } | |||
4308 | ||||
4309 | DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(const ASTContext &C, | |||
4310 | unsigned NumIndexExprs) { | |||
4311 | void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1), | |||
4312 | alignof(DesignatedInitExpr)); | |||
4313 | return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); | |||
4314 | } | |||
4315 | ||||
4316 | void DesignatedInitExpr::setDesignators(const ASTContext &C, | |||
4317 | const Designator *Desigs, | |||
4318 | unsigned NumDesigs) { | |||
4319 | Designators = new (C) Designator[NumDesigs]; | |||
4320 | NumDesignators = NumDesigs; | |||
4321 | for (unsigned I = 0; I != NumDesigs; ++I) | |||
4322 | Designators[I] = Desigs[I]; | |||
4323 | } | |||
4324 | ||||
4325 | SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { | |||
4326 | DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); | |||
4327 | if (size() == 1) | |||
4328 | return DIE->getDesignator(0)->getSourceRange(); | |||
4329 | return SourceRange(DIE->getDesignator(0)->getBeginLoc(), | |||
4330 | DIE->getDesignator(size() - 1)->getEndLoc()); | |||
4331 | } | |||
4332 | ||||
4333 | SourceLocation DesignatedInitExpr::getBeginLoc() const { | |||
4334 | SourceLocation StartLoc; | |||
4335 | auto *DIE = const_cast<DesignatedInitExpr *>(this); | |||
4336 | Designator &First = *DIE->getDesignator(0); | |||
4337 | if (First.isFieldDesignator()) { | |||
4338 | if (GNUSyntax) | |||
4339 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); | |||
4340 | else | |||
4341 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); | |||
4342 | } else | |||
4343 | StartLoc = | |||
4344 | SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); | |||
4345 | return StartLoc; | |||
4346 | } | |||
4347 | ||||
4348 | SourceLocation DesignatedInitExpr::getEndLoc() const { | |||
4349 | return getInit()->getEndLoc(); | |||
4350 | } | |||
4351 | ||||
4352 | Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) const { | |||
4353 | assert(D.Kind == Designator::ArrayDesignator && "Requires array designator")((D.Kind == Designator::ArrayDesignator && "Requires array designator" ) ? static_cast<void> (0) : __assert_fail ("D.Kind == Designator::ArrayDesignator && \"Requires array designator\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4353, __PRETTY_FUNCTION__)); | |||
4354 | return getSubExpr(D.ArrayOrRange.Index + 1); | |||
4355 | } | |||
4356 | ||||
4357 | Expr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const { | |||
4358 | assert(D.Kind == Designator::ArrayRangeDesignator &&((D.Kind == Designator::ArrayRangeDesignator && "Requires array range designator" ) ? static_cast<void> (0) : __assert_fail ("D.Kind == Designator::ArrayRangeDesignator && \"Requires array range designator\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4359, __PRETTY_FUNCTION__)) | |||
4359 | "Requires array range designator")((D.Kind == Designator::ArrayRangeDesignator && "Requires array range designator" ) ? static_cast<void> (0) : __assert_fail ("D.Kind == Designator::ArrayRangeDesignator && \"Requires array range designator\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4359, __PRETTY_FUNCTION__)); | |||
4360 | return getSubExpr(D.ArrayOrRange.Index + 1); | |||
4361 | } | |||
4362 | ||||
4363 | Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const { | |||
4364 | assert(D.Kind == Designator::ArrayRangeDesignator &&((D.Kind == Designator::ArrayRangeDesignator && "Requires array range designator" ) ? static_cast<void> (0) : __assert_fail ("D.Kind == Designator::ArrayRangeDesignator && \"Requires array range designator\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4365, __PRETTY_FUNCTION__)) | |||
4365 | "Requires array range designator")((D.Kind == Designator::ArrayRangeDesignator && "Requires array range designator" ) ? static_cast<void> (0) : __assert_fail ("D.Kind == Designator::ArrayRangeDesignator && \"Requires array range designator\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4365, __PRETTY_FUNCTION__)); | |||
4366 | return getSubExpr(D.ArrayOrRange.Index + 2); | |||
4367 | } | |||
4368 | ||||
4369 | /// Replaces the designator at index @p Idx with the series | |||
4370 | /// of designators in [First, Last). | |||
4371 | void DesignatedInitExpr::ExpandDesignator(const ASTContext &C, unsigned Idx, | |||
4372 | const Designator *First, | |||
4373 | const Designator *Last) { | |||
4374 | unsigned NumNewDesignators = Last - First; | |||
4375 | if (NumNewDesignators == 0) { | |||
4376 | std::copy_backward(Designators + Idx + 1, | |||
4377 | Designators + NumDesignators, | |||
4378 | Designators + Idx); | |||
4379 | --NumNewDesignators; | |||
4380 | return; | |||
4381 | } else if (NumNewDesignators == 1) { | |||
4382 | Designators[Idx] = *First; | |||
4383 | return; | |||
4384 | } | |||
4385 | ||||
4386 | Designator *NewDesignators | |||
4387 | = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; | |||
4388 | std::copy(Designators, Designators + Idx, NewDesignators); | |||
4389 | std::copy(First, Last, NewDesignators + Idx); | |||
4390 | std::copy(Designators + Idx + 1, Designators + NumDesignators, | |||
4391 | NewDesignators + Idx + NumNewDesignators); | |||
4392 | Designators = NewDesignators; | |||
4393 | NumDesignators = NumDesignators - 1 + NumNewDesignators; | |||
4394 | } | |||
4395 | ||||
4396 | DesignatedInitUpdateExpr::DesignatedInitUpdateExpr(const ASTContext &C, | |||
4397 | SourceLocation lBraceLoc, Expr *baseExpr, SourceLocation rBraceLoc) | |||
4398 | : Expr(DesignatedInitUpdateExprClass, baseExpr->getType(), VK_RValue, | |||
4399 | OK_Ordinary, false, false, false, false) { | |||
4400 | BaseAndUpdaterExprs[0] = baseExpr; | |||
4401 | ||||
4402 | InitListExpr *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc); | |||
4403 | ILE->setType(baseExpr->getType()); | |||
4404 | BaseAndUpdaterExprs[1] = ILE; | |||
4405 | } | |||
4406 | ||||
4407 | SourceLocation DesignatedInitUpdateExpr::getBeginLoc() const { | |||
4408 | return getBase()->getBeginLoc(); | |||
4409 | } | |||
4410 | ||||
4411 | SourceLocation DesignatedInitUpdateExpr::getEndLoc() const { | |||
4412 | return getBase()->getEndLoc(); | |||
4413 | } | |||
4414 | ||||
4415 | ParenListExpr::ParenListExpr(SourceLocation LParenLoc, ArrayRef<Expr *> Exprs, | |||
4416 | SourceLocation RParenLoc) | |||
4417 | : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, | |||
4418 | false, false), | |||
4419 | LParenLoc(LParenLoc), RParenLoc(RParenLoc) { | |||
4420 | ParenListExprBits.NumExprs = Exprs.size(); | |||
4421 | ||||
4422 | for (unsigned I = 0, N = Exprs.size(); I != N; ++I) { | |||
4423 | if (Exprs[I]->isTypeDependent()) | |||
4424 | ExprBits.TypeDependent = true; | |||
4425 | if (Exprs[I]->isValueDependent()) | |||
4426 | ExprBits.ValueDependent = true; | |||
4427 | if (Exprs[I]->isInstantiationDependent()) | |||
4428 | ExprBits.InstantiationDependent = true; | |||
4429 | if (Exprs[I]->containsUnexpandedParameterPack()) | |||
4430 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
4431 | ||||
4432 | getTrailingObjects<Stmt *>()[I] = Exprs[I]; | |||
4433 | } | |||
4434 | } | |||
4435 | ||||
4436 | ParenListExpr::ParenListExpr(EmptyShell Empty, unsigned NumExprs) | |||
4437 | : Expr(ParenListExprClass, Empty) { | |||
4438 | ParenListExprBits.NumExprs = NumExprs; | |||
4439 | } | |||
4440 | ||||
4441 | ParenListExpr *ParenListExpr::Create(const ASTContext &Ctx, | |||
4442 | SourceLocation LParenLoc, | |||
4443 | ArrayRef<Expr *> Exprs, | |||
4444 | SourceLocation RParenLoc) { | |||
4445 | void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(Exprs.size()), | |||
4446 | alignof(ParenListExpr)); | |||
4447 | return new (Mem) ParenListExpr(LParenLoc, Exprs, RParenLoc); | |||
4448 | } | |||
4449 | ||||
4450 | ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx, | |||
4451 | unsigned NumExprs) { | |||
4452 | void *Mem = | |||
4453 | Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumExprs), alignof(ParenListExpr)); | |||
4454 | return new (Mem) ParenListExpr(EmptyShell(), NumExprs); | |||
4455 | } | |||
4456 | ||||
4457 | const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { | |||
4458 | if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) | |||
4459 | e = ewc->getSubExpr(); | |||
4460 | if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) | |||
4461 | e = m->GetTemporaryExpr(); | |||
4462 | e = cast<CXXConstructExpr>(e)->getArg(0); | |||
4463 | while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) | |||
4464 | e = ice->getSubExpr(); | |||
4465 | return cast<OpaqueValueExpr>(e); | |||
4466 | } | |||
4467 | ||||
4468 | PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &Context, | |||
4469 | EmptyShell sh, | |||
4470 | unsigned numSemanticExprs) { | |||
4471 | void *buffer = | |||
4472 | Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs), | |||
4473 | alignof(PseudoObjectExpr)); | |||
4474 | return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); | |||
4475 | } | |||
4476 | ||||
4477 | PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) | |||
4478 | : Expr(PseudoObjectExprClass, shell) { | |||
4479 | PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; | |||
4480 | } | |||
4481 | ||||
4482 | PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax, | |||
4483 | ArrayRef<Expr*> semantics, | |||
4484 | unsigned resultIndex) { | |||
4485 | assert(syntax && "no syntactic expression!")((syntax && "no syntactic expression!") ? static_cast <void> (0) : __assert_fail ("syntax && \"no syntactic expression!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4485, __PRETTY_FUNCTION__)); | |||
4486 | assert(semantics.size() && "no semantic expressions!")((semantics.size() && "no semantic expressions!") ? static_cast <void> (0) : __assert_fail ("semantics.size() && \"no semantic expressions!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4486, __PRETTY_FUNCTION__)); | |||
4487 | ||||
4488 | QualType type; | |||
4489 | ExprValueKind VK; | |||
4490 | if (resultIndex == NoResult) { | |||
4491 | type = C.VoidTy; | |||
4492 | VK = VK_RValue; | |||
4493 | } else { | |||
4494 | assert(resultIndex < semantics.size())((resultIndex < semantics.size()) ? static_cast<void> (0) : __assert_fail ("resultIndex < semantics.size()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4494, __PRETTY_FUNCTION__)); | |||
4495 | type = semantics[resultIndex]->getType(); | |||
4496 | VK = semantics[resultIndex]->getValueKind(); | |||
4497 | assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary)((semantics[resultIndex]->getObjectKind() == OK_Ordinary) ? static_cast<void> (0) : __assert_fail ("semantics[resultIndex]->getObjectKind() == OK_Ordinary" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4497, __PRETTY_FUNCTION__)); | |||
4498 | } | |||
4499 | ||||
4500 | void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1), | |||
4501 | alignof(PseudoObjectExpr)); | |||
4502 | return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, | |||
4503 | resultIndex); | |||
4504 | } | |||
4505 | ||||
4506 | PseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, | |||
4507 | Expr *syntax, ArrayRef<Expr*> semantics, | |||
4508 | unsigned resultIndex) | |||
4509 | : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, | |||
4510 | /*filled in at end of ctor*/ false, false, false, false) { | |||
4511 | PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; | |||
4512 | PseudoObjectExprBits.ResultIndex = resultIndex + 1; | |||
4513 | ||||
4514 | for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { | |||
4515 | Expr *E = (i == 0 ? syntax : semantics[i-1]); | |||
4516 | getSubExprsBuffer()[i] = E; | |||
4517 | ||||
4518 | if (E->isTypeDependent()) | |||
4519 | ExprBits.TypeDependent = true; | |||
4520 | if (E->isValueDependent()) | |||
4521 | ExprBits.ValueDependent = true; | |||
4522 | if (E->isInstantiationDependent()) | |||
4523 | ExprBits.InstantiationDependent = true; | |||
4524 | if (E->containsUnexpandedParameterPack()) | |||
4525 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
4526 | ||||
4527 | if (isa<OpaqueValueExpr>(E)) | |||
4528 | assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr &&((cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && "opaque-value semantic expressions for pseudo-object " "operations must have sources") ? static_cast<void> (0 ) : __assert_fail ("cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && \"opaque-value semantic expressions for pseudo-object \" \"operations must have sources\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4530, __PRETTY_FUNCTION__)) | |||
4529 | "opaque-value semantic expressions for pseudo-object "((cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && "opaque-value semantic expressions for pseudo-object " "operations must have sources") ? static_cast<void> (0 ) : __assert_fail ("cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && \"opaque-value semantic expressions for pseudo-object \" \"operations must have sources\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4530, __PRETTY_FUNCTION__)) | |||
4530 | "operations must have sources")((cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && "opaque-value semantic expressions for pseudo-object " "operations must have sources") ? static_cast<void> (0 ) : __assert_fail ("cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && \"opaque-value semantic expressions for pseudo-object \" \"operations must have sources\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4530, __PRETTY_FUNCTION__)); | |||
4531 | } | |||
4532 | } | |||
4533 | ||||
4534 | //===----------------------------------------------------------------------===// | |||
4535 | // Child Iterators for iterating over subexpressions/substatements | |||
4536 | //===----------------------------------------------------------------------===// | |||
4537 | ||||
4538 | // UnaryExprOrTypeTraitExpr | |||
4539 | Stmt::child_range UnaryExprOrTypeTraitExpr::children() { | |||
4540 | const_child_range CCR = | |||
4541 | const_cast<const UnaryExprOrTypeTraitExpr *>(this)->children(); | |||
4542 | return child_range(cast_away_const(CCR.begin()), cast_away_const(CCR.end())); | |||
4543 | } | |||
4544 | ||||
4545 | Stmt::const_child_range UnaryExprOrTypeTraitExpr::children() const { | |||
4546 | // If this is of a type and the type is a VLA type (and not a typedef), the | |||
4547 | // size expression of the VLA needs to be treated as an executable expression. | |||
4548 | // Why isn't this weirdness documented better in StmtIterator? | |||
4549 | if (isArgumentType()) { | |||
4550 | if (const VariableArrayType *T = | |||
4551 | dyn_cast<VariableArrayType>(getArgumentType().getTypePtr())) | |||
4552 | return const_child_range(const_child_iterator(T), const_child_iterator()); | |||
4553 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
4554 | } | |||
4555 | return const_child_range(&Argument.Ex, &Argument.Ex + 1); | |||
4556 | } | |||
4557 | ||||
4558 | AtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, | |||
4559 | QualType t, AtomicOp op, SourceLocation RP) | |||
4560 | : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, | |||
4561 | false, false, false, false), | |||
4562 | NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) | |||
4563 | { | |||
4564 | assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions")((args.size() == getNumSubExprs(op) && "wrong number of subexpressions" ) ? static_cast<void> (0) : __assert_fail ("args.size() == getNumSubExprs(op) && \"wrong number of subexpressions\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4564, __PRETTY_FUNCTION__)); | |||
4565 | for (unsigned i = 0; i != args.size(); i++) { | |||
4566 | if (args[i]->isTypeDependent()) | |||
4567 | ExprBits.TypeDependent = true; | |||
4568 | if (args[i]->isValueDependent()) | |||
4569 | ExprBits.ValueDependent = true; | |||
4570 | if (args[i]->isInstantiationDependent()) | |||
4571 | ExprBits.InstantiationDependent = true; | |||
4572 | if (args[i]->containsUnexpandedParameterPack()) | |||
4573 | ExprBits.ContainsUnexpandedParameterPack = true; | |||
4574 | ||||
4575 | SubExprs[i] = args[i]; | |||
4576 | } | |||
4577 | } | |||
4578 | ||||
4579 | unsigned AtomicExpr::getNumSubExprs(AtomicOp Op) { | |||
4580 | switch (Op) { | |||
4581 | case AO__c11_atomic_init: | |||
4582 | case AO__opencl_atomic_init: | |||
4583 | case AO__c11_atomic_load: | |||
4584 | case AO__atomic_load_n: | |||
4585 | return 2; | |||
4586 | ||||
4587 | case AO__opencl_atomic_load: | |||
4588 | case AO__c11_atomic_store: | |||
4589 | case AO__c11_atomic_exchange: | |||
4590 | case AO__atomic_load: | |||
4591 | case AO__atomic_store: | |||
4592 | case AO__atomic_store_n: | |||
4593 | case AO__atomic_exchange_n: | |||
4594 | case AO__c11_atomic_fetch_add: | |||
4595 | case AO__c11_atomic_fetch_sub: | |||
4596 | case AO__c11_atomic_fetch_and: | |||
4597 | case AO__c11_atomic_fetch_or: | |||
4598 | case AO__c11_atomic_fetch_xor: | |||
4599 | case AO__atomic_fetch_add: | |||
4600 | case AO__atomic_fetch_sub: | |||
4601 | case AO__atomic_fetch_and: | |||
4602 | case AO__atomic_fetch_or: | |||
4603 | case AO__atomic_fetch_xor: | |||
4604 | case AO__atomic_fetch_nand: | |||
4605 | case AO__atomic_add_fetch: | |||
4606 | case AO__atomic_sub_fetch: | |||
4607 | case AO__atomic_and_fetch: | |||
4608 | case AO__atomic_or_fetch: | |||
4609 | case AO__atomic_xor_fetch: | |||
4610 | case AO__atomic_nand_fetch: | |||
4611 | case AO__atomic_fetch_min: | |||
4612 | case AO__atomic_fetch_max: | |||
4613 | return 3; | |||
4614 | ||||
4615 | case AO__opencl_atomic_store: | |||
4616 | case AO__opencl_atomic_exchange: | |||
4617 | case AO__opencl_atomic_fetch_add: | |||
4618 | case AO__opencl_atomic_fetch_sub: | |||
4619 | case AO__opencl_atomic_fetch_and: | |||
4620 | case AO__opencl_atomic_fetch_or: | |||
4621 | case AO__opencl_atomic_fetch_xor: | |||
4622 | case AO__opencl_atomic_fetch_min: | |||
4623 | case AO__opencl_atomic_fetch_max: | |||
4624 | case AO__atomic_exchange: | |||
4625 | return 4; | |||
4626 | ||||
4627 | case AO__c11_atomic_compare_exchange_strong: | |||
4628 | case AO__c11_atomic_compare_exchange_weak: | |||
4629 | return 5; | |||
4630 | ||||
4631 | case AO__opencl_atomic_compare_exchange_strong: | |||
4632 | case AO__opencl_atomic_compare_exchange_weak: | |||
4633 | case AO__atomic_compare_exchange: | |||
4634 | case AO__atomic_compare_exchange_n: | |||
4635 | return 6; | |||
4636 | } | |||
4637 | llvm_unreachable("unknown atomic op")::llvm::llvm_unreachable_internal("unknown atomic op", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4637); | |||
4638 | } | |||
4639 | ||||
4640 | QualType AtomicExpr::getValueType() const { | |||
4641 | auto T = getPtr()->getType()->castAs<PointerType>()->getPointeeType(); | |||
4642 | if (auto AT = T->getAs<AtomicType>()) | |||
4643 | return AT->getValueType(); | |||
4644 | return T; | |||
4645 | } | |||
4646 | ||||
4647 | QualType OMPArraySectionExpr::getBaseOriginalType(const Expr *Base) { | |||
4648 | unsigned ArraySectionCount = 0; | |||
4649 | while (auto *OASE = dyn_cast<OMPArraySectionExpr>(Base->IgnoreParens())) { | |||
4650 | Base = OASE->getBase(); | |||
4651 | ++ArraySectionCount; | |||
4652 | } | |||
4653 | while (auto *ASE = | |||
4654 | dyn_cast<ArraySubscriptExpr>(Base->IgnoreParenImpCasts())) { | |||
4655 | Base = ASE->getBase(); | |||
4656 | ++ArraySectionCount; | |||
4657 | } | |||
4658 | Base = Base->IgnoreParenImpCasts(); | |||
4659 | auto OriginalTy = Base->getType(); | |||
4660 | if (auto *DRE = dyn_cast<DeclRefExpr>(Base)) | |||
4661 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) | |||
4662 | OriginalTy = PVD->getOriginalType().getNonReferenceType(); | |||
4663 | ||||
4664 | for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) { | |||
4665 | if (OriginalTy->isAnyPointerType()) | |||
4666 | OriginalTy = OriginalTy->getPointeeType(); | |||
4667 | else { | |||
4668 | assert (OriginalTy->isArrayType())((OriginalTy->isArrayType()) ? static_cast<void> (0) : __assert_fail ("OriginalTy->isArrayType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/Expr.cpp" , 4668, __PRETTY_FUNCTION__)); | |||
4669 | OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType(); | |||
4670 | } | |||
4671 | } | |||
4672 | return OriginalTy; | |||
4673 | } |
1 | //===- Type.h - C Language Family Type Representation -----------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | /// \file |
10 | /// C Language Family Type Representation |
11 | /// |
12 | /// This file defines the clang::Type interface and subclasses, used to |
13 | /// represent types for languages in the C family. |
14 | // |
15 | //===----------------------------------------------------------------------===// |
16 | |
17 | #ifndef LLVM_CLANG_AST_TYPE_H |
18 | #define LLVM_CLANG_AST_TYPE_H |
19 | |
20 | #include "clang/AST/NestedNameSpecifier.h" |
21 | #include "clang/AST/TemplateName.h" |
22 | #include "clang/Basic/AddressSpaces.h" |
23 | #include "clang/Basic/AttrKinds.h" |
24 | #include "clang/Basic/Diagnostic.h" |
25 | #include "clang/Basic/ExceptionSpecificationType.h" |
26 | #include "clang/Basic/LLVM.h" |
27 | #include "clang/Basic/Linkage.h" |
28 | #include "clang/Basic/PartialDiagnostic.h" |
29 | #include "clang/Basic/SourceLocation.h" |
30 | #include "clang/Basic/Specifiers.h" |
31 | #include "clang/Basic/Visibility.h" |
32 | #include "llvm/ADT/APInt.h" |
33 | #include "llvm/ADT/APSInt.h" |
34 | #include "llvm/ADT/ArrayRef.h" |
35 | #include "llvm/ADT/FoldingSet.h" |
36 | #include "llvm/ADT/None.h" |
37 | #include "llvm/ADT/Optional.h" |
38 | #include "llvm/ADT/PointerIntPair.h" |
39 | #include "llvm/ADT/PointerUnion.h" |
40 | #include "llvm/ADT/StringRef.h" |
41 | #include "llvm/ADT/Twine.h" |
42 | #include "llvm/ADT/iterator_range.h" |
43 | #include "llvm/Support/Casting.h" |
44 | #include "llvm/Support/Compiler.h" |
45 | #include "llvm/Support/ErrorHandling.h" |
46 | #include "llvm/Support/PointerLikeTypeTraits.h" |
47 | #include "llvm/Support/type_traits.h" |
48 | #include "llvm/Support/TrailingObjects.h" |
49 | #include <cassert> |
50 | #include <cstddef> |
51 | #include <cstdint> |
52 | #include <cstring> |
53 | #include <string> |
54 | #include <type_traits> |
55 | #include <utility> |
56 | |
57 | namespace clang { |
58 | |
59 | class ExtQuals; |
60 | class QualType; |
61 | class TagDecl; |
62 | class Type; |
63 | |
64 | enum { |
65 | TypeAlignmentInBits = 4, |
66 | TypeAlignment = 1 << TypeAlignmentInBits |
67 | }; |
68 | |
69 | } // namespace clang |
70 | |
71 | namespace llvm { |
72 | |
73 | template <typename T> |
74 | struct PointerLikeTypeTraits; |
75 | template<> |
76 | struct PointerLikeTypeTraits< ::clang::Type*> { |
77 | static inline void *getAsVoidPointer(::clang::Type *P) { return P; } |
78 | |
79 | static inline ::clang::Type *getFromVoidPointer(void *P) { |
80 | return static_cast< ::clang::Type*>(P); |
81 | } |
82 | |
83 | enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; |
84 | }; |
85 | |
86 | template<> |
87 | struct PointerLikeTypeTraits< ::clang::ExtQuals*> { |
88 | static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } |
89 | |
90 | static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { |
91 | return static_cast< ::clang::ExtQuals*>(P); |
92 | } |
93 | |
94 | enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; |
95 | }; |
96 | |
97 | } // namespace llvm |
98 | |
99 | namespace clang { |
100 | |
101 | class ASTContext; |
102 | template <typename> class CanQual; |
103 | class CXXRecordDecl; |
104 | class DeclContext; |
105 | class EnumDecl; |
106 | class Expr; |
107 | class ExtQualsTypeCommonBase; |
108 | class FunctionDecl; |
109 | class IdentifierInfo; |
110 | class NamedDecl; |
111 | class ObjCInterfaceDecl; |
112 | class ObjCProtocolDecl; |
113 | class ObjCTypeParamDecl; |
114 | struct PrintingPolicy; |
115 | class RecordDecl; |
116 | class Stmt; |
117 | class TagDecl; |
118 | class TemplateArgument; |
119 | class TemplateArgumentListInfo; |
120 | class TemplateArgumentLoc; |
121 | class TemplateTypeParmDecl; |
122 | class TypedefNameDecl; |
123 | class UnresolvedUsingTypenameDecl; |
124 | |
125 | using CanQualType = CanQual<Type>; |
126 | |
127 | // Provide forward declarations for all of the *Type classes. |
128 | #define TYPE(Class, Base) class Class##Type; |
129 | #include "clang/AST/TypeNodes.inc" |
130 | |
131 | /// The collection of all-type qualifiers we support. |
132 | /// Clang supports five independent qualifiers: |
133 | /// * C99: const, volatile, and restrict |
134 | /// * MS: __unaligned |
135 | /// * Embedded C (TR18037): address spaces |
136 | /// * Objective C: the GC attributes (none, weak, or strong) |
137 | class Qualifiers { |
138 | public: |
139 | enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. |
140 | Const = 0x1, |
141 | Restrict = 0x2, |
142 | Volatile = 0x4, |
143 | CVRMask = Const | Volatile | Restrict |
144 | }; |
145 | |
146 | enum GC { |
147 | GCNone = 0, |
148 | Weak, |
149 | Strong |
150 | }; |
151 | |
152 | enum ObjCLifetime { |
153 | /// There is no lifetime qualification on this type. |
154 | OCL_None, |
155 | |
156 | /// This object can be modified without requiring retains or |
157 | /// releases. |
158 | OCL_ExplicitNone, |
159 | |
160 | /// Assigning into this object requires the old value to be |
161 | /// released and the new value to be retained. The timing of the |
162 | /// release of the old value is inexact: it may be moved to |
163 | /// immediately after the last known point where the value is |
164 | /// live. |
165 | OCL_Strong, |
166 | |
167 | /// Reading or writing from this object requires a barrier call. |
168 | OCL_Weak, |
169 | |
170 | /// Assigning into this object requires a lifetime extension. |
171 | OCL_Autoreleasing |
172 | }; |
173 | |
174 | enum { |
175 | /// The maximum supported address space number. |
176 | /// 23 bits should be enough for anyone. |
177 | MaxAddressSpace = 0x7fffffu, |
178 | |
179 | /// The width of the "fast" qualifier mask. |
180 | FastWidth = 3, |
181 | |
182 | /// The fast qualifier mask. |
183 | FastMask = (1 << FastWidth) - 1 |
184 | }; |
185 | |
186 | /// Returns the common set of qualifiers while removing them from |
187 | /// the given sets. |
188 | static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) { |
189 | // If both are only CVR-qualified, bit operations are sufficient. |
190 | if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) { |
191 | Qualifiers Q; |
192 | Q.Mask = L.Mask & R.Mask; |
193 | L.Mask &= ~Q.Mask; |
194 | R.Mask &= ~Q.Mask; |
195 | return Q; |
196 | } |
197 | |
198 | Qualifiers Q; |
199 | unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers(); |
200 | Q.addCVRQualifiers(CommonCRV); |
201 | L.removeCVRQualifiers(CommonCRV); |
202 | R.removeCVRQualifiers(CommonCRV); |
203 | |
204 | if (L.getObjCGCAttr() == R.getObjCGCAttr()) { |
205 | Q.setObjCGCAttr(L.getObjCGCAttr()); |
206 | L.removeObjCGCAttr(); |
207 | R.removeObjCGCAttr(); |
208 | } |
209 | |
210 | if (L.getObjCLifetime() == R.getObjCLifetime()) { |
211 | Q.setObjCLifetime(L.getObjCLifetime()); |
212 | L.removeObjCLifetime(); |
213 | R.removeObjCLifetime(); |
214 | } |
215 | |
216 | if (L.getAddressSpace() == R.getAddressSpace()) { |
217 | Q.setAddressSpace(L.getAddressSpace()); |
218 | L.removeAddressSpace(); |
219 | R.removeAddressSpace(); |
220 | } |
221 | return Q; |
222 | } |
223 | |
224 | static Qualifiers fromFastMask(unsigned Mask) { |
225 | Qualifiers Qs; |
226 | Qs.addFastQualifiers(Mask); |
227 | return Qs; |
228 | } |
229 | |
230 | static Qualifiers fromCVRMask(unsigned CVR) { |
231 | Qualifiers Qs; |
232 | Qs.addCVRQualifiers(CVR); |
233 | return Qs; |
234 | } |
235 | |
236 | static Qualifiers fromCVRUMask(unsigned CVRU) { |
237 | Qualifiers Qs; |
238 | Qs.addCVRUQualifiers(CVRU); |
239 | return Qs; |
240 | } |
241 | |
242 | // Deserialize qualifiers from an opaque representation. |
243 | static Qualifiers fromOpaqueValue(unsigned opaque) { |
244 | Qualifiers Qs; |
245 | Qs.Mask = opaque; |
246 | return Qs; |
247 | } |
248 | |
249 | // Serialize these qualifiers into an opaque representation. |
250 | unsigned getAsOpaqueValue() const { |
251 | return Mask; |
252 | } |
253 | |
254 | bool hasConst() const { return Mask & Const; } |
255 | bool hasOnlyConst() const { return Mask == Const; } |
256 | void removeConst() { Mask &= ~Const; } |
257 | void addConst() { Mask |= Const; } |
258 | |
259 | bool hasVolatile() const { return Mask & Volatile; } |
260 | bool hasOnlyVolatile() const { return Mask == Volatile; } |
261 | void removeVolatile() { Mask &= ~Volatile; } |
262 | void addVolatile() { Mask |= Volatile; } |
263 | |
264 | bool hasRestrict() const { return Mask & Restrict; } |
265 | bool hasOnlyRestrict() const { return Mask == Restrict; } |
266 | void removeRestrict() { Mask &= ~Restrict; } |
267 | void addRestrict() { Mask |= Restrict; } |
268 | |
269 | bool hasCVRQualifiers() const { return getCVRQualifiers(); } |
270 | unsigned getCVRQualifiers() const { return Mask & CVRMask; } |
271 | unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); } |
272 | |
273 | void setCVRQualifiers(unsigned mask) { |
274 | assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits")((!(mask & ~CVRMask) && "bitmask contains non-CVR bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~CVRMask) && \"bitmask contains non-CVR bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 274, __PRETTY_FUNCTION__)); |
275 | Mask = (Mask & ~CVRMask) | mask; |
276 | } |
277 | void removeCVRQualifiers(unsigned mask) { |
278 | assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits")((!(mask & ~CVRMask) && "bitmask contains non-CVR bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~CVRMask) && \"bitmask contains non-CVR bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 278, __PRETTY_FUNCTION__)); |
279 | Mask &= ~mask; |
280 | } |
281 | void removeCVRQualifiers() { |
282 | removeCVRQualifiers(CVRMask); |
283 | } |
284 | void addCVRQualifiers(unsigned mask) { |
285 | assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits")((!(mask & ~CVRMask) && "bitmask contains non-CVR bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~CVRMask) && \"bitmask contains non-CVR bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 285, __PRETTY_FUNCTION__)); |
286 | Mask |= mask; |
287 | } |
288 | void addCVRUQualifiers(unsigned mask) { |
289 | assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits")((!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~CVRMask & ~UMask) && \"bitmask contains non-CVRU bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 289, __PRETTY_FUNCTION__)); |
290 | Mask |= mask; |
291 | } |
292 | |
293 | bool hasUnaligned() const { return Mask & UMask; } |
294 | void setUnaligned(bool flag) { |
295 | Mask = (Mask & ~UMask) | (flag ? UMask : 0); |
296 | } |
297 | void removeUnaligned() { Mask &= ~UMask; } |
298 | void addUnaligned() { Mask |= UMask; } |
299 | |
300 | bool hasObjCGCAttr() const { return Mask & GCAttrMask; } |
301 | GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } |
302 | void setObjCGCAttr(GC type) { |
303 | Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); |
304 | } |
305 | void removeObjCGCAttr() { setObjCGCAttr(GCNone); } |
306 | void addObjCGCAttr(GC type) { |
307 | assert(type)((type) ? static_cast<void> (0) : __assert_fail ("type" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 307, __PRETTY_FUNCTION__)); |
308 | setObjCGCAttr(type); |
309 | } |
310 | Qualifiers withoutObjCGCAttr() const { |
311 | Qualifiers qs = *this; |
312 | qs.removeObjCGCAttr(); |
313 | return qs; |
314 | } |
315 | Qualifiers withoutObjCLifetime() const { |
316 | Qualifiers qs = *this; |
317 | qs.removeObjCLifetime(); |
318 | return qs; |
319 | } |
320 | Qualifiers withoutAddressSpace() const { |
321 | Qualifiers qs = *this; |
322 | qs.removeAddressSpace(); |
323 | return qs; |
324 | } |
325 | |
326 | bool hasObjCLifetime() const { return Mask & LifetimeMask; } |
327 | ObjCLifetime getObjCLifetime() const { |
328 | return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift); |
329 | } |
330 | void setObjCLifetime(ObjCLifetime type) { |
331 | Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift); |
332 | } |
333 | void removeObjCLifetime() { setObjCLifetime(OCL_None); } |
334 | void addObjCLifetime(ObjCLifetime type) { |
335 | assert(type)((type) ? static_cast<void> (0) : __assert_fail ("type" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 335, __PRETTY_FUNCTION__)); |
336 | assert(!hasObjCLifetime())((!hasObjCLifetime()) ? static_cast<void> (0) : __assert_fail ("!hasObjCLifetime()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 336, __PRETTY_FUNCTION__)); |
337 | Mask |= (type << LifetimeShift); |
338 | } |
339 | |
340 | /// True if the lifetime is neither None or ExplicitNone. |
341 | bool hasNonTrivialObjCLifetime() const { |
342 | ObjCLifetime lifetime = getObjCLifetime(); |
343 | return (lifetime > OCL_ExplicitNone); |
344 | } |
345 | |
346 | /// True if the lifetime is either strong or weak. |
347 | bool hasStrongOrWeakObjCLifetime() const { |
348 | ObjCLifetime lifetime = getObjCLifetime(); |
349 | return (lifetime == OCL_Strong || lifetime == OCL_Weak); |
350 | } |
351 | |
352 | bool hasAddressSpace() const { return Mask & AddressSpaceMask; } |
353 | LangAS getAddressSpace() const { |
354 | return static_cast<LangAS>(Mask >> AddressSpaceShift); |
355 | } |
356 | bool hasTargetSpecificAddressSpace() const { |
357 | return isTargetAddressSpace(getAddressSpace()); |
358 | } |
359 | /// Get the address space attribute value to be printed by diagnostics. |
360 | unsigned getAddressSpaceAttributePrintValue() const { |
361 | auto Addr = getAddressSpace(); |
362 | // This function is not supposed to be used with language specific |
363 | // address spaces. If that happens, the diagnostic message should consider |
364 | // printing the QualType instead of the address space value. |
365 | assert(Addr == LangAS::Default || hasTargetSpecificAddressSpace())((Addr == LangAS::Default || hasTargetSpecificAddressSpace()) ? static_cast<void> (0) : __assert_fail ("Addr == LangAS::Default || hasTargetSpecificAddressSpace()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 365, __PRETTY_FUNCTION__)); |
366 | if (Addr != LangAS::Default) |
367 | return toTargetAddressSpace(Addr); |
368 | // TODO: The diagnostic messages where Addr may be 0 should be fixed |
369 | // since it cannot differentiate the situation where 0 denotes the default |
370 | // address space or user specified __attribute__((address_space(0))). |
371 | return 0; |
372 | } |
373 | void setAddressSpace(LangAS space) { |
374 | assert((unsigned)space <= MaxAddressSpace)(((unsigned)space <= MaxAddressSpace) ? static_cast<void > (0) : __assert_fail ("(unsigned)space <= MaxAddressSpace" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 374, __PRETTY_FUNCTION__)); |
375 | Mask = (Mask & ~AddressSpaceMask) |
376 | | (((uint32_t) space) << AddressSpaceShift); |
377 | } |
378 | void removeAddressSpace() { setAddressSpace(LangAS::Default); } |
379 | void addAddressSpace(LangAS space) { |
380 | assert(space != LangAS::Default)((space != LangAS::Default) ? static_cast<void> (0) : __assert_fail ("space != LangAS::Default", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 380, __PRETTY_FUNCTION__)); |
381 | setAddressSpace(space); |
382 | } |
383 | |
384 | // Fast qualifiers are those that can be allocated directly |
385 | // on a QualType object. |
386 | bool hasFastQualifiers() const { return getFastQualifiers(); } |
387 | unsigned getFastQualifiers() const { return Mask & FastMask; } |
388 | void setFastQualifiers(unsigned mask) { |
389 | assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits")((!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~FastMask) && \"bitmask contains non-fast qualifier bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 389, __PRETTY_FUNCTION__)); |
390 | Mask = (Mask & ~FastMask) | mask; |
391 | } |
392 | void removeFastQualifiers(unsigned mask) { |
393 | assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits")((!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~FastMask) && \"bitmask contains non-fast qualifier bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 393, __PRETTY_FUNCTION__)); |
394 | Mask &= ~mask; |
395 | } |
396 | void removeFastQualifiers() { |
397 | removeFastQualifiers(FastMask); |
398 | } |
399 | void addFastQualifiers(unsigned mask) { |
400 | assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits")((!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits" ) ? static_cast<void> (0) : __assert_fail ("!(mask & ~FastMask) && \"bitmask contains non-fast qualifier bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 400, __PRETTY_FUNCTION__)); |
401 | Mask |= mask; |
402 | } |
403 | |
404 | /// Return true if the set contains any qualifiers which require an ExtQuals |
405 | /// node to be allocated. |
406 | bool hasNonFastQualifiers() const { return Mask & ~FastMask; } |
407 | Qualifiers getNonFastQualifiers() const { |
408 | Qualifiers Quals = *this; |
409 | Quals.setFastQualifiers(0); |
410 | return Quals; |
411 | } |
412 | |
413 | /// Return true if the set contains any qualifiers. |
414 | bool hasQualifiers() const { return Mask; } |
415 | bool empty() const { return !Mask; } |
416 | |
417 | /// Add the qualifiers from the given set to this set. |
418 | void addQualifiers(Qualifiers Q) { |
419 | // If the other set doesn't have any non-boolean qualifiers, just |
420 | // bit-or it in. |
421 | if (!(Q.Mask & ~CVRMask)) |
422 | Mask |= Q.Mask; |
423 | else { |
424 | Mask |= (Q.Mask & CVRMask); |
425 | if (Q.hasAddressSpace()) |
426 | addAddressSpace(Q.getAddressSpace()); |
427 | if (Q.hasObjCGCAttr()) |
428 | addObjCGCAttr(Q.getObjCGCAttr()); |
429 | if (Q.hasObjCLifetime()) |
430 | addObjCLifetime(Q.getObjCLifetime()); |
431 | } |
432 | } |
433 | |
434 | /// Remove the qualifiers from the given set from this set. |
435 | void removeQualifiers(Qualifiers Q) { |
436 | // If the other set doesn't have any non-boolean qualifiers, just |
437 | // bit-and the inverse in. |
438 | if (!(Q.Mask & ~CVRMask)) |
439 | Mask &= ~Q.Mask; |
440 | else { |
441 | Mask &= ~(Q.Mask & CVRMask); |
442 | if (getObjCGCAttr() == Q.getObjCGCAttr()) |
443 | removeObjCGCAttr(); |
444 | if (getObjCLifetime() == Q.getObjCLifetime()) |
445 | removeObjCLifetime(); |
446 | if (getAddressSpace() == Q.getAddressSpace()) |
447 | removeAddressSpace(); |
448 | } |
449 | } |
450 | |
451 | /// Add the qualifiers from the given set to this set, given that |
452 | /// they don't conflict. |
453 | void addConsistentQualifiers(Qualifiers qs) { |
454 | assert(getAddressSpace() == qs.getAddressSpace() ||((getAddressSpace() == qs.getAddressSpace() || !hasAddressSpace () || !qs.hasAddressSpace()) ? static_cast<void> (0) : __assert_fail ("getAddressSpace() == qs.getAddressSpace() || !hasAddressSpace() || !qs.hasAddressSpace()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 455, __PRETTY_FUNCTION__)) |
455 | !hasAddressSpace() || !qs.hasAddressSpace())((getAddressSpace() == qs.getAddressSpace() || !hasAddressSpace () || !qs.hasAddressSpace()) ? static_cast<void> (0) : __assert_fail ("getAddressSpace() == qs.getAddressSpace() || !hasAddressSpace() || !qs.hasAddressSpace()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 455, __PRETTY_FUNCTION__)); |
456 | assert(getObjCGCAttr() == qs.getObjCGCAttr() ||((getObjCGCAttr() == qs.getObjCGCAttr() || !hasObjCGCAttr() || !qs.hasObjCGCAttr()) ? static_cast<void> (0) : __assert_fail ("getObjCGCAttr() == qs.getObjCGCAttr() || !hasObjCGCAttr() || !qs.hasObjCGCAttr()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 457, __PRETTY_FUNCTION__)) |
457 | !hasObjCGCAttr() || !qs.hasObjCGCAttr())((getObjCGCAttr() == qs.getObjCGCAttr() || !hasObjCGCAttr() || !qs.hasObjCGCAttr()) ? static_cast<void> (0) : __assert_fail ("getObjCGCAttr() == qs.getObjCGCAttr() || !hasObjCGCAttr() || !qs.hasObjCGCAttr()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 457, __PRETTY_FUNCTION__)); |
458 | assert(getObjCLifetime() == qs.getObjCLifetime() ||((getObjCLifetime() == qs.getObjCLifetime() || !hasObjCLifetime () || !qs.hasObjCLifetime()) ? static_cast<void> (0) : __assert_fail ("getObjCLifetime() == qs.getObjCLifetime() || !hasObjCLifetime() || !qs.hasObjCLifetime()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 459, __PRETTY_FUNCTION__)) |
459 | !hasObjCLifetime() || !qs.hasObjCLifetime())((getObjCLifetime() == qs.getObjCLifetime() || !hasObjCLifetime () || !qs.hasObjCLifetime()) ? static_cast<void> (0) : __assert_fail ("getObjCLifetime() == qs.getObjCLifetime() || !hasObjCLifetime() || !qs.hasObjCLifetime()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 459, __PRETTY_FUNCTION__)); |
460 | Mask |= qs.Mask; |
461 | } |
462 | |
463 | /// Returns true if address space A is equal to or a superset of B. |
464 | /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of |
465 | /// overlapping address spaces. |
466 | /// CL1.1 or CL1.2: |
467 | /// every address space is a superset of itself. |
468 | /// CL2.0 adds: |
469 | /// __generic is a superset of any address space except for __constant. |
470 | static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) { |
471 | // Address spaces must match exactly. |
472 | return A == B || |
473 | // Otherwise in OpenCLC v2.0 s6.5.5: every address space except |
474 | // for __constant can be used as __generic. |
475 | (A == LangAS::opencl_generic && B != LangAS::opencl_constant); |
476 | } |
477 | |
478 | /// Returns true if the address space in these qualifiers is equal to or |
479 | /// a superset of the address space in the argument qualifiers. |
480 | bool isAddressSpaceSupersetOf(Qualifiers other) const { |
481 | return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()); |
482 | } |
483 | |
484 | /// Determines if these qualifiers compatibly include another set. |
485 | /// Generally this answers the question of whether an object with the other |
486 | /// qualifiers can be safely used as an object with these qualifiers. |
487 | bool compatiblyIncludes(Qualifiers other) const { |
488 | return isAddressSpaceSupersetOf(other) && |
489 | // ObjC GC qualifiers can match, be added, or be removed, but can't |
490 | // be changed. |
491 | (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() || |
492 | !other.hasObjCGCAttr()) && |
493 | // ObjC lifetime qualifiers must match exactly. |
494 | getObjCLifetime() == other.getObjCLifetime() && |
495 | // CVR qualifiers may subset. |
496 | (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) && |
497 | // U qualifier may superset. |
498 | (!other.hasUnaligned() || hasUnaligned()); |
499 | } |
500 | |
501 | /// Determines if these qualifiers compatibly include another set of |
502 | /// qualifiers from the narrow perspective of Objective-C ARC lifetime. |
503 | /// |
504 | /// One set of Objective-C lifetime qualifiers compatibly includes the other |
505 | /// if the lifetime qualifiers match, or if both are non-__weak and the |
506 | /// including set also contains the 'const' qualifier, or both are non-__weak |
507 | /// and one is None (which can only happen in non-ARC modes). |
508 | bool compatiblyIncludesObjCLifetime(Qualifiers other) const { |
509 | if (getObjCLifetime() == other.getObjCLifetime()) |
510 | return true; |
511 | |
512 | if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak) |
513 | return false; |
514 | |
515 | if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None) |
516 | return true; |
517 | |
518 | return hasConst(); |
519 | } |
520 | |
521 | /// Determine whether this set of qualifiers is a strict superset of |
522 | /// another set of qualifiers, not considering qualifier compatibility. |
523 | bool isStrictSupersetOf(Qualifiers Other) const; |
524 | |
525 | bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } |
526 | bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } |
527 | |
528 | explicit operator bool() const { return hasQualifiers(); } |
529 | |
530 | Qualifiers &operator+=(Qualifiers R) { |
531 | addQualifiers(R); |
532 | return *this; |
533 | } |
534 | |
535 | // Union two qualifier sets. If an enumerated qualifier appears |
536 | // in both sets, use the one from the right. |
537 | friend Qualifiers operator+(Qualifiers L, Qualifiers R) { |
538 | L += R; |
539 | return L; |
540 | } |
541 | |
542 | Qualifiers &operator-=(Qualifiers R) { |
543 | removeQualifiers(R); |
544 | return *this; |
545 | } |
546 | |
547 | /// Compute the difference between two qualifier sets. |
548 | friend Qualifiers operator-(Qualifiers L, Qualifiers R) { |
549 | L -= R; |
550 | return L; |
551 | } |
552 | |
553 | std::string getAsString() const; |
554 | std::string getAsString(const PrintingPolicy &Policy) const; |
555 | |
556 | bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const; |
557 | void print(raw_ostream &OS, const PrintingPolicy &Policy, |
558 | bool appendSpaceIfNonEmpty = false) const; |
559 | |
560 | void Profile(llvm::FoldingSetNodeID &ID) const { |
561 | ID.AddInteger(Mask); |
562 | } |
563 | |
564 | private: |
565 | // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31| |
566 | // |C R V|U|GCAttr|Lifetime|AddressSpace| |
567 | uint32_t Mask = 0; |
568 | |
569 | static const uint32_t UMask = 0x8; |
570 | static const uint32_t UShift = 3; |
571 | static const uint32_t GCAttrMask = 0x30; |
572 | static const uint32_t GCAttrShift = 4; |
573 | static const uint32_t LifetimeMask = 0x1C0; |
574 | static const uint32_t LifetimeShift = 6; |
575 | static const uint32_t AddressSpaceMask = |
576 | ~(CVRMask | UMask | GCAttrMask | LifetimeMask); |
577 | static const uint32_t AddressSpaceShift = 9; |
578 | }; |
579 | |
580 | /// A std::pair-like structure for storing a qualified type split |
581 | /// into its local qualifiers and its locally-unqualified type. |
582 | struct SplitQualType { |
583 | /// The locally-unqualified type. |
584 | const Type *Ty = nullptr; |
585 | |
586 | /// The local qualifiers. |
587 | Qualifiers Quals; |
588 | |
589 | SplitQualType() = default; |
590 | SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {} |
591 | |
592 | SplitQualType getSingleStepDesugaredType() const; // end of this file |
593 | |
594 | // Make std::tie work. |
595 | std::pair<const Type *,Qualifiers> asPair() const { |
596 | return std::pair<const Type *, Qualifiers>(Ty, Quals); |
597 | } |
598 | |
599 | friend bool operator==(SplitQualType a, SplitQualType b) { |
600 | return a.Ty == b.Ty && a.Quals == b.Quals; |
601 | } |
602 | friend bool operator!=(SplitQualType a, SplitQualType b) { |
603 | return a.Ty != b.Ty || a.Quals != b.Quals; |
604 | } |
605 | }; |
606 | |
607 | /// The kind of type we are substituting Objective-C type arguments into. |
608 | /// |
609 | /// The kind of substitution affects the replacement of type parameters when |
610 | /// no concrete type information is provided, e.g., when dealing with an |
611 | /// unspecialized type. |
612 | enum class ObjCSubstitutionContext { |
613 | /// An ordinary type. |
614 | Ordinary, |
615 | |
616 | /// The result type of a method or function. |
617 | Result, |
618 | |
619 | /// The parameter type of a method or function. |
620 | Parameter, |
621 | |
622 | /// The type of a property. |
623 | Property, |
624 | |
625 | /// The superclass of a type. |
626 | Superclass, |
627 | }; |
628 | |
629 | /// A (possibly-)qualified type. |
630 | /// |
631 | /// For efficiency, we don't store CV-qualified types as nodes on their |
632 | /// own: instead each reference to a type stores the qualifiers. This |
633 | /// greatly reduces the number of nodes we need to allocate for types (for |
634 | /// example we only need one for 'int', 'const int', 'volatile int', |
635 | /// 'const volatile int', etc). |
636 | /// |
637 | /// As an added efficiency bonus, instead of making this a pair, we |
638 | /// just store the two bits we care about in the low bits of the |
639 | /// pointer. To handle the packing/unpacking, we make QualType be a |
640 | /// simple wrapper class that acts like a smart pointer. A third bit |
641 | /// indicates whether there are extended qualifiers present, in which |
642 | /// case the pointer points to a special structure. |
643 | class QualType { |
644 | friend class QualifierCollector; |
645 | |
646 | // Thankfully, these are efficiently composable. |
647 | llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>, |
648 | Qualifiers::FastWidth> Value; |
649 | |
650 | const ExtQuals *getExtQualsUnsafe() const { |
651 | return Value.getPointer().get<const ExtQuals*>(); |
652 | } |
653 | |
654 | const Type *getTypePtrUnsafe() const { |
655 | return Value.getPointer().get<const Type*>(); |
656 | } |
657 | |
658 | const ExtQualsTypeCommonBase *getCommonPtr() const { |
659 | assert(!isNull() && "Cannot retrieve a NULL type pointer")((!isNull() && "Cannot retrieve a NULL type pointer") ? static_cast<void> (0) : __assert_fail ("!isNull() && \"Cannot retrieve a NULL type pointer\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 659, __PRETTY_FUNCTION__)); |
660 | auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); |
661 | CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); |
662 | return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); |
663 | } |
664 | |
665 | public: |
666 | QualType() = default; |
667 | QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {} |
668 | QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {} |
669 | |
670 | unsigned getLocalFastQualifiers() const { return Value.getInt(); } |
671 | void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } |
672 | |
673 | /// Retrieves a pointer to the underlying (unqualified) type. |
674 | /// |
675 | /// This function requires that the type not be NULL. If the type might be |
676 | /// NULL, use the (slightly less efficient) \c getTypePtrOrNull(). |
677 | const Type *getTypePtr() const; |
678 | |
679 | const Type *getTypePtrOrNull() const; |
680 | |
681 | /// Retrieves a pointer to the name of the base type. |
682 | const IdentifierInfo *getBaseTypeIdentifier() const; |
683 | |
684 | /// Divides a QualType into its unqualified type and a set of local |
685 | /// qualifiers. |
686 | SplitQualType split() const; |
687 | |
688 | void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } |
689 | |
690 | static QualType getFromOpaquePtr(const void *Ptr) { |
691 | QualType T; |
692 | T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); |
693 | return T; |
694 | } |
695 | |
696 | const Type &operator*() const { |
697 | return *getTypePtr(); |
698 | } |
699 | |
700 | const Type *operator->() const { |
701 | return getTypePtr(); |
702 | } |
703 | |
704 | bool isCanonical() const; |
705 | bool isCanonicalAsParam() const; |
706 | |
707 | /// Return true if this QualType doesn't point to a type yet. |
708 | bool isNull() const { |
709 | return Value.getPointer().isNull(); |
710 | } |
711 | |
712 | /// Determine whether this particular QualType instance has the |
713 | /// "const" qualifier set, without looking through typedefs that may have |
714 | /// added "const" at a different level. |
715 | bool isLocalConstQualified() const { |
716 | return (getLocalFastQualifiers() & Qualifiers::Const); |
717 | } |
718 | |
719 | /// Determine whether this type is const-qualified. |
720 | bool isConstQualified() const; |
721 | |
722 | /// Determine whether this particular QualType instance has the |
723 | /// "restrict" qualifier set, without looking through typedefs that may have |
724 | /// added "restrict" at a different level. |
725 | bool isLocalRestrictQualified() const { |
726 | return (getLocalFastQualifiers() & Qualifiers::Restrict); |
727 | } |
728 | |
729 | /// Determine whether this type is restrict-qualified. |
730 | bool isRestrictQualified() const; |
731 | |
732 | /// Determine whether this particular QualType instance has the |
733 | /// "volatile" qualifier set, without looking through typedefs that may have |
734 | /// added "volatile" at a different level. |
735 | bool isLocalVolatileQualified() const { |
736 | return (getLocalFastQualifiers() & Qualifiers::Volatile); |
737 | } |
738 | |
739 | /// Determine whether this type is volatile-qualified. |
740 | bool isVolatileQualified() const; |
741 | |
742 | /// Determine whether this particular QualType instance has any |
743 | /// qualifiers, without looking through any typedefs that might add |
744 | /// qualifiers at a different level. |
745 | bool hasLocalQualifiers() const { |
746 | return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); |
747 | } |
748 | |
749 | /// Determine whether this type has any qualifiers. |
750 | bool hasQualifiers() const; |
751 | |
752 | /// Determine whether this particular QualType instance has any |
753 | /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType |
754 | /// instance. |
755 | bool hasLocalNonFastQualifiers() const { |
756 | return Value.getPointer().is<const ExtQuals*>(); |
757 | } |
758 | |
759 | /// Retrieve the set of qualifiers local to this particular QualType |
760 | /// instance, not including any qualifiers acquired through typedefs or |
761 | /// other sugar. |
762 | Qualifiers getLocalQualifiers() const; |
763 | |
764 | /// Retrieve the set of qualifiers applied to this type. |
765 | Qualifiers getQualifiers() const; |
766 | |
767 | /// Retrieve the set of CVR (const-volatile-restrict) qualifiers |
768 | /// local to this particular QualType instance, not including any qualifiers |
769 | /// acquired through typedefs or other sugar. |
770 | unsigned getLocalCVRQualifiers() const { |
771 | return getLocalFastQualifiers(); |
772 | } |
773 | |
774 | /// Retrieve the set of CVR (const-volatile-restrict) qualifiers |
775 | /// applied to this type. |
776 | unsigned getCVRQualifiers() const; |
777 | |
778 | bool isConstant(const ASTContext& Ctx) const { |
779 | return QualType::isConstant(*this, Ctx); |
780 | } |
781 | |
782 | /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10). |
783 | bool isPODType(const ASTContext &Context) const; |
784 | |
785 | /// Return true if this is a POD type according to the rules of the C++98 |
786 | /// standard, regardless of the current compilation's language. |
787 | bool isCXX98PODType(const ASTContext &Context) const; |
788 | |
789 | /// Return true if this is a POD type according to the more relaxed rules |
790 | /// of the C++11 standard, regardless of the current compilation's language. |
791 | /// (C++0x [basic.types]p9). Note that, unlike |
792 | /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account. |
793 | bool isCXX11PODType(const ASTContext &Context) const; |
794 | |
795 | /// Return true if this is a trivial type per (C++0x [basic.types]p9) |
796 | bool isTrivialType(const ASTContext &Context) const; |
797 | |
798 | /// Return true if this is a trivially copyable type (C++0x [basic.types]p9) |
799 | bool isTriviallyCopyableType(const ASTContext &Context) const; |
800 | |
801 | |
802 | /// Returns true if it is a class and it might be dynamic. |
803 | bool mayBeDynamicClass() const; |
804 | |
805 | /// Returns true if it is not a class or if the class might not be dynamic. |
806 | bool mayBeNotDynamicClass() const; |
807 | |
808 | // Don't promise in the API that anything besides 'const' can be |
809 | // easily added. |
810 | |
811 | /// Add the `const` type qualifier to this QualType. |
812 | void addConst() { |
813 | addFastQualifiers(Qualifiers::Const); |
814 | } |
815 | QualType withConst() const { |
816 | return withFastQualifiers(Qualifiers::Const); |
817 | } |
818 | |
819 | /// Add the `volatile` type qualifier to this QualType. |
820 | void addVolatile() { |
821 | addFastQualifiers(Qualifiers::Volatile); |
822 | } |
823 | QualType withVolatile() const { |
824 | return withFastQualifiers(Qualifiers::Volatile); |
825 | } |
826 | |
827 | /// Add the `restrict` qualifier to this QualType. |
828 | void addRestrict() { |
829 | addFastQualifiers(Qualifiers::Restrict); |
830 | } |
831 | QualType withRestrict() const { |
832 | return withFastQualifiers(Qualifiers::Restrict); |
833 | } |
834 | |
835 | QualType withCVRQualifiers(unsigned CVR) const { |
836 | return withFastQualifiers(CVR); |
837 | } |
838 | |
839 | void addFastQualifiers(unsigned TQs) { |
840 | assert(!(TQs & ~Qualifiers::FastMask)((!(TQs & ~Qualifiers::FastMask) && "non-fast qualifier bits set in mask!" ) ? static_cast<void> (0) : __assert_fail ("!(TQs & ~Qualifiers::FastMask) && \"non-fast qualifier bits set in mask!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 841, __PRETTY_FUNCTION__)) |
841 | && "non-fast qualifier bits set in mask!")((!(TQs & ~Qualifiers::FastMask) && "non-fast qualifier bits set in mask!" ) ? static_cast<void> (0) : __assert_fail ("!(TQs & ~Qualifiers::FastMask) && \"non-fast qualifier bits set in mask!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 841, __PRETTY_FUNCTION__)); |
842 | Value.setInt(Value.getInt() | TQs); |
843 | } |
844 | |
845 | void removeLocalConst(); |
846 | void removeLocalVolatile(); |
847 | void removeLocalRestrict(); |
848 | void removeLocalCVRQualifiers(unsigned Mask); |
849 | |
850 | void removeLocalFastQualifiers() { Value.setInt(0); } |
851 | void removeLocalFastQualifiers(unsigned Mask) { |
852 | assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers")((!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers" ) ? static_cast<void> (0) : __assert_fail ("!(Mask & ~Qualifiers::FastMask) && \"mask has non-fast qualifiers\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 852, __PRETTY_FUNCTION__)); |
853 | Value.setInt(Value.getInt() & ~Mask); |
854 | } |
855 | |
856 | // Creates a type with the given qualifiers in addition to any |
857 | // qualifiers already on this type. |
858 | QualType withFastQualifiers(unsigned TQs) const { |
859 | QualType T = *this; |
860 | T.addFastQualifiers(TQs); |
861 | return T; |
862 | } |
863 | |
864 | // Creates a type with exactly the given fast qualifiers, removing |
865 | // any existing fast qualifiers. |
866 | QualType withExactLocalFastQualifiers(unsigned TQs) const { |
867 | return withoutLocalFastQualifiers().withFastQualifiers(TQs); |
868 | } |
869 | |
870 | // Removes fast qualifiers, but leaves any extended qualifiers in place. |
871 | QualType withoutLocalFastQualifiers() const { |
872 | QualType T = *this; |
873 | T.removeLocalFastQualifiers(); |
874 | return T; |
875 | } |
876 | |
877 | QualType getCanonicalType() const; |
878 | |
879 | /// Return this type with all of the instance-specific qualifiers |
880 | /// removed, but without removing any qualifiers that may have been applied |
881 | /// through typedefs. |
882 | QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } |
883 | |
884 | /// Retrieve the unqualified variant of the given type, |
885 | /// removing as little sugar as possible. |
886 | /// |
887 | /// This routine looks through various kinds of sugar to find the |
888 | /// least-desugared type that is unqualified. For example, given: |
889 | /// |
890 | /// \code |
891 | /// typedef int Integer; |
892 | /// typedef const Integer CInteger; |
893 | /// typedef CInteger DifferenceType; |
894 | /// \endcode |
895 | /// |
896 | /// Executing \c getUnqualifiedType() on the type \c DifferenceType will |
897 | /// desugar until we hit the type \c Integer, which has no qualifiers on it. |
898 | /// |
899 | /// The resulting type might still be qualified if it's sugar for an array |
900 | /// type. To strip qualifiers even from within a sugared array type, use |
901 | /// ASTContext::getUnqualifiedArrayType. |
902 | inline QualType getUnqualifiedType() const; |
903 | |
904 | /// Retrieve the unqualified variant of the given type, removing as little |
905 | /// sugar as possible. |
906 | /// |
907 | /// Like getUnqualifiedType(), but also returns the set of |
908 | /// qualifiers that were built up. |
909 | /// |
910 | /// The resulting type might still be qualified if it's sugar for an array |
911 | /// type. To strip qualifiers even from within a sugared array type, use |
912 | /// ASTContext::getUnqualifiedArrayType. |
913 | inline SplitQualType getSplitUnqualifiedType() const; |
914 | |
915 | /// Determine whether this type is more qualified than the other |
916 | /// given type, requiring exact equality for non-CVR qualifiers. |
917 | bool isMoreQualifiedThan(QualType Other) const; |
918 | |
919 | /// Determine whether this type is at least as qualified as the other |
920 | /// given type, requiring exact equality for non-CVR qualifiers. |
921 | bool isAtLeastAsQualifiedAs(QualType Other) const; |
922 | |
923 | QualType getNonReferenceType() const; |
924 | |
925 | /// Determine the type of a (typically non-lvalue) expression with the |
926 | /// specified result type. |
927 | /// |
928 | /// This routine should be used for expressions for which the return type is |
929 | /// explicitly specified (e.g., in a cast or call) and isn't necessarily |
930 | /// an lvalue. It removes a top-level reference (since there are no |
931 | /// expressions of reference type) and deletes top-level cvr-qualifiers |
932 | /// from non-class types (in C++) or all types (in C). |
933 | QualType getNonLValueExprType(const ASTContext &Context) const; |
934 | |
935 | /// Return the specified type with any "sugar" removed from |
936 | /// the type. This takes off typedefs, typeof's etc. If the outer level of |
937 | /// the type is already concrete, it returns it unmodified. This is similar |
938 | /// to getting the canonical type, but it doesn't remove *all* typedefs. For |
939 | /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is |
940 | /// concrete. |
941 | /// |
942 | /// Qualifiers are left in place. |
943 | QualType getDesugaredType(const ASTContext &Context) const { |
944 | return getDesugaredType(*this, Context); |
945 | } |
946 | |
947 | SplitQualType getSplitDesugaredType() const { |
948 | return getSplitDesugaredType(*this); |
949 | } |
950 | |
951 | /// Return the specified type with one level of "sugar" removed from |
952 | /// the type. |
953 | /// |
954 | /// This routine takes off the first typedef, typeof, etc. If the outer level |
955 | /// of the type is already concrete, it returns it unmodified. |
956 | QualType getSingleStepDesugaredType(const ASTContext &Context) const { |
957 | return getSingleStepDesugaredTypeImpl(*this, Context); |
958 | } |
959 | |
960 | /// Returns the specified type after dropping any |
961 | /// outer-level parentheses. |
962 | QualType IgnoreParens() const { |
963 | if (isa<ParenType>(*this)) |
964 | return QualType::IgnoreParens(*this); |
965 | return *this; |
966 | } |
967 | |
968 | /// Indicate whether the specified types and qualifiers are identical. |
969 | friend bool operator==(const QualType &LHS, const QualType &RHS) { |
970 | return LHS.Value == RHS.Value; |
971 | } |
972 | friend bool operator!=(const QualType &LHS, const QualType &RHS) { |
973 | return LHS.Value != RHS.Value; |
974 | } |
975 | friend bool operator<(const QualType &LHS, const QualType &RHS) { |
976 | return LHS.Value < RHS.Value; |
977 | } |
978 | |
979 | static std::string getAsString(SplitQualType split, |
980 | const PrintingPolicy &Policy) { |
981 | return getAsString(split.Ty, split.Quals, Policy); |
982 | } |
983 | static std::string getAsString(const Type *ty, Qualifiers qs, |
984 | const PrintingPolicy &Policy); |
985 | |
986 | std::string getAsString() const; |
987 | std::string getAsString(const PrintingPolicy &Policy) const; |
988 | |
989 | void print(raw_ostream &OS, const PrintingPolicy &Policy, |
990 | const Twine &PlaceHolder = Twine(), |
991 | unsigned Indentation = 0) const; |
992 | |
993 | static void print(SplitQualType split, raw_ostream &OS, |
994 | const PrintingPolicy &policy, const Twine &PlaceHolder, |
995 | unsigned Indentation = 0) { |
996 | return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation); |
997 | } |
998 | |
999 | static void print(const Type *ty, Qualifiers qs, |
1000 | raw_ostream &OS, const PrintingPolicy &policy, |
1001 | const Twine &PlaceHolder, |
1002 | unsigned Indentation = 0); |
1003 | |
1004 | void getAsStringInternal(std::string &Str, |
1005 | const PrintingPolicy &Policy) const; |
1006 | |
1007 | static void getAsStringInternal(SplitQualType split, std::string &out, |
1008 | const PrintingPolicy &policy) { |
1009 | return getAsStringInternal(split.Ty, split.Quals, out, policy); |
1010 | } |
1011 | |
1012 | static void getAsStringInternal(const Type *ty, Qualifiers qs, |
1013 | std::string &out, |
1014 | const PrintingPolicy &policy); |
1015 | |
1016 | class StreamedQualTypeHelper { |
1017 | const QualType &T; |
1018 | const PrintingPolicy &Policy; |
1019 | const Twine &PlaceHolder; |
1020 | unsigned Indentation; |
1021 | |
1022 | public: |
1023 | StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy, |
1024 | const Twine &PlaceHolder, unsigned Indentation) |
1025 | : T(T), Policy(Policy), PlaceHolder(PlaceHolder), |
1026 | Indentation(Indentation) {} |
1027 | |
1028 | friend raw_ostream &operator<<(raw_ostream &OS, |
1029 | const StreamedQualTypeHelper &SQT) { |
1030 | SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation); |
1031 | return OS; |
1032 | } |
1033 | }; |
1034 | |
1035 | StreamedQualTypeHelper stream(const PrintingPolicy &Policy, |
1036 | const Twine &PlaceHolder = Twine(), |
1037 | unsigned Indentation = 0) const { |
1038 | return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation); |
1039 | } |
1040 | |
1041 | void dump(const char *s) const; |
1042 | void dump() const; |
1043 | void dump(llvm::raw_ostream &OS) const; |
1044 | |
1045 | void Profile(llvm::FoldingSetNodeID &ID) const { |
1046 | ID.AddPointer(getAsOpaquePtr()); |
1047 | } |
1048 | |
1049 | /// Return the address space of this type. |
1050 | inline LangAS getAddressSpace() const; |
1051 | |
1052 | /// Returns gc attribute of this type. |
1053 | inline Qualifiers::GC getObjCGCAttr() const; |
1054 | |
1055 | /// true when Type is objc's weak. |
1056 | bool isObjCGCWeak() const { |
1057 | return getObjCGCAttr() == Qualifiers::Weak; |
1058 | } |
1059 | |
1060 | /// true when Type is objc's strong. |
1061 | bool isObjCGCStrong() const { |
1062 | return getObjCGCAttr() == Qualifiers::Strong; |
1063 | } |
1064 | |
1065 | /// Returns lifetime attribute of this type. |
1066 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
1067 | return getQualifiers().getObjCLifetime(); |
1068 | } |
1069 | |
1070 | bool hasNonTrivialObjCLifetime() const { |
1071 | return getQualifiers().hasNonTrivialObjCLifetime(); |
1072 | } |
1073 | |
1074 | bool hasStrongOrWeakObjCLifetime() const { |
1075 | return getQualifiers().hasStrongOrWeakObjCLifetime(); |
1076 | } |
1077 | |
1078 | // true when Type is objc's weak and weak is enabled but ARC isn't. |
1079 | bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const; |
1080 | |
1081 | enum PrimitiveDefaultInitializeKind { |
1082 | /// The type does not fall into any of the following categories. Note that |
1083 | /// this case is zero-valued so that values of this enum can be used as a |
1084 | /// boolean condition for non-triviality. |
1085 | PDIK_Trivial, |
1086 | |
1087 | /// The type is an Objective-C retainable pointer type that is qualified |
1088 | /// with the ARC __strong qualifier. |
1089 | PDIK_ARCStrong, |
1090 | |
1091 | /// The type is an Objective-C retainable pointer type that is qualified |
1092 | /// with the ARC __weak qualifier. |
1093 | PDIK_ARCWeak, |
1094 | |
1095 | /// The type is a struct containing a field whose type is not PCK_Trivial. |
1096 | PDIK_Struct |
1097 | }; |
1098 | |
1099 | /// Functions to query basic properties of non-trivial C struct types. |
1100 | |
1101 | /// Check if this is a non-trivial type that would cause a C struct |
1102 | /// transitively containing this type to be non-trivial to default initialize |
1103 | /// and return the kind. |
1104 | PrimitiveDefaultInitializeKind |
1105 | isNonTrivialToPrimitiveDefaultInitialize() const; |
1106 | |
1107 | enum PrimitiveCopyKind { |
1108 | /// The type does not fall into any of the following categories. Note that |
1109 | /// this case is zero-valued so that values of this enum can be used as a |
1110 | /// boolean condition for non-triviality. |
1111 | PCK_Trivial, |
1112 | |
1113 | /// The type would be trivial except that it is volatile-qualified. Types |
1114 | /// that fall into one of the other non-trivial cases may additionally be |
1115 | /// volatile-qualified. |
1116 | PCK_VolatileTrivial, |
1117 | |
1118 | /// The type is an Objective-C retainable pointer type that is qualified |
1119 | /// with the ARC __strong qualifier. |
1120 | PCK_ARCStrong, |
1121 | |
1122 | /// The type is an Objective-C retainable pointer type that is qualified |
1123 | /// with the ARC __weak qualifier. |
1124 | PCK_ARCWeak, |
1125 | |
1126 | /// The type is a struct containing a field whose type is neither |
1127 | /// PCK_Trivial nor PCK_VolatileTrivial. |
1128 | /// Note that a C++ struct type does not necessarily match this; C++ copying |
1129 | /// semantics are too complex to express here, in part because they depend |
1130 | /// on the exact constructor or assignment operator that is chosen by |
1131 | /// overload resolution to do the copy. |
1132 | PCK_Struct |
1133 | }; |
1134 | |
1135 | /// Check if this is a non-trivial type that would cause a C struct |
1136 | /// transitively containing this type to be non-trivial to copy and return the |
1137 | /// kind. |
1138 | PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const; |
1139 | |
1140 | /// Check if this is a non-trivial type that would cause a C struct |
1141 | /// transitively containing this type to be non-trivial to destructively |
1142 | /// move and return the kind. Destructive move in this context is a C++-style |
1143 | /// move in which the source object is placed in a valid but unspecified state |
1144 | /// after it is moved, as opposed to a truly destructive move in which the |
1145 | /// source object is placed in an uninitialized state. |
1146 | PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const; |
1147 | |
1148 | enum DestructionKind { |
1149 | DK_none, |
1150 | DK_cxx_destructor, |
1151 | DK_objc_strong_lifetime, |
1152 | DK_objc_weak_lifetime, |
1153 | DK_nontrivial_c_struct |
1154 | }; |
1155 | |
1156 | /// Returns a nonzero value if objects of this type require |
1157 | /// non-trivial work to clean up after. Non-zero because it's |
1158 | /// conceivable that qualifiers (objc_gc(weak)?) could make |
1159 | /// something require destruction. |
1160 | DestructionKind isDestructedType() const { |
1161 | return isDestructedTypeImpl(*this); |
1162 | } |
1163 | |
1164 | /// Check if this is or contains a C union that is non-trivial to |
1165 | /// default-initialize, which is a union that has a member that is non-trivial |
1166 | /// to default-initialize. If this returns true, |
1167 | /// isNonTrivialToPrimitiveDefaultInitialize returns PDIK_Struct. |
1168 | bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const; |
1169 | |
1170 | /// Check if this is or contains a C union that is non-trivial to destruct, |
1171 | /// which is a union that has a member that is non-trivial to destruct. If |
1172 | /// this returns true, isDestructedType returns DK_nontrivial_c_struct. |
1173 | bool hasNonTrivialToPrimitiveDestructCUnion() const; |
1174 | |
1175 | /// Check if this is or contains a C union that is non-trivial to copy, which |
1176 | /// is a union that has a member that is non-trivial to copy. If this returns |
1177 | /// true, isNonTrivialToPrimitiveCopy returns PCK_Struct. |
1178 | bool hasNonTrivialToPrimitiveCopyCUnion() const; |
1179 | |
1180 | /// Determine whether expressions of the given type are forbidden |
1181 | /// from being lvalues in C. |
1182 | /// |
1183 | /// The expression types that are forbidden to be lvalues are: |
1184 | /// - 'void', but not qualified void |
1185 | /// - function types |
1186 | /// |
1187 | /// The exact rule here is C99 6.3.2.1: |
1188 | /// An lvalue is an expression with an object type or an incomplete |
1189 | /// type other than void. |
1190 | bool isCForbiddenLValueType() const; |
1191 | |
1192 | /// Substitute type arguments for the Objective-C type parameters used in the |
1193 | /// subject type. |
1194 | /// |
1195 | /// \param ctx ASTContext in which the type exists. |
1196 | /// |
1197 | /// \param typeArgs The type arguments that will be substituted for the |
1198 | /// Objective-C type parameters in the subject type, which are generally |
1199 | /// computed via \c Type::getObjCSubstitutions. If empty, the type |
1200 | /// parameters will be replaced with their bounds or id/Class, as appropriate |
1201 | /// for the context. |
1202 | /// |
1203 | /// \param context The context in which the subject type was written. |
1204 | /// |
1205 | /// \returns the resulting type. |
1206 | QualType substObjCTypeArgs(ASTContext &ctx, |
1207 | ArrayRef<QualType> typeArgs, |
1208 | ObjCSubstitutionContext context) const; |
1209 | |
1210 | /// Substitute type arguments from an object type for the Objective-C type |
1211 | /// parameters used in the subject type. |
1212 | /// |
1213 | /// This operation combines the computation of type arguments for |
1214 | /// substitution (\c Type::getObjCSubstitutions) with the actual process of |
1215 | /// substitution (\c QualType::substObjCTypeArgs) for the convenience of |
1216 | /// callers that need to perform a single substitution in isolation. |
1217 | /// |
1218 | /// \param objectType The type of the object whose member type we're |
1219 | /// substituting into. For example, this might be the receiver of a message |
1220 | /// or the base of a property access. |
1221 | /// |
1222 | /// \param dc The declaration context from which the subject type was |
1223 | /// retrieved, which indicates (for example) which type parameters should |
1224 | /// be substituted. |
1225 | /// |
1226 | /// \param context The context in which the subject type was written. |
1227 | /// |
1228 | /// \returns the subject type after replacing all of the Objective-C type |
1229 | /// parameters with their corresponding arguments. |
1230 | QualType substObjCMemberType(QualType objectType, |
1231 | const DeclContext *dc, |
1232 | ObjCSubstitutionContext context) const; |
1233 | |
1234 | /// Strip Objective-C "__kindof" types from the given type. |
1235 | QualType stripObjCKindOfType(const ASTContext &ctx) const; |
1236 | |
1237 | /// Remove all qualifiers including _Atomic. |
1238 | QualType getAtomicUnqualifiedType() const; |
1239 | |
1240 | private: |
1241 | // These methods are implemented in a separate translation unit; |
1242 | // "static"-ize them to avoid creating temporary QualTypes in the |
1243 | // caller. |
1244 | static bool isConstant(QualType T, const ASTContext& Ctx); |
1245 | static QualType getDesugaredType(QualType T, const ASTContext &Context); |
1246 | static SplitQualType getSplitDesugaredType(QualType T); |
1247 | static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); |
1248 | static QualType getSingleStepDesugaredTypeImpl(QualType type, |
1249 | const ASTContext &C); |
1250 | static QualType IgnoreParens(QualType T); |
1251 | static DestructionKind isDestructedTypeImpl(QualType type); |
1252 | |
1253 | /// Check if \param RD is or contains a non-trivial C union. |
1254 | static bool hasNonTrivialToPrimitiveDefaultInitializeCUnion(const RecordDecl *RD); |
1255 | static bool hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD); |
1256 | static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD); |
1257 | }; |
1258 | |
1259 | } // namespace clang |
1260 | |
1261 | namespace llvm { |
1262 | |
1263 | /// Implement simplify_type for QualType, so that we can dyn_cast from QualType |
1264 | /// to a specific Type class. |
1265 | template<> struct simplify_type< ::clang::QualType> { |
1266 | using SimpleType = const ::clang::Type *; |
1267 | |
1268 | static SimpleType getSimplifiedValue(::clang::QualType Val) { |
1269 | return Val.getTypePtr(); |
1270 | } |
1271 | }; |
1272 | |
1273 | // Teach SmallPtrSet that QualType is "basically a pointer". |
1274 | template<> |
1275 | struct PointerLikeTypeTraits<clang::QualType> { |
1276 | static inline void *getAsVoidPointer(clang::QualType P) { |
1277 | return P.getAsOpaquePtr(); |
1278 | } |
1279 | |
1280 | static inline clang::QualType getFromVoidPointer(void *P) { |
1281 | return clang::QualType::getFromOpaquePtr(P); |
1282 | } |
1283 | |
1284 | // Various qualifiers go in low bits. |
1285 | enum { NumLowBitsAvailable = 0 }; |
1286 | }; |
1287 | |
1288 | } // namespace llvm |
1289 | |
1290 | namespace clang { |
1291 | |
1292 | /// Base class that is common to both the \c ExtQuals and \c Type |
1293 | /// classes, which allows \c QualType to access the common fields between the |
1294 | /// two. |
1295 | class ExtQualsTypeCommonBase { |
1296 | friend class ExtQuals; |
1297 | friend class QualType; |
1298 | friend class Type; |
1299 | |
1300 | /// The "base" type of an extended qualifiers type (\c ExtQuals) or |
1301 | /// a self-referential pointer (for \c Type). |
1302 | /// |
1303 | /// This pointer allows an efficient mapping from a QualType to its |
1304 | /// underlying type pointer. |
1305 | const Type *const BaseType; |
1306 | |
1307 | /// The canonical type of this type. A QualType. |
1308 | QualType CanonicalType; |
1309 | |
1310 | ExtQualsTypeCommonBase(const Type *baseType, QualType canon) |
1311 | : BaseType(baseType), CanonicalType(canon) {} |
1312 | }; |
1313 | |
1314 | /// We can encode up to four bits in the low bits of a |
1315 | /// type pointer, but there are many more type qualifiers that we want |
1316 | /// to be able to apply to an arbitrary type. Therefore we have this |
1317 | /// struct, intended to be heap-allocated and used by QualType to |
1318 | /// store qualifiers. |
1319 | /// |
1320 | /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers |
1321 | /// in three low bits on the QualType pointer; a fourth bit records whether |
1322 | /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, |
1323 | /// Objective-C GC attributes) are much more rare. |
1324 | class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { |
1325 | // NOTE: changing the fast qualifiers should be straightforward as |
1326 | // long as you don't make 'const' non-fast. |
1327 | // 1. Qualifiers: |
1328 | // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). |
1329 | // Fast qualifiers must occupy the low-order bits. |
1330 | // b) Update Qualifiers::FastWidth and FastMask. |
1331 | // 2. QualType: |
1332 | // a) Update is{Volatile,Restrict}Qualified(), defined inline. |
1333 | // b) Update remove{Volatile,Restrict}, defined near the end of |
1334 | // this header. |
1335 | // 3. ASTContext: |
1336 | // a) Update get{Volatile,Restrict}Type. |
1337 | |
1338 | /// The immutable set of qualifiers applied by this node. Always contains |
1339 | /// extended qualifiers. |
1340 | Qualifiers Quals; |
1341 | |
1342 | ExtQuals *this_() { return this; } |
1343 | |
1344 | public: |
1345 | ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) |
1346 | : ExtQualsTypeCommonBase(baseType, |
1347 | canon.isNull() ? QualType(this_(), 0) : canon), |
1348 | Quals(quals) { |
1349 | assert(Quals.hasNonFastQualifiers()((Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers" ) ? static_cast<void> (0) : __assert_fail ("Quals.hasNonFastQualifiers() && \"ExtQuals created with no fast qualifiers\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1350, __PRETTY_FUNCTION__)) |
1350 | && "ExtQuals created with no fast qualifiers")((Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers" ) ? static_cast<void> (0) : __assert_fail ("Quals.hasNonFastQualifiers() && \"ExtQuals created with no fast qualifiers\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1350, __PRETTY_FUNCTION__)); |
1351 | assert(!Quals.hasFastQualifiers()((!Quals.hasFastQualifiers() && "ExtQuals created with fast qualifiers" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasFastQualifiers() && \"ExtQuals created with fast qualifiers\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1352, __PRETTY_FUNCTION__)) |
1352 | && "ExtQuals created with fast qualifiers")((!Quals.hasFastQualifiers() && "ExtQuals created with fast qualifiers" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasFastQualifiers() && \"ExtQuals created with fast qualifiers\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1352, __PRETTY_FUNCTION__)); |
1353 | } |
1354 | |
1355 | Qualifiers getQualifiers() const { return Quals; } |
1356 | |
1357 | bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } |
1358 | Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } |
1359 | |
1360 | bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); } |
1361 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
1362 | return Quals.getObjCLifetime(); |
1363 | } |
1364 | |
1365 | bool hasAddressSpace() const { return Quals.hasAddressSpace(); } |
1366 | LangAS getAddressSpace() const { return Quals.getAddressSpace(); } |
1367 | |
1368 | const Type *getBaseType() const { return BaseType; } |
1369 | |
1370 | public: |
1371 | void Profile(llvm::FoldingSetNodeID &ID) const { |
1372 | Profile(ID, getBaseType(), Quals); |
1373 | } |
1374 | |
1375 | static void Profile(llvm::FoldingSetNodeID &ID, |
1376 | const Type *BaseType, |
1377 | Qualifiers Quals) { |
1378 | assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!")((!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasFastQualifiers() && \"fast qualifiers in ExtQuals hash!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1378, __PRETTY_FUNCTION__)); |
1379 | ID.AddPointer(BaseType); |
1380 | Quals.Profile(ID); |
1381 | } |
1382 | }; |
1383 | |
1384 | /// The kind of C++11 ref-qualifier associated with a function type. |
1385 | /// This determines whether a member function's "this" object can be an |
1386 | /// lvalue, rvalue, or neither. |
1387 | enum RefQualifierKind { |
1388 | /// No ref-qualifier was provided. |
1389 | RQ_None = 0, |
1390 | |
1391 | /// An lvalue ref-qualifier was provided (\c &). |
1392 | RQ_LValue, |
1393 | |
1394 | /// An rvalue ref-qualifier was provided (\c &&). |
1395 | RQ_RValue |
1396 | }; |
1397 | |
1398 | /// Which keyword(s) were used to create an AutoType. |
1399 | enum class AutoTypeKeyword { |
1400 | /// auto |
1401 | Auto, |
1402 | |
1403 | /// decltype(auto) |
1404 | DecltypeAuto, |
1405 | |
1406 | /// __auto_type (GNU extension) |
1407 | GNUAutoType |
1408 | }; |
1409 | |
1410 | /// The base class of the type hierarchy. |
1411 | /// |
1412 | /// A central concept with types is that each type always has a canonical |
1413 | /// type. A canonical type is the type with any typedef names stripped out |
1414 | /// of it or the types it references. For example, consider: |
1415 | /// |
1416 | /// typedef int foo; |
1417 | /// typedef foo* bar; |
1418 | /// 'int *' 'foo *' 'bar' |
1419 | /// |
1420 | /// There will be a Type object created for 'int'. Since int is canonical, its |
1421 | /// CanonicalType pointer points to itself. There is also a Type for 'foo' (a |
1422 | /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next |
1423 | /// there is a PointerType that represents 'int*', which, like 'int', is |
1424 | /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical |
1425 | /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type |
1426 | /// is also 'int*'. |
1427 | /// |
1428 | /// Non-canonical types are useful for emitting diagnostics, without losing |
1429 | /// information about typedefs being used. Canonical types are useful for type |
1430 | /// comparisons (they allow by-pointer equality tests) and useful for reasoning |
1431 | /// about whether something has a particular form (e.g. is a function type), |
1432 | /// because they implicitly, recursively, strip all typedefs out of a type. |
1433 | /// |
1434 | /// Types, once created, are immutable. |
1435 | /// |
1436 | class alignas(8) Type : public ExtQualsTypeCommonBase { |
1437 | public: |
1438 | enum TypeClass { |
1439 | #define TYPE(Class, Base) Class, |
1440 | #define LAST_TYPE(Class) TypeLast = Class |
1441 | #define ABSTRACT_TYPE(Class, Base) |
1442 | #include "clang/AST/TypeNodes.inc" |
1443 | }; |
1444 | |
1445 | private: |
1446 | /// Bitfields required by the Type class. |
1447 | class TypeBitfields { |
1448 | friend class Type; |
1449 | template <class T> friend class TypePropertyCache; |
1450 | |
1451 | /// TypeClass bitfield - Enum that specifies what subclass this belongs to. |
1452 | unsigned TC : 8; |
1453 | |
1454 | /// Whether this type is a dependent type (C++ [temp.dep.type]). |
1455 | unsigned Dependent : 1; |
1456 | |
1457 | /// Whether this type somehow involves a template parameter, even |
1458 | /// if the resolution of the type does not depend on a template parameter. |
1459 | unsigned InstantiationDependent : 1; |
1460 | |
1461 | /// Whether this type is a variably-modified type (C99 6.7.5). |
1462 | unsigned VariablyModified : 1; |
1463 | |
1464 | /// Whether this type contains an unexpanded parameter pack |
1465 | /// (for C++11 variadic templates). |
1466 | unsigned ContainsUnexpandedParameterPack : 1; |
1467 | |
1468 | /// True if the cache (i.e. the bitfields here starting with |
1469 | /// 'Cache') is valid. |
1470 | mutable unsigned CacheValid : 1; |
1471 | |
1472 | /// Linkage of this type. |
1473 | mutable unsigned CachedLinkage : 3; |
1474 | |
1475 | /// Whether this type involves and local or unnamed types. |
1476 | mutable unsigned CachedLocalOrUnnamed : 1; |
1477 | |
1478 | /// Whether this type comes from an AST file. |
1479 | mutable unsigned FromAST : 1; |
1480 | |
1481 | bool isCacheValid() const { |
1482 | return CacheValid; |
1483 | } |
1484 | |
1485 | Linkage getLinkage() const { |
1486 | assert(isCacheValid() && "getting linkage from invalid cache")((isCacheValid() && "getting linkage from invalid cache" ) ? static_cast<void> (0) : __assert_fail ("isCacheValid() && \"getting linkage from invalid cache\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1486, __PRETTY_FUNCTION__)); |
1487 | return static_cast<Linkage>(CachedLinkage); |
1488 | } |
1489 | |
1490 | bool hasLocalOrUnnamedType() const { |
1491 | assert(isCacheValid() && "getting linkage from invalid cache")((isCacheValid() && "getting linkage from invalid cache" ) ? static_cast<void> (0) : __assert_fail ("isCacheValid() && \"getting linkage from invalid cache\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 1491, __PRETTY_FUNCTION__)); |
1492 | return CachedLocalOrUnnamed; |
1493 | } |
1494 | }; |
1495 | enum { NumTypeBits = 18 }; |
1496 | |
1497 | protected: |
1498 | // These classes allow subclasses to somewhat cleanly pack bitfields |
1499 | // into Type. |
1500 | |
1501 | class ArrayTypeBitfields { |
1502 | friend class ArrayType; |
1503 | |
1504 | unsigned : NumTypeBits; |
1505 | |
1506 | /// CVR qualifiers from declarations like |
1507 | /// 'int X[static restrict 4]'. For function parameters only. |
1508 | unsigned IndexTypeQuals : 3; |
1509 | |
1510 | /// Storage class qualifiers from declarations like |
1511 | /// 'int X[static restrict 4]'. For function parameters only. |
1512 | /// Actually an ArrayType::ArraySizeModifier. |
1513 | unsigned SizeModifier : 3; |
1514 | }; |
1515 | |
1516 | class BuiltinTypeBitfields { |
1517 | friend class BuiltinType; |
1518 | |
1519 | unsigned : NumTypeBits; |
1520 | |
1521 | /// The kind (BuiltinType::Kind) of builtin type this is. |
1522 | unsigned Kind : 8; |
1523 | }; |
1524 | |
1525 | /// FunctionTypeBitfields store various bits belonging to FunctionProtoType. |
1526 | /// Only common bits are stored here. Additional uncommon bits are stored |
1527 | /// in a trailing object after FunctionProtoType. |
1528 | class FunctionTypeBitfields { |
1529 | friend class FunctionProtoType; |
1530 | friend class FunctionType; |
1531 | |
1532 | unsigned : NumTypeBits; |
1533 | |
1534 | /// Extra information which affects how the function is called, like |
1535 | /// regparm and the calling convention. |
1536 | unsigned ExtInfo : 12; |
1537 | |
1538 | /// The ref-qualifier associated with a \c FunctionProtoType. |
1539 | /// |
1540 | /// This is a value of type \c RefQualifierKind. |
1541 | unsigned RefQualifier : 2; |
1542 | |
1543 | /// Used only by FunctionProtoType, put here to pack with the |
1544 | /// other bitfields. |
1545 | /// The qualifiers are part of FunctionProtoType because... |
1546 | /// |
1547 | /// C++ 8.3.5p4: The return type, the parameter type list and the |
1548 | /// cv-qualifier-seq, [...], are part of the function type. |
1549 | unsigned FastTypeQuals : Qualifiers::FastWidth; |
1550 | /// Whether this function has extended Qualifiers. |
1551 | unsigned HasExtQuals : 1; |
1552 | |
1553 | /// The number of parameters this function has, not counting '...'. |
1554 | /// According to [implimits] 8 bits should be enough here but this is |
1555 | /// somewhat easy to exceed with metaprogramming and so we would like to |
1556 | /// keep NumParams as wide as reasonably possible. |
1557 | unsigned NumParams : 16; |
1558 | |
1559 | /// The type of exception specification this function has. |
1560 | unsigned ExceptionSpecType : 4; |
1561 | |
1562 | /// Whether this function has extended parameter information. |
1563 | unsigned HasExtParameterInfos : 1; |
1564 | |
1565 | /// Whether the function is variadic. |
1566 | unsigned Variadic : 1; |
1567 | |
1568 | /// Whether this function has a trailing return type. |
1569 | unsigned HasTrailingReturn : 1; |
1570 | }; |
1571 | |
1572 | class ObjCObjectTypeBitfields { |
1573 | friend class ObjCObjectType; |
1574 | |
1575 | unsigned : NumTypeBits; |
1576 | |
1577 | /// The number of type arguments stored directly on this object type. |
1578 | unsigned NumTypeArgs : 7; |
1579 | |
1580 | /// The number of protocols stored directly on this object type. |
1581 | unsigned NumProtocols : 6; |
1582 | |
1583 | /// Whether this is a "kindof" type. |
1584 | unsigned IsKindOf : 1; |
1585 | }; |
1586 | |
1587 | class ReferenceTypeBitfields { |
1588 | friend class ReferenceType; |
1589 | |
1590 | unsigned : NumTypeBits; |
1591 | |
1592 | /// True if the type was originally spelled with an lvalue sigil. |
1593 | /// This is never true of rvalue references but can also be false |
1594 | /// on lvalue references because of C++0x [dcl.typedef]p9, |
1595 | /// as follows: |
1596 | /// |
1597 | /// typedef int &ref; // lvalue, spelled lvalue |
1598 | /// typedef int &&rvref; // rvalue |
1599 | /// ref &a; // lvalue, inner ref, spelled lvalue |
1600 | /// ref &&a; // lvalue, inner ref |
1601 | /// rvref &a; // lvalue, inner ref, spelled lvalue |
1602 | /// rvref &&a; // rvalue, inner ref |
1603 | unsigned SpelledAsLValue : 1; |
1604 | |
1605 | /// True if the inner type is a reference type. This only happens |
1606 | /// in non-canonical forms. |
1607 | unsigned InnerRef : 1; |
1608 | }; |
1609 | |
1610 | class TypeWithKeywordBitfields { |
1611 | friend class TypeWithKeyword; |
1612 | |
1613 | unsigned : NumTypeBits; |
1614 | |
1615 | /// An ElaboratedTypeKeyword. 8 bits for efficient access. |
1616 | unsigned Keyword : 8; |
1617 | }; |
1618 | |
1619 | enum { NumTypeWithKeywordBits = 8 }; |
1620 | |
1621 | class ElaboratedTypeBitfields { |
1622 | friend class ElaboratedType; |
1623 | |
1624 | unsigned : NumTypeBits; |
1625 | unsigned : NumTypeWithKeywordBits; |
1626 | |
1627 | /// Whether the ElaboratedType has a trailing OwnedTagDecl. |
1628 | unsigned HasOwnedTagDecl : 1; |
1629 | }; |
1630 | |
1631 | class VectorTypeBitfields { |
1632 | friend class VectorType; |
1633 | friend class DependentVectorType; |
1634 | |
1635 | unsigned : NumTypeBits; |
1636 | |
1637 | /// The kind of vector, either a generic vector type or some |
1638 | /// target-specific vector type such as for AltiVec or Neon. |
1639 | unsigned VecKind : 3; |
1640 | |
1641 | /// The number of elements in the vector. |
1642 | unsigned NumElements : 29 - NumTypeBits; |
1643 | |
1644 | enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 }; |
1645 | }; |
1646 | |
1647 | class AttributedTypeBitfields { |
1648 | friend class AttributedType; |
1649 | |
1650 | unsigned : NumTypeBits; |
1651 | |
1652 | /// An AttributedType::Kind |
1653 | unsigned AttrKind : 32 - NumTypeBits; |
1654 | }; |
1655 | |
1656 | class AutoTypeBitfields { |
1657 | friend class AutoType; |
1658 | |
1659 | unsigned : NumTypeBits; |
1660 | |
1661 | /// Was this placeholder type spelled as 'auto', 'decltype(auto)', |
1662 | /// or '__auto_type'? AutoTypeKeyword value. |
1663 | unsigned Keyword : 2; |
1664 | }; |
1665 | |
1666 | class SubstTemplateTypeParmPackTypeBitfields { |
1667 | friend class SubstTemplateTypeParmPackType; |
1668 | |
1669 | unsigned : NumTypeBits; |
1670 | |
1671 | /// The number of template arguments in \c Arguments, which is |
1672 | /// expected to be able to hold at least 1024 according to [implimits]. |
1673 | /// However as this limit is somewhat easy to hit with template |
1674 | /// metaprogramming we'd prefer to keep it as large as possible. |
1675 | /// At the moment it has been left as a non-bitfield since this type |
1676 | /// safely fits in 64 bits as an unsigned, so there is no reason to |
1677 | /// introduce the performance impact of a bitfield. |
1678 | unsigned NumArgs; |
1679 | }; |
1680 | |
1681 | class TemplateSpecializationTypeBitfields { |
1682 | friend class TemplateSpecializationType; |
1683 | |
1684 | unsigned : NumTypeBits; |
1685 | |
1686 | /// Whether this template specialization type is a substituted type alias. |
1687 | unsigned TypeAlias : 1; |
1688 | |
1689 | /// The number of template arguments named in this class template |
1690 | /// specialization, which is expected to be able to hold at least 1024 |
1691 | /// according to [implimits]. However, as this limit is somewhat easy to |
1692 | /// hit with template metaprogramming we'd prefer to keep it as large |
1693 | /// as possible. At the moment it has been left as a non-bitfield since |
1694 | /// this type safely fits in 64 bits as an unsigned, so there is no reason |
1695 | /// to introduce the performance impact of a bitfield. |
1696 | unsigned NumArgs; |
1697 | }; |
1698 | |
1699 | class DependentTemplateSpecializationTypeBitfields { |
1700 | friend class DependentTemplateSpecializationType; |
1701 | |
1702 | unsigned : NumTypeBits; |
1703 | unsigned : NumTypeWithKeywordBits; |
1704 | |
1705 | /// The number of template arguments named in this class template |
1706 | /// specialization, which is expected to be able to hold at least 1024 |
1707 | /// according to [implimits]. However, as this limit is somewhat easy to |
1708 | /// hit with template metaprogramming we'd prefer to keep it as large |
1709 | /// as possible. At the moment it has been left as a non-bitfield since |
1710 | /// this type safely fits in 64 bits as an unsigned, so there is no reason |
1711 | /// to introduce the performance impact of a bitfield. |
1712 | unsigned NumArgs; |
1713 | }; |
1714 | |
1715 | class PackExpansionTypeBitfields { |
1716 | friend class PackExpansionType; |
1717 | |
1718 | unsigned : NumTypeBits; |
1719 | |
1720 | /// The number of expansions that this pack expansion will |
1721 | /// generate when substituted (+1), which is expected to be able to |
1722 | /// hold at least 1024 according to [implimits]. However, as this limit |
1723 | /// is somewhat easy to hit with template metaprogramming we'd prefer to |
1724 | /// keep it as large as possible. At the moment it has been left as a |
1725 | /// non-bitfield since this type safely fits in 64 bits as an unsigned, so |
1726 | /// there is no reason to introduce the performance impact of a bitfield. |
1727 | /// |
1728 | /// This field will only have a non-zero value when some of the parameter |
1729 | /// packs that occur within the pattern have been substituted but others |
1730 | /// have not. |
1731 | unsigned NumExpansions; |
1732 | }; |
1733 | |
1734 | union { |
1735 | TypeBitfields TypeBits; |
1736 | ArrayTypeBitfields ArrayTypeBits; |
1737 | AttributedTypeBitfields AttributedTypeBits; |
1738 | AutoTypeBitfields AutoTypeBits; |
1739 | BuiltinTypeBitfields BuiltinTypeBits; |
1740 | FunctionTypeBitfields FunctionTypeBits; |
1741 | ObjCObjectTypeBitfields ObjCObjectTypeBits; |
1742 | ReferenceTypeBitfields ReferenceTypeBits; |
1743 | TypeWithKeywordBitfields TypeWithKeywordBits; |
1744 | ElaboratedTypeBitfields ElaboratedTypeBits; |
1745 | VectorTypeBitfields VectorTypeBits; |
1746 | SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits; |
1747 | TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits; |
1748 | DependentTemplateSpecializationTypeBitfields |
1749 | DependentTemplateSpecializationTypeBits; |
1750 | PackExpansionTypeBitfields PackExpansionTypeBits; |
1751 | |
1752 | static_assert(sizeof(TypeBitfields) <= 8, |
1753 | "TypeBitfields is larger than 8 bytes!"); |
1754 | static_assert(sizeof(ArrayTypeBitfields) <= 8, |
1755 | "ArrayTypeBitfields is larger than 8 bytes!"); |
1756 | static_assert(sizeof(AttributedTypeBitfields) <= 8, |
1757 | "AttributedTypeBitfields is larger than 8 bytes!"); |
1758 | static_assert(sizeof(AutoTypeBitfields) <= 8, |
1759 | "AutoTypeBitfields is larger than 8 bytes!"); |
1760 | static_assert(sizeof(BuiltinTypeBitfields) <= 8, |
1761 | "BuiltinTypeBitfields is larger than 8 bytes!"); |
1762 | static_assert(sizeof(FunctionTypeBitfields) <= 8, |
1763 | "FunctionTypeBitfields is larger than 8 bytes!"); |
1764 | static_assert(sizeof(ObjCObjectTypeBitfields) <= 8, |
1765 | "ObjCObjectTypeBitfields is larger than 8 bytes!"); |
1766 | static_assert(sizeof(ReferenceTypeBitfields) <= 8, |
1767 | "ReferenceTypeBitfields is larger than 8 bytes!"); |
1768 | static_assert(sizeof(TypeWithKeywordBitfields) <= 8, |
1769 | "TypeWithKeywordBitfields is larger than 8 bytes!"); |
1770 | static_assert(sizeof(ElaboratedTypeBitfields) <= 8, |
1771 | "ElaboratedTypeBitfields is larger than 8 bytes!"); |
1772 | static_assert(sizeof(VectorTypeBitfields) <= 8, |
1773 | "VectorTypeBitfields is larger than 8 bytes!"); |
1774 | static_assert(sizeof(SubstTemplateTypeParmPackTypeBitfields) <= 8, |
1775 | "SubstTemplateTypeParmPackTypeBitfields is larger" |
1776 | " than 8 bytes!"); |
1777 | static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8, |
1778 | "TemplateSpecializationTypeBitfields is larger" |
1779 | " than 8 bytes!"); |
1780 | static_assert(sizeof(DependentTemplateSpecializationTypeBitfields) <= 8, |
1781 | "DependentTemplateSpecializationTypeBitfields is larger" |
1782 | " than 8 bytes!"); |
1783 | static_assert(sizeof(PackExpansionTypeBitfields) <= 8, |
1784 | "PackExpansionTypeBitfields is larger than 8 bytes"); |
1785 | }; |
1786 | |
1787 | private: |
1788 | template <class T> friend class TypePropertyCache; |
1789 | |
1790 | /// Set whether this type comes from an AST file. |
1791 | void setFromAST(bool V = true) const { |
1792 | TypeBits.FromAST = V; |
1793 | } |
1794 | |
1795 | protected: |
1796 | friend class ASTContext; |
1797 | |
1798 | Type(TypeClass tc, QualType canon, bool Dependent, |
1799 | bool InstantiationDependent, bool VariablyModified, |
1800 | bool ContainsUnexpandedParameterPack) |
1801 | : ExtQualsTypeCommonBase(this, |
1802 | canon.isNull() ? QualType(this_(), 0) : canon) { |
1803 | TypeBits.TC = tc; |
1804 | TypeBits.Dependent = Dependent; |
1805 | TypeBits.InstantiationDependent = Dependent || InstantiationDependent; |
1806 | TypeBits.VariablyModified = VariablyModified; |
1807 | TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
1808 | TypeBits.CacheValid = false; |
1809 | TypeBits.CachedLocalOrUnnamed = false; |
1810 | TypeBits.CachedLinkage = NoLinkage; |
1811 | TypeBits.FromAST = false; |
1812 | } |
1813 | |
1814 | // silence VC++ warning C4355: 'this' : used in base member initializer list |
1815 | Type *this_() { return this; } |
1816 | |
1817 | void setDependent(bool D = true) { |
1818 | TypeBits.Dependent = D; |
1819 | if (D) |
1820 | TypeBits.InstantiationDependent = true; |
1821 | } |
1822 | |
1823 | void setInstantiationDependent(bool D = true) { |
1824 | TypeBits.InstantiationDependent = D; } |
1825 | |
1826 | void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; } |
1827 | |
1828 | void setContainsUnexpandedParameterPack(bool PP = true) { |
1829 | TypeBits.ContainsUnexpandedParameterPack = PP; |
1830 | } |
1831 | |
1832 | public: |
1833 | friend class ASTReader; |
1834 | friend class ASTWriter; |
1835 | |
1836 | Type(const Type &) = delete; |
1837 | Type(Type &&) = delete; |
1838 | Type &operator=(const Type &) = delete; |
1839 | Type &operator=(Type &&) = delete; |
1840 | |
1841 | TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } |
1842 | |
1843 | /// Whether this type comes from an AST file. |
1844 | bool isFromAST() const { return TypeBits.FromAST; } |
1845 | |
1846 | /// Whether this type is or contains an unexpanded parameter |
1847 | /// pack, used to support C++0x variadic templates. |
1848 | /// |
1849 | /// A type that contains a parameter pack shall be expanded by the |
1850 | /// ellipsis operator at some point. For example, the typedef in the |
1851 | /// following example contains an unexpanded parameter pack 'T': |
1852 | /// |
1853 | /// \code |
1854 | /// template<typename ...T> |
1855 | /// struct X { |
1856 | /// typedef T* pointer_types; // ill-formed; T is a parameter pack. |
1857 | /// }; |
1858 | /// \endcode |
1859 | /// |
1860 | /// Note that this routine does not specify which |
1861 | bool containsUnexpandedParameterPack() const { |
1862 | return TypeBits.ContainsUnexpandedParameterPack; |
1863 | } |
1864 | |
1865 | /// Determines if this type would be canonical if it had no further |
1866 | /// qualification. |
1867 | bool isCanonicalUnqualified() const { |
1868 | return CanonicalType == QualType(this, 0); |
1869 | } |
1870 | |
1871 | /// Pull a single level of sugar off of this locally-unqualified type. |
1872 | /// Users should generally prefer SplitQualType::getSingleStepDesugaredType() |
1873 | /// or QualType::getSingleStepDesugaredType(const ASTContext&). |
1874 | QualType getLocallyUnqualifiedSingleStepDesugaredType() const; |
1875 | |
1876 | /// Types are partitioned into 3 broad categories (C99 6.2.5p1): |
1877 | /// object types, function types, and incomplete types. |
1878 | |
1879 | /// Return true if this is an incomplete type. |
1880 | /// A type that can describe objects, but which lacks information needed to |
1881 | /// determine its size (e.g. void, or a fwd declared struct). Clients of this |
1882 | /// routine will need to determine if the size is actually required. |
1883 | /// |
1884 | /// Def If non-null, and the type refers to some kind of declaration |
1885 | /// that can be completed (such as a C struct, C++ class, or Objective-C |
1886 | /// class), will be set to the declaration. |
1887 | bool isIncompleteType(NamedDecl **Def = nullptr) const; |
1888 | |
1889 | /// Return true if this is an incomplete or object |
1890 | /// type, in other words, not a function type. |
1891 | bool isIncompleteOrObjectType() const { |
1892 | return !isFunctionType(); |
1893 | } |
1894 | |
1895 | /// Determine whether this type is an object type. |
1896 | bool isObjectType() const { |
1897 | // C++ [basic.types]p8: |
1898 | // An object type is a (possibly cv-qualified) type that is not a |
1899 | // function type, not a reference type, and not a void type. |
1900 | return !isReferenceType() && !isFunctionType() && !isVoidType(); |
1901 | } |
1902 | |
1903 | /// Return true if this is a literal type |
1904 | /// (C++11 [basic.types]p10) |
1905 | bool isLiteralType(const ASTContext &Ctx) const; |
1906 | |
1907 | /// Test if this type is a standard-layout type. |
1908 | /// (C++0x [basic.type]p9) |
1909 | bool isStandardLayoutType() const; |
1910 | |
1911 | /// Helper methods to distinguish type categories. All type predicates |
1912 | /// operate on the canonical type, ignoring typedefs and qualifiers. |
1913 | |
1914 | /// Returns true if the type is a builtin type. |
1915 | bool isBuiltinType() const; |
1916 | |
1917 | /// Test for a particular builtin type. |
1918 | bool isSpecificBuiltinType(unsigned K) const; |
1919 | |
1920 | /// Test for a type which does not represent an actual type-system type but |
1921 | /// is instead used as a placeholder for various convenient purposes within |
1922 | /// Clang. All such types are BuiltinTypes. |
1923 | bool isPlaceholderType() const; |
1924 | const BuiltinType *getAsPlaceholderType() const; |
1925 | |
1926 | /// Test for a specific placeholder type. |
1927 | bool isSpecificPlaceholderType(unsigned K) const; |
1928 | |
1929 | /// Test for a placeholder type other than Overload; see |
1930 | /// BuiltinType::isNonOverloadPlaceholderType. |
1931 | bool isNonOverloadPlaceholderType() const; |
1932 | |
1933 | /// isIntegerType() does *not* include complex integers (a GCC extension). |
1934 | /// isComplexIntegerType() can be used to test for complex integers. |
1935 | bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) |
1936 | bool isEnumeralType() const; |
1937 | |
1938 | /// Determine whether this type is a scoped enumeration type. |
1939 | bool isScopedEnumeralType() const; |
1940 | bool isBooleanType() const; |
1941 | bool isCharType() const; |
1942 | bool isWideCharType() const; |
1943 | bool isChar8Type() const; |
1944 | bool isChar16Type() const; |
1945 | bool isChar32Type() const; |
1946 | bool isAnyCharacterType() const; |
1947 | bool isIntegralType(const ASTContext &Ctx) const; |
1948 | |
1949 | /// Determine whether this type is an integral or enumeration type. |
1950 | bool isIntegralOrEnumerationType() const; |
1951 | |
1952 | /// Determine whether this type is an integral or unscoped enumeration type. |
1953 | bool isIntegralOrUnscopedEnumerationType() const; |
1954 | |
1955 | /// Floating point categories. |
1956 | bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) |
1957 | /// isComplexType() does *not* include complex integers (a GCC extension). |
1958 | /// isComplexIntegerType() can be used to test for complex integers. |
1959 | bool isComplexType() const; // C99 6.2.5p11 (complex) |
1960 | bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. |
1961 | bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) |
1962 | bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half) |
1963 | bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661 |
1964 | bool isFloat128Type() const; |
1965 | bool isRealType() const; // C99 6.2.5p17 (real floating + integer) |
1966 | bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) |
1967 | bool isVoidType() const; // C99 6.2.5p19 |
1968 | bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) |
1969 | bool isAggregateType() const; |
1970 | bool isFundamentalType() const; |
1971 | bool isCompoundType() const; |
1972 | |
1973 | // Type Predicates: Check to see if this type is structurally the specified |
1974 | // type, ignoring typedefs and qualifiers. |
1975 | bool isFunctionType() const; |
1976 | bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } |
1977 | bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } |
1978 | bool isPointerType() const; |
1979 | bool isAnyPointerType() const; // Any C pointer or ObjC object pointer |
1980 | bool isBlockPointerType() const; |
1981 | bool isVoidPointerType() const; |
1982 | bool isReferenceType() const; |
1983 | bool isLValueReferenceType() const; |
1984 | bool isRValueReferenceType() const; |
1985 | bool isFunctionPointerType() const; |
1986 | bool isFunctionReferenceType() const; |
1987 | bool isMemberPointerType() const; |
1988 | bool isMemberFunctionPointerType() const; |
1989 | bool isMemberDataPointerType() const; |
1990 | bool isArrayType() const; |
1991 | bool isConstantArrayType() const; |
1992 | bool isIncompleteArrayType() const; |
1993 | bool isVariableArrayType() const; |
1994 | bool isDependentSizedArrayType() const; |
1995 | bool isRecordType() const; |
1996 | bool isClassType() const; |
1997 | bool isStructureType() const; |
1998 | bool isObjCBoxableRecordType() const; |
1999 | bool isInterfaceType() const; |
2000 | bool isStructureOrClassType() const; |
2001 | bool isUnionType() const; |
2002 | bool isComplexIntegerType() const; // GCC _Complex integer type. |
2003 | bool isVectorType() const; // GCC vector type. |
2004 | bool isExtVectorType() const; // Extended vector type. |
2005 | bool isDependentAddressSpaceType() const; // value-dependent address space qualifier |
2006 | bool isObjCObjectPointerType() const; // pointer to ObjC object |
2007 | bool isObjCRetainableType() const; // ObjC object or block pointer |
2008 | bool isObjCLifetimeType() const; // (array of)* retainable type |
2009 | bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type |
2010 | bool isObjCNSObjectType() const; // __attribute__((NSObject)) |
2011 | bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class)) |
2012 | // FIXME: change this to 'raw' interface type, so we can used 'interface' type |
2013 | // for the common case. |
2014 | bool isObjCObjectType() const; // NSString or typeof(*(id)0) |
2015 | bool isObjCQualifiedInterfaceType() const; // NSString<foo> |
2016 | bool isObjCQualifiedIdType() const; // id<foo> |
2017 | bool isObjCQualifiedClassType() const; // Class<foo> |
2018 | bool isObjCObjectOrInterfaceType() const; |
2019 | bool isObjCIdType() const; // id |
2020 | bool isDecltypeType() const; |
2021 | /// Was this type written with the special inert-in-ARC __unsafe_unretained |
2022 | /// qualifier? |
2023 | /// |
2024 | /// This approximates the answer to the following question: if this |
2025 | /// translation unit were compiled in ARC, would this type be qualified |
2026 | /// with __unsafe_unretained? |
2027 | bool isObjCInertUnsafeUnretainedType() const { |
2028 | return hasAttr(attr::ObjCInertUnsafeUnretained); |
2029 | } |
2030 | |
2031 | /// Whether the type is Objective-C 'id' or a __kindof type of an |
2032 | /// object type, e.g., __kindof NSView * or __kindof id |
2033 | /// <NSCopying>. |
2034 | /// |
2035 | /// \param bound Will be set to the bound on non-id subtype types, |
2036 | /// which will be (possibly specialized) Objective-C class type, or |
2037 | /// null for 'id. |
2038 | bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, |
2039 | const ObjCObjectType *&bound) const; |
2040 | |
2041 | bool isObjCClassType() const; // Class |
2042 | |
2043 | /// Whether the type is Objective-C 'Class' or a __kindof type of an |
2044 | /// Class type, e.g., __kindof Class <NSCopying>. |
2045 | /// |
2046 | /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound |
2047 | /// here because Objective-C's type system cannot express "a class |
2048 | /// object for a subclass of NSFoo". |
2049 | bool isObjCClassOrClassKindOfType() const; |
2050 | |
2051 | bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const; |
2052 | bool isObjCSelType() const; // Class |
2053 | bool isObjCBuiltinType() const; // 'id' or 'Class' |
2054 | bool isObjCARCBridgableType() const; |
2055 | bool isCARCBridgableType() const; |
2056 | bool isTemplateTypeParmType() const; // C++ template type parameter |
2057 | bool isNullPtrType() const; // C++11 std::nullptr_t |
2058 | bool isNothrowT() const; // C++ std::nothrow_t |
2059 | bool isAlignValT() const; // C++17 std::align_val_t |
2060 | bool isStdByteType() const; // C++17 std::byte |
2061 | bool isAtomicType() const; // C11 _Atomic() |
2062 | |
2063 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
2064 | bool is##Id##Type() const; |
2065 | #include "clang/Basic/OpenCLImageTypes.def" |
2066 | |
2067 | bool isImageType() const; // Any OpenCL image type |
2068 | |
2069 | bool isSamplerT() const; // OpenCL sampler_t |
2070 | bool isEventT() const; // OpenCL event_t |
2071 | bool isClkEventT() const; // OpenCL clk_event_t |
2072 | bool isQueueT() const; // OpenCL queue_t |
2073 | bool isReserveIDT() const; // OpenCL reserve_id_t |
2074 | |
2075 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
2076 | bool is##Id##Type() const; |
2077 | #include "clang/Basic/OpenCLExtensionTypes.def" |
2078 | // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL extension |
2079 | bool isOCLIntelSubgroupAVCType() const; |
2080 | bool isOCLExtOpaqueType() const; // Any OpenCL extension type |
2081 | |
2082 | bool isPipeType() const; // OpenCL pipe type |
2083 | bool isOpenCLSpecificType() const; // Any OpenCL specific type |
2084 | |
2085 | /// Determines if this type, which must satisfy |
2086 | /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather |
2087 | /// than implicitly __strong. |
2088 | bool isObjCARCImplicitlyUnretainedType() const; |
2089 | |
2090 | /// Return the implicit lifetime for this type, which must not be dependent. |
2091 | Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const; |
2092 | |
2093 | enum ScalarTypeKind { |
2094 | STK_CPointer, |
2095 | STK_BlockPointer, |
2096 | STK_ObjCObjectPointer, |
2097 | STK_MemberPointer, |
2098 | STK_Bool, |
2099 | STK_Integral, |
2100 | STK_Floating, |
2101 | STK_IntegralComplex, |
2102 | STK_FloatingComplex, |
2103 | STK_FixedPoint |
2104 | }; |
2105 | |
2106 | /// Given that this is a scalar type, classify it. |
2107 | ScalarTypeKind getScalarTypeKind() const; |
2108 | |
2109 | /// Whether this type is a dependent type, meaning that its definition |
2110 | /// somehow depends on a template parameter (C++ [temp.dep.type]). |
2111 | bool isDependentType() const { return TypeBits.Dependent; } |
2112 | |
2113 | /// Determine whether this type is an instantiation-dependent type, |
2114 | /// meaning that the type involves a template parameter (even if the |
2115 | /// definition does not actually depend on the type substituted for that |
2116 | /// template parameter). |
2117 | bool isInstantiationDependentType() const { |
2118 | return TypeBits.InstantiationDependent; |
2119 | } |
2120 | |
2121 | /// Determine whether this type is an undeduced type, meaning that |
2122 | /// it somehow involves a C++11 'auto' type or similar which has not yet been |
2123 | /// deduced. |
2124 | bool isUndeducedType() const; |
2125 | |
2126 | /// Whether this type is a variably-modified type (C99 6.7.5). |
2127 | bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } |
2128 | |
2129 | /// Whether this type involves a variable-length array type |
2130 | /// with a definite size. |
2131 | bool hasSizedVLAType() const; |
2132 | |
2133 | /// Whether this type is or contains a local or unnamed type. |
2134 | bool hasUnnamedOrLocalType() const; |
2135 | |
2136 | bool isOverloadableType() const; |
2137 | |
2138 | /// Determine wither this type is a C++ elaborated-type-specifier. |
2139 | bool isElaboratedTypeSpecifier() const; |
2140 | |
2141 | bool canDecayToPointerType() const; |
2142 | |
2143 | /// Whether this type is represented natively as a pointer. This includes |
2144 | /// pointers, references, block pointers, and Objective-C interface, |
2145 | /// qualified id, and qualified interface types, as well as nullptr_t. |
2146 | bool hasPointerRepresentation() const; |
2147 | |
2148 | /// Whether this type can represent an objective pointer type for the |
2149 | /// purpose of GC'ability |
2150 | bool hasObjCPointerRepresentation() const; |
2151 | |
2152 | /// Determine whether this type has an integer representation |
2153 | /// of some sort, e.g., it is an integer type or a vector. |
2154 | bool hasIntegerRepresentation() const; |
2155 | |
2156 | /// Determine whether this type has an signed integer representation |
2157 | /// of some sort, e.g., it is an signed integer type or a vector. |
2158 | bool hasSignedIntegerRepresentation() const; |
2159 | |
2160 | /// Determine whether this type has an unsigned integer representation |
2161 | /// of some sort, e.g., it is an unsigned integer type or a vector. |
2162 | bool hasUnsignedIntegerRepresentation() const; |
2163 | |
2164 | /// Determine whether this type has a floating-point representation |
2165 | /// of some sort, e.g., it is a floating-point type or a vector thereof. |
2166 | bool hasFloatingRepresentation() const; |
2167 | |
2168 | // Type Checking Functions: Check to see if this type is structurally the |
2169 | // specified type, ignoring typedefs and qualifiers, and return a pointer to |
2170 | // the best type we can. |
2171 | const RecordType *getAsStructureType() const; |
2172 | /// NOTE: getAs*ArrayType are methods on ASTContext. |
2173 | const RecordType *getAsUnionType() const; |
2174 | const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. |
2175 | const ObjCObjectType *getAsObjCInterfaceType() const; |
2176 | |
2177 | // The following is a convenience method that returns an ObjCObjectPointerType |
2178 | // for object declared using an interface. |
2179 | const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; |
2180 | const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; |
2181 | const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; |
2182 | const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; |
2183 | |
2184 | /// Retrieves the CXXRecordDecl that this type refers to, either |
2185 | /// because the type is a RecordType or because it is the injected-class-name |
2186 | /// type of a class template or class template partial specialization. |
2187 | CXXRecordDecl *getAsCXXRecordDecl() const; |
2188 | |
2189 | /// Retrieves the RecordDecl this type refers to. |
2190 | RecordDecl *getAsRecordDecl() const; |
2191 | |
2192 | /// Retrieves the TagDecl that this type refers to, either |
2193 | /// because the type is a TagType or because it is the injected-class-name |
2194 | /// type of a class template or class template partial specialization. |
2195 | TagDecl *getAsTagDecl() const; |
2196 | |
2197 | /// If this is a pointer or reference to a RecordType, return the |
2198 | /// CXXRecordDecl that the type refers to. |
2199 | /// |
2200 | /// If this is not a pointer or reference, or the type being pointed to does |
2201 | /// not refer to a CXXRecordDecl, returns NULL. |
2202 | const CXXRecordDecl *getPointeeCXXRecordDecl() const; |
2203 | |
2204 | /// Get the DeducedType whose type will be deduced for a variable with |
2205 | /// an initializer of this type. This looks through declarators like pointer |
2206 | /// types, but not through decltype or typedefs. |
2207 | DeducedType *getContainedDeducedType() const; |
2208 | |
2209 | /// Get the AutoType whose type will be deduced for a variable with |
2210 | /// an initializer of this type. This looks through declarators like pointer |
2211 | /// types, but not through decltype or typedefs. |
2212 | AutoType *getContainedAutoType() const { |
2213 | return dyn_cast_or_null<AutoType>(getContainedDeducedType()); |
2214 | } |
2215 | |
2216 | /// Determine whether this type was written with a leading 'auto' |
2217 | /// corresponding to a trailing return type (possibly for a nested |
2218 | /// function type within a pointer to function type or similar). |
2219 | bool hasAutoForTrailingReturnType() const; |
2220 | |
2221 | /// Member-template getAs<specific type>'. Look through sugar for |
2222 | /// an instance of \<specific type>. This scheme will eventually |
2223 | /// replace the specific getAsXXXX methods above. |
2224 | /// |
2225 | /// There are some specializations of this member template listed |
2226 | /// immediately following this class. |
2227 | template <typename T> const T *getAs() const; |
2228 | |
2229 | /// Member-template getAsAdjusted<specific type>. Look through specific kinds |
2230 | /// of sugar (parens, attributes, etc) for an instance of \<specific type>. |
2231 | /// This is used when you need to walk over sugar nodes that represent some |
2232 | /// kind of type adjustment from a type that was written as a \<specific type> |
2233 | /// to another type that is still canonically a \<specific type>. |
2234 | template <typename T> const T *getAsAdjusted() const; |
2235 | |
2236 | /// A variant of getAs<> for array types which silently discards |
2237 | /// qualifiers from the outermost type. |
2238 | const ArrayType *getAsArrayTypeUnsafe() const; |
2239 | |
2240 | /// Member-template castAs<specific type>. Look through sugar for |
2241 | /// the underlying instance of \<specific type>. |
2242 | /// |
2243 | /// This method has the same relationship to getAs<T> as cast<T> has |
2244 | /// to dyn_cast<T>; which is to say, the underlying type *must* |
2245 | /// have the intended type, and this method will never return null. |
2246 | template <typename T> const T *castAs() const; |
2247 | |
2248 | /// A variant of castAs<> for array type which silently discards |
2249 | /// qualifiers from the outermost type. |
2250 | const ArrayType *castAsArrayTypeUnsafe() const; |
2251 | |
2252 | /// Determine whether this type had the specified attribute applied to it |
2253 | /// (looking through top-level type sugar). |
2254 | bool hasAttr(attr::Kind AK) const; |
2255 | |
2256 | /// Get the base element type of this type, potentially discarding type |
2257 | /// qualifiers. This should never be used when type qualifiers |
2258 | /// are meaningful. |
2259 | const Type *getBaseElementTypeUnsafe() const; |
2260 | |
2261 | /// If this is an array type, return the element type of the array, |
2262 | /// potentially with type qualifiers missing. |
2263 | /// This should never be used when type qualifiers are meaningful. |
2264 | const Type *getArrayElementTypeNoTypeQual() const; |
2265 | |
2266 | /// If this is a pointer type, return the pointee type. |
2267 | /// If this is an array type, return the array element type. |
2268 | /// This should never be used when type qualifiers are meaningful. |
2269 | const Type *getPointeeOrArrayElementType() const; |
2270 | |
2271 | /// If this is a pointer, ObjC object pointer, or block |
2272 | /// pointer, this returns the respective pointee. |
2273 | QualType getPointeeType() const; |
2274 | |
2275 | /// Return the specified type with any "sugar" removed from the type, |
2276 | /// removing any typedefs, typeofs, etc., as well as any qualifiers. |
2277 | const Type *getUnqualifiedDesugaredType() const; |
2278 | |
2279 | /// More type predicates useful for type checking/promotion |
2280 | bool isPromotableIntegerType() const; // C99 6.3.1.1p2 |
2281 | |
2282 | /// Return true if this is an integer type that is |
2283 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
2284 | /// or an enum decl which has a signed representation. |
2285 | bool isSignedIntegerType() const; |
2286 | |
2287 | /// Return true if this is an integer type that is |
2288 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], |
2289 | /// or an enum decl which has an unsigned representation. |
2290 | bool isUnsignedIntegerType() const; |
2291 | |
2292 | /// Determines whether this is an integer type that is signed or an |
2293 | /// enumeration types whose underlying type is a signed integer type. |
2294 | bool isSignedIntegerOrEnumerationType() const; |
2295 | |
2296 | /// Determines whether this is an integer type that is unsigned or an |
2297 | /// enumeration types whose underlying type is a unsigned integer type. |
2298 | bool isUnsignedIntegerOrEnumerationType() const; |
2299 | |
2300 | /// Return true if this is a fixed point type according to |
2301 | /// ISO/IEC JTC1 SC22 WG14 N1169. |
2302 | bool isFixedPointType() const; |
2303 | |
2304 | /// Return true if this is a fixed point or integer type. |
2305 | bool isFixedPointOrIntegerType() const; |
2306 | |
2307 | /// Return true if this is a saturated fixed point type according to |
2308 | /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned. |
2309 | bool isSaturatedFixedPointType() const; |
2310 | |
2311 | /// Return true if this is a saturated fixed point type according to |
2312 | /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned. |
2313 | bool isUnsaturatedFixedPointType() const; |
2314 | |
2315 | /// Return true if this is a fixed point type that is signed according |
2316 | /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated. |
2317 | bool isSignedFixedPointType() const; |
2318 | |
2319 | /// Return true if this is a fixed point type that is unsigned according |
2320 | /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated. |
2321 | bool isUnsignedFixedPointType() const; |
2322 | |
2323 | /// Return true if this is not a variable sized type, |
2324 | /// according to the rules of C99 6.7.5p3. It is not legal to call this on |
2325 | /// incomplete types. |
2326 | bool isConstantSizeType() const; |
2327 | |
2328 | /// Returns true if this type can be represented by some |
2329 | /// set of type specifiers. |
2330 | bool isSpecifierType() const; |
2331 | |
2332 | /// Determine the linkage of this type. |
2333 | Linkage getLinkage() const; |
2334 | |
2335 | /// Determine the visibility of this type. |
2336 | Visibility getVisibility() const { |
2337 | return getLinkageAndVisibility().getVisibility(); |
2338 | } |
2339 | |
2340 | /// Return true if the visibility was explicitly set is the code. |
2341 | bool isVisibilityExplicit() const { |
2342 | return getLinkageAndVisibility().isVisibilityExplicit(); |
2343 | } |
2344 | |
2345 | /// Determine the linkage and visibility of this type. |
2346 | LinkageInfo getLinkageAndVisibility() const; |
2347 | |
2348 | /// True if the computed linkage is valid. Used for consistency |
2349 | /// checking. Should always return true. |
2350 | bool isLinkageValid() const; |
2351 | |
2352 | /// Determine the nullability of the given type. |
2353 | /// |
2354 | /// Note that nullability is only captured as sugar within the type |
2355 | /// system, not as part of the canonical type, so nullability will |
2356 | /// be lost by canonicalization and desugaring. |
2357 | Optional<NullabilityKind> getNullability(const ASTContext &context) const; |
2358 | |
2359 | /// Determine whether the given type can have a nullability |
2360 | /// specifier applied to it, i.e., if it is any kind of pointer type. |
2361 | /// |
2362 | /// \param ResultIfUnknown The value to return if we don't yet know whether |
2363 | /// this type can have nullability because it is dependent. |
2364 | bool canHaveNullability(bool ResultIfUnknown = true) const; |
2365 | |
2366 | /// Retrieve the set of substitutions required when accessing a member |
2367 | /// of the Objective-C receiver type that is declared in the given context. |
2368 | /// |
2369 | /// \c *this is the type of the object we're operating on, e.g., the |
2370 | /// receiver for a message send or the base of a property access, and is |
2371 | /// expected to be of some object or object pointer type. |
2372 | /// |
2373 | /// \param dc The declaration context for which we are building up a |
2374 | /// substitution mapping, which should be an Objective-C class, extension, |
2375 | /// category, or method within. |
2376 | /// |
2377 | /// \returns an array of type arguments that can be substituted for |
2378 | /// the type parameters of the given declaration context in any type described |
2379 | /// within that context, or an empty optional to indicate that no |
2380 | /// substitution is required. |
2381 | Optional<ArrayRef<QualType>> |
2382 | getObjCSubstitutions(const DeclContext *dc) const; |
2383 | |
2384 | /// Determines if this is an ObjC interface type that may accept type |
2385 | /// parameters. |
2386 | bool acceptsObjCTypeParams() const; |
2387 | |
2388 | const char *getTypeClassName() const; |
2389 | |
2390 | QualType getCanonicalTypeInternal() const { |
2391 | return CanonicalType; |
2392 | } |
2393 | |
2394 | CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h |
2395 | void dump() const; |
2396 | void dump(llvm::raw_ostream &OS) const; |
2397 | }; |
2398 | |
2399 | /// This will check for a TypedefType by removing any existing sugar |
2400 | /// until it reaches a TypedefType or a non-sugared type. |
2401 | template <> const TypedefType *Type::getAs() const; |
2402 | |
2403 | /// This will check for a TemplateSpecializationType by removing any |
2404 | /// existing sugar until it reaches a TemplateSpecializationType or a |
2405 | /// non-sugared type. |
2406 | template <> const TemplateSpecializationType *Type::getAs() const; |
2407 | |
2408 | /// This will check for an AttributedType by removing any existing sugar |
2409 | /// until it reaches an AttributedType or a non-sugared type. |
2410 | template <> const AttributedType *Type::getAs() const; |
2411 | |
2412 | // We can do canonical leaf types faster, because we don't have to |
2413 | // worry about preserving child type decoration. |
2414 | #define TYPE(Class, Base) |
2415 | #define LEAF_TYPE(Class) \ |
2416 | template <> inline const Class##Type *Type::getAs() const { \ |
2417 | return dyn_cast<Class##Type>(CanonicalType); \ |
2418 | } \ |
2419 | template <> inline const Class##Type *Type::castAs() const { \ |
2420 | return cast<Class##Type>(CanonicalType); \ |
2421 | } |
2422 | #include "clang/AST/TypeNodes.inc" |
2423 | |
2424 | /// This class is used for builtin types like 'int'. Builtin |
2425 | /// types are always canonical and have a literal name field. |
2426 | class BuiltinType : public Type { |
2427 | public: |
2428 | enum Kind { |
2429 | // OpenCL image types |
2430 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id, |
2431 | #include "clang/Basic/OpenCLImageTypes.def" |
2432 | // OpenCL extension types |
2433 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id, |
2434 | #include "clang/Basic/OpenCLExtensionTypes.def" |
2435 | // SVE Types |
2436 | #define SVE_TYPE(Name, Id, SingletonId) Id, |
2437 | #include "clang/Basic/AArch64SVEACLETypes.def" |
2438 | // All other builtin types |
2439 | #define BUILTIN_TYPE(Id, SingletonId) Id, |
2440 | #define LAST_BUILTIN_TYPE(Id) LastKind = Id |
2441 | #include "clang/AST/BuiltinTypes.def" |
2442 | }; |
2443 | |
2444 | private: |
2445 | friend class ASTContext; // ASTContext creates these. |
2446 | |
2447 | BuiltinType(Kind K) |
2448 | : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), |
2449 | /*InstantiationDependent=*/(K == Dependent), |
2450 | /*VariablyModified=*/false, |
2451 | /*Unexpanded parameter pack=*/false) { |
2452 | BuiltinTypeBits.Kind = K; |
2453 | } |
2454 | |
2455 | public: |
2456 | Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } |
2457 | StringRef getName(const PrintingPolicy &Policy) const; |
2458 | |
2459 | const char *getNameAsCString(const PrintingPolicy &Policy) const { |
2460 | // The StringRef is null-terminated. |
2461 | StringRef str = getName(Policy); |
2462 | assert(!str.empty() && str.data()[str.size()] == '\0')((!str.empty() && str.data()[str.size()] == '\0') ? static_cast <void> (0) : __assert_fail ("!str.empty() && str.data()[str.size()] == '\\0'" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 2462, __PRETTY_FUNCTION__)); |
2463 | return str.data(); |
2464 | } |
2465 | |
2466 | bool isSugared() const { return false; } |
2467 | QualType desugar() const { return QualType(this, 0); } |
2468 | |
2469 | bool isInteger() const { |
2470 | return getKind() >= Bool && getKind() <= Int128; |
2471 | } |
2472 | |
2473 | bool isSignedInteger() const { |
2474 | return getKind() >= Char_S && getKind() <= Int128; |
2475 | } |
2476 | |
2477 | bool isUnsignedInteger() const { |
2478 | return getKind() >= Bool && getKind() <= UInt128; |
2479 | } |
2480 | |
2481 | bool isFloatingPoint() const { |
2482 | return getKind() >= Half && getKind() <= Float128; |
2483 | } |
2484 | |
2485 | /// Determines whether the given kind corresponds to a placeholder type. |
2486 | static bool isPlaceholderTypeKind(Kind K) { |
2487 | return K >= Overload; |
2488 | } |
2489 | |
2490 | /// Determines whether this type is a placeholder type, i.e. a type |
2491 | /// which cannot appear in arbitrary positions in a fully-formed |
2492 | /// expression. |
2493 | bool isPlaceholderType() const { |
2494 | return isPlaceholderTypeKind(getKind()); |
2495 | } |
2496 | |
2497 | /// Determines whether this type is a placeholder type other than |
2498 | /// Overload. Most placeholder types require only syntactic |
2499 | /// information about their context in order to be resolved (e.g. |
2500 | /// whether it is a call expression), which means they can (and |
2501 | /// should) be resolved in an earlier "phase" of analysis. |
2502 | /// Overload expressions sometimes pick up further information |
2503 | /// from their context, like whether the context expects a |
2504 | /// specific function-pointer type, and so frequently need |
2505 | /// special treatment. |
2506 | bool isNonOverloadPlaceholderType() const { |
2507 | return getKind() > Overload; |
2508 | } |
2509 | |
2510 | static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } |
2511 | }; |
2512 | |
2513 | /// Complex values, per C99 6.2.5p11. This supports the C99 complex |
2514 | /// types (_Complex float etc) as well as the GCC integer complex extensions. |
2515 | class ComplexType : public Type, public llvm::FoldingSetNode { |
2516 | friend class ASTContext; // ASTContext creates these. |
2517 | |
2518 | QualType ElementType; |
2519 | |
2520 | ComplexType(QualType Element, QualType CanonicalPtr) |
2521 | : Type(Complex, CanonicalPtr, Element->isDependentType(), |
2522 | Element->isInstantiationDependentType(), |
2523 | Element->isVariablyModifiedType(), |
2524 | Element->containsUnexpandedParameterPack()), |
2525 | ElementType(Element) {} |
2526 | |
2527 | public: |
2528 | QualType getElementType() const { return ElementType; } |
2529 | |
2530 | bool isSugared() const { return false; } |
2531 | QualType desugar() const { return QualType(this, 0); } |
2532 | |
2533 | void Profile(llvm::FoldingSetNodeID &ID) { |
2534 | Profile(ID, getElementType()); |
2535 | } |
2536 | |
2537 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { |
2538 | ID.AddPointer(Element.getAsOpaquePtr()); |
2539 | } |
2540 | |
2541 | static bool classof(const Type *T) { return T->getTypeClass() == Complex; } |
2542 | }; |
2543 | |
2544 | /// Sugar for parentheses used when specifying types. |
2545 | class ParenType : public Type, public llvm::FoldingSetNode { |
2546 | friend class ASTContext; // ASTContext creates these. |
2547 | |
2548 | QualType Inner; |
2549 | |
2550 | ParenType(QualType InnerType, QualType CanonType) |
2551 | : Type(Paren, CanonType, InnerType->isDependentType(), |
2552 | InnerType->isInstantiationDependentType(), |
2553 | InnerType->isVariablyModifiedType(), |
2554 | InnerType->containsUnexpandedParameterPack()), |
2555 | Inner(InnerType) {} |
2556 | |
2557 | public: |
2558 | QualType getInnerType() const { return Inner; } |
2559 | |
2560 | bool isSugared() const { return true; } |
2561 | QualType desugar() const { return getInnerType(); } |
2562 | |
2563 | void Profile(llvm::FoldingSetNodeID &ID) { |
2564 | Profile(ID, getInnerType()); |
2565 | } |
2566 | |
2567 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { |
2568 | Inner.Profile(ID); |
2569 | } |
2570 | |
2571 | static bool classof(const Type *T) { return T->getTypeClass() == Paren; } |
2572 | }; |
2573 | |
2574 | /// PointerType - C99 6.7.5.1 - Pointer Declarators. |
2575 | class PointerType : public Type, public llvm::FoldingSetNode { |
2576 | friend class ASTContext; // ASTContext creates these. |
2577 | |
2578 | QualType PointeeType; |
2579 | |
2580 | PointerType(QualType Pointee, QualType CanonicalPtr) |
2581 | : Type(Pointer, CanonicalPtr, Pointee->isDependentType(), |
2582 | Pointee->isInstantiationDependentType(), |
2583 | Pointee->isVariablyModifiedType(), |
2584 | Pointee->containsUnexpandedParameterPack()), |
2585 | PointeeType(Pointee) {} |
2586 | |
2587 | public: |
2588 | QualType getPointeeType() const { return PointeeType; } |
2589 | |
2590 | /// Returns true if address spaces of pointers overlap. |
2591 | /// OpenCL v2.0 defines conversion rules for pointers to different |
2592 | /// address spaces (OpenCLC v2.0 s6.5.5) and notion of overlapping |
2593 | /// address spaces. |
2594 | /// CL1.1 or CL1.2: |
2595 | /// address spaces overlap iff they are they same. |
2596 | /// CL2.0 adds: |
2597 | /// __generic overlaps with any address space except for __constant. |
2598 | bool isAddressSpaceOverlapping(const PointerType &other) const { |
2599 | Qualifiers thisQuals = PointeeType.getQualifiers(); |
2600 | Qualifiers otherQuals = other.getPointeeType().getQualifiers(); |
2601 | // Address spaces overlap if at least one of them is a superset of another |
2602 | return thisQuals.isAddressSpaceSupersetOf(otherQuals) || |
2603 | otherQuals.isAddressSpaceSupersetOf(thisQuals); |
2604 | } |
2605 | |
2606 | bool isSugared() const { return false; } |
2607 | QualType desugar() const { return QualType(this, 0); } |
2608 | |
2609 | void Profile(llvm::FoldingSetNodeID &ID) { |
2610 | Profile(ID, getPointeeType()); |
2611 | } |
2612 | |
2613 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { |
2614 | ID.AddPointer(Pointee.getAsOpaquePtr()); |
2615 | } |
2616 | |
2617 | static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } |
2618 | }; |
2619 | |
2620 | /// Represents a type which was implicitly adjusted by the semantic |
2621 | /// engine for arbitrary reasons. For example, array and function types can |
2622 | /// decay, and function types can have their calling conventions adjusted. |
2623 | class AdjustedType : public Type, public llvm::FoldingSetNode { |
2624 | QualType OriginalTy; |
2625 | QualType AdjustedTy; |
2626 | |
2627 | protected: |
2628 | friend class ASTContext; // ASTContext creates these. |
2629 | |
2630 | AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, |
2631 | QualType CanonicalPtr) |
2632 | : Type(TC, CanonicalPtr, OriginalTy->isDependentType(), |
2633 | OriginalTy->isInstantiationDependentType(), |
2634 | OriginalTy->isVariablyModifiedType(), |
2635 | OriginalTy->containsUnexpandedParameterPack()), |
2636 | OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {} |
2637 | |
2638 | public: |
2639 | QualType getOriginalType() const { return OriginalTy; } |
2640 | QualType getAdjustedType() const { return AdjustedTy; } |
2641 | |
2642 | bool isSugared() const { return true; } |
2643 | QualType desugar() const { return AdjustedTy; } |
2644 | |
2645 | void Profile(llvm::FoldingSetNodeID &ID) { |
2646 | Profile(ID, OriginalTy, AdjustedTy); |
2647 | } |
2648 | |
2649 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) { |
2650 | ID.AddPointer(Orig.getAsOpaquePtr()); |
2651 | ID.AddPointer(New.getAsOpaquePtr()); |
2652 | } |
2653 | |
2654 | static bool classof(const Type *T) { |
2655 | return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed; |
2656 | } |
2657 | }; |
2658 | |
2659 | /// Represents a pointer type decayed from an array or function type. |
2660 | class DecayedType : public AdjustedType { |
2661 | friend class ASTContext; // ASTContext creates these. |
2662 | |
2663 | inline |
2664 | DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical); |
2665 | |
2666 | public: |
2667 | QualType getDecayedType() const { return getAdjustedType(); } |
2668 | |
2669 | inline QualType getPointeeType() const; |
2670 | |
2671 | static bool classof(const Type *T) { return T->getTypeClass() == Decayed; } |
2672 | }; |
2673 | |
2674 | /// Pointer to a block type. |
2675 | /// This type is to represent types syntactically represented as |
2676 | /// "void (^)(int)", etc. Pointee is required to always be a function type. |
2677 | class BlockPointerType : public Type, public llvm::FoldingSetNode { |
2678 | friend class ASTContext; // ASTContext creates these. |
2679 | |
2680 | // Block is some kind of pointer type |
2681 | QualType PointeeType; |
2682 | |
2683 | BlockPointerType(QualType Pointee, QualType CanonicalCls) |
2684 | : Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), |
2685 | Pointee->isInstantiationDependentType(), |
2686 | Pointee->isVariablyModifiedType(), |
2687 | Pointee->containsUnexpandedParameterPack()), |
2688 | PointeeType(Pointee) {} |
2689 | |
2690 | public: |
2691 | // Get the pointee type. Pointee is required to always be a function type. |
2692 | QualType getPointeeType() const { return PointeeType; } |
2693 | |
2694 | bool isSugared() const { return false; } |
2695 | QualType desugar() const { return QualType(this, 0); } |
2696 | |
2697 | void Profile(llvm::FoldingSetNodeID &ID) { |
2698 | Profile(ID, getPointeeType()); |
2699 | } |
2700 | |
2701 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { |
2702 | ID.AddPointer(Pointee.getAsOpaquePtr()); |
2703 | } |
2704 | |
2705 | static bool classof(const Type *T) { |
2706 | return T->getTypeClass() == BlockPointer; |
2707 | } |
2708 | }; |
2709 | |
2710 | /// Base for LValueReferenceType and RValueReferenceType |
2711 | class ReferenceType : public Type, public llvm::FoldingSetNode { |
2712 | QualType PointeeType; |
2713 | |
2714 | protected: |
2715 | ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, |
2716 | bool SpelledAsLValue) |
2717 | : Type(tc, CanonicalRef, Referencee->isDependentType(), |
2718 | Referencee->isInstantiationDependentType(), |
2719 | Referencee->isVariablyModifiedType(), |
2720 | Referencee->containsUnexpandedParameterPack()), |
2721 | PointeeType(Referencee) { |
2722 | ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; |
2723 | ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); |
2724 | } |
2725 | |
2726 | public: |
2727 | bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } |
2728 | bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } |
2729 | |
2730 | QualType getPointeeTypeAsWritten() const { return PointeeType; } |
2731 | |
2732 | QualType getPointeeType() const { |
2733 | // FIXME: this might strip inner qualifiers; okay? |
2734 | const ReferenceType *T = this; |
2735 | while (T->isInnerRef()) |
2736 | T = T->PointeeType->castAs<ReferenceType>(); |
2737 | return T->PointeeType; |
2738 | } |
2739 | |
2740 | void Profile(llvm::FoldingSetNodeID &ID) { |
2741 | Profile(ID, PointeeType, isSpelledAsLValue()); |
2742 | } |
2743 | |
2744 | static void Profile(llvm::FoldingSetNodeID &ID, |
2745 | QualType Referencee, |
2746 | bool SpelledAsLValue) { |
2747 | ID.AddPointer(Referencee.getAsOpaquePtr()); |
2748 | ID.AddBoolean(SpelledAsLValue); |
2749 | } |
2750 | |
2751 | static bool classof(const Type *T) { |
2752 | return T->getTypeClass() == LValueReference || |
2753 | T->getTypeClass() == RValueReference; |
2754 | } |
2755 | }; |
2756 | |
2757 | /// An lvalue reference type, per C++11 [dcl.ref]. |
2758 | class LValueReferenceType : public ReferenceType { |
2759 | friend class ASTContext; // ASTContext creates these |
2760 | |
2761 | LValueReferenceType(QualType Referencee, QualType CanonicalRef, |
2762 | bool SpelledAsLValue) |
2763 | : ReferenceType(LValueReference, Referencee, CanonicalRef, |
2764 | SpelledAsLValue) {} |
2765 | |
2766 | public: |
2767 | bool isSugared() const { return false; } |
2768 | QualType desugar() const { return QualType(this, 0); } |
2769 | |
2770 | static bool classof(const Type *T) { |
2771 | return T->getTypeClass() == LValueReference; |
2772 | } |
2773 | }; |
2774 | |
2775 | /// An rvalue reference type, per C++11 [dcl.ref]. |
2776 | class RValueReferenceType : public ReferenceType { |
2777 | friend class ASTContext; // ASTContext creates these |
2778 | |
2779 | RValueReferenceType(QualType Referencee, QualType CanonicalRef) |
2780 | : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {} |
2781 | |
2782 | public: |
2783 | bool isSugared() const { return false; } |
2784 | QualType desugar() const { return QualType(this, 0); } |
2785 | |
2786 | static bool classof(const Type *T) { |
2787 | return T->getTypeClass() == RValueReference; |
2788 | } |
2789 | }; |
2790 | |
2791 | /// A pointer to member type per C++ 8.3.3 - Pointers to members. |
2792 | /// |
2793 | /// This includes both pointers to data members and pointer to member functions. |
2794 | class MemberPointerType : public Type, public llvm::FoldingSetNode { |
2795 | friend class ASTContext; // ASTContext creates these. |
2796 | |
2797 | QualType PointeeType; |
2798 | |
2799 | /// The class of which the pointee is a member. Must ultimately be a |
2800 | /// RecordType, but could be a typedef or a template parameter too. |
2801 | const Type *Class; |
2802 | |
2803 | MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) |
2804 | : Type(MemberPointer, CanonicalPtr, |
2805 | Cls->isDependentType() || Pointee->isDependentType(), |
2806 | (Cls->isInstantiationDependentType() || |
2807 | Pointee->isInstantiationDependentType()), |
2808 | Pointee->isVariablyModifiedType(), |
2809 | (Cls->containsUnexpandedParameterPack() || |
2810 | Pointee->containsUnexpandedParameterPack())), |
2811 | PointeeType(Pointee), Class(Cls) {} |
2812 | |
2813 | public: |
2814 | QualType getPointeeType() const { return PointeeType; } |
2815 | |
2816 | /// Returns true if the member type (i.e. the pointee type) is a |
2817 | /// function type rather than a data-member type. |
2818 | bool isMemberFunctionPointer() const { |
2819 | return PointeeType->isFunctionProtoType(); |
2820 | } |
2821 | |
2822 | /// Returns true if the member type (i.e. the pointee type) is a |
2823 | /// data type rather than a function type. |
2824 | bool isMemberDataPointer() const { |
2825 | return !PointeeType->isFunctionProtoType(); |
2826 | } |
2827 | |
2828 | const Type *getClass() const { return Class; } |
2829 | CXXRecordDecl *getMostRecentCXXRecordDecl() const; |
2830 | |
2831 | bool isSugared() const { return false; } |
2832 | QualType desugar() const { return QualType(this, 0); } |
2833 | |
2834 | void Profile(llvm::FoldingSetNodeID &ID) { |
2835 | Profile(ID, getPointeeType(), getClass()); |
2836 | } |
2837 | |
2838 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, |
2839 | const Type *Class) { |
2840 | ID.AddPointer(Pointee.getAsOpaquePtr()); |
2841 | ID.AddPointer(Class); |
2842 | } |
2843 | |
2844 | static bool classof(const Type *T) { |
2845 | return T->getTypeClass() == MemberPointer; |
2846 | } |
2847 | }; |
2848 | |
2849 | /// Represents an array type, per C99 6.7.5.2 - Array Declarators. |
2850 | class ArrayType : public Type, public llvm::FoldingSetNode { |
2851 | public: |
2852 | /// Capture whether this is a normal array (e.g. int X[4]) |
2853 | /// an array with a static size (e.g. int X[static 4]), or an array |
2854 | /// with a star size (e.g. int X[*]). |
2855 | /// 'static' is only allowed on function parameters. |
2856 | enum ArraySizeModifier { |
2857 | Normal, Static, Star |
2858 | }; |
2859 | |
2860 | private: |
2861 | /// The element type of the array. |
2862 | QualType ElementType; |
2863 | |
2864 | protected: |
2865 | friend class ASTContext; // ASTContext creates these. |
2866 | |
2867 | // C++ [temp.dep.type]p1: |
2868 | // A type is dependent if it is... |
2869 | // - an array type constructed from any dependent type or whose |
2870 | // size is specified by a constant expression that is |
2871 | // value-dependent, |
2872 | ArrayType(TypeClass tc, QualType et, QualType can, |
2873 | ArraySizeModifier sm, unsigned tq, |
2874 | bool ContainsUnexpandedParameterPack) |
2875 | : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, |
2876 | et->isInstantiationDependentType() || tc == DependentSizedArray, |
2877 | (tc == VariableArray || et->isVariablyModifiedType()), |
2878 | ContainsUnexpandedParameterPack), |
2879 | ElementType(et) { |
2880 | ArrayTypeBits.IndexTypeQuals = tq; |
2881 | ArrayTypeBits.SizeModifier = sm; |
2882 | } |
2883 | |
2884 | public: |
2885 | QualType getElementType() const { return ElementType; } |
2886 | |
2887 | ArraySizeModifier getSizeModifier() const { |
2888 | return ArraySizeModifier(ArrayTypeBits.SizeModifier); |
2889 | } |
2890 | |
2891 | Qualifiers getIndexTypeQualifiers() const { |
2892 | return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); |
2893 | } |
2894 | |
2895 | unsigned getIndexTypeCVRQualifiers() const { |
2896 | return ArrayTypeBits.IndexTypeQuals; |
2897 | } |
2898 | |
2899 | static bool classof(const Type *T) { |
2900 | return T->getTypeClass() == ConstantArray || |
2901 | T->getTypeClass() == VariableArray || |
2902 | T->getTypeClass() == IncompleteArray || |
2903 | T->getTypeClass() == DependentSizedArray; |
2904 | } |
2905 | }; |
2906 | |
2907 | /// Represents the canonical version of C arrays with a specified constant size. |
2908 | /// For example, the canonical type for 'int A[4 + 4*100]' is a |
2909 | /// ConstantArrayType where the element type is 'int' and the size is 404. |
2910 | class ConstantArrayType : public ArrayType { |
2911 | llvm::APInt Size; // Allows us to unique the type. |
2912 | |
2913 | ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, |
2914 | ArraySizeModifier sm, unsigned tq) |
2915 | : ArrayType(ConstantArray, et, can, sm, tq, |
2916 | et->containsUnexpandedParameterPack()), |
2917 | Size(size) {} |
2918 | |
2919 | protected: |
2920 | friend class ASTContext; // ASTContext creates these. |
2921 | |
2922 | ConstantArrayType(TypeClass tc, QualType et, QualType can, |
2923 | const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) |
2924 | : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()), |
2925 | Size(size) {} |
2926 | |
2927 | public: |
2928 | const llvm::APInt &getSize() const { return Size; } |
2929 | bool isSugared() const { return false; } |
2930 | QualType desugar() const { return QualType(this, 0); } |
2931 | |
2932 | /// Determine the number of bits required to address a member of |
2933 | // an array with the given element type and number of elements. |
2934 | static unsigned getNumAddressingBits(const ASTContext &Context, |
2935 | QualType ElementType, |
2936 | const llvm::APInt &NumElements); |
2937 | |
2938 | /// Determine the maximum number of active bits that an array's size |
2939 | /// can require, which limits the maximum size of the array. |
2940 | static unsigned getMaxSizeBits(const ASTContext &Context); |
2941 | |
2942 | void Profile(llvm::FoldingSetNodeID &ID) { |
2943 | Profile(ID, getElementType(), getSize(), |
2944 | getSizeModifier(), getIndexTypeCVRQualifiers()); |
2945 | } |
2946 | |
2947 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, |
2948 | const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, |
2949 | unsigned TypeQuals) { |
2950 | ID.AddPointer(ET.getAsOpaquePtr()); |
2951 | ID.AddInteger(ArraySize.getZExtValue()); |
2952 | ID.AddInteger(SizeMod); |
2953 | ID.AddInteger(TypeQuals); |
2954 | } |
2955 | |
2956 | static bool classof(const Type *T) { |
2957 | return T->getTypeClass() == ConstantArray; |
2958 | } |
2959 | }; |
2960 | |
2961 | /// Represents a C array with an unspecified size. For example 'int A[]' has |
2962 | /// an IncompleteArrayType where the element type is 'int' and the size is |
2963 | /// unspecified. |
2964 | class IncompleteArrayType : public ArrayType { |
2965 | friend class ASTContext; // ASTContext creates these. |
2966 | |
2967 | IncompleteArrayType(QualType et, QualType can, |
2968 | ArraySizeModifier sm, unsigned tq) |
2969 | : ArrayType(IncompleteArray, et, can, sm, tq, |
2970 | et->containsUnexpandedParameterPack()) {} |
2971 | |
2972 | public: |
2973 | friend class StmtIteratorBase; |
2974 | |
2975 | bool isSugared() const { return false; } |
2976 | QualType desugar() const { return QualType(this, 0); } |
2977 | |
2978 | static bool classof(const Type *T) { |
2979 | return T->getTypeClass() == IncompleteArray; |
2980 | } |
2981 | |
2982 | void Profile(llvm::FoldingSetNodeID &ID) { |
2983 | Profile(ID, getElementType(), getSizeModifier(), |
2984 | getIndexTypeCVRQualifiers()); |
2985 | } |
2986 | |
2987 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, |
2988 | ArraySizeModifier SizeMod, unsigned TypeQuals) { |
2989 | ID.AddPointer(ET.getAsOpaquePtr()); |
2990 | ID.AddInteger(SizeMod); |
2991 | ID.AddInteger(TypeQuals); |
2992 | } |
2993 | }; |
2994 | |
2995 | /// Represents a C array with a specified size that is not an |
2996 | /// integer-constant-expression. For example, 'int s[x+foo()]'. |
2997 | /// Since the size expression is an arbitrary expression, we store it as such. |
2998 | /// |
2999 | /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and |
3000 | /// should not be: two lexically equivalent variable array types could mean |
3001 | /// different things, for example, these variables do not have the same type |
3002 | /// dynamically: |
3003 | /// |
3004 | /// void foo(int x) { |
3005 | /// int Y[x]; |
3006 | /// ++x; |
3007 | /// int Z[x]; |
3008 | /// } |
3009 | class VariableArrayType : public ArrayType { |
3010 | friend class ASTContext; // ASTContext creates these. |
3011 | |
3012 | /// An assignment-expression. VLA's are only permitted within |
3013 | /// a function block. |
3014 | Stmt *SizeExpr; |
3015 | |
3016 | /// The range spanned by the left and right array brackets. |
3017 | SourceRange Brackets; |
3018 | |
3019 | VariableArrayType(QualType et, QualType can, Expr *e, |
3020 | ArraySizeModifier sm, unsigned tq, |
3021 | SourceRange brackets) |
3022 | : ArrayType(VariableArray, et, can, sm, tq, |
3023 | et->containsUnexpandedParameterPack()), |
3024 | SizeExpr((Stmt*) e), Brackets(brackets) {} |
3025 | |
3026 | public: |
3027 | friend class StmtIteratorBase; |
3028 | |
3029 | Expr *getSizeExpr() const { |
3030 | // We use C-style casts instead of cast<> here because we do not wish |
3031 | // to have a dependency of Type.h on Stmt.h/Expr.h. |
3032 | return (Expr*) SizeExpr; |
3033 | } |
3034 | |
3035 | SourceRange getBracketsRange() const { return Brackets; } |
3036 | SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } |
3037 | SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } |
3038 | |
3039 | bool isSugared() const { return false; } |
3040 | QualType desugar() const { return QualType(this, 0); } |
3041 | |
3042 | static bool classof(const Type *T) { |
3043 | return T->getTypeClass() == VariableArray; |
3044 | } |
3045 | |
3046 | void Profile(llvm::FoldingSetNodeID &ID) { |
3047 | llvm_unreachable("Cannot unique VariableArrayTypes.")::llvm::llvm_unreachable_internal("Cannot unique VariableArrayTypes." , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 3047); |
3048 | } |
3049 | }; |
3050 | |
3051 | /// Represents an array type in C++ whose size is a value-dependent expression. |
3052 | /// |
3053 | /// For example: |
3054 | /// \code |
3055 | /// template<typename T, int Size> |
3056 | /// class array { |
3057 | /// T data[Size]; |
3058 | /// }; |
3059 | /// \endcode |
3060 | /// |
3061 | /// For these types, we won't actually know what the array bound is |
3062 | /// until template instantiation occurs, at which point this will |
3063 | /// become either a ConstantArrayType or a VariableArrayType. |
3064 | class DependentSizedArrayType : public ArrayType { |
3065 | friend class ASTContext; // ASTContext creates these. |
3066 | |
3067 | const ASTContext &Context; |
3068 | |
3069 | /// An assignment expression that will instantiate to the |
3070 | /// size of the array. |
3071 | /// |
3072 | /// The expression itself might be null, in which case the array |
3073 | /// type will have its size deduced from an initializer. |
3074 | Stmt *SizeExpr; |
3075 | |
3076 | /// The range spanned by the left and right array brackets. |
3077 | SourceRange Brackets; |
3078 | |
3079 | DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, |
3080 | Expr *e, ArraySizeModifier sm, unsigned tq, |
3081 | SourceRange brackets); |
3082 | |
3083 | public: |
3084 | friend class StmtIteratorBase; |
3085 | |
3086 | Expr *getSizeExpr() const { |
3087 | // We use C-style casts instead of cast<> here because we do not wish |
3088 | // to have a dependency of Type.h on Stmt.h/Expr.h. |
3089 | return (Expr*) SizeExpr; |
3090 | } |
3091 | |
3092 | SourceRange getBracketsRange() const { return Brackets; } |
3093 | SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } |
3094 | SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } |
3095 | |
3096 | bool isSugared() const { return false; } |
3097 | QualType desugar() const { return QualType(this, 0); } |
3098 | |
3099 | static bool classof(const Type *T) { |
3100 | return T->getTypeClass() == DependentSizedArray; |
3101 | } |
3102 | |
3103 | void Profile(llvm::FoldingSetNodeID &ID) { |
3104 | Profile(ID, Context, getElementType(), |
3105 | getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); |
3106 | } |
3107 | |
3108 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
3109 | QualType ET, ArraySizeModifier SizeMod, |
3110 | unsigned TypeQuals, Expr *E); |
3111 | }; |
3112 | |
3113 | /// Represents an extended address space qualifier where the input address space |
3114 | /// value is dependent. Non-dependent address spaces are not represented with a |
3115 | /// special Type subclass; they are stored on an ExtQuals node as part of a QualType. |
3116 | /// |
3117 | /// For example: |
3118 | /// \code |
3119 | /// template<typename T, int AddrSpace> |
3120 | /// class AddressSpace { |
3121 | /// typedef T __attribute__((address_space(AddrSpace))) type; |
3122 | /// } |
3123 | /// \endcode |
3124 | class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode { |
3125 | friend class ASTContext; |
3126 | |
3127 | const ASTContext &Context; |
3128 | Expr *AddrSpaceExpr; |
3129 | QualType PointeeType; |
3130 | SourceLocation loc; |
3131 | |
3132 | DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType, |
3133 | QualType can, Expr *AddrSpaceExpr, |
3134 | SourceLocation loc); |
3135 | |
3136 | public: |
3137 | Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; } |
3138 | QualType getPointeeType() const { return PointeeType; } |
3139 | SourceLocation getAttributeLoc() const { return loc; } |
3140 | |
3141 | bool isSugared() const { return false; } |
3142 | QualType desugar() const { return QualType(this, 0); } |
3143 | |
3144 | static bool classof(const Type *T) { |
3145 | return T->getTypeClass() == DependentAddressSpace; |
3146 | } |
3147 | |
3148 | void Profile(llvm::FoldingSetNodeID &ID) { |
3149 | Profile(ID, Context, getPointeeType(), getAddrSpaceExpr()); |
3150 | } |
3151 | |
3152 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
3153 | QualType PointeeType, Expr *AddrSpaceExpr); |
3154 | }; |
3155 | |
3156 | /// Represents an extended vector type where either the type or size is |
3157 | /// dependent. |
3158 | /// |
3159 | /// For example: |
3160 | /// \code |
3161 | /// template<typename T, int Size> |
3162 | /// class vector { |
3163 | /// typedef T __attribute__((ext_vector_type(Size))) type; |
3164 | /// } |
3165 | /// \endcode |
3166 | class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { |
3167 | friend class ASTContext; |
3168 | |
3169 | const ASTContext &Context; |
3170 | Expr *SizeExpr; |
3171 | |
3172 | /// The element type of the array. |
3173 | QualType ElementType; |
3174 | |
3175 | SourceLocation loc; |
3176 | |
3177 | DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, |
3178 | QualType can, Expr *SizeExpr, SourceLocation loc); |
3179 | |
3180 | public: |
3181 | Expr *getSizeExpr() const { return SizeExpr; } |
3182 | QualType getElementType() const { return ElementType; } |
3183 | SourceLocation getAttributeLoc() const { return loc; } |
3184 | |
3185 | bool isSugared() const { return false; } |
3186 | QualType desugar() const { return QualType(this, 0); } |
3187 | |
3188 | static bool classof(const Type *T) { |
3189 | return T->getTypeClass() == DependentSizedExtVector; |
3190 | } |
3191 | |
3192 | void Profile(llvm::FoldingSetNodeID &ID) { |
3193 | Profile(ID, Context, getElementType(), getSizeExpr()); |
3194 | } |
3195 | |
3196 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
3197 | QualType ElementType, Expr *SizeExpr); |
3198 | }; |
3199 | |
3200 | |
3201 | /// Represents a GCC generic vector type. This type is created using |
3202 | /// __attribute__((vector_size(n)), where "n" specifies the vector size in |
3203 | /// bytes; or from an Altivec __vector or vector declaration. |
3204 | /// Since the constructor takes the number of vector elements, the |
3205 | /// client is responsible for converting the size into the number of elements. |
3206 | class VectorType : public Type, public llvm::FoldingSetNode { |
3207 | public: |
3208 | enum VectorKind { |
3209 | /// not a target-specific vector type |
3210 | GenericVector, |
3211 | |
3212 | /// is AltiVec vector |
3213 | AltiVecVector, |
3214 | |
3215 | /// is AltiVec 'vector Pixel' |
3216 | AltiVecPixel, |
3217 | |
3218 | /// is AltiVec 'vector bool ...' |
3219 | AltiVecBool, |
3220 | |
3221 | /// is ARM Neon vector |
3222 | NeonVector, |
3223 | |
3224 | /// is ARM Neon polynomial vector |
3225 | NeonPolyVector |
3226 | }; |
3227 | |
3228 | protected: |
3229 | friend class ASTContext; // ASTContext creates these. |
3230 | |
3231 | /// The element type of the vector. |
3232 | QualType ElementType; |
3233 | |
3234 | VectorType(QualType vecType, unsigned nElements, QualType canonType, |
3235 | VectorKind vecKind); |
3236 | |
3237 | VectorType(TypeClass tc, QualType vecType, unsigned nElements, |
3238 | QualType canonType, VectorKind vecKind); |
3239 | |
3240 | public: |
3241 | QualType getElementType() const { return ElementType; } |
3242 | unsigned getNumElements() const { return VectorTypeBits.NumElements; } |
3243 | |
3244 | static bool isVectorSizeTooLarge(unsigned NumElements) { |
3245 | return NumElements > VectorTypeBitfields::MaxNumElements; |
3246 | } |
3247 | |
3248 | bool isSugared() const { return false; } |
3249 | QualType desugar() const { return QualType(this, 0); } |
3250 | |
3251 | VectorKind getVectorKind() const { |
3252 | return VectorKind(VectorTypeBits.VecKind); |
3253 | } |
3254 | |
3255 | void Profile(llvm::FoldingSetNodeID &ID) { |
3256 | Profile(ID, getElementType(), getNumElements(), |
3257 | getTypeClass(), getVectorKind()); |
3258 | } |
3259 | |
3260 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, |
3261 | unsigned NumElements, TypeClass TypeClass, |
3262 | VectorKind VecKind) { |
3263 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
3264 | ID.AddInteger(NumElements); |
3265 | ID.AddInteger(TypeClass); |
3266 | ID.AddInteger(VecKind); |
3267 | } |
3268 | |
3269 | static bool classof(const Type *T) { |
3270 | return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; |
3271 | } |
3272 | }; |
3273 | |
3274 | /// Represents a vector type where either the type or size is dependent. |
3275 | //// |
3276 | /// For example: |
3277 | /// \code |
3278 | /// template<typename T, int Size> |
3279 | /// class vector { |
3280 | /// typedef T __attribute__((vector_size(Size))) type; |
3281 | /// } |
3282 | /// \endcode |
3283 | class DependentVectorType : public Type, public llvm::FoldingSetNode { |
3284 | friend class ASTContext; |
3285 | |
3286 | const ASTContext &Context; |
3287 | QualType ElementType; |
3288 | Expr *SizeExpr; |
3289 | SourceLocation Loc; |
3290 | |
3291 | DependentVectorType(const ASTContext &Context, QualType ElementType, |
3292 | QualType CanonType, Expr *SizeExpr, |
3293 | SourceLocation Loc, VectorType::VectorKind vecKind); |
3294 | |
3295 | public: |
3296 | Expr *getSizeExpr() const { return SizeExpr; } |
3297 | QualType getElementType() const { return ElementType; } |
3298 | SourceLocation getAttributeLoc() const { return Loc; } |
3299 | VectorType::VectorKind getVectorKind() const { |
3300 | return VectorType::VectorKind(VectorTypeBits.VecKind); |
3301 | } |
3302 | |
3303 | bool isSugared() const { return false; } |
3304 | QualType desugar() const { return QualType(this, 0); } |
3305 | |
3306 | static bool classof(const Type *T) { |
3307 | return T->getTypeClass() == DependentVector; |
3308 | } |
3309 | |
3310 | void Profile(llvm::FoldingSetNodeID &ID) { |
3311 | Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind()); |
3312 | } |
3313 | |
3314 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
3315 | QualType ElementType, const Expr *SizeExpr, |
3316 | VectorType::VectorKind VecKind); |
3317 | }; |
3318 | |
3319 | /// ExtVectorType - Extended vector type. This type is created using |
3320 | /// __attribute__((ext_vector_type(n)), where "n" is the number of elements. |
3321 | /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This |
3322 | /// class enables syntactic extensions, like Vector Components for accessing |
3323 | /// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL |
3324 | /// Shading Language). |
3325 | class ExtVectorType : public VectorType { |
3326 | friend class ASTContext; // ASTContext creates these. |
3327 | |
3328 | ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) |
3329 | : VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} |
3330 | |
3331 | public: |
3332 | static int getPointAccessorIdx(char c) { |
3333 | switch (c) { |
3334 | default: return -1; |
3335 | case 'x': case 'r': return 0; |
3336 | case 'y': case 'g': return 1; |
3337 | case 'z': case 'b': return 2; |
3338 | case 'w': case 'a': return 3; |
3339 | } |
3340 | } |
3341 | |
3342 | static int getNumericAccessorIdx(char c) { |
3343 | switch (c) { |
3344 | default: return -1; |
3345 | case '0': return 0; |
3346 | case '1': return 1; |
3347 | case '2': return 2; |
3348 | case '3': return 3; |
3349 | case '4': return 4; |
3350 | case '5': return 5; |
3351 | case '6': return 6; |
3352 | case '7': return 7; |
3353 | case '8': return 8; |
3354 | case '9': return 9; |
3355 | case 'A': |
3356 | case 'a': return 10; |
3357 | case 'B': |
3358 | case 'b': return 11; |
3359 | case 'C': |
3360 | case 'c': return 12; |
3361 | case 'D': |
3362 | case 'd': return 13; |
3363 | case 'E': |
3364 | case 'e': return 14; |
3365 | case 'F': |
3366 | case 'f': return 15; |
3367 | } |
3368 | } |
3369 | |
3370 | static int getAccessorIdx(char c, bool isNumericAccessor) { |
3371 | if (isNumericAccessor) |
3372 | return getNumericAccessorIdx(c); |
3373 | else |
3374 | return getPointAccessorIdx(c); |
3375 | } |
3376 | |
3377 | bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const { |
3378 | if (int idx = getAccessorIdx(c, isNumericAccessor)+1) |
3379 | return unsigned(idx-1) < getNumElements(); |
3380 | return false; |
3381 | } |
3382 | |
3383 | bool isSugared() const { return false; } |
3384 | QualType desugar() const { return QualType(this, 0); } |
3385 | |
3386 | static bool classof(const Type *T) { |
3387 | return T->getTypeClass() == ExtVector; |
3388 | } |
3389 | }; |
3390 | |
3391 | /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base |
3392 | /// class of FunctionNoProtoType and FunctionProtoType. |
3393 | class FunctionType : public Type { |
3394 | // The type returned by the function. |
3395 | QualType ResultType; |
3396 | |
3397 | public: |
3398 | /// Interesting information about a specific parameter that can't simply |
3399 | /// be reflected in parameter's type. This is only used by FunctionProtoType |
3400 | /// but is in FunctionType to make this class available during the |
3401 | /// specification of the bases of FunctionProtoType. |
3402 | /// |
3403 | /// It makes sense to model language features this way when there's some |
3404 | /// sort of parameter-specific override (such as an attribute) that |
3405 | /// affects how the function is called. For example, the ARC ns_consumed |
3406 | /// attribute changes whether a parameter is passed at +0 (the default) |
3407 | /// or +1 (ns_consumed). This must be reflected in the function type, |
3408 | /// but isn't really a change to the parameter type. |
3409 | /// |
3410 | /// One serious disadvantage of modelling language features this way is |
3411 | /// that they generally do not work with language features that attempt |
3412 | /// to destructure types. For example, template argument deduction will |
3413 | /// not be able to match a parameter declared as |
3414 | /// T (*)(U) |
3415 | /// against an argument of type |
3416 | /// void (*)(__attribute__((ns_consumed)) id) |
3417 | /// because the substitution of T=void, U=id into the former will |
3418 | /// not produce the latter. |
3419 | class ExtParameterInfo { |
3420 | enum { |
3421 | ABIMask = 0x0F, |
3422 | IsConsumed = 0x10, |
3423 | HasPassObjSize = 0x20, |
3424 | IsNoEscape = 0x40, |
3425 | }; |
3426 | unsigned char Data = 0; |
3427 | |
3428 | public: |
3429 | ExtParameterInfo() = default; |
3430 | |
3431 | /// Return the ABI treatment of this parameter. |
3432 | ParameterABI getABI() const { return ParameterABI(Data & ABIMask); } |
3433 | ExtParameterInfo withABI(ParameterABI kind) const { |
3434 | ExtParameterInfo copy = *this; |
3435 | copy.Data = (copy.Data & ~ABIMask) | unsigned(kind); |
3436 | return copy; |
3437 | } |
3438 | |
3439 | /// Is this parameter considered "consumed" by Objective-C ARC? |
3440 | /// Consumed parameters must have retainable object type. |
3441 | bool isConsumed() const { return (Data & IsConsumed); } |
3442 | ExtParameterInfo withIsConsumed(bool consumed) const { |
3443 | ExtParameterInfo copy = *this; |
3444 | if (consumed) |
3445 | copy.Data |= IsConsumed; |
3446 | else |
3447 | copy.Data &= ~IsConsumed; |
3448 | return copy; |
3449 | } |
3450 | |
3451 | bool hasPassObjectSize() const { return Data & HasPassObjSize; } |
3452 | ExtParameterInfo withHasPassObjectSize() const { |
3453 | ExtParameterInfo Copy = *this; |
3454 | Copy.Data |= HasPassObjSize; |
3455 | return Copy; |
3456 | } |
3457 | |
3458 | bool isNoEscape() const { return Data & IsNoEscape; } |
3459 | ExtParameterInfo withIsNoEscape(bool NoEscape) const { |
3460 | ExtParameterInfo Copy = *this; |
3461 | if (NoEscape) |
3462 | Copy.Data |= IsNoEscape; |
3463 | else |
3464 | Copy.Data &= ~IsNoEscape; |
3465 | return Copy; |
3466 | } |
3467 | |
3468 | unsigned char getOpaqueValue() const { return Data; } |
3469 | static ExtParameterInfo getFromOpaqueValue(unsigned char data) { |
3470 | ExtParameterInfo result; |
3471 | result.Data = data; |
3472 | return result; |
3473 | } |
3474 | |
3475 | friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs) { |
3476 | return lhs.Data == rhs.Data; |
3477 | } |
3478 | |
3479 | friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs) { |
3480 | return lhs.Data != rhs.Data; |
3481 | } |
3482 | }; |
3483 | |
3484 | /// A class which abstracts out some details necessary for |
3485 | /// making a call. |
3486 | /// |
3487 | /// It is not actually used directly for storing this information in |
3488 | /// a FunctionType, although FunctionType does currently use the |
3489 | /// same bit-pattern. |
3490 | /// |
3491 | // If you add a field (say Foo), other than the obvious places (both, |
3492 | // constructors, compile failures), what you need to update is |
3493 | // * Operator== |
3494 | // * getFoo |
3495 | // * withFoo |
3496 | // * functionType. Add Foo, getFoo. |
3497 | // * ASTContext::getFooType |
3498 | // * ASTContext::mergeFunctionTypes |
3499 | // * FunctionNoProtoType::Profile |
3500 | // * FunctionProtoType::Profile |
3501 | // * TypePrinter::PrintFunctionProto |
3502 | // * AST read and write |
3503 | // * Codegen |
3504 | class ExtInfo { |
3505 | friend class FunctionType; |
3506 | |
3507 | // Feel free to rearrange or add bits, but if you go over 12, |
3508 | // you'll need to adjust both the Bits field below and |
3509 | // Type::FunctionTypeBitfields. |
3510 | |
3511 | // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck| |
3512 | // |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 | |
3513 | // |
3514 | // regparm is either 0 (no regparm attribute) or the regparm value+1. |
3515 | enum { CallConvMask = 0x1F }; |
3516 | enum { NoReturnMask = 0x20 }; |
3517 | enum { ProducesResultMask = 0x40 }; |
3518 | enum { NoCallerSavedRegsMask = 0x80 }; |
3519 | enum { NoCfCheckMask = 0x800 }; |
3520 | enum { |
3521 | RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask | |
3522 | NoCallerSavedRegsMask | NoCfCheckMask), |
3523 | RegParmOffset = 8 |
3524 | }; // Assumed to be the last field |
3525 | uint16_t Bits = CC_C; |
3526 | |
3527 | ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {} |
3528 | |
3529 | public: |
3530 | // Constructor with no defaults. Use this when you know that you |
3531 | // have all the elements (when reading an AST file for example). |
3532 | ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, |
3533 | bool producesResult, bool noCallerSavedRegs, bool NoCfCheck) { |
3534 | assert((!hasRegParm || regParm < 7) && "Invalid regparm value")(((!hasRegParm || regParm < 7) && "Invalid regparm value" ) ? static_cast<void> (0) : __assert_fail ("(!hasRegParm || regParm < 7) && \"Invalid regparm value\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 3534, __PRETTY_FUNCTION__)); |
3535 | Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) | |
3536 | (producesResult ? ProducesResultMask : 0) | |
3537 | (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) | |
3538 | (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) | |
3539 | (NoCfCheck ? NoCfCheckMask : 0); |
3540 | } |
3541 | |
3542 | // Constructor with all defaults. Use when for example creating a |
3543 | // function known to use defaults. |
3544 | ExtInfo() = default; |
3545 | |
3546 | // Constructor with just the calling convention, which is an important part |
3547 | // of the canonical type. |
3548 | ExtInfo(CallingConv CC) : Bits(CC) {} |
3549 | |
3550 | bool getNoReturn() const { return Bits & NoReturnMask; } |
3551 | bool getProducesResult() const { return Bits & ProducesResultMask; } |
3552 | bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; } |
3553 | bool getNoCfCheck() const { return Bits & NoCfCheckMask; } |
3554 | bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; } |
3555 | |
3556 | unsigned getRegParm() const { |
3557 | unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset; |
3558 | if (RegParm > 0) |
3559 | --RegParm; |
3560 | return RegParm; |
3561 | } |
3562 | |
3563 | CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } |
3564 | |
3565 | bool operator==(ExtInfo Other) const { |
3566 | return Bits == Other.Bits; |
3567 | } |
3568 | bool operator!=(ExtInfo Other) const { |
3569 | return Bits != Other.Bits; |
3570 | } |
3571 | |
3572 | // Note that we don't have setters. That is by design, use |
3573 | // the following with methods instead of mutating these objects. |
3574 | |
3575 | ExtInfo withNoReturn(bool noReturn) const { |
3576 | if (noReturn) |
3577 | return ExtInfo(Bits | NoReturnMask); |
3578 | else |
3579 | return ExtInfo(Bits & ~NoReturnMask); |
3580 | } |
3581 | |
3582 | ExtInfo withProducesResult(bool producesResult) const { |
3583 | if (producesResult) |
3584 | return ExtInfo(Bits | ProducesResultMask); |
3585 | else |
3586 | return ExtInfo(Bits & ~ProducesResultMask); |
3587 | } |
3588 | |
3589 | ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const { |
3590 | if (noCallerSavedRegs) |
3591 | return ExtInfo(Bits | NoCallerSavedRegsMask); |
3592 | else |
3593 | return ExtInfo(Bits & ~NoCallerSavedRegsMask); |
3594 | } |
3595 | |
3596 | ExtInfo withNoCfCheck(bool noCfCheck) const { |
3597 | if (noCfCheck) |
3598 | return ExtInfo(Bits | NoCfCheckMask); |
3599 | else |
3600 | return ExtInfo(Bits & ~NoCfCheckMask); |
3601 | } |
3602 | |
3603 | ExtInfo withRegParm(unsigned RegParm) const { |
3604 | assert(RegParm < 7 && "Invalid regparm value")((RegParm < 7 && "Invalid regparm value") ? static_cast <void> (0) : __assert_fail ("RegParm < 7 && \"Invalid regparm value\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 3604, __PRETTY_FUNCTION__)); |
3605 | return ExtInfo((Bits & ~RegParmMask) | |
3606 | ((RegParm + 1) << RegParmOffset)); |
3607 | } |
3608 | |
3609 | ExtInfo withCallingConv(CallingConv cc) const { |
3610 | return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); |
3611 | } |
3612 | |
3613 | void Profile(llvm::FoldingSetNodeID &ID) const { |
3614 | ID.AddInteger(Bits); |
3615 | } |
3616 | }; |
3617 | |
3618 | /// A simple holder for a QualType representing a type in an |
3619 | /// exception specification. Unfortunately needed by FunctionProtoType |
3620 | /// because TrailingObjects cannot handle repeated types. |
3621 | struct ExceptionType { QualType Type; }; |
3622 | |
3623 | /// A simple holder for various uncommon bits which do not fit in |
3624 | /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the |
3625 | /// alignment of subsequent objects in TrailingObjects. You must update |
3626 | /// hasExtraBitfields in FunctionProtoType after adding extra data here. |
3627 | struct alignas(void *) FunctionTypeExtraBitfields { |
3628 | /// The number of types in the exception specification. |
3629 | /// A whole unsigned is not needed here and according to |
3630 | /// [implimits] 8 bits would be enough here. |
3631 | unsigned NumExceptionType; |
3632 | }; |
3633 | |
3634 | protected: |
3635 | FunctionType(TypeClass tc, QualType res, |
3636 | QualType Canonical, bool Dependent, |
3637 | bool InstantiationDependent, |
3638 | bool VariablyModified, bool ContainsUnexpandedParameterPack, |
3639 | ExtInfo Info) |
3640 | : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, |
3641 | ContainsUnexpandedParameterPack), |
3642 | ResultType(res) { |
3643 | FunctionTypeBits.ExtInfo = Info.Bits; |
3644 | } |
3645 | |
3646 | Qualifiers getFastTypeQuals() const { |
3647 | return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals); |
3648 | } |
3649 | |
3650 | public: |
3651 | QualType getReturnType() const { return ResultType; } |
3652 | |
3653 | bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } |
3654 | unsigned getRegParmType() const { return getExtInfo().getRegParm(); } |
3655 | |
3656 | /// Determine whether this function type includes the GNU noreturn |
3657 | /// attribute. The C++11 [[noreturn]] attribute does not affect the function |
3658 | /// type. |
3659 | bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } |
3660 | |
3661 | CallingConv getCallConv() const { return getExtInfo().getCC(); } |
3662 | ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } |
3663 | |
3664 | static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0, |
3665 | "Const, volatile and restrict are assumed to be a subset of " |
3666 | "the fast qualifiers."); |
3667 | |
3668 | bool isConst() const { return getFastTypeQuals().hasConst(); } |
3669 | bool isVolatile() const { return getFastTypeQuals().hasVolatile(); } |
3670 | bool isRestrict() const { return getFastTypeQuals().hasRestrict(); } |
3671 | |
3672 | /// Determine the type of an expression that calls a function of |
3673 | /// this type. |
3674 | QualType getCallResultType(const ASTContext &Context) const { |
3675 | return getReturnType().getNonLValueExprType(Context); |
3676 | } |
3677 | |
3678 | static StringRef getNameForCallConv(CallingConv CC); |
3679 | |
3680 | static bool classof(const Type *T) { |
3681 | return T->getTypeClass() == FunctionNoProto || |
3682 | T->getTypeClass() == FunctionProto; |
3683 | } |
3684 | }; |
3685 | |
3686 | /// Represents a K&R-style 'int foo()' function, which has |
3687 | /// no information available about its arguments. |
3688 | class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { |
3689 | friend class ASTContext; // ASTContext creates these. |
3690 | |
3691 | FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) |
3692 | : FunctionType(FunctionNoProto, Result, Canonical, |
3693 | /*Dependent=*/false, /*InstantiationDependent=*/false, |
3694 | Result->isVariablyModifiedType(), |
3695 | /*ContainsUnexpandedParameterPack=*/false, Info) {} |
3696 | |
3697 | public: |
3698 | // No additional state past what FunctionType provides. |
3699 | |
3700 | bool isSugared() const { return false; } |
3701 | QualType desugar() const { return QualType(this, 0); } |
3702 | |
3703 | void Profile(llvm::FoldingSetNodeID &ID) { |
3704 | Profile(ID, getReturnType(), getExtInfo()); |
3705 | } |
3706 | |
3707 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, |
3708 | ExtInfo Info) { |
3709 | Info.Profile(ID); |
3710 | ID.AddPointer(ResultType.getAsOpaquePtr()); |
3711 | } |
3712 | |
3713 | static bool classof(const Type *T) { |
3714 | return T->getTypeClass() == FunctionNoProto; |
3715 | } |
3716 | }; |
3717 | |
3718 | /// Represents a prototype with parameter type info, e.g. |
3719 | /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no |
3720 | /// parameters, not as having a single void parameter. Such a type can have |
3721 | /// an exception specification, but this specification is not part of the |
3722 | /// canonical type. FunctionProtoType has several trailing objects, some of |
3723 | /// which optional. For more information about the trailing objects see |
3724 | /// the first comment inside FunctionProtoType. |
3725 | class FunctionProtoType final |
3726 | : public FunctionType, |
3727 | public llvm::FoldingSetNode, |
3728 | private llvm::TrailingObjects< |
3729 | FunctionProtoType, QualType, FunctionType::FunctionTypeExtraBitfields, |
3730 | FunctionType::ExceptionType, Expr *, FunctionDecl *, |
3731 | FunctionType::ExtParameterInfo, Qualifiers> { |
3732 | friend class ASTContext; // ASTContext creates these. |
3733 | friend TrailingObjects; |
3734 | |
3735 | // FunctionProtoType is followed by several trailing objects, some of |
3736 | // which optional. They are in order: |
3737 | // |
3738 | // * An array of getNumParams() QualType holding the parameter types. |
3739 | // Always present. Note that for the vast majority of FunctionProtoType, |
3740 | // these will be the only trailing objects. |
3741 | // |
3742 | // * Optionally if some extra data is stored in FunctionTypeExtraBitfields |
3743 | // (see FunctionTypeExtraBitfields and FunctionTypeBitfields): |
3744 | // a single FunctionTypeExtraBitfields. Present if and only if |
3745 | // hasExtraBitfields() is true. |
3746 | // |
3747 | // * Optionally exactly one of: |
3748 | // * an array of getNumExceptions() ExceptionType, |
3749 | // * a single Expr *, |
3750 | // * a pair of FunctionDecl *, |
3751 | // * a single FunctionDecl * |
3752 | // used to store information about the various types of exception |
3753 | // specification. See getExceptionSpecSize for the details. |
3754 | // |
3755 | // * Optionally an array of getNumParams() ExtParameterInfo holding |
3756 | // an ExtParameterInfo for each of the parameters. Present if and |
3757 | // only if hasExtParameterInfos() is true. |
3758 | // |
3759 | // * Optionally a Qualifiers object to represent extra qualifiers that can't |
3760 | // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and only |
3761 | // if hasExtQualifiers() is true. |
3762 | // |
3763 | // The optional FunctionTypeExtraBitfields has to be before the data |
3764 | // related to the exception specification since it contains the number |
3765 | // of exception types. |
3766 | // |
3767 | // We put the ExtParameterInfos last. If all were equal, it would make |
3768 | // more sense to put these before the exception specification, because |
3769 | // it's much easier to skip past them compared to the elaborate switch |
3770 | // required to skip the exception specification. However, all is not |
3771 | // equal; ExtParameterInfos are used to model very uncommon features, |
3772 | // and it's better not to burden the more common paths. |
3773 | |
3774 | public: |
3775 | /// Holds information about the various types of exception specification. |
3776 | /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is |
3777 | /// used to group together the various bits of information about the |
3778 | /// exception specification. |
3779 | struct ExceptionSpecInfo { |
3780 | /// The kind of exception specification this is. |
3781 | ExceptionSpecificationType Type = EST_None; |
3782 | |
3783 | /// Explicitly-specified list of exception types. |
3784 | ArrayRef<QualType> Exceptions; |
3785 | |
3786 | /// Noexcept expression, if this is a computed noexcept specification. |
3787 | Expr *NoexceptExpr = nullptr; |
3788 | |
3789 | /// The function whose exception specification this is, for |
3790 | /// EST_Unevaluated and EST_Uninstantiated. |
3791 | FunctionDecl *SourceDecl = nullptr; |
3792 | |
3793 | /// The function template whose exception specification this is instantiated |
3794 | /// from, for EST_Uninstantiated. |
3795 | FunctionDecl *SourceTemplate = nullptr; |
3796 | |
3797 | ExceptionSpecInfo() = default; |
3798 | |
3799 | ExceptionSpecInfo(ExceptionSpecificationType EST) : Type(EST) {} |
3800 | }; |
3801 | |
3802 | /// Extra information about a function prototype. ExtProtoInfo is not |
3803 | /// stored as such in FunctionProtoType but is used to group together |
3804 | /// the various bits of extra information about a function prototype. |
3805 | struct ExtProtoInfo { |
3806 | FunctionType::ExtInfo ExtInfo; |
3807 | bool Variadic : 1; |
3808 | bool HasTrailingReturn : 1; |
3809 | Qualifiers TypeQuals; |
3810 | RefQualifierKind RefQualifier = RQ_None; |
3811 | ExceptionSpecInfo ExceptionSpec; |
3812 | const ExtParameterInfo *ExtParameterInfos = nullptr; |
3813 | |
3814 | ExtProtoInfo() : Variadic(false), HasTrailingReturn(false) {} |
3815 | |
3816 | ExtProtoInfo(CallingConv CC) |
3817 | : ExtInfo(CC), Variadic(false), HasTrailingReturn(false) {} |
3818 | |
3819 | ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI) { |
3820 | ExtProtoInfo Result(*this); |
3821 | Result.ExceptionSpec = ESI; |
3822 | return Result; |
3823 | } |
3824 | }; |
3825 | |
3826 | private: |
3827 | unsigned numTrailingObjects(OverloadToken<QualType>) const { |
3828 | return getNumParams(); |
3829 | } |
3830 | |
3831 | unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const { |
3832 | return hasExtraBitfields(); |
3833 | } |
3834 | |
3835 | unsigned numTrailingObjects(OverloadToken<ExceptionType>) const { |
3836 | return getExceptionSpecSize().NumExceptionType; |
3837 | } |
3838 | |
3839 | unsigned numTrailingObjects(OverloadToken<Expr *>) const { |
3840 | return getExceptionSpecSize().NumExprPtr; |
3841 | } |
3842 | |
3843 | unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const { |
3844 | return getExceptionSpecSize().NumFunctionDeclPtr; |
3845 | } |
3846 | |
3847 | unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const { |
3848 | return hasExtParameterInfos() ? getNumParams() : 0; |
3849 | } |
3850 | |
3851 | /// Determine whether there are any argument types that |
3852 | /// contain an unexpanded parameter pack. |
3853 | static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, |
3854 | unsigned numArgs) { |
3855 | for (unsigned Idx = 0; Idx < numArgs; ++Idx) |
3856 | if (ArgArray[Idx]->containsUnexpandedParameterPack()) |
3857 | return true; |
3858 | |
3859 | return false; |
3860 | } |
3861 | |
3862 | FunctionProtoType(QualType result, ArrayRef<QualType> params, |
3863 | QualType canonical, const ExtProtoInfo &epi); |
3864 | |
3865 | /// This struct is returned by getExceptionSpecSize and is used to |
3866 | /// translate an ExceptionSpecificationType to the number and kind |
3867 | /// of trailing objects related to the exception specification. |
3868 | struct ExceptionSpecSizeHolder { |
3869 | unsigned NumExceptionType; |
3870 | unsigned NumExprPtr; |
3871 | unsigned NumFunctionDeclPtr; |
3872 | }; |
3873 | |
3874 | /// Return the number and kind of trailing objects |
3875 | /// related to the exception specification. |
3876 | static ExceptionSpecSizeHolder |
3877 | getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) { |
3878 | switch (EST) { |
3879 | case EST_None: |
3880 | case EST_DynamicNone: |
3881 | case EST_MSAny: |
3882 | case EST_BasicNoexcept: |
3883 | case EST_Unparsed: |
3884 | case EST_NoThrow: |
3885 | return {0, 0, 0}; |
3886 | |
3887 | case EST_Dynamic: |
3888 | return {NumExceptions, 0, 0}; |
3889 | |
3890 | case EST_DependentNoexcept: |
3891 | case EST_NoexceptFalse: |
3892 | case EST_NoexceptTrue: |
3893 | return {0, 1, 0}; |
3894 | |
3895 | case EST_Uninstantiated: |
3896 | return {0, 0, 2}; |
3897 | |
3898 | case EST_Unevaluated: |
3899 | return {0, 0, 1}; |
3900 | } |
3901 | llvm_unreachable("bad exception specification kind")::llvm::llvm_unreachable_internal("bad exception specification kind" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 3901); |
3902 | } |
3903 | |
3904 | /// Return the number and kind of trailing objects |
3905 | /// related to the exception specification. |
3906 | ExceptionSpecSizeHolder getExceptionSpecSize() const { |
3907 | return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions()); |
3908 | } |
3909 | |
3910 | /// Whether the trailing FunctionTypeExtraBitfields is present. |
3911 | static bool hasExtraBitfields(ExceptionSpecificationType EST) { |
3912 | // If the exception spec type is EST_Dynamic then we have > 0 exception |
3913 | // types and the exact number is stored in FunctionTypeExtraBitfields. |
3914 | return EST == EST_Dynamic; |
3915 | } |
3916 | |
3917 | /// Whether the trailing FunctionTypeExtraBitfields is present. |
3918 | bool hasExtraBitfields() const { |
3919 | return hasExtraBitfields(getExceptionSpecType()); |
3920 | } |
3921 | |
3922 | bool hasExtQualifiers() const { |
3923 | return FunctionTypeBits.HasExtQuals; |
3924 | } |
3925 | |
3926 | public: |
3927 | unsigned getNumParams() const { return FunctionTypeBits.NumParams; } |
3928 | |
3929 | QualType getParamType(unsigned i) const { |
3930 | assert(i < getNumParams() && "invalid parameter index")((i < getNumParams() && "invalid parameter index") ? static_cast<void> (0) : __assert_fail ("i < getNumParams() && \"invalid parameter index\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 3930, __PRETTY_FUNCTION__)); |
3931 | return param_type_begin()[i]; |
3932 | } |
3933 | |
3934 | ArrayRef<QualType> getParamTypes() const { |
3935 | return llvm::makeArrayRef(param_type_begin(), param_type_end()); |
3936 | } |
3937 | |
3938 | ExtProtoInfo getExtProtoInfo() const { |
3939 | ExtProtoInfo EPI; |
3940 | EPI.ExtInfo = getExtInfo(); |
3941 | EPI.Variadic = isVariadic(); |
3942 | EPI.HasTrailingReturn = hasTrailingReturn(); |
3943 | EPI.ExceptionSpec.Type = getExceptionSpecType(); |
3944 | EPI.TypeQuals = getMethodQuals(); |
3945 | EPI.RefQualifier = getRefQualifier(); |
3946 | if (EPI.ExceptionSpec.Type == EST_Dynamic) { |
3947 | EPI.ExceptionSpec.Exceptions = exceptions(); |
3948 | } else if (isComputedNoexcept(EPI.ExceptionSpec.Type)) { |
3949 | EPI.ExceptionSpec.NoexceptExpr = getNoexceptExpr(); |
3950 | } else if (EPI.ExceptionSpec.Type == EST_Uninstantiated) { |
3951 | EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl(); |
3952 | EPI.ExceptionSpec.SourceTemplate = getExceptionSpecTemplate(); |
3953 | } else if (EPI.ExceptionSpec.Type == EST_Unevaluated) { |
3954 | EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl(); |
3955 | } |
3956 | EPI.ExtParameterInfos = getExtParameterInfosOrNull(); |
3957 | return EPI; |
3958 | } |
3959 | |
3960 | /// Get the kind of exception specification on this function. |
3961 | ExceptionSpecificationType getExceptionSpecType() const { |
3962 | return static_cast<ExceptionSpecificationType>( |
3963 | FunctionTypeBits.ExceptionSpecType); |
3964 | } |
3965 | |
3966 | /// Return whether this function has any kind of exception spec. |
3967 | bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; } |
3968 | |
3969 | /// Return whether this function has a dynamic (throw) exception spec. |
3970 | bool hasDynamicExceptionSpec() const { |
3971 | return isDynamicExceptionSpec(getExceptionSpecType()); |
3972 | } |
3973 | |
3974 | /// Return whether this function has a noexcept exception spec. |
3975 | bool hasNoexceptExceptionSpec() const { |
3976 | return isNoexceptExceptionSpec(getExceptionSpecType()); |
3977 | } |
3978 | |
3979 | /// Return whether this function has a dependent exception spec. |
3980 | bool hasDependentExceptionSpec() const; |
3981 | |
3982 | /// Return whether this function has an instantiation-dependent exception |
3983 | /// spec. |
3984 | bool hasInstantiationDependentExceptionSpec() const; |
3985 | |
3986 | /// Return the number of types in the exception specification. |
3987 | unsigned getNumExceptions() const { |
3988 | return getExceptionSpecType() == EST_Dynamic |
3989 | ? getTrailingObjects<FunctionTypeExtraBitfields>() |
3990 | ->NumExceptionType |
3991 | : 0; |
3992 | } |
3993 | |
3994 | /// Return the ith exception type, where 0 <= i < getNumExceptions(). |
3995 | QualType getExceptionType(unsigned i) const { |
3996 | assert(i < getNumExceptions() && "Invalid exception number!")((i < getNumExceptions() && "Invalid exception number!" ) ? static_cast<void> (0) : __assert_fail ("i < getNumExceptions() && \"Invalid exception number!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 3996, __PRETTY_FUNCTION__)); |
3997 | return exception_begin()[i]; |
3998 | } |
3999 | |
4000 | /// Return the expression inside noexcept(expression), or a null pointer |
4001 | /// if there is none (because the exception spec is not of this form). |
4002 | Expr *getNoexceptExpr() const { |
4003 | if (!isComputedNoexcept(getExceptionSpecType())) |
4004 | return nullptr; |
4005 | return *getTrailingObjects<Expr *>(); |
4006 | } |
4007 | |
4008 | /// If this function type has an exception specification which hasn't |
4009 | /// been determined yet (either because it has not been evaluated or because |
4010 | /// it has not been instantiated), this is the function whose exception |
4011 | /// specification is represented by this type. |
4012 | FunctionDecl *getExceptionSpecDecl() const { |
4013 | if (getExceptionSpecType() != EST_Uninstantiated && |
4014 | getExceptionSpecType() != EST_Unevaluated) |
4015 | return nullptr; |
4016 | return getTrailingObjects<FunctionDecl *>()[0]; |
4017 | } |
4018 | |
4019 | /// If this function type has an uninstantiated exception |
4020 | /// specification, this is the function whose exception specification |
4021 | /// should be instantiated to find the exception specification for |
4022 | /// this type. |
4023 | FunctionDecl *getExceptionSpecTemplate() const { |
4024 | if (getExceptionSpecType() != EST_Uninstantiated) |
4025 | return nullptr; |
4026 | return getTrailingObjects<FunctionDecl *>()[1]; |
4027 | } |
4028 | |
4029 | /// Determine whether this function type has a non-throwing exception |
4030 | /// specification. |
4031 | CanThrowResult canThrow() const; |
4032 | |
4033 | /// Determine whether this function type has a non-throwing exception |
4034 | /// specification. If this depends on template arguments, returns |
4035 | /// \c ResultIfDependent. |
4036 | bool isNothrow(bool ResultIfDependent = false) const { |
4037 | return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot; |
4038 | } |
4039 | |
4040 | /// Whether this function prototype is variadic. |
4041 | bool isVariadic() const { return FunctionTypeBits.Variadic; } |
4042 | |
4043 | /// Determines whether this function prototype contains a |
4044 | /// parameter pack at the end. |
4045 | /// |
4046 | /// A function template whose last parameter is a parameter pack can be |
4047 | /// called with an arbitrary number of arguments, much like a variadic |
4048 | /// function. |
4049 | bool isTemplateVariadic() const; |
4050 | |
4051 | /// Whether this function prototype has a trailing return type. |
4052 | bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; } |
4053 | |
4054 | Qualifiers getMethodQuals() const { |
4055 | if (hasExtQualifiers()) |
4056 | return *getTrailingObjects<Qualifiers>(); |
4057 | else |
4058 | return getFastTypeQuals(); |
4059 | } |
4060 | |
4061 | /// Retrieve the ref-qualifier associated with this function type. |
4062 | RefQualifierKind getRefQualifier() const { |
4063 | return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); |
4064 | } |
4065 | |
4066 | using param_type_iterator = const QualType *; |
4067 | using param_type_range = llvm::iterator_range<param_type_iterator>; |
4068 | |
4069 | param_type_range param_types() const { |
4070 | return param_type_range(param_type_begin(), param_type_end()); |
4071 | } |
4072 | |
4073 | param_type_iterator param_type_begin() const { |
4074 | return getTrailingObjects<QualType>(); |
4075 | } |
4076 | |
4077 | param_type_iterator param_type_end() const { |
4078 | return param_type_begin() + getNumParams(); |
4079 | } |
4080 | |
4081 | using exception_iterator = const QualType *; |
4082 | |
4083 | ArrayRef<QualType> exceptions() const { |
4084 | return llvm::makeArrayRef(exception_begin(), exception_end()); |
4085 | } |
4086 | |
4087 | exception_iterator exception_begin() const { |
4088 | return reinterpret_cast<exception_iterator>( |
4089 | getTrailingObjects<ExceptionType>()); |
4090 | } |
4091 | |
4092 | exception_iterator exception_end() const { |
4093 | return exception_begin() + getNumExceptions(); |
4094 | } |
4095 | |
4096 | /// Is there any interesting extra information for any of the parameters |
4097 | /// of this function type? |
4098 | bool hasExtParameterInfos() const { |
4099 | return FunctionTypeBits.HasExtParameterInfos; |
4100 | } |
4101 | |
4102 | ArrayRef<ExtParameterInfo> getExtParameterInfos() const { |
4103 | assert(hasExtParameterInfos())((hasExtParameterInfos()) ? static_cast<void> (0) : __assert_fail ("hasExtParameterInfos()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4103, __PRETTY_FUNCTION__)); |
4104 | return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(), |
4105 | getNumParams()); |
4106 | } |
4107 | |
4108 | /// Return a pointer to the beginning of the array of extra parameter |
4109 | /// information, if present, or else null if none of the parameters |
4110 | /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos. |
4111 | const ExtParameterInfo *getExtParameterInfosOrNull() const { |
4112 | if (!hasExtParameterInfos()) |
4113 | return nullptr; |
4114 | return getTrailingObjects<ExtParameterInfo>(); |
4115 | } |
4116 | |
4117 | ExtParameterInfo getExtParameterInfo(unsigned I) const { |
4118 | assert(I < getNumParams() && "parameter index out of range")((I < getNumParams() && "parameter index out of range" ) ? static_cast<void> (0) : __assert_fail ("I < getNumParams() && \"parameter index out of range\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4118, __PRETTY_FUNCTION__)); |
4119 | if (hasExtParameterInfos()) |
4120 | return getTrailingObjects<ExtParameterInfo>()[I]; |
4121 | return ExtParameterInfo(); |
4122 | } |
4123 | |
4124 | ParameterABI getParameterABI(unsigned I) const { |
4125 | assert(I < getNumParams() && "parameter index out of range")((I < getNumParams() && "parameter index out of range" ) ? static_cast<void> (0) : __assert_fail ("I < getNumParams() && \"parameter index out of range\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4125, __PRETTY_FUNCTION__)); |
4126 | if (hasExtParameterInfos()) |
4127 | return getTrailingObjects<ExtParameterInfo>()[I].getABI(); |
4128 | return ParameterABI::Ordinary; |
4129 | } |
4130 | |
4131 | bool isParamConsumed(unsigned I) const { |
4132 | assert(I < getNumParams() && "parameter index out of range")((I < getNumParams() && "parameter index out of range" ) ? static_cast<void> (0) : __assert_fail ("I < getNumParams() && \"parameter index out of range\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4132, __PRETTY_FUNCTION__)); |
4133 | if (hasExtParameterInfos()) |
4134 | return getTrailingObjects<ExtParameterInfo>()[I].isConsumed(); |
4135 | return false; |
4136 | } |
4137 | |
4138 | bool isSugared() const { return false; } |
4139 | QualType desugar() const { return QualType(this, 0); } |
4140 | |
4141 | void printExceptionSpecification(raw_ostream &OS, |
4142 | const PrintingPolicy &Policy) const; |
4143 | |
4144 | static bool classof(const Type *T) { |
4145 | return T->getTypeClass() == FunctionProto; |
4146 | } |
4147 | |
4148 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); |
4149 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
4150 | param_type_iterator ArgTys, unsigned NumArgs, |
4151 | const ExtProtoInfo &EPI, const ASTContext &Context, |
4152 | bool Canonical); |
4153 | }; |
4154 | |
4155 | /// Represents the dependent type named by a dependently-scoped |
4156 | /// typename using declaration, e.g. |
4157 | /// using typename Base<T>::foo; |
4158 | /// |
4159 | /// Template instantiation turns these into the underlying type. |
4160 | class UnresolvedUsingType : public Type { |
4161 | friend class ASTContext; // ASTContext creates these. |
4162 | |
4163 | UnresolvedUsingTypenameDecl *Decl; |
4164 | |
4165 | UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) |
4166 | : Type(UnresolvedUsing, QualType(), true, true, false, |
4167 | /*ContainsUnexpandedParameterPack=*/false), |
4168 | Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} |
4169 | |
4170 | public: |
4171 | UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } |
4172 | |
4173 | bool isSugared() const { return false; } |
4174 | QualType desugar() const { return QualType(this, 0); } |
4175 | |
4176 | static bool classof(const Type *T) { |
4177 | return T->getTypeClass() == UnresolvedUsing; |
4178 | } |
4179 | |
4180 | void Profile(llvm::FoldingSetNodeID &ID) { |
4181 | return Profile(ID, Decl); |
4182 | } |
4183 | |
4184 | static void Profile(llvm::FoldingSetNodeID &ID, |
4185 | UnresolvedUsingTypenameDecl *D) { |
4186 | ID.AddPointer(D); |
4187 | } |
4188 | }; |
4189 | |
4190 | class TypedefType : public Type { |
4191 | TypedefNameDecl *Decl; |
4192 | |
4193 | protected: |
4194 | friend class ASTContext; // ASTContext creates these. |
4195 | |
4196 | TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can) |
4197 | : Type(tc, can, can->isDependentType(), |
4198 | can->isInstantiationDependentType(), |
4199 | can->isVariablyModifiedType(), |
4200 | /*ContainsUnexpandedParameterPack=*/false), |
4201 | Decl(const_cast<TypedefNameDecl*>(D)) { |
4202 | assert(!isa<TypedefType>(can) && "Invalid canonical type")((!isa<TypedefType>(can) && "Invalid canonical type" ) ? static_cast<void> (0) : __assert_fail ("!isa<TypedefType>(can) && \"Invalid canonical type\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4202, __PRETTY_FUNCTION__)); |
4203 | } |
4204 | |
4205 | public: |
4206 | TypedefNameDecl *getDecl() const { return Decl; } |
4207 | |
4208 | bool isSugared() const { return true; } |
4209 | QualType desugar() const; |
4210 | |
4211 | static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } |
4212 | }; |
4213 | |
4214 | /// Sugar type that represents a type that was qualified by a qualifier written |
4215 | /// as a macro invocation. |
4216 | class MacroQualifiedType : public Type { |
4217 | friend class ASTContext; // ASTContext creates these. |
4218 | |
4219 | QualType UnderlyingTy; |
4220 | const IdentifierInfo *MacroII; |
4221 | |
4222 | MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy, |
4223 | const IdentifierInfo *MacroII) |
4224 | : Type(MacroQualified, CanonTy, UnderlyingTy->isDependentType(), |
4225 | UnderlyingTy->isInstantiationDependentType(), |
4226 | UnderlyingTy->isVariablyModifiedType(), |
4227 | UnderlyingTy->containsUnexpandedParameterPack()), |
4228 | UnderlyingTy(UnderlyingTy), MacroII(MacroII) { |
4229 | assert(isa<AttributedType>(UnderlyingTy) &&((isa<AttributedType>(UnderlyingTy) && "Expected a macro qualified type to only wrap attributed types." ) ? static_cast<void> (0) : __assert_fail ("isa<AttributedType>(UnderlyingTy) && \"Expected a macro qualified type to only wrap attributed types.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4230, __PRETTY_FUNCTION__)) |
4230 | "Expected a macro qualified type to only wrap attributed types.")((isa<AttributedType>(UnderlyingTy) && "Expected a macro qualified type to only wrap attributed types." ) ? static_cast<void> (0) : __assert_fail ("isa<AttributedType>(UnderlyingTy) && \"Expected a macro qualified type to only wrap attributed types.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4230, __PRETTY_FUNCTION__)); |
4231 | } |
4232 | |
4233 | public: |
4234 | const IdentifierInfo *getMacroIdentifier() const { return MacroII; } |
4235 | QualType getUnderlyingType() const { return UnderlyingTy; } |
4236 | |
4237 | /// Return this attributed type's modified type with no qualifiers attached to |
4238 | /// it. |
4239 | QualType getModifiedType() const; |
4240 | |
4241 | bool isSugared() const { return true; } |
4242 | QualType desugar() const; |
4243 | |
4244 | static bool classof(const Type *T) { |
4245 | return T->getTypeClass() == MacroQualified; |
4246 | } |
4247 | }; |
4248 | |
4249 | /// Represents a `typeof` (or __typeof__) expression (a GCC extension). |
4250 | class TypeOfExprType : public Type { |
4251 | Expr *TOExpr; |
4252 | |
4253 | protected: |
4254 | friend class ASTContext; // ASTContext creates these. |
4255 | |
4256 | TypeOfExprType(Expr *E, QualType can = QualType()); |
4257 | |
4258 | public: |
4259 | Expr *getUnderlyingExpr() const { return TOExpr; } |
4260 | |
4261 | /// Remove a single level of sugar. |
4262 | QualType desugar() const; |
4263 | |
4264 | /// Returns whether this type directly provides sugar. |
4265 | bool isSugared() const; |
4266 | |
4267 | static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } |
4268 | }; |
4269 | |
4270 | /// Internal representation of canonical, dependent |
4271 | /// `typeof(expr)` types. |
4272 | /// |
4273 | /// This class is used internally by the ASTContext to manage |
4274 | /// canonical, dependent types, only. Clients will only see instances |
4275 | /// of this class via TypeOfExprType nodes. |
4276 | class DependentTypeOfExprType |
4277 | : public TypeOfExprType, public llvm::FoldingSetNode { |
4278 | const ASTContext &Context; |
4279 | |
4280 | public: |
4281 | DependentTypeOfExprType(const ASTContext &Context, Expr *E) |
4282 | : TypeOfExprType(E), Context(Context) {} |
4283 | |
4284 | void Profile(llvm::FoldingSetNodeID &ID) { |
4285 | Profile(ID, Context, getUnderlyingExpr()); |
4286 | } |
4287 | |
4288 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
4289 | Expr *E); |
4290 | }; |
4291 | |
4292 | /// Represents `typeof(type)`, a GCC extension. |
4293 | class TypeOfType : public Type { |
4294 | friend class ASTContext; // ASTContext creates these. |
4295 | |
4296 | QualType TOType; |
4297 | |
4298 | TypeOfType(QualType T, QualType can) |
4299 | : Type(TypeOf, can, T->isDependentType(), |
4300 | T->isInstantiationDependentType(), |
4301 | T->isVariablyModifiedType(), |
4302 | T->containsUnexpandedParameterPack()), |
4303 | TOType(T) { |
4304 | assert(!isa<TypedefType>(can) && "Invalid canonical type")((!isa<TypedefType>(can) && "Invalid canonical type" ) ? static_cast<void> (0) : __assert_fail ("!isa<TypedefType>(can) && \"Invalid canonical type\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4304, __PRETTY_FUNCTION__)); |
4305 | } |
4306 | |
4307 | public: |
4308 | QualType getUnderlyingType() const { return TOType; } |
4309 | |
4310 | /// Remove a single level of sugar. |
4311 | QualType desugar() const { return getUnderlyingType(); } |
4312 | |
4313 | /// Returns whether this type directly provides sugar. |
4314 | bool isSugared() const { return true; } |
4315 | |
4316 | static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } |
4317 | }; |
4318 | |
4319 | /// Represents the type `decltype(expr)` (C++11). |
4320 | class DecltypeType : public Type { |
4321 | Expr *E; |
4322 | QualType UnderlyingType; |
4323 | |
4324 | protected: |
4325 | friend class ASTContext; // ASTContext creates these. |
4326 | |
4327 | DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); |
4328 | |
4329 | public: |
4330 | Expr *getUnderlyingExpr() const { return E; } |
4331 | QualType getUnderlyingType() const { return UnderlyingType; } |
4332 | |
4333 | /// Remove a single level of sugar. |
4334 | QualType desugar() const; |
4335 | |
4336 | /// Returns whether this type directly provides sugar. |
4337 | bool isSugared() const; |
4338 | |
4339 | static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } |
4340 | }; |
4341 | |
4342 | /// Internal representation of canonical, dependent |
4343 | /// decltype(expr) types. |
4344 | /// |
4345 | /// This class is used internally by the ASTContext to manage |
4346 | /// canonical, dependent types, only. Clients will only see instances |
4347 | /// of this class via DecltypeType nodes. |
4348 | class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { |
4349 | const ASTContext &Context; |
4350 | |
4351 | public: |
4352 | DependentDecltypeType(const ASTContext &Context, Expr *E); |
4353 | |
4354 | void Profile(llvm::FoldingSetNodeID &ID) { |
4355 | Profile(ID, Context, getUnderlyingExpr()); |
4356 | } |
4357 | |
4358 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
4359 | Expr *E); |
4360 | }; |
4361 | |
4362 | /// A unary type transform, which is a type constructed from another. |
4363 | class UnaryTransformType : public Type { |
4364 | public: |
4365 | enum UTTKind { |
4366 | EnumUnderlyingType |
4367 | }; |
4368 | |
4369 | private: |
4370 | /// The untransformed type. |
4371 | QualType BaseType; |
4372 | |
4373 | /// The transformed type if not dependent, otherwise the same as BaseType. |
4374 | QualType UnderlyingType; |
4375 | |
4376 | UTTKind UKind; |
4377 | |
4378 | protected: |
4379 | friend class ASTContext; |
4380 | |
4381 | UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, |
4382 | QualType CanonicalTy); |
4383 | |
4384 | public: |
4385 | bool isSugared() const { return !isDependentType(); } |
4386 | QualType desugar() const { return UnderlyingType; } |
4387 | |
4388 | QualType getUnderlyingType() const { return UnderlyingType; } |
4389 | QualType getBaseType() const { return BaseType; } |
4390 | |
4391 | UTTKind getUTTKind() const { return UKind; } |
4392 | |
4393 | static bool classof(const Type *T) { |
4394 | return T->getTypeClass() == UnaryTransform; |
4395 | } |
4396 | }; |
4397 | |
4398 | /// Internal representation of canonical, dependent |
4399 | /// __underlying_type(type) types. |
4400 | /// |
4401 | /// This class is used internally by the ASTContext to manage |
4402 | /// canonical, dependent types, only. Clients will only see instances |
4403 | /// of this class via UnaryTransformType nodes. |
4404 | class DependentUnaryTransformType : public UnaryTransformType, |
4405 | public llvm::FoldingSetNode { |
4406 | public: |
4407 | DependentUnaryTransformType(const ASTContext &C, QualType BaseType, |
4408 | UTTKind UKind); |
4409 | |
4410 | void Profile(llvm::FoldingSetNodeID &ID) { |
4411 | Profile(ID, getBaseType(), getUTTKind()); |
4412 | } |
4413 | |
4414 | static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, |
4415 | UTTKind UKind) { |
4416 | ID.AddPointer(BaseType.getAsOpaquePtr()); |
4417 | ID.AddInteger((unsigned)UKind); |
4418 | } |
4419 | }; |
4420 | |
4421 | class TagType : public Type { |
4422 | friend class ASTReader; |
4423 | |
4424 | /// Stores the TagDecl associated with this type. The decl may point to any |
4425 | /// TagDecl that declares the entity. |
4426 | TagDecl *decl; |
4427 | |
4428 | protected: |
4429 | TagType(TypeClass TC, const TagDecl *D, QualType can); |
4430 | |
4431 | public: |
4432 | TagDecl *getDecl() const; |
4433 | |
4434 | /// Determines whether this type is in the process of being defined. |
4435 | bool isBeingDefined() const; |
4436 | |
4437 | static bool classof(const Type *T) { |
4438 | return T->getTypeClass() == Enum || T->getTypeClass() == Record; |
4439 | } |
4440 | }; |
4441 | |
4442 | /// A helper class that allows the use of isa/cast/dyncast |
4443 | /// to detect TagType objects of structs/unions/classes. |
4444 | class RecordType : public TagType { |
4445 | protected: |
4446 | friend class ASTContext; // ASTContext creates these. |
4447 | |
4448 | explicit RecordType(const RecordDecl *D) |
4449 | : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {} |
4450 | explicit RecordType(TypeClass TC, RecordDecl *D) |
4451 | : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {} |
4452 | |
4453 | public: |
4454 | RecordDecl *getDecl() const { |
4455 | return reinterpret_cast<RecordDecl*>(TagType::getDecl()); |
4456 | } |
4457 | |
4458 | /// Recursively check all fields in the record for const-ness. If any field |
4459 | /// is declared const, return true. Otherwise, return false. |
4460 | bool hasConstFields() const; |
4461 | |
4462 | bool isSugared() const { return false; } |
4463 | QualType desugar() const { return QualType(this, 0); } |
4464 | |
4465 | static bool classof(const Type *T) { return T->getTypeClass() == Record; } |
4466 | }; |
4467 | |
4468 | /// A helper class that allows the use of isa/cast/dyncast |
4469 | /// to detect TagType objects of enums. |
4470 | class EnumType : public TagType { |
4471 | friend class ASTContext; // ASTContext creates these. |
4472 | |
4473 | explicit EnumType(const EnumDecl *D) |
4474 | : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {} |
4475 | |
4476 | public: |
4477 | EnumDecl *getDecl() const { |
4478 | return reinterpret_cast<EnumDecl*>(TagType::getDecl()); |
4479 | } |
4480 | |
4481 | bool isSugared() const { return false; } |
4482 | QualType desugar() const { return QualType(this, 0); } |
4483 | |
4484 | static bool classof(const Type *T) { return T->getTypeClass() == Enum; } |
4485 | }; |
4486 | |
4487 | /// An attributed type is a type to which a type attribute has been applied. |
4488 | /// |
4489 | /// The "modified type" is the fully-sugared type to which the attributed |
4490 | /// type was applied; generally it is not canonically equivalent to the |
4491 | /// attributed type. The "equivalent type" is the minimally-desugared type |
4492 | /// which the type is canonically equivalent to. |
4493 | /// |
4494 | /// For example, in the following attributed type: |
4495 | /// int32_t __attribute__((vector_size(16))) |
4496 | /// - the modified type is the TypedefType for int32_t |
4497 | /// - the equivalent type is VectorType(16, int32_t) |
4498 | /// - the canonical type is VectorType(16, int) |
4499 | class AttributedType : public Type, public llvm::FoldingSetNode { |
4500 | public: |
4501 | using Kind = attr::Kind; |
4502 | |
4503 | private: |
4504 | friend class ASTContext; // ASTContext creates these |
4505 | |
4506 | QualType ModifiedType; |
4507 | QualType EquivalentType; |
4508 | |
4509 | AttributedType(QualType canon, attr::Kind attrKind, QualType modified, |
4510 | QualType equivalent) |
4511 | : Type(Attributed, canon, equivalent->isDependentType(), |
4512 | equivalent->isInstantiationDependentType(), |
4513 | equivalent->isVariablyModifiedType(), |
4514 | equivalent->containsUnexpandedParameterPack()), |
4515 | ModifiedType(modified), EquivalentType(equivalent) { |
4516 | AttributedTypeBits.AttrKind = attrKind; |
4517 | } |
4518 | |
4519 | public: |
4520 | Kind getAttrKind() const { |
4521 | return static_cast<Kind>(AttributedTypeBits.AttrKind); |
4522 | } |
4523 | |
4524 | QualType getModifiedType() const { return ModifiedType; } |
4525 | QualType getEquivalentType() const { return EquivalentType; } |
4526 | |
4527 | bool isSugared() const { return true; } |
4528 | QualType desugar() const { return getEquivalentType(); } |
4529 | |
4530 | /// Does this attribute behave like a type qualifier? |
4531 | /// |
4532 | /// A type qualifier adjusts a type to provide specialized rules for |
4533 | /// a specific object, like the standard const and volatile qualifiers. |
4534 | /// This includes attributes controlling things like nullability, |
4535 | /// address spaces, and ARC ownership. The value of the object is still |
4536 | /// largely described by the modified type. |
4537 | /// |
4538 | /// In contrast, many type attributes "rewrite" their modified type to |
4539 | /// produce a fundamentally different type, not necessarily related in any |
4540 | /// formalizable way to the original type. For example, calling convention |
4541 | /// and vector attributes are not simple type qualifiers. |
4542 | /// |
4543 | /// Type qualifiers are often, but not always, reflected in the canonical |
4544 | /// type. |
4545 | bool isQualifier() const; |
4546 | |
4547 | bool isMSTypeSpec() const; |
4548 | |
4549 | bool isCallingConv() const; |
4550 | |
4551 | llvm::Optional<NullabilityKind> getImmediateNullability() const; |
4552 | |
4553 | /// Retrieve the attribute kind corresponding to the given |
4554 | /// nullability kind. |
4555 | static Kind getNullabilityAttrKind(NullabilityKind kind) { |
4556 | switch (kind) { |
4557 | case NullabilityKind::NonNull: |
4558 | return attr::TypeNonNull; |
4559 | |
4560 | case NullabilityKind::Nullable: |
4561 | return attr::TypeNullable; |
4562 | |
4563 | case NullabilityKind::Unspecified: |
4564 | return attr::TypeNullUnspecified; |
4565 | } |
4566 | llvm_unreachable("Unknown nullability kind.")::llvm::llvm_unreachable_internal("Unknown nullability kind." , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4566); |
4567 | } |
4568 | |
4569 | /// Strip off the top-level nullability annotation on the given |
4570 | /// type, if it's there. |
4571 | /// |
4572 | /// \param T The type to strip. If the type is exactly an |
4573 | /// AttributedType specifying nullability (without looking through |
4574 | /// type sugar), the nullability is returned and this type changed |
4575 | /// to the underlying modified type. |
4576 | /// |
4577 | /// \returns the top-level nullability, if present. |
4578 | static Optional<NullabilityKind> stripOuterNullability(QualType &T); |
4579 | |
4580 | void Profile(llvm::FoldingSetNodeID &ID) { |
4581 | Profile(ID, getAttrKind(), ModifiedType, EquivalentType); |
4582 | } |
4583 | |
4584 | static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, |
4585 | QualType modified, QualType equivalent) { |
4586 | ID.AddInteger(attrKind); |
4587 | ID.AddPointer(modified.getAsOpaquePtr()); |
4588 | ID.AddPointer(equivalent.getAsOpaquePtr()); |
4589 | } |
4590 | |
4591 | static bool classof(const Type *T) { |
4592 | return T->getTypeClass() == Attributed; |
4593 | } |
4594 | }; |
4595 | |
4596 | class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { |
4597 | friend class ASTContext; // ASTContext creates these |
4598 | |
4599 | // Helper data collector for canonical types. |
4600 | struct CanonicalTTPTInfo { |
4601 | unsigned Depth : 15; |
4602 | unsigned ParameterPack : 1; |
4603 | unsigned Index : 16; |
4604 | }; |
4605 | |
4606 | union { |
4607 | // Info for the canonical type. |
4608 | CanonicalTTPTInfo CanTTPTInfo; |
4609 | |
4610 | // Info for the non-canonical type. |
4611 | TemplateTypeParmDecl *TTPDecl; |
4612 | }; |
4613 | |
4614 | /// Build a non-canonical type. |
4615 | TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) |
4616 | : Type(TemplateTypeParm, Canon, /*Dependent=*/true, |
4617 | /*InstantiationDependent=*/true, |
4618 | /*VariablyModified=*/false, |
4619 | Canon->containsUnexpandedParameterPack()), |
4620 | TTPDecl(TTPDecl) {} |
4621 | |
4622 | /// Build the canonical type. |
4623 | TemplateTypeParmType(unsigned D, unsigned I, bool PP) |
4624 | : Type(TemplateTypeParm, QualType(this, 0), |
4625 | /*Dependent=*/true, |
4626 | /*InstantiationDependent=*/true, |
4627 | /*VariablyModified=*/false, PP) { |
4628 | CanTTPTInfo.Depth = D; |
4629 | CanTTPTInfo.Index = I; |
4630 | CanTTPTInfo.ParameterPack = PP; |
4631 | } |
4632 | |
4633 | const CanonicalTTPTInfo& getCanTTPTInfo() const { |
4634 | QualType Can = getCanonicalTypeInternal(); |
4635 | return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo; |
4636 | } |
4637 | |
4638 | public: |
4639 | unsigned getDepth() const { return getCanTTPTInfo().Depth; } |
4640 | unsigned getIndex() const { return getCanTTPTInfo().Index; } |
4641 | bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } |
4642 | |
4643 | TemplateTypeParmDecl *getDecl() const { |
4644 | return isCanonicalUnqualified() ? nullptr : TTPDecl; |
4645 | } |
4646 | |
4647 | IdentifierInfo *getIdentifier() const; |
4648 | |
4649 | bool isSugared() const { return false; } |
4650 | QualType desugar() const { return QualType(this, 0); } |
4651 | |
4652 | void Profile(llvm::FoldingSetNodeID &ID) { |
4653 | Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); |
4654 | } |
4655 | |
4656 | static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, |
4657 | unsigned Index, bool ParameterPack, |
4658 | TemplateTypeParmDecl *TTPDecl) { |
4659 | ID.AddInteger(Depth); |
4660 | ID.AddInteger(Index); |
4661 | ID.AddBoolean(ParameterPack); |
4662 | ID.AddPointer(TTPDecl); |
4663 | } |
4664 | |
4665 | static bool classof(const Type *T) { |
4666 | return T->getTypeClass() == TemplateTypeParm; |
4667 | } |
4668 | }; |
4669 | |
4670 | /// Represents the result of substituting a type for a template |
4671 | /// type parameter. |
4672 | /// |
4673 | /// Within an instantiated template, all template type parameters have |
4674 | /// been replaced with these. They are used solely to record that a |
4675 | /// type was originally written as a template type parameter; |
4676 | /// therefore they are never canonical. |
4677 | class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { |
4678 | friend class ASTContext; |
4679 | |
4680 | // The original type parameter. |
4681 | const TemplateTypeParmType *Replaced; |
4682 | |
4683 | SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) |
4684 | : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), |
4685 | Canon->isInstantiationDependentType(), |
4686 | Canon->isVariablyModifiedType(), |
4687 | Canon->containsUnexpandedParameterPack()), |
4688 | Replaced(Param) {} |
4689 | |
4690 | public: |
4691 | /// Gets the template parameter that was substituted for. |
4692 | const TemplateTypeParmType *getReplacedParameter() const { |
4693 | return Replaced; |
4694 | } |
4695 | |
4696 | /// Gets the type that was substituted for the template |
4697 | /// parameter. |
4698 | QualType getReplacementType() const { |
4699 | return getCanonicalTypeInternal(); |
4700 | } |
4701 | |
4702 | bool isSugared() const { return true; } |
4703 | QualType desugar() const { return getReplacementType(); } |
4704 | |
4705 | void Profile(llvm::FoldingSetNodeID &ID) { |
4706 | Profile(ID, getReplacedParameter(), getReplacementType()); |
4707 | } |
4708 | |
4709 | static void Profile(llvm::FoldingSetNodeID &ID, |
4710 | const TemplateTypeParmType *Replaced, |
4711 | QualType Replacement) { |
4712 | ID.AddPointer(Replaced); |
4713 | ID.AddPointer(Replacement.getAsOpaquePtr()); |
4714 | } |
4715 | |
4716 | static bool classof(const Type *T) { |
4717 | return T->getTypeClass() == SubstTemplateTypeParm; |
4718 | } |
4719 | }; |
4720 | |
4721 | /// Represents the result of substituting a set of types for a template |
4722 | /// type parameter pack. |
4723 | /// |
4724 | /// When a pack expansion in the source code contains multiple parameter packs |
4725 | /// and those parameter packs correspond to different levels of template |
4726 | /// parameter lists, this type node is used to represent a template type |
4727 | /// parameter pack from an outer level, which has already had its argument pack |
4728 | /// substituted but that still lives within a pack expansion that itself |
4729 | /// could not be instantiated. When actually performing a substitution into |
4730 | /// that pack expansion (e.g., when all template parameters have corresponding |
4731 | /// arguments), this type will be replaced with the \c SubstTemplateTypeParmType |
4732 | /// at the current pack substitution index. |
4733 | class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { |
4734 | friend class ASTContext; |
4735 | |
4736 | /// The original type parameter. |
4737 | const TemplateTypeParmType *Replaced; |
4738 | |
4739 | /// A pointer to the set of template arguments that this |
4740 | /// parameter pack is instantiated with. |
4741 | const TemplateArgument *Arguments; |
4742 | |
4743 | SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, |
4744 | QualType Canon, |
4745 | const TemplateArgument &ArgPack); |
4746 | |
4747 | public: |
4748 | IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); } |
4749 | |
4750 | /// Gets the template parameter that was substituted for. |
4751 | const TemplateTypeParmType *getReplacedParameter() const { |
4752 | return Replaced; |
4753 | } |
4754 | |
4755 | unsigned getNumArgs() const { |
4756 | return SubstTemplateTypeParmPackTypeBits.NumArgs; |
4757 | } |
4758 | |
4759 | bool isSugared() const { return false; } |
4760 | QualType desugar() const { return QualType(this, 0); } |
4761 | |
4762 | TemplateArgument getArgumentPack() const; |
4763 | |
4764 | void Profile(llvm::FoldingSetNodeID &ID); |
4765 | static void Profile(llvm::FoldingSetNodeID &ID, |
4766 | const TemplateTypeParmType *Replaced, |
4767 | const TemplateArgument &ArgPack); |
4768 | |
4769 | static bool classof(const Type *T) { |
4770 | return T->getTypeClass() == SubstTemplateTypeParmPack; |
4771 | } |
4772 | }; |
4773 | |
4774 | /// Common base class for placeholders for types that get replaced by |
4775 | /// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced |
4776 | /// class template types, and (eventually) constrained type names from the C++ |
4777 | /// Concepts TS. |
4778 | /// |
4779 | /// These types are usually a placeholder for a deduced type. However, before |
4780 | /// the initializer is attached, or (usually) if the initializer is |
4781 | /// type-dependent, there is no deduced type and the type is canonical. In |
4782 | /// the latter case, it is also a dependent type. |
4783 | class DeducedType : public Type { |
4784 | protected: |
4785 | DeducedType(TypeClass TC, QualType DeducedAsType, bool IsDependent, |
4786 | bool IsInstantiationDependent, bool ContainsParameterPack) |
4787 | : Type(TC, |
4788 | // FIXME: Retain the sugared deduced type? |
4789 | DeducedAsType.isNull() ? QualType(this, 0) |
4790 | : DeducedAsType.getCanonicalType(), |
4791 | IsDependent, IsInstantiationDependent, |
4792 | /*VariablyModified=*/false, ContainsParameterPack) { |
4793 | if (!DeducedAsType.isNull()) { |
4794 | if (DeducedAsType->isDependentType()) |
4795 | setDependent(); |
4796 | if (DeducedAsType->isInstantiationDependentType()) |
4797 | setInstantiationDependent(); |
4798 | if (DeducedAsType->containsUnexpandedParameterPack()) |
4799 | setContainsUnexpandedParameterPack(); |
4800 | } |
4801 | } |
4802 | |
4803 | public: |
4804 | bool isSugared() const { return !isCanonicalUnqualified(); } |
4805 | QualType desugar() const { return getCanonicalTypeInternal(); } |
4806 | |
4807 | /// Get the type deduced for this placeholder type, or null if it's |
4808 | /// either not been deduced or was deduced to a dependent type. |
4809 | QualType getDeducedType() const { |
4810 | return !isCanonicalUnqualified() ? getCanonicalTypeInternal() : QualType(); |
4811 | } |
4812 | bool isDeduced() const { |
4813 | return !isCanonicalUnqualified() || isDependentType(); |
4814 | } |
4815 | |
4816 | static bool classof(const Type *T) { |
4817 | return T->getTypeClass() == Auto || |
4818 | T->getTypeClass() == DeducedTemplateSpecialization; |
4819 | } |
4820 | }; |
4821 | |
4822 | /// Represents a C++11 auto or C++14 decltype(auto) type. |
4823 | class AutoType : public DeducedType, public llvm::FoldingSetNode { |
4824 | friend class ASTContext; // ASTContext creates these |
4825 | |
4826 | AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword, |
4827 | bool IsDeducedAsDependent, bool IsDeducedAsPack) |
4828 | : DeducedType(Auto, DeducedAsType, IsDeducedAsDependent, |
4829 | IsDeducedAsDependent, IsDeducedAsPack) { |
4830 | AutoTypeBits.Keyword = (unsigned)Keyword; |
4831 | } |
4832 | |
4833 | public: |
4834 | bool isDecltypeAuto() const { |
4835 | return getKeyword() == AutoTypeKeyword::DecltypeAuto; |
4836 | } |
4837 | |
4838 | AutoTypeKeyword getKeyword() const { |
4839 | return (AutoTypeKeyword)AutoTypeBits.Keyword; |
4840 | } |
4841 | |
4842 | void Profile(llvm::FoldingSetNodeID &ID) { |
4843 | Profile(ID, getDeducedType(), getKeyword(), isDependentType(), |
4844 | containsUnexpandedParameterPack()); |
4845 | } |
4846 | |
4847 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced, |
4848 | AutoTypeKeyword Keyword, bool IsDependent, bool IsPack) { |
4849 | ID.AddPointer(Deduced.getAsOpaquePtr()); |
4850 | ID.AddInteger((unsigned)Keyword); |
4851 | ID.AddBoolean(IsDependent); |
4852 | ID.AddBoolean(IsPack); |
4853 | } |
4854 | |
4855 | static bool classof(const Type *T) { |
4856 | return T->getTypeClass() == Auto; |
4857 | } |
4858 | }; |
4859 | |
4860 | /// Represents a C++17 deduced template specialization type. |
4861 | class DeducedTemplateSpecializationType : public DeducedType, |
4862 | public llvm::FoldingSetNode { |
4863 | friend class ASTContext; // ASTContext creates these |
4864 | |
4865 | /// The name of the template whose arguments will be deduced. |
4866 | TemplateName Template; |
4867 | |
4868 | DeducedTemplateSpecializationType(TemplateName Template, |
4869 | QualType DeducedAsType, |
4870 | bool IsDeducedAsDependent) |
4871 | : DeducedType(DeducedTemplateSpecialization, DeducedAsType, |
4872 | IsDeducedAsDependent || Template.isDependent(), |
4873 | IsDeducedAsDependent || Template.isInstantiationDependent(), |
4874 | Template.containsUnexpandedParameterPack()), |
4875 | Template(Template) {} |
4876 | |
4877 | public: |
4878 | /// Retrieve the name of the template that we are deducing. |
4879 | TemplateName getTemplateName() const { return Template;} |
4880 | |
4881 | void Profile(llvm::FoldingSetNodeID &ID) { |
4882 | Profile(ID, getTemplateName(), getDeducedType(), isDependentType()); |
4883 | } |
4884 | |
4885 | static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, |
4886 | QualType Deduced, bool IsDependent) { |
4887 | Template.Profile(ID); |
4888 | ID.AddPointer(Deduced.getAsOpaquePtr()); |
4889 | ID.AddBoolean(IsDependent); |
4890 | } |
4891 | |
4892 | static bool classof(const Type *T) { |
4893 | return T->getTypeClass() == DeducedTemplateSpecialization; |
4894 | } |
4895 | }; |
4896 | |
4897 | /// Represents a type template specialization; the template |
4898 | /// must be a class template, a type alias template, or a template |
4899 | /// template parameter. A template which cannot be resolved to one of |
4900 | /// these, e.g. because it is written with a dependent scope |
4901 | /// specifier, is instead represented as a |
4902 | /// @c DependentTemplateSpecializationType. |
4903 | /// |
4904 | /// A non-dependent template specialization type is always "sugar", |
4905 | /// typically for a \c RecordType. For example, a class template |
4906 | /// specialization type of \c vector<int> will refer to a tag type for |
4907 | /// the instantiation \c std::vector<int, std::allocator<int>> |
4908 | /// |
4909 | /// Template specializations are dependent if either the template or |
4910 | /// any of the template arguments are dependent, in which case the |
4911 | /// type may also be canonical. |
4912 | /// |
4913 | /// Instances of this type are allocated with a trailing array of |
4914 | /// TemplateArguments, followed by a QualType representing the |
4915 | /// non-canonical aliased type when the template is a type alias |
4916 | /// template. |
4917 | class alignas(8) TemplateSpecializationType |
4918 | : public Type, |
4919 | public llvm::FoldingSetNode { |
4920 | friend class ASTContext; // ASTContext creates these |
4921 | |
4922 | /// The name of the template being specialized. This is |
4923 | /// either a TemplateName::Template (in which case it is a |
4924 | /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a |
4925 | /// TypeAliasTemplateDecl*), a |
4926 | /// TemplateName::SubstTemplateTemplateParmPack, or a |
4927 | /// TemplateName::SubstTemplateTemplateParm (in which case the |
4928 | /// replacement must, recursively, be one of these). |
4929 | TemplateName Template; |
4930 | |
4931 | TemplateSpecializationType(TemplateName T, |
4932 | ArrayRef<TemplateArgument> Args, |
4933 | QualType Canon, |
4934 | QualType Aliased); |
4935 | |
4936 | public: |
4937 | /// Determine whether any of the given template arguments are dependent. |
4938 | static bool anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
4939 | bool &InstantiationDependent); |
4940 | |
4941 | static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &, |
4942 | bool &InstantiationDependent); |
4943 | |
4944 | /// True if this template specialization type matches a current |
4945 | /// instantiation in the context in which it is found. |
4946 | bool isCurrentInstantiation() const { |
4947 | return isa<InjectedClassNameType>(getCanonicalTypeInternal()); |
4948 | } |
4949 | |
4950 | /// Determine if this template specialization type is for a type alias |
4951 | /// template that has been substituted. |
4952 | /// |
4953 | /// Nearly every template specialization type whose template is an alias |
4954 | /// template will be substituted. However, this is not the case when |
4955 | /// the specialization contains a pack expansion but the template alias |
4956 | /// does not have a corresponding parameter pack, e.g., |
4957 | /// |
4958 | /// \code |
4959 | /// template<typename T, typename U, typename V> struct S; |
4960 | /// template<typename T, typename U> using A = S<T, int, U>; |
4961 | /// template<typename... Ts> struct X { |
4962 | /// typedef A<Ts...> type; // not a type alias |
4963 | /// }; |
4964 | /// \endcode |
4965 | bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; } |
4966 | |
4967 | /// Get the aliased type, if this is a specialization of a type alias |
4968 | /// template. |
4969 | QualType getAliasedType() const { |
4970 | assert(isTypeAlias() && "not a type alias template specialization")((isTypeAlias() && "not a type alias template specialization" ) ? static_cast<void> (0) : __assert_fail ("isTypeAlias() && \"not a type alias template specialization\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 4970, __PRETTY_FUNCTION__)); |
4971 | return *reinterpret_cast<const QualType*>(end()); |
4972 | } |
4973 | |
4974 | using iterator = const TemplateArgument *; |
4975 | |
4976 | iterator begin() const { return getArgs(); } |
4977 | iterator end() const; // defined inline in TemplateBase.h |
4978 | |
4979 | /// Retrieve the name of the template that we are specializing. |
4980 | TemplateName getTemplateName() const { return Template; } |
4981 | |
4982 | /// Retrieve the template arguments. |
4983 | const TemplateArgument *getArgs() const { |
4984 | return reinterpret_cast<const TemplateArgument *>(this + 1); |
4985 | } |
4986 | |
4987 | /// Retrieve the number of template arguments. |
4988 | unsigned getNumArgs() const { |
4989 | return TemplateSpecializationTypeBits.NumArgs; |
4990 | } |
4991 | |
4992 | /// Retrieve a specific template argument as a type. |
4993 | /// \pre \c isArgType(Arg) |
4994 | const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h |
4995 | |
4996 | ArrayRef<TemplateArgument> template_arguments() const { |
4997 | return {getArgs(), getNumArgs()}; |
4998 | } |
4999 | |
5000 | bool isSugared() const { |
5001 | return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); |
5002 | } |
5003 | |
5004 | QualType desugar() const { |
5005 | return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal(); |
5006 | } |
5007 | |
5008 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { |
5009 | Profile(ID, Template, template_arguments(), Ctx); |
5010 | if (isTypeAlias()) |
5011 | getAliasedType().Profile(ID); |
5012 | } |
5013 | |
5014 | static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, |
5015 | ArrayRef<TemplateArgument> Args, |
5016 | const ASTContext &Context); |
5017 | |
5018 | static bool classof(const Type *T) { |
5019 | return T->getTypeClass() == TemplateSpecialization; |
5020 | } |
5021 | }; |
5022 | |
5023 | /// Print a template argument list, including the '<' and '>' |
5024 | /// enclosing the template arguments. |
5025 | void printTemplateArgumentList(raw_ostream &OS, |
5026 | ArrayRef<TemplateArgument> Args, |
5027 | const PrintingPolicy &Policy); |
5028 | |
5029 | void printTemplateArgumentList(raw_ostream &OS, |
5030 | ArrayRef<TemplateArgumentLoc> Args, |
5031 | const PrintingPolicy &Policy); |
5032 | |
5033 | void printTemplateArgumentList(raw_ostream &OS, |
5034 | const TemplateArgumentListInfo &Args, |
5035 | const PrintingPolicy &Policy); |
5036 | |
5037 | /// The injected class name of a C++ class template or class |
5038 | /// template partial specialization. Used to record that a type was |
5039 | /// spelled with a bare identifier rather than as a template-id; the |
5040 | /// equivalent for non-templated classes is just RecordType. |
5041 | /// |
5042 | /// Injected class name types are always dependent. Template |
5043 | /// instantiation turns these into RecordTypes. |
5044 | /// |
5045 | /// Injected class name types are always canonical. This works |
5046 | /// because it is impossible to compare an injected class name type |
5047 | /// with the corresponding non-injected template type, for the same |
5048 | /// reason that it is impossible to directly compare template |
5049 | /// parameters from different dependent contexts: injected class name |
5050 | /// types can only occur within the scope of a particular templated |
5051 | /// declaration, and within that scope every template specialization |
5052 | /// will canonicalize to the injected class name (when appropriate |
5053 | /// according to the rules of the language). |
5054 | class InjectedClassNameType : public Type { |
5055 | friend class ASTContext; // ASTContext creates these. |
5056 | friend class ASTNodeImporter; |
5057 | friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not |
5058 | // currently suitable for AST reading, too much |
5059 | // interdependencies. |
5060 | |
5061 | CXXRecordDecl *Decl; |
5062 | |
5063 | /// The template specialization which this type represents. |
5064 | /// For example, in |
5065 | /// template <class T> class A { ... }; |
5066 | /// this is A<T>, whereas in |
5067 | /// template <class X, class Y> class A<B<X,Y> > { ... }; |
5068 | /// this is A<B<X,Y> >. |
5069 | /// |
5070 | /// It is always unqualified, always a template specialization type, |
5071 | /// and always dependent. |
5072 | QualType InjectedType; |
5073 | |
5074 | InjectedClassNameType(CXXRecordDecl *D, QualType TST) |
5075 | : Type(InjectedClassName, QualType(), /*Dependent=*/true, |
5076 | /*InstantiationDependent=*/true, |
5077 | /*VariablyModified=*/false, |
5078 | /*ContainsUnexpandedParameterPack=*/false), |
5079 | Decl(D), InjectedType(TST) { |
5080 | assert(isa<TemplateSpecializationType>(TST))((isa<TemplateSpecializationType>(TST)) ? static_cast< void> (0) : __assert_fail ("isa<TemplateSpecializationType>(TST)" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5080, __PRETTY_FUNCTION__)); |
5081 | assert(!TST.hasQualifiers())((!TST.hasQualifiers()) ? static_cast<void> (0) : __assert_fail ("!TST.hasQualifiers()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5081, __PRETTY_FUNCTION__)); |
5082 | assert(TST->isDependentType())((TST->isDependentType()) ? static_cast<void> (0) : __assert_fail ("TST->isDependentType()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5082, __PRETTY_FUNCTION__)); |
5083 | } |
5084 | |
5085 | public: |
5086 | QualType getInjectedSpecializationType() const { return InjectedType; } |
5087 | |
5088 | const TemplateSpecializationType *getInjectedTST() const { |
5089 | return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); |
5090 | } |
5091 | |
5092 | TemplateName getTemplateName() const { |
5093 | return getInjectedTST()->getTemplateName(); |
5094 | } |
5095 | |
5096 | CXXRecordDecl *getDecl() const; |
5097 | |
5098 | bool isSugared() const { return false; } |
5099 | QualType desugar() const { return QualType(this, 0); } |
5100 | |
5101 | static bool classof(const Type *T) { |
5102 | return T->getTypeClass() == InjectedClassName; |
5103 | } |
5104 | }; |
5105 | |
5106 | /// The kind of a tag type. |
5107 | enum TagTypeKind { |
5108 | /// The "struct" keyword. |
5109 | TTK_Struct, |
5110 | |
5111 | /// The "__interface" keyword. |
5112 | TTK_Interface, |
5113 | |
5114 | /// The "union" keyword. |
5115 | TTK_Union, |
5116 | |
5117 | /// The "class" keyword. |
5118 | TTK_Class, |
5119 | |
5120 | /// The "enum" keyword. |
5121 | TTK_Enum |
5122 | }; |
5123 | |
5124 | /// The elaboration keyword that precedes a qualified type name or |
5125 | /// introduces an elaborated-type-specifier. |
5126 | enum ElaboratedTypeKeyword { |
5127 | /// The "struct" keyword introduces the elaborated-type-specifier. |
5128 | ETK_Struct, |
5129 | |
5130 | /// The "__interface" keyword introduces the elaborated-type-specifier. |
5131 | ETK_Interface, |
5132 | |
5133 | /// The "union" keyword introduces the elaborated-type-specifier. |
5134 | ETK_Union, |
5135 | |
5136 | /// The "class" keyword introduces the elaborated-type-specifier. |
5137 | ETK_Class, |
5138 | |
5139 | /// The "enum" keyword introduces the elaborated-type-specifier. |
5140 | ETK_Enum, |
5141 | |
5142 | /// The "typename" keyword precedes the qualified type name, e.g., |
5143 | /// \c typename T::type. |
5144 | ETK_Typename, |
5145 | |
5146 | /// No keyword precedes the qualified type name. |
5147 | ETK_None |
5148 | }; |
5149 | |
5150 | /// A helper class for Type nodes having an ElaboratedTypeKeyword. |
5151 | /// The keyword in stored in the free bits of the base class. |
5152 | /// Also provides a few static helpers for converting and printing |
5153 | /// elaborated type keyword and tag type kind enumerations. |
5154 | class TypeWithKeyword : public Type { |
5155 | protected: |
5156 | TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, |
5157 | QualType Canonical, bool Dependent, |
5158 | bool InstantiationDependent, bool VariablyModified, |
5159 | bool ContainsUnexpandedParameterPack) |
5160 | : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, |
5161 | ContainsUnexpandedParameterPack) { |
5162 | TypeWithKeywordBits.Keyword = Keyword; |
5163 | } |
5164 | |
5165 | public: |
5166 | ElaboratedTypeKeyword getKeyword() const { |
5167 | return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); |
5168 | } |
5169 | |
5170 | /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword. |
5171 | static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); |
5172 | |
5173 | /// Converts a type specifier (DeclSpec::TST) into a tag type kind. |
5174 | /// It is an error to provide a type specifier which *isn't* a tag kind here. |
5175 | static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); |
5176 | |
5177 | /// Converts a TagTypeKind into an elaborated type keyword. |
5178 | static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); |
5179 | |
5180 | /// Converts an elaborated type keyword into a TagTypeKind. |
5181 | /// It is an error to provide an elaborated type keyword |
5182 | /// which *isn't* a tag kind here. |
5183 | static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); |
5184 | |
5185 | static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); |
5186 | |
5187 | static StringRef getKeywordName(ElaboratedTypeKeyword Keyword); |
5188 | |
5189 | static StringRef getTagTypeKindName(TagTypeKind Kind) { |
5190 | return getKeywordName(getKeywordForTagTypeKind(Kind)); |
5191 | } |
5192 | |
5193 | class CannotCastToThisType {}; |
5194 | static CannotCastToThisType classof(const Type *); |
5195 | }; |
5196 | |
5197 | /// Represents a type that was referred to using an elaborated type |
5198 | /// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, |
5199 | /// or both. |
5200 | /// |
5201 | /// This type is used to keep track of a type name as written in the |
5202 | /// source code, including tag keywords and any nested-name-specifiers. |
5203 | /// The type itself is always "sugar", used to express what was written |
5204 | /// in the source code but containing no additional semantic information. |
5205 | class ElaboratedType final |
5206 | : public TypeWithKeyword, |
5207 | public llvm::FoldingSetNode, |
5208 | private llvm::TrailingObjects<ElaboratedType, TagDecl *> { |
5209 | friend class ASTContext; // ASTContext creates these |
5210 | friend TrailingObjects; |
5211 | |
5212 | /// The nested name specifier containing the qualifier. |
5213 | NestedNameSpecifier *NNS; |
5214 | |
5215 | /// The type that this qualified name refers to. |
5216 | QualType NamedType; |
5217 | |
5218 | /// The (re)declaration of this tag type owned by this occurrence is stored |
5219 | /// as a trailing object if there is one. Use getOwnedTagDecl to obtain |
5220 | /// it, or obtain a null pointer if there is none. |
5221 | |
5222 | ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, |
5223 | QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl) |
5224 | : TypeWithKeyword(Keyword, Elaborated, CanonType, |
5225 | NamedType->isDependentType(), |
5226 | NamedType->isInstantiationDependentType(), |
5227 | NamedType->isVariablyModifiedType(), |
5228 | NamedType->containsUnexpandedParameterPack()), |
5229 | NNS(NNS), NamedType(NamedType) { |
5230 | ElaboratedTypeBits.HasOwnedTagDecl = false; |
5231 | if (OwnedTagDecl) { |
5232 | ElaboratedTypeBits.HasOwnedTagDecl = true; |
5233 | *getTrailingObjects<TagDecl *>() = OwnedTagDecl; |
5234 | } |
5235 | assert(!(Keyword == ETK_None && NNS == nullptr) &&((!(Keyword == ETK_None && NNS == nullptr) && "ElaboratedType cannot have elaborated type keyword " "and name qualifier both null." ) ? static_cast<void> (0) : __assert_fail ("!(Keyword == ETK_None && NNS == nullptr) && \"ElaboratedType cannot have elaborated type keyword \" \"and name qualifier both null.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5237, __PRETTY_FUNCTION__)) |
5236 | "ElaboratedType cannot have elaborated type keyword "((!(Keyword == ETK_None && NNS == nullptr) && "ElaboratedType cannot have elaborated type keyword " "and name qualifier both null." ) ? static_cast<void> (0) : __assert_fail ("!(Keyword == ETK_None && NNS == nullptr) && \"ElaboratedType cannot have elaborated type keyword \" \"and name qualifier both null.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5237, __PRETTY_FUNCTION__)) |
5237 | "and name qualifier both null.")((!(Keyword == ETK_None && NNS == nullptr) && "ElaboratedType cannot have elaborated type keyword " "and name qualifier both null." ) ? static_cast<void> (0) : __assert_fail ("!(Keyword == ETK_None && NNS == nullptr) && \"ElaboratedType cannot have elaborated type keyword \" \"and name qualifier both null.\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5237, __PRETTY_FUNCTION__)); |
5238 | } |
5239 | |
5240 | public: |
5241 | /// Retrieve the qualification on this type. |
5242 | NestedNameSpecifier *getQualifier() const { return NNS; } |
5243 | |
5244 | /// Retrieve the type named by the qualified-id. |
5245 | QualType getNamedType() const { return NamedType; } |
5246 | |
5247 | /// Remove a single level of sugar. |
5248 | QualType desugar() const { return getNamedType(); } |
5249 | |
5250 | /// Returns whether this type directly provides sugar. |
5251 | bool isSugared() const { return true; } |
5252 | |
5253 | /// Return the (re)declaration of this type owned by this occurrence of this |
5254 | /// type, or nullptr if there is none. |
5255 | TagDecl *getOwnedTagDecl() const { |
5256 | return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>() |
5257 | : nullptr; |
5258 | } |
5259 | |
5260 | void Profile(llvm::FoldingSetNodeID &ID) { |
5261 | Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl()); |
5262 | } |
5263 | |
5264 | static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, |
5265 | NestedNameSpecifier *NNS, QualType NamedType, |
5266 | TagDecl *OwnedTagDecl) { |
5267 | ID.AddInteger(Keyword); |
5268 | ID.AddPointer(NNS); |
5269 | NamedType.Profile(ID); |
5270 | ID.AddPointer(OwnedTagDecl); |
5271 | } |
5272 | |
5273 | static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } |
5274 | }; |
5275 | |
5276 | /// Represents a qualified type name for which the type name is |
5277 | /// dependent. |
5278 | /// |
5279 | /// DependentNameType represents a class of dependent types that involve a |
5280 | /// possibly dependent nested-name-specifier (e.g., "T::") followed by a |
5281 | /// name of a type. The DependentNameType may start with a "typename" (for a |
5282 | /// typename-specifier), "class", "struct", "union", or "enum" (for a |
5283 | /// dependent elaborated-type-specifier), or nothing (in contexts where we |
5284 | /// know that we must be referring to a type, e.g., in a base class specifier). |
5285 | /// Typically the nested-name-specifier is dependent, but in MSVC compatibility |
5286 | /// mode, this type is used with non-dependent names to delay name lookup until |
5287 | /// instantiation. |
5288 | class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { |
5289 | friend class ASTContext; // ASTContext creates these |
5290 | |
5291 | /// The nested name specifier containing the qualifier. |
5292 | NestedNameSpecifier *NNS; |
5293 | |
5294 | /// The type that this typename specifier refers to. |
5295 | const IdentifierInfo *Name; |
5296 | |
5297 | DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, |
5298 | const IdentifierInfo *Name, QualType CanonType) |
5299 | : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, |
5300 | /*InstantiationDependent=*/true, |
5301 | /*VariablyModified=*/false, |
5302 | NNS->containsUnexpandedParameterPack()), |
5303 | NNS(NNS), Name(Name) {} |
5304 | |
5305 | public: |
5306 | /// Retrieve the qualification on this type. |
5307 | NestedNameSpecifier *getQualifier() const { return NNS; } |
5308 | |
5309 | /// Retrieve the type named by the typename specifier as an identifier. |
5310 | /// |
5311 | /// This routine will return a non-NULL identifier pointer when the |
5312 | /// form of the original typename was terminated by an identifier, |
5313 | /// e.g., "typename T::type". |
5314 | const IdentifierInfo *getIdentifier() const { |
5315 | return Name; |
5316 | } |
5317 | |
5318 | bool isSugared() const { return false; } |
5319 | QualType desugar() const { return QualType(this, 0); } |
5320 | |
5321 | void Profile(llvm::FoldingSetNodeID &ID) { |
5322 | Profile(ID, getKeyword(), NNS, Name); |
5323 | } |
5324 | |
5325 | static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, |
5326 | NestedNameSpecifier *NNS, const IdentifierInfo *Name) { |
5327 | ID.AddInteger(Keyword); |
5328 | ID.AddPointer(NNS); |
5329 | ID.AddPointer(Name); |
5330 | } |
5331 | |
5332 | static bool classof(const Type *T) { |
5333 | return T->getTypeClass() == DependentName; |
5334 | } |
5335 | }; |
5336 | |
5337 | /// Represents a template specialization type whose template cannot be |
5338 | /// resolved, e.g. |
5339 | /// A<T>::template B<T> |
5340 | class alignas(8) DependentTemplateSpecializationType |
5341 | : public TypeWithKeyword, |
5342 | public llvm::FoldingSetNode { |
5343 | friend class ASTContext; // ASTContext creates these |
5344 | |
5345 | /// The nested name specifier containing the qualifier. |
5346 | NestedNameSpecifier *NNS; |
5347 | |
5348 | /// The identifier of the template. |
5349 | const IdentifierInfo *Name; |
5350 | |
5351 | DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, |
5352 | NestedNameSpecifier *NNS, |
5353 | const IdentifierInfo *Name, |
5354 | ArrayRef<TemplateArgument> Args, |
5355 | QualType Canon); |
5356 | |
5357 | const TemplateArgument *getArgBuffer() const { |
5358 | return reinterpret_cast<const TemplateArgument*>(this+1); |
5359 | } |
5360 | |
5361 | TemplateArgument *getArgBuffer() { |
5362 | return reinterpret_cast<TemplateArgument*>(this+1); |
5363 | } |
5364 | |
5365 | public: |
5366 | NestedNameSpecifier *getQualifier() const { return NNS; } |
5367 | const IdentifierInfo *getIdentifier() const { return Name; } |
5368 | |
5369 | /// Retrieve the template arguments. |
5370 | const TemplateArgument *getArgs() const { |
5371 | return getArgBuffer(); |
5372 | } |
5373 | |
5374 | /// Retrieve the number of template arguments. |
5375 | unsigned getNumArgs() const { |
5376 | return DependentTemplateSpecializationTypeBits.NumArgs; |
5377 | } |
5378 | |
5379 | const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h |
5380 | |
5381 | ArrayRef<TemplateArgument> template_arguments() const { |
5382 | return {getArgs(), getNumArgs()}; |
5383 | } |
5384 | |
5385 | using iterator = const TemplateArgument *; |
5386 | |
5387 | iterator begin() const { return getArgs(); } |
5388 | iterator end() const; // inline in TemplateBase.h |
5389 | |
5390 | bool isSugared() const { return false; } |
5391 | QualType desugar() const { return QualType(this, 0); } |
5392 | |
5393 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { |
5394 | Profile(ID, Context, getKeyword(), NNS, Name, {getArgs(), getNumArgs()}); |
5395 | } |
5396 | |
5397 | static void Profile(llvm::FoldingSetNodeID &ID, |
5398 | const ASTContext &Context, |
5399 | ElaboratedTypeKeyword Keyword, |
5400 | NestedNameSpecifier *Qualifier, |
5401 | const IdentifierInfo *Name, |
5402 | ArrayRef<TemplateArgument> Args); |
5403 | |
5404 | static bool classof(const Type *T) { |
5405 | return T->getTypeClass() == DependentTemplateSpecialization; |
5406 | } |
5407 | }; |
5408 | |
5409 | /// Represents a pack expansion of types. |
5410 | /// |
5411 | /// Pack expansions are part of C++11 variadic templates. A pack |
5412 | /// expansion contains a pattern, which itself contains one or more |
5413 | /// "unexpanded" parameter packs. When instantiated, a pack expansion |
5414 | /// produces a series of types, each instantiated from the pattern of |
5415 | /// the expansion, where the Ith instantiation of the pattern uses the |
5416 | /// Ith arguments bound to each of the unexpanded parameter packs. The |
5417 | /// pack expansion is considered to "expand" these unexpanded |
5418 | /// parameter packs. |
5419 | /// |
5420 | /// \code |
5421 | /// template<typename ...Types> struct tuple; |
5422 | /// |
5423 | /// template<typename ...Types> |
5424 | /// struct tuple_of_references { |
5425 | /// typedef tuple<Types&...> type; |
5426 | /// }; |
5427 | /// \endcode |
5428 | /// |
5429 | /// Here, the pack expansion \c Types&... is represented via a |
5430 | /// PackExpansionType whose pattern is Types&. |
5431 | class PackExpansionType : public Type, public llvm::FoldingSetNode { |
5432 | friend class ASTContext; // ASTContext creates these |
5433 | |
5434 | /// The pattern of the pack expansion. |
5435 | QualType Pattern; |
5436 | |
5437 | PackExpansionType(QualType Pattern, QualType Canon, |
5438 | Optional<unsigned> NumExpansions) |
5439 | : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(), |
5440 | /*InstantiationDependent=*/true, |
5441 | /*VariablyModified=*/Pattern->isVariablyModifiedType(), |
5442 | /*ContainsUnexpandedParameterPack=*/false), |
5443 | Pattern(Pattern) { |
5444 | PackExpansionTypeBits.NumExpansions = |
5445 | NumExpansions ? *NumExpansions + 1 : 0; |
5446 | } |
5447 | |
5448 | public: |
5449 | /// Retrieve the pattern of this pack expansion, which is the |
5450 | /// type that will be repeatedly instantiated when instantiating the |
5451 | /// pack expansion itself. |
5452 | QualType getPattern() const { return Pattern; } |
5453 | |
5454 | /// Retrieve the number of expansions that this pack expansion will |
5455 | /// generate, if known. |
5456 | Optional<unsigned> getNumExpansions() const { |
5457 | if (PackExpansionTypeBits.NumExpansions) |
5458 | return PackExpansionTypeBits.NumExpansions - 1; |
5459 | return None; |
5460 | } |
5461 | |
5462 | bool isSugared() const { return !Pattern->isDependentType(); } |
5463 | QualType desugar() const { return isSugared() ? Pattern : QualType(this, 0); } |
5464 | |
5465 | void Profile(llvm::FoldingSetNodeID &ID) { |
5466 | Profile(ID, getPattern(), getNumExpansions()); |
5467 | } |
5468 | |
5469 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, |
5470 | Optional<unsigned> NumExpansions) { |
5471 | ID.AddPointer(Pattern.getAsOpaquePtr()); |
5472 | ID.AddBoolean(NumExpansions.hasValue()); |
5473 | if (NumExpansions) |
5474 | ID.AddInteger(*NumExpansions); |
5475 | } |
5476 | |
5477 | static bool classof(const Type *T) { |
5478 | return T->getTypeClass() == PackExpansion; |
5479 | } |
5480 | }; |
5481 | |
5482 | /// This class wraps the list of protocol qualifiers. For types that can |
5483 | /// take ObjC protocol qualifers, they can subclass this class. |
5484 | template <class T> |
5485 | class ObjCProtocolQualifiers { |
5486 | protected: |
5487 | ObjCProtocolQualifiers() = default; |
5488 | |
5489 | ObjCProtocolDecl * const *getProtocolStorage() const { |
5490 | return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage(); |
5491 | } |
5492 | |
5493 | ObjCProtocolDecl **getProtocolStorage() { |
5494 | return static_cast<T*>(this)->getProtocolStorageImpl(); |
5495 | } |
5496 | |
5497 | void setNumProtocols(unsigned N) { |
5498 | static_cast<T*>(this)->setNumProtocolsImpl(N); |
5499 | } |
5500 | |
5501 | void initialize(ArrayRef<ObjCProtocolDecl *> protocols) { |
5502 | setNumProtocols(protocols.size()); |
5503 | assert(getNumProtocols() == protocols.size() &&((getNumProtocols() == protocols.size() && "bitfield overflow in protocol count" ) ? static_cast<void> (0) : __assert_fail ("getNumProtocols() == protocols.size() && \"bitfield overflow in protocol count\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5504, __PRETTY_FUNCTION__)) |
5504 | "bitfield overflow in protocol count")((getNumProtocols() == protocols.size() && "bitfield overflow in protocol count" ) ? static_cast<void> (0) : __assert_fail ("getNumProtocols() == protocols.size() && \"bitfield overflow in protocol count\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5504, __PRETTY_FUNCTION__)); |
5505 | if (!protocols.empty()) |
5506 | memcpy(getProtocolStorage(), protocols.data(), |
5507 | protocols.size() * sizeof(ObjCProtocolDecl*)); |
5508 | } |
5509 | |
5510 | public: |
5511 | using qual_iterator = ObjCProtocolDecl * const *; |
5512 | using qual_range = llvm::iterator_range<qual_iterator>; |
5513 | |
5514 | qual_range quals() const { return qual_range(qual_begin(), qual_end()); } |
5515 | qual_iterator qual_begin() const { return getProtocolStorage(); } |
5516 | qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } |
5517 | |
5518 | bool qual_empty() const { return getNumProtocols() == 0; } |
5519 | |
5520 | /// Return the number of qualifying protocols in this type, or 0 if |
5521 | /// there are none. |
5522 | unsigned getNumProtocols() const { |
5523 | return static_cast<const T*>(this)->getNumProtocolsImpl(); |
5524 | } |
5525 | |
5526 | /// Fetch a protocol by index. |
5527 | ObjCProtocolDecl *getProtocol(unsigned I) const { |
5528 | assert(I < getNumProtocols() && "Out-of-range protocol access")((I < getNumProtocols() && "Out-of-range protocol access" ) ? static_cast<void> (0) : __assert_fail ("I < getNumProtocols() && \"Out-of-range protocol access\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5528, __PRETTY_FUNCTION__)); |
5529 | return qual_begin()[I]; |
5530 | } |
5531 | |
5532 | /// Retrieve all of the protocol qualifiers. |
5533 | ArrayRef<ObjCProtocolDecl *> getProtocols() const { |
5534 | return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols()); |
5535 | } |
5536 | }; |
5537 | |
5538 | /// Represents a type parameter type in Objective C. It can take |
5539 | /// a list of protocols. |
5540 | class ObjCTypeParamType : public Type, |
5541 | public ObjCProtocolQualifiers<ObjCTypeParamType>, |
5542 | public llvm::FoldingSetNode { |
5543 | friend class ASTContext; |
5544 | friend class ObjCProtocolQualifiers<ObjCTypeParamType>; |
5545 | |
5546 | /// The number of protocols stored on this type. |
5547 | unsigned NumProtocols : 6; |
5548 | |
5549 | ObjCTypeParamDecl *OTPDecl; |
5550 | |
5551 | /// The protocols are stored after the ObjCTypeParamType node. In the |
5552 | /// canonical type, the list of protocols are sorted alphabetically |
5553 | /// and uniqued. |
5554 | ObjCProtocolDecl **getProtocolStorageImpl(); |
5555 | |
5556 | /// Return the number of qualifying protocols in this interface type, |
5557 | /// or 0 if there are none. |
5558 | unsigned getNumProtocolsImpl() const { |
5559 | return NumProtocols; |
5560 | } |
5561 | |
5562 | void setNumProtocolsImpl(unsigned N) { |
5563 | NumProtocols = N; |
5564 | } |
5565 | |
5566 | ObjCTypeParamType(const ObjCTypeParamDecl *D, |
5567 | QualType can, |
5568 | ArrayRef<ObjCProtocolDecl *> protocols); |
5569 | |
5570 | public: |
5571 | bool isSugared() const { return true; } |
5572 | QualType desugar() const { return getCanonicalTypeInternal(); } |
5573 | |
5574 | static bool classof(const Type *T) { |
5575 | return T->getTypeClass() == ObjCTypeParam; |
5576 | } |
5577 | |
5578 | void Profile(llvm::FoldingSetNodeID &ID); |
5579 | static void Profile(llvm::FoldingSetNodeID &ID, |
5580 | const ObjCTypeParamDecl *OTPDecl, |
5581 | ArrayRef<ObjCProtocolDecl *> protocols); |
5582 | |
5583 | ObjCTypeParamDecl *getDecl() const { return OTPDecl; } |
5584 | }; |
5585 | |
5586 | /// Represents a class type in Objective C. |
5587 | /// |
5588 | /// Every Objective C type is a combination of a base type, a set of |
5589 | /// type arguments (optional, for parameterized classes) and a list of |
5590 | /// protocols. |
5591 | /// |
5592 | /// Given the following declarations: |
5593 | /// \code |
5594 | /// \@class C<T>; |
5595 | /// \@protocol P; |
5596 | /// \endcode |
5597 | /// |
5598 | /// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType |
5599 | /// with base C and no protocols. |
5600 | /// |
5601 | /// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P]. |
5602 | /// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no |
5603 | /// protocol list. |
5604 | /// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*', |
5605 | /// and protocol list [P]. |
5606 | /// |
5607 | /// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose |
5608 | /// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType |
5609 | /// and no protocols. |
5610 | /// |
5611 | /// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType |
5612 | /// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually |
5613 | /// this should get its own sugar class to better represent the source. |
5614 | class ObjCObjectType : public Type, |
5615 | public ObjCProtocolQualifiers<ObjCObjectType> { |
5616 | friend class ObjCProtocolQualifiers<ObjCObjectType>; |
5617 | |
5618 | // ObjCObjectType.NumTypeArgs - the number of type arguments stored |
5619 | // after the ObjCObjectPointerType node. |
5620 | // ObjCObjectType.NumProtocols - the number of protocols stored |
5621 | // after the type arguments of ObjCObjectPointerType node. |
5622 | // |
5623 | // These protocols are those written directly on the type. If |
5624 | // protocol qualifiers ever become additive, the iterators will need |
5625 | // to get kindof complicated. |
5626 | // |
5627 | // In the canonical object type, these are sorted alphabetically |
5628 | // and uniqued. |
5629 | |
5630 | /// Either a BuiltinType or an InterfaceType or sugar for either. |
5631 | QualType BaseType; |
5632 | |
5633 | /// Cached superclass type. |
5634 | mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool> |
5635 | CachedSuperClassType; |
5636 | |
5637 | QualType *getTypeArgStorage(); |
5638 | const QualType *getTypeArgStorage() const { |
5639 | return const_cast<ObjCObjectType *>(this)->getTypeArgStorage(); |
5640 | } |
5641 | |
5642 | ObjCProtocolDecl **getProtocolStorageImpl(); |
5643 | /// Return the number of qualifying protocols in this interface type, |
5644 | /// or 0 if there are none. |
5645 | unsigned getNumProtocolsImpl() const { |
5646 | return ObjCObjectTypeBits.NumProtocols; |
5647 | } |
5648 | void setNumProtocolsImpl(unsigned N) { |
5649 | ObjCObjectTypeBits.NumProtocols = N; |
5650 | } |
5651 | |
5652 | protected: |
5653 | enum Nonce_ObjCInterface { Nonce_ObjCInterface }; |
5654 | |
5655 | ObjCObjectType(QualType Canonical, QualType Base, |
5656 | ArrayRef<QualType> typeArgs, |
5657 | ArrayRef<ObjCProtocolDecl *> protocols, |
5658 | bool isKindOf); |
5659 | |
5660 | ObjCObjectType(enum Nonce_ObjCInterface) |
5661 | : Type(ObjCInterface, QualType(), false, false, false, false), |
5662 | BaseType(QualType(this_(), 0)) { |
5663 | ObjCObjectTypeBits.NumProtocols = 0; |
5664 | ObjCObjectTypeBits.NumTypeArgs = 0; |
5665 | ObjCObjectTypeBits.IsKindOf = 0; |
5666 | } |
5667 | |
5668 | void computeSuperClassTypeSlow() const; |
5669 | |
5670 | public: |
5671 | /// Gets the base type of this object type. This is always (possibly |
5672 | /// sugar for) one of: |
5673 | /// - the 'id' builtin type (as opposed to the 'id' type visible to the |
5674 | /// user, which is a typedef for an ObjCObjectPointerType) |
5675 | /// - the 'Class' builtin type (same caveat) |
5676 | /// - an ObjCObjectType (currently always an ObjCInterfaceType) |
5677 | QualType getBaseType() const { return BaseType; } |
5678 | |
5679 | bool isObjCId() const { |
5680 | return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); |
5681 | } |
5682 | |
5683 | bool isObjCClass() const { |
5684 | return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); |
5685 | } |
5686 | |
5687 | bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } |
5688 | bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } |
5689 | bool isObjCUnqualifiedIdOrClass() const { |
5690 | if (!qual_empty()) return false; |
5691 | if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) |
5692 | return T->getKind() == BuiltinType::ObjCId || |
5693 | T->getKind() == BuiltinType::ObjCClass; |
5694 | return false; |
5695 | } |
5696 | bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } |
5697 | bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } |
5698 | |
5699 | /// Gets the interface declaration for this object type, if the base type |
5700 | /// really is an interface. |
5701 | ObjCInterfaceDecl *getInterface() const; |
5702 | |
5703 | /// Determine whether this object type is "specialized", meaning |
5704 | /// that it has type arguments. |
5705 | bool isSpecialized() const; |
5706 | |
5707 | /// Determine whether this object type was written with type arguments. |
5708 | bool isSpecializedAsWritten() const { |
5709 | return ObjCObjectTypeBits.NumTypeArgs > 0; |
5710 | } |
5711 | |
5712 | /// Determine whether this object type is "unspecialized", meaning |
5713 | /// that it has no type arguments. |
5714 | bool isUnspecialized() const { return !isSpecialized(); } |
5715 | |
5716 | /// Determine whether this object type is "unspecialized" as |
5717 | /// written, meaning that it has no type arguments. |
5718 | bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); } |
5719 | |
5720 | /// Retrieve the type arguments of this object type (semantically). |
5721 | ArrayRef<QualType> getTypeArgs() const; |
5722 | |
5723 | /// Retrieve the type arguments of this object type as they were |
5724 | /// written. |
5725 | ArrayRef<QualType> getTypeArgsAsWritten() const { |
5726 | return llvm::makeArrayRef(getTypeArgStorage(), |
5727 | ObjCObjectTypeBits.NumTypeArgs); |
5728 | } |
5729 | |
5730 | /// Whether this is a "__kindof" type as written. |
5731 | bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; } |
5732 | |
5733 | /// Whether this ia a "__kindof" type (semantically). |
5734 | bool isKindOfType() const; |
5735 | |
5736 | /// Retrieve the type of the superclass of this object type. |
5737 | /// |
5738 | /// This operation substitutes any type arguments into the |
5739 | /// superclass of the current class type, potentially producing a |
5740 | /// specialization of the superclass type. Produces a null type if |
5741 | /// there is no superclass. |
5742 | QualType getSuperClassType() const { |
5743 | if (!CachedSuperClassType.getInt()) |
5744 | computeSuperClassTypeSlow(); |
5745 | |
5746 | assert(CachedSuperClassType.getInt() && "Superclass not set?")((CachedSuperClassType.getInt() && "Superclass not set?" ) ? static_cast<void> (0) : __assert_fail ("CachedSuperClassType.getInt() && \"Superclass not set?\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 5746, __PRETTY_FUNCTION__)); |
5747 | return QualType(CachedSuperClassType.getPointer(), 0); |
5748 | } |
5749 | |
5750 | /// Strip off the Objective-C "kindof" type and (with it) any |
5751 | /// protocol qualifiers. |
5752 | QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const; |
5753 | |
5754 | bool isSugared() const { return false; } |
5755 | QualType desugar() const { return QualType(this, 0); } |
5756 | |
5757 | static bool classof(const Type *T) { |
5758 | return T->getTypeClass() == ObjCObject || |
5759 | T->getTypeClass() == ObjCInterface; |
5760 | } |
5761 | }; |
5762 | |
5763 | /// A class providing a concrete implementation |
5764 | /// of ObjCObjectType, so as to not increase the footprint of |
5765 | /// ObjCInterfaceType. Code outside of ASTContext and the core type |
5766 | /// system should not reference this type. |
5767 | class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { |
5768 | friend class ASTContext; |
5769 | |
5770 | // If anyone adds fields here, ObjCObjectType::getProtocolStorage() |
5771 | // will need to be modified. |
5772 | |
5773 | ObjCObjectTypeImpl(QualType Canonical, QualType Base, |
5774 | ArrayRef<QualType> typeArgs, |
5775 | ArrayRef<ObjCProtocolDecl *> protocols, |
5776 | bool isKindOf) |
5777 | : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {} |
5778 | |
5779 | public: |
5780 | void Profile(llvm::FoldingSetNodeID &ID); |
5781 | static void Profile(llvm::FoldingSetNodeID &ID, |
5782 | QualType Base, |
5783 | ArrayRef<QualType> typeArgs, |
5784 | ArrayRef<ObjCProtocolDecl *> protocols, |
5785 | bool isKindOf); |
5786 | }; |
5787 | |
5788 | inline QualType *ObjCObjectType::getTypeArgStorage() { |
5789 | return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1); |
5790 | } |
5791 | |
5792 | inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() { |
5793 | return reinterpret_cast<ObjCProtocolDecl**>( |
5794 | getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs); |
5795 | } |
5796 | |
5797 | inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() { |
5798 | return reinterpret_cast<ObjCProtocolDecl**>( |
5799 | static_cast<ObjCTypeParamType*>(this)+1); |
5800 | } |
5801 | |
5802 | /// Interfaces are the core concept in Objective-C for object oriented design. |
5803 | /// They basically correspond to C++ classes. There are two kinds of interface |
5804 | /// types: normal interfaces like `NSString`, and qualified interfaces, which |
5805 | /// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`. |
5806 | /// |
5807 | /// ObjCInterfaceType guarantees the following properties when considered |
5808 | /// as a subtype of its superclass, ObjCObjectType: |
5809 | /// - There are no protocol qualifiers. To reinforce this, code which |
5810 | /// tries to invoke the protocol methods via an ObjCInterfaceType will |
5811 | /// fail to compile. |
5812 | /// - It is its own base type. That is, if T is an ObjCInterfaceType*, |
5813 | /// T->getBaseType() == QualType(T, 0). |
5814 | class ObjCInterfaceType : public ObjCObjectType { |
5815 | friend class ASTContext; // ASTContext creates these. |
5816 | friend class ASTReader; |
5817 | friend class ObjCInterfaceDecl; |
5818 | |
5819 | mutable ObjCInterfaceDecl *Decl; |
5820 | |
5821 | ObjCInterfaceType(const ObjCInterfaceDecl *D) |
5822 | : ObjCObjectType(Nonce_ObjCInterface), |
5823 | Decl(const_cast<ObjCInterfaceDecl*>(D)) {} |
5824 | |
5825 | public: |
5826 | /// Get the declaration of this interface. |
5827 | ObjCInterfaceDecl *getDecl() const { return Decl; } |
5828 | |
5829 | bool isSugared() const { return false; } |
5830 | QualType desugar() const { return QualType(this, 0); } |
5831 | |
5832 | static bool classof(const Type *T) { |
5833 | return T->getTypeClass() == ObjCInterface; |
5834 | } |
5835 | |
5836 | // Nonsense to "hide" certain members of ObjCObjectType within this |
5837 | // class. People asking for protocols on an ObjCInterfaceType are |
5838 | // not going to get what they want: ObjCInterfaceTypes are |
5839 | // guaranteed to have no protocols. |
5840 | enum { |
5841 | qual_iterator, |
5842 | qual_begin, |
5843 | qual_end, |
5844 | getNumProtocols, |
5845 | getProtocol |
5846 | }; |
5847 | }; |
5848 | |
5849 | inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { |
5850 | QualType baseType = getBaseType(); |
5851 | while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) { |
5852 | if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT)) |
5853 | return T->getDecl(); |
5854 | |
5855 | baseType = ObjT->getBaseType(); |
5856 | } |
5857 | |
5858 | return nullptr; |
5859 | } |
5860 | |
5861 | /// Represents a pointer to an Objective C object. |
5862 | /// |
5863 | /// These are constructed from pointer declarators when the pointee type is |
5864 | /// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class' |
5865 | /// types are typedefs for these, and the protocol-qualified types 'id<P>' |
5866 | /// and 'Class<P>' are translated into these. |
5867 | /// |
5868 | /// Pointers to pointers to Objective C objects are still PointerTypes; |
5869 | /// only the first level of pointer gets it own type implementation. |
5870 | class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { |
5871 | friend class ASTContext; // ASTContext creates these. |
5872 | |
5873 | QualType PointeeType; |
5874 | |
5875 | ObjCObjectPointerType(QualType Canonical, QualType Pointee) |
5876 | : Type(ObjCObjectPointer, Canonical, |
5877 | Pointee->isDependentType(), |
5878 | Pointee->isInstantiationDependentType(), |
5879 | Pointee->isVariablyModifiedType(), |
5880 | Pointee->containsUnexpandedParameterPack()), |
5881 | PointeeType(Pointee) {} |
5882 | |
5883 | public: |
5884 | /// Gets the type pointed to by this ObjC pointer. |
5885 | /// The result will always be an ObjCObjectType or sugar thereof. |
5886 | QualType getPointeeType() const { return PointeeType; } |
5887 | |
5888 | /// Gets the type pointed to by this ObjC pointer. Always returns non-null. |
5889 | /// |
5890 | /// This method is equivalent to getPointeeType() except that |
5891 | /// it discards any typedefs (or other sugar) between this |
5892 | /// type and the "outermost" object type. So for: |
5893 | /// \code |
5894 | /// \@class A; \@protocol P; \@protocol Q; |
5895 | /// typedef A<P> AP; |
5896 | /// typedef A A1; |
5897 | /// typedef A1<P> A1P; |
5898 | /// typedef A1P<Q> A1PQ; |
5899 | /// \endcode |
5900 | /// For 'A*', getObjectType() will return 'A'. |
5901 | /// For 'A<P>*', getObjectType() will return 'A<P>'. |
5902 | /// For 'AP*', getObjectType() will return 'A<P>'. |
5903 | /// For 'A1*', getObjectType() will return 'A'. |
5904 | /// For 'A1<P>*', getObjectType() will return 'A1<P>'. |
5905 | /// For 'A1P*', getObjectType() will return 'A1<P>'. |
5906 | /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because |
5907 | /// adding protocols to a protocol-qualified base discards the |
5908 | /// old qualifiers (for now). But if it didn't, getObjectType() |
5909 | /// would return 'A1P<Q>' (and we'd have to make iterating over |
5910 | /// qualifiers more complicated). |
5911 | const ObjCObjectType *getObjectType() const { |
5912 | return PointeeType->castAs<ObjCObjectType>(); |
5913 | } |
5914 | |
5915 | /// If this pointer points to an Objective C |
5916 | /// \@interface type, gets the type for that interface. Any protocol |
5917 | /// qualifiers on the interface are ignored. |
5918 | /// |
5919 | /// \return null if the base type for this pointer is 'id' or 'Class' |
5920 | const ObjCInterfaceType *getInterfaceType() const; |
5921 | |
5922 | /// If this pointer points to an Objective \@interface |
5923 | /// type, gets the declaration for that interface. |
5924 | /// |
5925 | /// \return null if the base type for this pointer is 'id' or 'Class' |
5926 | ObjCInterfaceDecl *getInterfaceDecl() const { |
5927 | return getObjectType()->getInterface(); |
5928 | } |
5929 | |
5930 | /// True if this is equivalent to the 'id' type, i.e. if |
5931 | /// its object type is the primitive 'id' type with no protocols. |
5932 | bool isObjCIdType() const { |
5933 | return getObjectType()->isObjCUnqualifiedId(); |
5934 | } |
5935 | |
5936 | /// True if this is equivalent to the 'Class' type, |
5937 | /// i.e. if its object tive is the primitive 'Class' type with no protocols. |
5938 | bool isObjCClassType() const { |
5939 | return getObjectType()->isObjCUnqualifiedClass(); |
5940 | } |
5941 | |
5942 | /// True if this is equivalent to the 'id' or 'Class' type, |
5943 | bool isObjCIdOrClassType() const { |
5944 | return getObjectType()->isObjCUnqualifiedIdOrClass(); |
5945 | } |
5946 | |
5947 | /// True if this is equivalent to 'id<P>' for some non-empty set of |
5948 | /// protocols. |
5949 | bool isObjCQualifiedIdType() const { |
5950 | return getObjectType()->isObjCQualifiedId(); |
5951 | } |
5952 | |
5953 | /// True if this is equivalent to 'Class<P>' for some non-empty set of |
5954 | /// protocols. |
5955 | bool isObjCQualifiedClassType() const { |
5956 | return getObjectType()->isObjCQualifiedClass(); |
5957 | } |
5958 | |
5959 | /// Whether this is a "__kindof" type. |
5960 | bool isKindOfType() const { return getObjectType()->isKindOfType(); } |
5961 | |
5962 | /// Whether this type is specialized, meaning that it has type arguments. |
5963 | bool isSpecialized() const { return getObjectType()->isSpecialized(); } |
5964 | |
5965 | /// Whether this type is specialized, meaning that it has type arguments. |
5966 | bool isSpecializedAsWritten() const { |
5967 | return getObjectType()->isSpecializedAsWritten(); |
5968 | } |
5969 | |
5970 | /// Whether this type is unspecialized, meaning that is has no type arguments. |
5971 | bool isUnspecialized() const { return getObjectType()->isUnspecialized(); } |
5972 | |
5973 | /// Determine whether this object type is "unspecialized" as |
5974 | /// written, meaning that it has no type arguments. |
5975 | bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); } |
5976 | |
5977 | /// Retrieve the type arguments for this type. |
5978 | ArrayRef<QualType> getTypeArgs() const { |
5979 | return getObjectType()->getTypeArgs(); |
5980 | } |
5981 | |
5982 | /// Retrieve the type arguments for this type. |
5983 | ArrayRef<QualType> getTypeArgsAsWritten() const { |
5984 | return getObjectType()->getTypeArgsAsWritten(); |
5985 | } |
5986 | |
5987 | /// An iterator over the qualifiers on the object type. Provided |
5988 | /// for convenience. This will always iterate over the full set of |
5989 | /// protocols on a type, not just those provided directly. |
5990 | using qual_iterator = ObjCObjectType::qual_iterator; |
5991 | using qual_range = llvm::iterator_range<qual_iterator>; |
5992 | |
5993 | qual_range quals() const { return qual_range(qual_begin(), qual_end()); } |
5994 | |
5995 | qual_iterator qual_begin() const { |
5996 | return getObjectType()->qual_begin(); |
5997 | } |
5998 | |
5999 | qual_iterator qual_end() const { |
6000 | return getObjectType()->qual_end(); |
6001 | } |
6002 | |
6003 | bool qual_empty() const { return getObjectType()->qual_empty(); } |
6004 | |
6005 | /// Return the number of qualifying protocols on the object type. |
6006 | unsigned getNumProtocols() const { |
6007 | return getObjectType()->getNumProtocols(); |
6008 | } |
6009 | |
6010 | /// Retrieve a qualifying protocol by index on the object type. |
6011 | ObjCProtocolDecl *getProtocol(unsigned I) const { |
6012 | return getObjectType()->getProtocol(I); |
6013 | } |
6014 | |
6015 | bool isSugared() const { return false; } |
6016 | QualType desugar() const { return QualType(this, 0); } |
6017 | |
6018 | /// Retrieve the type of the superclass of this object pointer type. |
6019 | /// |
6020 | /// This operation substitutes any type arguments into the |
6021 | /// superclass of the current class type, potentially producing a |
6022 | /// pointer to a specialization of the superclass type. Produces a |
6023 | /// null type if there is no superclass. |
6024 | QualType getSuperClassType() const; |
6025 | |
6026 | /// Strip off the Objective-C "kindof" type and (with it) any |
6027 | /// protocol qualifiers. |
6028 | const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals( |
6029 | const ASTContext &ctx) const; |
6030 | |
6031 | void Profile(llvm::FoldingSetNodeID &ID) { |
6032 | Profile(ID, getPointeeType()); |
6033 | } |
6034 | |
6035 | static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { |
6036 | ID.AddPointer(T.getAsOpaquePtr()); |
6037 | } |
6038 | |
6039 | static bool classof(const Type *T) { |
6040 | return T->getTypeClass() == ObjCObjectPointer; |
6041 | } |
6042 | }; |
6043 | |
6044 | class AtomicType : public Type, public llvm::FoldingSetNode { |
6045 | friend class ASTContext; // ASTContext creates these. |
6046 | |
6047 | QualType ValueType; |
6048 | |
6049 | AtomicType(QualType ValTy, QualType Canonical) |
6050 | : Type(Atomic, Canonical, ValTy->isDependentType(), |
6051 | ValTy->isInstantiationDependentType(), |
6052 | ValTy->isVariablyModifiedType(), |
6053 | ValTy->containsUnexpandedParameterPack()), |
6054 | ValueType(ValTy) {} |
6055 | |
6056 | public: |
6057 | /// Gets the type contained by this atomic type, i.e. |
6058 | /// the type returned by performing an atomic load of this atomic type. |
6059 | QualType getValueType() const { return ValueType; } |
6060 | |
6061 | bool isSugared() const { return false; } |
6062 | QualType desugar() const { return QualType(this, 0); } |
6063 | |
6064 | void Profile(llvm::FoldingSetNodeID &ID) { |
6065 | Profile(ID, getValueType()); |
6066 | } |
6067 | |
6068 | static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { |
6069 | ID.AddPointer(T.getAsOpaquePtr()); |
6070 | } |
6071 | |
6072 | static bool classof(const Type *T) { |
6073 | return T->getTypeClass() == Atomic; |
6074 | } |
6075 | }; |
6076 | |
6077 | /// PipeType - OpenCL20. |
6078 | class PipeType : public Type, public llvm::FoldingSetNode { |
6079 | friend class ASTContext; // ASTContext creates these. |
6080 | |
6081 | QualType ElementType; |
6082 | bool isRead; |
6083 | |
6084 | PipeType(QualType elemType, QualType CanonicalPtr, bool isRead) |
6085 | : Type(Pipe, CanonicalPtr, elemType->isDependentType(), |
6086 | elemType->isInstantiationDependentType(), |
6087 | elemType->isVariablyModifiedType(), |
6088 | elemType->containsUnexpandedParameterPack()), |
6089 | ElementType(elemType), isRead(isRead) {} |
6090 | |
6091 | public: |
6092 | QualType getElementType() const { return ElementType; } |
6093 | |
6094 | bool isSugared() const { return false; } |
6095 | |
6096 | QualType desugar() const { return QualType(this, 0); } |
6097 | |
6098 | void Profile(llvm::FoldingSetNodeID &ID) { |
6099 | Profile(ID, getElementType(), isReadOnly()); |
6100 | } |
6101 | |
6102 | static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) { |
6103 | ID.AddPointer(T.getAsOpaquePtr()); |
6104 | ID.AddBoolean(isRead); |
6105 | } |
6106 | |
6107 | static bool classof(const Type *T) { |
6108 | return T->getTypeClass() == Pipe; |
6109 | } |
6110 | |
6111 | bool isReadOnly() const { return isRead; } |
6112 | }; |
6113 | |
6114 | /// A qualifier set is used to build a set of qualifiers. |
6115 | class QualifierCollector : public Qualifiers { |
6116 | public: |
6117 | QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} |
6118 | |
6119 | /// Collect any qualifiers on the given type and return an |
6120 | /// unqualified type. The qualifiers are assumed to be consistent |
6121 | /// with those already in the type. |
6122 | const Type *strip(QualType type) { |
6123 | addFastQualifiers(type.getLocalFastQualifiers()); |
6124 | if (!type.hasLocalNonFastQualifiers()) |
6125 | return type.getTypePtrUnsafe(); |
6126 | |
6127 | const ExtQuals *extQuals = type.getExtQualsUnsafe(); |
6128 | addConsistentQualifiers(extQuals->getQualifiers()); |
6129 | return extQuals->getBaseType(); |
6130 | } |
6131 | |
6132 | /// Apply the collected qualifiers to the given type. |
6133 | QualType apply(const ASTContext &Context, QualType QT) const; |
6134 | |
6135 | /// Apply the collected qualifiers to the given type. |
6136 | QualType apply(const ASTContext &Context, const Type* T) const; |
6137 | }; |
6138 | |
6139 | // Inline function definitions. |
6140 | |
6141 | inline SplitQualType SplitQualType::getSingleStepDesugaredType() const { |
6142 | SplitQualType desugar = |
6143 | Ty->getLocallyUnqualifiedSingleStepDesugaredType().split(); |
6144 | desugar.Quals.addConsistentQualifiers(Quals); |
6145 | return desugar; |
6146 | } |
6147 | |
6148 | inline const Type *QualType::getTypePtr() const { |
6149 | return getCommonPtr()->BaseType; |
6150 | } |
6151 | |
6152 | inline const Type *QualType::getTypePtrOrNull() const { |
6153 | return (isNull() ? nullptr : getCommonPtr()->BaseType); |
6154 | } |
6155 | |
6156 | inline SplitQualType QualType::split() const { |
6157 | if (!hasLocalNonFastQualifiers()) |
6158 | return SplitQualType(getTypePtrUnsafe(), |
6159 | Qualifiers::fromFastMask(getLocalFastQualifiers())); |
6160 | |
6161 | const ExtQuals *eq = getExtQualsUnsafe(); |
6162 | Qualifiers qs = eq->getQualifiers(); |
6163 | qs.addFastQualifiers(getLocalFastQualifiers()); |
6164 | return SplitQualType(eq->getBaseType(), qs); |
6165 | } |
6166 | |
6167 | inline Qualifiers QualType::getLocalQualifiers() const { |
6168 | Qualifiers Quals; |
6169 | if (hasLocalNonFastQualifiers()) |
6170 | Quals = getExtQualsUnsafe()->getQualifiers(); |
6171 | Quals.addFastQualifiers(getLocalFastQualifiers()); |
6172 | return Quals; |
6173 | } |
6174 | |
6175 | inline Qualifiers QualType::getQualifiers() const { |
6176 | Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); |
6177 | quals.addFastQualifiers(getLocalFastQualifiers()); |
6178 | return quals; |
6179 | } |
6180 | |
6181 | inline unsigned QualType::getCVRQualifiers() const { |
6182 | unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); |
6183 | cvr |= getLocalCVRQualifiers(); |
6184 | return cvr; |
6185 | } |
6186 | |
6187 | inline QualType QualType::getCanonicalType() const { |
6188 | QualType canon = getCommonPtr()->CanonicalType; |
6189 | return canon.withFastQualifiers(getLocalFastQualifiers()); |
6190 | } |
6191 | |
6192 | inline bool QualType::isCanonical() const { |
6193 | return getTypePtr()->isCanonicalUnqualified(); |
6194 | } |
6195 | |
6196 | inline bool QualType::isCanonicalAsParam() const { |
6197 | if (!isCanonical()) return false; |
6198 | if (hasLocalQualifiers()) return false; |
6199 | |
6200 | const Type *T = getTypePtr(); |
6201 | if (T->isVariablyModifiedType() && T->hasSizedVLAType()) |
6202 | return false; |
6203 | |
6204 | return !isa<FunctionType>(T) && !isa<ArrayType>(T); |
6205 | } |
6206 | |
6207 | inline bool QualType::isConstQualified() const { |
6208 | return isLocalConstQualified() || |
6209 | getCommonPtr()->CanonicalType.isLocalConstQualified(); |
6210 | } |
6211 | |
6212 | inline bool QualType::isRestrictQualified() const { |
6213 | return isLocalRestrictQualified() || |
6214 | getCommonPtr()->CanonicalType.isLocalRestrictQualified(); |
6215 | } |
6216 | |
6217 | |
6218 | inline bool QualType::isVolatileQualified() const { |
6219 | return isLocalVolatileQualified() || |
6220 | getCommonPtr()->CanonicalType.isLocalVolatileQualified(); |
6221 | } |
6222 | |
6223 | inline bool QualType::hasQualifiers() const { |
6224 | return hasLocalQualifiers() || |
6225 | getCommonPtr()->CanonicalType.hasLocalQualifiers(); |
6226 | } |
6227 | |
6228 | inline QualType QualType::getUnqualifiedType() const { |
6229 | if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) |
6230 | return QualType(getTypePtr(), 0); |
6231 | |
6232 | return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0); |
6233 | } |
6234 | |
6235 | inline SplitQualType QualType::getSplitUnqualifiedType() const { |
6236 | if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) |
6237 | return split(); |
6238 | |
6239 | return getSplitUnqualifiedTypeImpl(*this); |
6240 | } |
6241 | |
6242 | inline void QualType::removeLocalConst() { |
6243 | removeLocalFastQualifiers(Qualifiers::Const); |
6244 | } |
6245 | |
6246 | inline void QualType::removeLocalRestrict() { |
6247 | removeLocalFastQualifiers(Qualifiers::Restrict); |
6248 | } |
6249 | |
6250 | inline void QualType::removeLocalVolatile() { |
6251 | removeLocalFastQualifiers(Qualifiers::Volatile); |
6252 | } |
6253 | |
6254 | inline void QualType::removeLocalCVRQualifiers(unsigned Mask) { |
6255 | assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits")((!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits" ) ? static_cast<void> (0) : __assert_fail ("!(Mask & ~Qualifiers::CVRMask) && \"mask has non-CVR bits\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 6255, __PRETTY_FUNCTION__)); |
6256 | static_assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask, |
6257 | "Fast bits differ from CVR bits!"); |
6258 | |
6259 | // Fast path: we don't need to touch the slow qualifiers. |
6260 | removeLocalFastQualifiers(Mask); |
6261 | } |
6262 | |
6263 | /// Return the address space of this type. |
6264 | inline LangAS QualType::getAddressSpace() const { |
6265 | return getQualifiers().getAddressSpace(); |
6266 | } |
6267 | |
6268 | /// Return the gc attribute of this type. |
6269 | inline Qualifiers::GC QualType::getObjCGCAttr() const { |
6270 | return getQualifiers().getObjCGCAttr(); |
6271 | } |
6272 | |
6273 | inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const { |
6274 | if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) |
6275 | return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD); |
6276 | return false; |
6277 | } |
6278 | |
6279 | inline bool QualType::hasNonTrivialToPrimitiveDestructCUnion() const { |
6280 | if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) |
6281 | return hasNonTrivialToPrimitiveDestructCUnion(RD); |
6282 | return false; |
6283 | } |
6284 | |
6285 | inline bool QualType::hasNonTrivialToPrimitiveCopyCUnion() const { |
6286 | if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) |
6287 | return hasNonTrivialToPrimitiveCopyCUnion(RD); |
6288 | return false; |
6289 | } |
6290 | |
6291 | inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { |
6292 | if (const auto *PT = t.getAs<PointerType>()) { |
6293 | if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>()) |
6294 | return FT->getExtInfo(); |
6295 | } else if (const auto *FT = t.getAs<FunctionType>()) |
6296 | return FT->getExtInfo(); |
6297 | |
6298 | return FunctionType::ExtInfo(); |
6299 | } |
6300 | |
6301 | inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { |
6302 | return getFunctionExtInfo(*t); |
6303 | } |
6304 | |
6305 | /// Determine whether this type is more |
6306 | /// qualified than the Other type. For example, "const volatile int" |
6307 | /// is more qualified than "const int", "volatile int", and |
6308 | /// "int". However, it is not more qualified than "const volatile |
6309 | /// int". |
6310 | inline bool QualType::isMoreQualifiedThan(QualType other) const { |
6311 | Qualifiers MyQuals = getQualifiers(); |
6312 | Qualifiers OtherQuals = other.getQualifiers(); |
6313 | return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals)); |
6314 | } |
6315 | |
6316 | /// Determine whether this type is at last |
6317 | /// as qualified as the Other type. For example, "const volatile |
6318 | /// int" is at least as qualified as "const int", "volatile int", |
6319 | /// "int", and "const volatile int". |
6320 | inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { |
6321 | Qualifiers OtherQuals = other.getQualifiers(); |
6322 | |
6323 | // Ignore __unaligned qualifier if this type is a void. |
6324 | if (getUnqualifiedType()->isVoidType()) |
6325 | OtherQuals.removeUnaligned(); |
6326 | |
6327 | return getQualifiers().compatiblyIncludes(OtherQuals); |
6328 | } |
6329 | |
6330 | /// If Type is a reference type (e.g., const |
6331 | /// int&), returns the type that the reference refers to ("const |
6332 | /// int"). Otherwise, returns the type itself. This routine is used |
6333 | /// throughout Sema to implement C++ 5p6: |
6334 | /// |
6335 | /// If an expression initially has the type "reference to T" (8.3.2, |
6336 | /// 8.5.3), the type is adjusted to "T" prior to any further |
6337 | /// analysis, the expression designates the object or function |
6338 | /// denoted by the reference, and the expression is an lvalue. |
6339 | inline QualType QualType::getNonReferenceType() const { |
6340 | if (const auto *RefType = (*this)->getAs<ReferenceType>()) |
6341 | return RefType->getPointeeType(); |
6342 | else |
6343 | return *this; |
6344 | } |
6345 | |
6346 | inline bool QualType::isCForbiddenLValueType() const { |
6347 | return ((getTypePtr()->isVoidType() && !hasQualifiers()) || |
6348 | getTypePtr()->isFunctionType()); |
6349 | } |
6350 | |
6351 | /// Tests whether the type is categorized as a fundamental type. |
6352 | /// |
6353 | /// \returns True for types specified in C++0x [basic.fundamental]. |
6354 | inline bool Type::isFundamentalType() const { |
6355 | return isVoidType() || |
6356 | isNullPtrType() || |
6357 | // FIXME: It's really annoying that we don't have an |
6358 | // 'isArithmeticType()' which agrees with the standard definition. |
6359 | (isArithmeticType() && !isEnumeralType()); |
6360 | } |
6361 | |
6362 | /// Tests whether the type is categorized as a compound type. |
6363 | /// |
6364 | /// \returns True for types specified in C++0x [basic.compound]. |
6365 | inline bool Type::isCompoundType() const { |
6366 | // C++0x [basic.compound]p1: |
6367 | // Compound types can be constructed in the following ways: |
6368 | // -- arrays of objects of a given type [...]; |
6369 | return isArrayType() || |
6370 | // -- functions, which have parameters of given types [...]; |
6371 | isFunctionType() || |
6372 | // -- pointers to void or objects or functions [...]; |
6373 | isPointerType() || |
6374 | // -- references to objects or functions of a given type. [...] |
6375 | isReferenceType() || |
6376 | // -- classes containing a sequence of objects of various types, [...]; |
6377 | isRecordType() || |
6378 | // -- unions, which are classes capable of containing objects of different |
6379 | // types at different times; |
6380 | isUnionType() || |
6381 | // -- enumerations, which comprise a set of named constant values. [...]; |
6382 | isEnumeralType() || |
6383 | // -- pointers to non-static class members, [...]. |
6384 | isMemberPointerType(); |
6385 | } |
6386 | |
6387 | inline bool Type::isFunctionType() const { |
6388 | return isa<FunctionType>(CanonicalType); |
6389 | } |
6390 | |
6391 | inline bool Type::isPointerType() const { |
6392 | return isa<PointerType>(CanonicalType); |
6393 | } |
6394 | |
6395 | inline bool Type::isAnyPointerType() const { |
6396 | return isPointerType() || isObjCObjectPointerType(); |
6397 | } |
6398 | |
6399 | inline bool Type::isBlockPointerType() const { |
6400 | return isa<BlockPointerType>(CanonicalType); |
6401 | } |
6402 | |
6403 | inline bool Type::isReferenceType() const { |
6404 | return isa<ReferenceType>(CanonicalType); |
6405 | } |
6406 | |
6407 | inline bool Type::isLValueReferenceType() const { |
6408 | return isa<LValueReferenceType>(CanonicalType); |
6409 | } |
6410 | |
6411 | inline bool Type::isRValueReferenceType() const { |
6412 | return isa<RValueReferenceType>(CanonicalType); |
6413 | } |
6414 | |
6415 | inline bool Type::isFunctionPointerType() const { |
6416 | if (const auto *T = getAs<PointerType>()) |
6417 | return T->getPointeeType()->isFunctionType(); |
6418 | else |
6419 | return false; |
6420 | } |
6421 | |
6422 | inline bool Type::isFunctionReferenceType() const { |
6423 | if (const auto *T = getAs<ReferenceType>()) |
6424 | return T->getPointeeType()->isFunctionType(); |
6425 | else |
6426 | return false; |
6427 | } |
6428 | |
6429 | inline bool Type::isMemberPointerType() const { |
6430 | return isa<MemberPointerType>(CanonicalType); |
6431 | } |
6432 | |
6433 | inline bool Type::isMemberFunctionPointerType() const { |
6434 | if (const auto *T = getAs<MemberPointerType>()) |
6435 | return T->isMemberFunctionPointer(); |
6436 | else |
6437 | return false; |
6438 | } |
6439 | |
6440 | inline bool Type::isMemberDataPointerType() const { |
6441 | if (const auto *T = getAs<MemberPointerType>()) |
6442 | return T->isMemberDataPointer(); |
6443 | else |
6444 | return false; |
6445 | } |
6446 | |
6447 | inline bool Type::isArrayType() const { |
6448 | return isa<ArrayType>(CanonicalType); |
6449 | } |
6450 | |
6451 | inline bool Type::isConstantArrayType() const { |
6452 | return isa<ConstantArrayType>(CanonicalType); |
6453 | } |
6454 | |
6455 | inline bool Type::isIncompleteArrayType() const { |
6456 | return isa<IncompleteArrayType>(CanonicalType); |
6457 | } |
6458 | |
6459 | inline bool Type::isVariableArrayType() const { |
6460 | return isa<VariableArrayType>(CanonicalType); |
6461 | } |
6462 | |
6463 | inline bool Type::isDependentSizedArrayType() const { |
6464 | return isa<DependentSizedArrayType>(CanonicalType); |
6465 | } |
6466 | |
6467 | inline bool Type::isBuiltinType() const { |
6468 | return isa<BuiltinType>(CanonicalType); |
6469 | } |
6470 | |
6471 | inline bool Type::isRecordType() const { |
6472 | return isa<RecordType>(CanonicalType); |
6473 | } |
6474 | |
6475 | inline bool Type::isEnumeralType() const { |
6476 | return isa<EnumType>(CanonicalType); |
6477 | } |
6478 | |
6479 | inline bool Type::isAnyComplexType() const { |
6480 | return isa<ComplexType>(CanonicalType); |
6481 | } |
6482 | |
6483 | inline bool Type::isVectorType() const { |
6484 | return isa<VectorType>(CanonicalType); |
6485 | } |
6486 | |
6487 | inline bool Type::isExtVectorType() const { |
6488 | return isa<ExtVectorType>(CanonicalType); |
6489 | } |
6490 | |
6491 | inline bool Type::isDependentAddressSpaceType() const { |
6492 | return isa<DependentAddressSpaceType>(CanonicalType); |
6493 | } |
6494 | |
6495 | inline bool Type::isObjCObjectPointerType() const { |
6496 | return isa<ObjCObjectPointerType>(CanonicalType); |
6497 | } |
6498 | |
6499 | inline bool Type::isObjCObjectType() const { |
6500 | return isa<ObjCObjectType>(CanonicalType); |
6501 | } |
6502 | |
6503 | inline bool Type::isObjCObjectOrInterfaceType() const { |
6504 | return isa<ObjCInterfaceType>(CanonicalType) || |
6505 | isa<ObjCObjectType>(CanonicalType); |
6506 | } |
6507 | |
6508 | inline bool Type::isAtomicType() const { |
6509 | return isa<AtomicType>(CanonicalType); |
6510 | } |
6511 | |
6512 | inline bool Type::isObjCQualifiedIdType() const { |
6513 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
6514 | return OPT->isObjCQualifiedIdType(); |
6515 | return false; |
6516 | } |
6517 | |
6518 | inline bool Type::isObjCQualifiedClassType() const { |
6519 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
6520 | return OPT->isObjCQualifiedClassType(); |
6521 | return false; |
6522 | } |
6523 | |
6524 | inline bool Type::isObjCIdType() const { |
6525 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
6526 | return OPT->isObjCIdType(); |
6527 | return false; |
6528 | } |
6529 | |
6530 | inline bool Type::isObjCClassType() const { |
6531 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
6532 | return OPT->isObjCClassType(); |
6533 | return false; |
6534 | } |
6535 | |
6536 | inline bool Type::isObjCSelType() const { |
6537 | if (const auto *OPT = getAs<PointerType>()) |
6538 | return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); |
6539 | return false; |
6540 | } |
6541 | |
6542 | inline bool Type::isObjCBuiltinType() const { |
6543 | return isObjCIdType() || isObjCClassType() || isObjCSelType(); |
6544 | } |
6545 | |
6546 | inline bool Type::isDecltypeType() const { |
6547 | return isa<DecltypeType>(this); |
6548 | } |
6549 | |
6550 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
6551 | inline bool Type::is##Id##Type() const { \ |
6552 | return isSpecificBuiltinType(BuiltinType::Id); \ |
6553 | } |
6554 | #include "clang/Basic/OpenCLImageTypes.def" |
6555 | |
6556 | inline bool Type::isSamplerT() const { |
6557 | return isSpecificBuiltinType(BuiltinType::OCLSampler); |
6558 | } |
6559 | |
6560 | inline bool Type::isEventT() const { |
6561 | return isSpecificBuiltinType(BuiltinType::OCLEvent); |
6562 | } |
6563 | |
6564 | inline bool Type::isClkEventT() const { |
6565 | return isSpecificBuiltinType(BuiltinType::OCLClkEvent); |
6566 | } |
6567 | |
6568 | inline bool Type::isQueueT() const { |
6569 | return isSpecificBuiltinType(BuiltinType::OCLQueue); |
6570 | } |
6571 | |
6572 | inline bool Type::isReserveIDT() const { |
6573 | return isSpecificBuiltinType(BuiltinType::OCLReserveID); |
6574 | } |
6575 | |
6576 | inline bool Type::isImageType() const { |
6577 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() || |
6578 | return |
6579 | #include "clang/Basic/OpenCLImageTypes.def" |
6580 | false; // end boolean or operation |
6581 | } |
6582 | |
6583 | inline bool Type::isPipeType() const { |
6584 | return isa<PipeType>(CanonicalType); |
6585 | } |
6586 | |
6587 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
6588 | inline bool Type::is##Id##Type() const { \ |
6589 | return isSpecificBuiltinType(BuiltinType::Id); \ |
6590 | } |
6591 | #include "clang/Basic/OpenCLExtensionTypes.def" |
6592 | |
6593 | inline bool Type::isOCLIntelSubgroupAVCType() const { |
6594 | #define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \ |
6595 | isOCLIntelSubgroupAVC##Id##Type() || |
6596 | return |
6597 | #include "clang/Basic/OpenCLExtensionTypes.def" |
6598 | false; // end of boolean or operation |
6599 | } |
6600 | |
6601 | inline bool Type::isOCLExtOpaqueType() const { |
6602 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() || |
6603 | return |
6604 | #include "clang/Basic/OpenCLExtensionTypes.def" |
6605 | false; // end of boolean or operation |
6606 | } |
6607 | |
6608 | inline bool Type::isOpenCLSpecificType() const { |
6609 | return isSamplerT() || isEventT() || isImageType() || isClkEventT() || |
6610 | isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType(); |
6611 | } |
6612 | |
6613 | inline bool Type::isTemplateTypeParmType() const { |
6614 | return isa<TemplateTypeParmType>(CanonicalType); |
6615 | } |
6616 | |
6617 | inline bool Type::isSpecificBuiltinType(unsigned K) const { |
6618 | if (const BuiltinType *BT = getAs<BuiltinType>()) |
6619 | if (BT->getKind() == (BuiltinType::Kind) K) |
6620 | return true; |
6621 | return false; |
6622 | } |
6623 | |
6624 | inline bool Type::isPlaceholderType() const { |
6625 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
6626 | return BT->isPlaceholderType(); |
6627 | return false; |
6628 | } |
6629 | |
6630 | inline const BuiltinType *Type::getAsPlaceholderType() const { |
6631 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
6632 | if (BT->isPlaceholderType()) |
6633 | return BT; |
6634 | return nullptr; |
6635 | } |
6636 | |
6637 | inline bool Type::isSpecificPlaceholderType(unsigned K) const { |
6638 | assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K))((BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)) ? static_cast<void> (0) : __assert_fail ("BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 6638, __PRETTY_FUNCTION__)); |
6639 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
6640 | return (BT->getKind() == (BuiltinType::Kind) K); |
6641 | return false; |
6642 | } |
6643 | |
6644 | inline bool Type::isNonOverloadPlaceholderType() const { |
6645 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
6646 | return BT->isNonOverloadPlaceholderType(); |
6647 | return false; |
6648 | } |
6649 | |
6650 | inline bool Type::isVoidType() const { |
6651 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6652 | return BT->getKind() == BuiltinType::Void; |
6653 | return false; |
6654 | } |
6655 | |
6656 | inline bool Type::isHalfType() const { |
6657 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6658 | return BT->getKind() == BuiltinType::Half; |
6659 | // FIXME: Should we allow complex __fp16? Probably not. |
6660 | return false; |
6661 | } |
6662 | |
6663 | inline bool Type::isFloat16Type() const { |
6664 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6665 | return BT->getKind() == BuiltinType::Float16; |
6666 | return false; |
6667 | } |
6668 | |
6669 | inline bool Type::isFloat128Type() const { |
6670 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6671 | return BT->getKind() == BuiltinType::Float128; |
6672 | return false; |
6673 | } |
6674 | |
6675 | inline bool Type::isNullPtrType() const { |
6676 | if (const auto *BT = getAs<BuiltinType>()) |
6677 | return BT->getKind() == BuiltinType::NullPtr; |
6678 | return false; |
6679 | } |
6680 | |
6681 | bool IsEnumDeclComplete(EnumDecl *); |
6682 | bool IsEnumDeclScoped(EnumDecl *); |
6683 | |
6684 | inline bool Type::isIntegerType() const { |
6685 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6686 | return BT->getKind() >= BuiltinType::Bool && |
6687 | BT->getKind() <= BuiltinType::Int128; |
6688 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { |
6689 | // Incomplete enum types are not treated as integer types. |
6690 | // FIXME: In C++, enum types are never integer types. |
6691 | return IsEnumDeclComplete(ET->getDecl()) && |
6692 | !IsEnumDeclScoped(ET->getDecl()); |
6693 | } |
6694 | return false; |
6695 | } |
6696 | |
6697 | inline bool Type::isFixedPointType() const { |
6698 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
6699 | return BT->getKind() >= BuiltinType::ShortAccum && |
6700 | BT->getKind() <= BuiltinType::SatULongFract; |
6701 | } |
6702 | return false; |
6703 | } |
6704 | |
6705 | inline bool Type::isFixedPointOrIntegerType() const { |
6706 | return isFixedPointType() || isIntegerType(); |
6707 | } |
6708 | |
6709 | inline bool Type::isSaturatedFixedPointType() const { |
6710 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
6711 | return BT->getKind() >= BuiltinType::SatShortAccum && |
6712 | BT->getKind() <= BuiltinType::SatULongFract; |
6713 | } |
6714 | return false; |
6715 | } |
6716 | |
6717 | inline bool Type::isUnsaturatedFixedPointType() const { |
6718 | return isFixedPointType() && !isSaturatedFixedPointType(); |
6719 | } |
6720 | |
6721 | inline bool Type::isSignedFixedPointType() const { |
6722 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
6723 | return ((BT->getKind() >= BuiltinType::ShortAccum && |
6724 | BT->getKind() <= BuiltinType::LongAccum) || |
6725 | (BT->getKind() >= BuiltinType::ShortFract && |
6726 | BT->getKind() <= BuiltinType::LongFract) || |
6727 | (BT->getKind() >= BuiltinType::SatShortAccum && |
6728 | BT->getKind() <= BuiltinType::SatLongAccum) || |
6729 | (BT->getKind() >= BuiltinType::SatShortFract && |
6730 | BT->getKind() <= BuiltinType::SatLongFract)); |
6731 | } |
6732 | return false; |
6733 | } |
6734 | |
6735 | inline bool Type::isUnsignedFixedPointType() const { |
6736 | return isFixedPointType() && !isSignedFixedPointType(); |
6737 | } |
6738 | |
6739 | inline bool Type::isScalarType() const { |
6740 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6741 | return BT->getKind() > BuiltinType::Void && |
6742 | BT->getKind() <= BuiltinType::NullPtr; |
6743 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
6744 | // Enums are scalar types, but only if they are defined. Incomplete enums |
6745 | // are not treated as scalar types. |
6746 | return IsEnumDeclComplete(ET->getDecl()); |
6747 | return isa<PointerType>(CanonicalType) || |
6748 | isa<BlockPointerType>(CanonicalType) || |
6749 | isa<MemberPointerType>(CanonicalType) || |
6750 | isa<ComplexType>(CanonicalType) || |
6751 | isa<ObjCObjectPointerType>(CanonicalType); |
6752 | } |
6753 | |
6754 | inline bool Type::isIntegralOrEnumerationType() const { |
6755 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6756 | return BT->getKind() >= BuiltinType::Bool && |
6757 | BT->getKind() <= BuiltinType::Int128; |
6758 | |
6759 | // Check for a complete enum type; incomplete enum types are not properly an |
6760 | // enumeration type in the sense required here. |
6761 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) |
6762 | return IsEnumDeclComplete(ET->getDecl()); |
6763 | |
6764 | return false; |
6765 | } |
6766 | |
6767 | inline bool Type::isBooleanType() const { |
6768 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
6769 | return BT->getKind() == BuiltinType::Bool; |
6770 | return false; |
6771 | } |
6772 | |
6773 | inline bool Type::isUndeducedType() const { |
6774 | auto *DT = getContainedDeducedType(); |
6775 | return DT && !DT->isDeduced(); |
6776 | } |
6777 | |
6778 | /// Determines whether this is a type for which one can define |
6779 | /// an overloaded operator. |
6780 | inline bool Type::isOverloadableType() const { |
6781 | return isDependentType() || isRecordType() || isEnumeralType(); |
6782 | } |
6783 | |
6784 | /// Determines whether this type can decay to a pointer type. |
6785 | inline bool Type::canDecayToPointerType() const { |
6786 | return isFunctionType() || isArrayType(); |
6787 | } |
6788 | |
6789 | inline bool Type::hasPointerRepresentation() const { |
6790 | return (isPointerType() || isReferenceType() || isBlockPointerType() || |
6791 | isObjCObjectPointerType() || isNullPtrType()); |
6792 | } |
6793 | |
6794 | inline bool Type::hasObjCPointerRepresentation() const { |
6795 | return isObjCObjectPointerType(); |
6796 | } |
6797 | |
6798 | inline const Type *Type::getBaseElementTypeUnsafe() const { |
6799 | const Type *type = this; |
6800 | while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) |
6801 | type = arrayType->getElementType().getTypePtr(); |
6802 | return type; |
6803 | } |
6804 | |
6805 | inline const Type *Type::getPointeeOrArrayElementType() const { |
6806 | const Type *type = this; |
6807 | if (type->isAnyPointerType()) |
6808 | return type->getPointeeType().getTypePtr(); |
6809 | else if (type->isArrayType()) |
6810 | return type->getBaseElementTypeUnsafe(); |
6811 | return type; |
6812 | } |
6813 | |
6814 | /// Insertion operator for diagnostics. This allows sending Qualifiers into a |
6815 | /// diagnostic with <<. |
6816 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
6817 | Qualifiers Q) { |
6818 | DB.AddTaggedVal(Q.getAsOpaqueValue(), |
6819 | DiagnosticsEngine::ArgumentKind::ak_qual); |
6820 | return DB; |
6821 | } |
6822 | |
6823 | /// Insertion operator for partial diagnostics. This allows sending Qualifiers |
6824 | /// into a diagnostic with <<. |
6825 | inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, |
6826 | Qualifiers Q) { |
6827 | PD.AddTaggedVal(Q.getAsOpaqueValue(), |
6828 | DiagnosticsEngine::ArgumentKind::ak_qual); |
6829 | return PD; |
6830 | } |
6831 | |
6832 | /// Insertion operator for diagnostics. This allows sending QualType's into a |
6833 | /// diagnostic with <<. |
6834 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
6835 | QualType T) { |
6836 | DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), |
6837 | DiagnosticsEngine::ak_qualtype); |
6838 | return DB; |
6839 | } |
6840 | |
6841 | /// Insertion operator for partial diagnostics. This allows sending QualType's |
6842 | /// into a diagnostic with <<. |
6843 | inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, |
6844 | QualType T) { |
6845 | PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), |
6846 | DiagnosticsEngine::ak_qualtype); |
6847 | return PD; |
6848 | } |
6849 | |
6850 | // Helper class template that is used by Type::getAs to ensure that one does |
6851 | // not try to look through a qualified type to get to an array type. |
6852 | template <typename T> |
6853 | using TypeIsArrayType = |
6854 | std::integral_constant<bool, std::is_same<T, ArrayType>::value || |
6855 | std::is_base_of<ArrayType, T>::value>; |
6856 | |
6857 | // Member-template getAs<specific type>'. |
6858 | template <typename T> const T *Type::getAs() const { |
6859 | static_assert(!TypeIsArrayType<T>::value, |
6860 | "ArrayType cannot be used with getAs!"); |
6861 | |
6862 | // If this is directly a T type, return it. |
6863 | if (const auto *Ty = dyn_cast<T>(this)) |
6864 | return Ty; |
6865 | |
6866 | // If the canonical form of this type isn't the right kind, reject it. |
6867 | if (!isa<T>(CanonicalType)) |
6868 | return nullptr; |
6869 | |
6870 | // If this is a typedef for the type, strip the typedef off without |
6871 | // losing all typedef information. |
6872 | return cast<T>(getUnqualifiedDesugaredType()); |
6873 | } |
6874 | |
6875 | template <typename T> const T *Type::getAsAdjusted() const { |
6876 | static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!"); |
6877 | |
6878 | // If this is directly a T type, return it. |
6879 | if (const auto *Ty = dyn_cast<T>(this)) |
6880 | return Ty; |
6881 | |
6882 | // If the canonical form of this type isn't the right kind, reject it. |
6883 | if (!isa<T>(CanonicalType)) |
6884 | return nullptr; |
6885 | |
6886 | // Strip off type adjustments that do not modify the underlying nature of the |
6887 | // type. |
6888 | const Type *Ty = this; |
6889 | while (Ty) { |
6890 | if (const auto *A = dyn_cast<AttributedType>(Ty)) |
6891 | Ty = A->getModifiedType().getTypePtr(); |
6892 | else if (const auto *E = dyn_cast<ElaboratedType>(Ty)) |
6893 | Ty = E->desugar().getTypePtr(); |
6894 | else if (const auto *P = dyn_cast<ParenType>(Ty)) |
6895 | Ty = P->desugar().getTypePtr(); |
6896 | else if (const auto *A = dyn_cast<AdjustedType>(Ty)) |
6897 | Ty = A->desugar().getTypePtr(); |
6898 | else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty)) |
6899 | Ty = M->desugar().getTypePtr(); |
6900 | else |
6901 | break; |
6902 | } |
6903 | |
6904 | // Just because the canonical type is correct does not mean we can use cast<>, |
6905 | // since we may not have stripped off all the sugar down to the base type. |
6906 | return dyn_cast<T>(Ty); |
6907 | } |
6908 | |
6909 | inline const ArrayType *Type::getAsArrayTypeUnsafe() const { |
6910 | // If this is directly an array type, return it. |
6911 | if (const auto *arr = dyn_cast<ArrayType>(this)) |
6912 | return arr; |
6913 | |
6914 | // If the canonical form of this type isn't the right kind, reject it. |
6915 | if (!isa<ArrayType>(CanonicalType)) |
6916 | return nullptr; |
6917 | |
6918 | // If this is a typedef for the type, strip the typedef off without |
6919 | // losing all typedef information. |
6920 | return cast<ArrayType>(getUnqualifiedDesugaredType()); |
6921 | } |
6922 | |
6923 | template <typename T> const T *Type::castAs() const { |
6924 | static_assert(!TypeIsArrayType<T>::value, |
6925 | "ArrayType cannot be used with castAs!"); |
6926 | |
6927 | if (const auto *ty = dyn_cast<T>(this)) return ty; |
6928 | assert(isa<T>(CanonicalType))((isa<T>(CanonicalType)) ? static_cast<void> (0) : __assert_fail ("isa<T>(CanonicalType)", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 6928, __PRETTY_FUNCTION__)); |
6929 | return cast<T>(getUnqualifiedDesugaredType()); |
6930 | } |
6931 | |
6932 | inline const ArrayType *Type::castAsArrayTypeUnsafe() const { |
6933 | assert(isa<ArrayType>(CanonicalType))((isa<ArrayType>(CanonicalType)) ? static_cast<void> (0) : __assert_fail ("isa<ArrayType>(CanonicalType)", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 6933, __PRETTY_FUNCTION__)); |
6934 | if (const auto *arr = dyn_cast<ArrayType>(this)) return arr; |
6935 | return cast<ArrayType>(getUnqualifiedDesugaredType()); |
6936 | } |
6937 | |
6938 | DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr, |
6939 | QualType CanonicalPtr) |
6940 | : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) { |
6941 | #ifndef NDEBUG |
6942 | QualType Adjusted = getAdjustedType(); |
6943 | (void)AttributedType::stripOuterNullability(Adjusted); |
6944 | assert(isa<PointerType>(Adjusted))((isa<PointerType>(Adjusted)) ? static_cast<void> (0) : __assert_fail ("isa<PointerType>(Adjusted)", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/Type.h" , 6944, __PRETTY_FUNCTION__)); |
6945 | #endif |
6946 | } |
6947 | |
6948 | QualType DecayedType::getPointeeType() const { |
6949 | QualType Decayed = getDecayedType(); |
6950 | (void)AttributedType::stripOuterNullability(Decayed); |
6951 | return cast<PointerType>(Decayed)->getPointeeType(); |
6952 | } |
6953 | |
6954 | // Get the decimal string representation of a fixed point type, represented |
6955 | // as a scaled integer. |
6956 | // TODO: At some point, we should change the arguments to instead just accept an |
6957 | // APFixedPoint instead of APSInt and scale. |
6958 | void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val, |
6959 | unsigned Scale); |
6960 | |
6961 | } // namespace clang |
6962 | |
6963 | #endif // LLVM_CLANG_AST_TYPE_H |