 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
26.4% |
55 / 208 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
39.9% |
83 / 208 |
| |
|
Line Coverage: |
86.9% |
430 / 495 |
| |
 |
|
 |
1 : //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file defines the Expr interface and subclasses for C++ expressions.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 : #define LLVM_CLANG_AST_EXPRCXX_H
16 :
17 : #include "clang/Basic/TypeTraits.h"
18 : #include "clang/AST/Expr.h"
19 : #include "clang/AST/UnresolvedSet.h"
20 : #include "clang/AST/TemplateBase.h"
21 :
22 : namespace clang {
23 :
24 : class CXXConstructorDecl;
25 : class CXXDestructorDecl;
26 : class CXXMethodDecl;
27 : class CXXTemporary;
28 : class TemplateArgumentListInfo;
29 :
30 : //===--------------------------------------------------------------------===//
31 : // C++ Expressions.
32 : //===--------------------------------------------------------------------===//
33 :
34 : /// \brief A call to an overloaded operator written using operator
35 : /// syntax.
36 : ///
37 : /// Represents a call to an overloaded operator written using operator
38 : /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
39 : /// normal call, this AST node provides better information about the
40 : /// syntactic representation of the call.
41 : ///
42 : /// In a C++ template, this expression node kind will be used whenever
43 : /// any of the arguments are type-dependent. In this case, the
44 : /// function itself will be a (possibly empty) set of functions and
45 : /// function templates that were found by name lookup at template
46 : /// definition time.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
19: branch 6 taken
47 19: class CXXOperatorCallExpr : public CallExpr {
48 : /// \brief The overloaded operator.
49 : OverloadedOperatorKind Operator;
50 :
51 : public:
52 : CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
53 : Expr **args, unsigned numargs, QualType t,
54 282: SourceLocation operatorloc)
55 : : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc),
56 282: Operator(Op) {}
57 0: explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
58 0: CallExpr(C, CXXOperatorCallExprClass, Empty) { }
59 :
60 :
61 : /// getOperator - Returns the kind of overloaded operator that this
62 : /// expression refers to.
63 872: OverloadedOperatorKind getOperator() const { return Operator; }
64 0: void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
65 :
66 : /// getOperatorLoc - Returns the location of the operator symbol in
67 : /// the expression. When @c getOperator()==OO_Call, this is the
68 : /// location of the right parentheses; when @c
69 : /// getOperator()==OO_Subscript, this is the location of the right
70 : /// bracket.
71 193: SourceLocation getOperatorLoc() const { return getRParenLoc(); }
72 :
73 : virtual SourceRange getSourceRange() const;
74 :
75 2016: static bool classof(const Stmt *T) {
76 2016: return T->getStmtClass() == CXXOperatorCallExprClass;
77 : }
78 : static bool classof(const CXXOperatorCallExpr *) { return true; }
79 : };
80 :
81 : /// CXXMemberCallExpr - Represents a call to a member function that
82 : /// may be written either with member call syntax (e.g., "obj.func()"
83 : /// or "objptr->func()") or with normal function-call syntax
84 : /// ("func()") within a member function that ends up calling a member
85 : /// function. The callee in either case is a MemberExpr that contains
86 : /// both the object argument and the member function, while the
87 : /// arguments are the arguments within the parentheses (not including
88 : /// the object argument).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
23: branch 6 taken
89 23: class CXXMemberCallExpr : public CallExpr {
90 : public:
91 : CXXMemberCallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs,
92 853: QualType t, SourceLocation rparenloc)
93 853: : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {}
94 :
95 : /// getImplicitObjectArgument - Retrieves the implicit object
96 : /// argument for the member call. For example, in "x.f(5)", this
97 : /// operation would return "x".
98 : Expr *getImplicitObjectArgument();
99 :
100 : virtual SourceRange getSourceRange() const;
101 :
102 2641: static bool classof(const Stmt *T) {
103 2641: return T->getStmtClass() == CXXMemberCallExprClass;
104 : }
105 : static bool classof(const CXXMemberCallExpr *) { return true; }
106 : };
107 :
108 : /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
109 : /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
110 : /// const_cast.
111 : ///
112 : /// This abstract class is inherited by all of the classes
113 : /// representing "named" casts, e.g., CXXStaticCastExpr,
114 : /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 9 not taken
0: branch 10 not taken
115 0: class CXXNamedCastExpr : public ExplicitCastExpr {
116 : private:
117 : SourceLocation Loc; // the location of the casting op
118 :
119 : protected:
120 : CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op,
121 268: TypeSourceInfo *writtenTy, SourceLocation l)
122 268: : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {}
123 :
124 4: explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell)
125 4: : ExplicitCastExpr(SC, Shell) { }
126 :
127 : public:
128 : const char *getCastName() const;
129 :
130 : /// \brief Retrieve the location of the cast operator keyword, e.g.,
131 : /// "static_cast".
132 55: SourceLocation getOperatorLoc() const { return Loc; }
133 4: void setOperatorLoc(SourceLocation L) { Loc = L; }
134 :
135 480: virtual SourceRange getSourceRange() const {
136 480: return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
137 : }
138 9: static bool classof(const Stmt *T) {
9: branch 1 taken
0: branch 2 not taken
139 9: switch (T->getStmtClass()) {
140 : case CXXNamedCastExprClass:
141 : case CXXStaticCastExprClass:
142 : case CXXDynamicCastExprClass:
143 : case CXXReinterpretCastExprClass:
144 : case CXXConstCastExprClass:
145 9: return true;
146 : default:
147 0: return false;
148 : }
149 : }
150 : static bool classof(const CXXNamedCastExpr *) { return true; }
151 : };
152 :
153 : /// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
154 : ///
155 : /// This expression node represents a C++ static cast, e.g.,
156 : /// @c static_cast<int>(1.0).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
157 0: class CXXStaticCastExpr : public CXXNamedCastExpr {
158 : public:
159 : CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op,
160 130: TypeSourceInfo *writtenTy, SourceLocation l)
161 130: : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {}
162 :
163 1: explicit CXXStaticCastExpr(EmptyShell Empty)
164 1: : CXXNamedCastExpr(CXXStaticCastExprClass, Empty) { }
165 :
166 9: static bool classof(const Stmt *T) {
167 9: return T->getStmtClass() == CXXStaticCastExprClass;
168 : }
169 : static bool classof(const CXXStaticCastExpr *) { return true; }
170 : };
171 :
172 : /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
173 : /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
174 : /// determine how to perform the type cast.
175 : ///
176 : /// This expression node represents a dynamic cast, e.g.,
177 : /// @c dynamic_cast<Derived*>(BasePtr).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
178 0: class CXXDynamicCastExpr : public CXXNamedCastExpr {
179 : public:
180 : CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op,
181 43: TypeSourceInfo *writtenTy, SourceLocation l)
182 43: : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {}
183 :
184 1: explicit CXXDynamicCastExpr(EmptyShell Empty)
185 1: : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty) { }
186 :
187 11: static bool classof(const Stmt *T) {
188 11: return T->getStmtClass() == CXXDynamicCastExprClass;
189 : }
190 : static bool classof(const CXXDynamicCastExpr *) { return true; }
191 : };
192 :
193 : /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
194 : /// [expr.reinterpret.cast]), which provides a differently-typed view
195 : /// of a value but performs no actual work at run time.
196 : ///
197 : /// This expression node represents a reinterpret cast, e.g.,
198 : /// @c reinterpret_cast<int>(VoidPtr).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
199 0: class CXXReinterpretCastExpr : public CXXNamedCastExpr {
200 : public:
201 : CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op,
202 72: TypeSourceInfo *writtenTy, SourceLocation l)
203 : : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op,
204 72: writtenTy, l) {}
205 :
206 1: explicit CXXReinterpretCastExpr(EmptyShell Empty)
207 1: : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty) { }
208 :
209 4: static bool classof(const Stmt *T) {
210 4: return T->getStmtClass() == CXXReinterpretCastExprClass;
211 : }
212 : static bool classof(const CXXReinterpretCastExpr *) { return true; }
213 : };
214 :
215 : /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
216 : /// which can remove type qualifiers but does not change the underlying value.
217 : ///
218 : /// This expression node represents a const cast, e.g.,
219 : /// @c const_cast<char*>(PtrToConstChar).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
220 0: class CXXConstCastExpr : public CXXNamedCastExpr {
221 : public:
222 : CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy,
223 23: SourceLocation l)
224 23: : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {}
225 :
226 1: explicit CXXConstCastExpr(EmptyShell Empty)
227 1: : CXXNamedCastExpr(CXXConstCastExprClass, Empty) { }
228 :
229 2: static bool classof(const Stmt *T) {
230 2: return T->getStmtClass() == CXXConstCastExprClass;
231 : }
232 : static bool classof(const CXXConstCastExpr *) { return true; }
233 : };
234 :
235 : /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
236 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
237 0: class CXXBoolLiteralExpr : public Expr {
238 : bool Value;
239 : SourceLocation Loc;
240 : public:
241 149: CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
242 149: Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
243 :
244 3: explicit CXXBoolLiteralExpr(EmptyShell Empty)
245 3: : Expr(CXXBoolLiteralExprClass, Empty) { }
246 :
247 364: bool getValue() const { return Value; }
248 3: void setValue(bool V) { Value = V; }
249 :
250 392: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
251 :
252 3: SourceLocation getLocation() const { return Loc; }
253 3: void setLocation(SourceLocation L) { Loc = L; }
254 :
255 109: static bool classof(const Stmt *T) {
256 109: return T->getStmtClass() == CXXBoolLiteralExprClass;
257 : }
258 : static bool classof(const CXXBoolLiteralExpr *) { return true; }
259 :
260 : // Iterators
261 : virtual child_iterator child_begin();
262 : virtual child_iterator child_end();
263 : };
264 :
265 : /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
0: branch 1 not taken
75: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
266 75: class CXXNullPtrLiteralExpr : public Expr {
267 : SourceLocation Loc;
268 : public:
269 108: CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
270 108: Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
271 :
272 1: explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
273 1: : Expr(CXXNullPtrLiteralExprClass, Empty) { }
274 :
275 39: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
276 :
277 1: SourceLocation getLocation() const { return Loc; }
278 1: void setLocation(SourceLocation L) { Loc = L; }
279 :
280 1: static bool classof(const Stmt *T) {
281 1: return T->getStmtClass() == CXXNullPtrLiteralExprClass;
282 : }
283 : static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
284 :
285 : virtual child_iterator child_begin();
286 : virtual child_iterator child_end();
287 : };
288 :
289 : /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
290 : /// the type_info that corresponds to the supplied type, or the (possibly
291 : /// dynamic) type of the supplied expression.
292 : ///
293 : /// This represents code like @c typeid(int) or @c typeid(*objPtr)
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
294 0: class CXXTypeidExpr : public Expr {
295 : private:
296 : bool isTypeOp : 1;
297 : union {
298 : void *Ty;
299 : Stmt *Ex;
300 : } Operand;
301 : SourceRange Range;
302 :
303 : public:
304 88: CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) :
305 : Expr(CXXTypeidExprClass, Ty,
306 : // typeid is never type-dependent (C++ [temp.dep.expr]p4)
307 : false,
308 : // typeid is value-dependent if the type or expression are dependent
309 : (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType()
310 : : static_cast<Expr*>(op)->isValueDependent())),
72: branch 0 taken
16: branch 1 taken
311 88: isTypeOp(isTypeOp), Range(r) {
72: branch 0 taken
16: branch 1 taken
312 88: if (isTypeOp)
313 72: Operand.Ty = op;
314 : else
315 : // op was an Expr*, so cast it back to that to be safe
316 16: Operand.Ex = static_cast<Expr*>(op);
317 88: }
318 :
319 289: bool isTypeOperand() const { return isTypeOp; }
320 73: QualType getTypeOperand() const {
73: branch 1 taken
0: branch 2 not taken
321 73: assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
322 73: return QualType::getFromOpaquePtr(Operand.Ty);
323 : }
324 17: Expr* getExprOperand() const {
0: branch 2 not taken
0: branch 2 not taken
325 17: assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
326 17: return static_cast<Expr*>(Operand.Ex);
327 : }
328 :
329 279: virtual SourceRange getSourceRange() const {
330 279: return Range;
331 : }
332 79: static bool classof(const Stmt *T) {
333 79: return T->getStmtClass() == CXXTypeidExprClass;
334 : }
335 : static bool classof(const CXXTypeidExpr *) { return true; }
336 :
337 : // Iterators
338 : virtual child_iterator child_begin();
339 : virtual child_iterator child_end();
340 : };
341 :
342 : /// CXXThisExpr - Represents the "this" expression in C++, which is a
343 : /// pointer to the object on which the current member function is
344 : /// executing (C++ [expr.prim]p3). Example:
345 : ///
346 : /// @code
347 : /// class Foo {
348 : /// public:
349 : /// void bar();
350 : /// void test() { this->bar(); }
351 : /// };
352 : /// @endcode
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
7: branch 6 taken
353 7: class CXXThisExpr : public Expr {
354 : SourceLocation Loc;
355 : bool Implicit : 1;
356 :
357 : public:
358 646: CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
359 : : Expr(CXXThisExprClass, Type,
360 : // 'this' is type-dependent if the class type of the enclosing
361 : // member function is dependent (C++ [temp.dep.expr]p2)
362 : Type->isDependentType(), Type->isDependentType()),
363 646: Loc(L), Implicit(isImplicit) { }
364 :
365 3387: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
366 :
367 617: bool isImplicit() const { return Implicit; }
368 : void setImplicit(bool I) { Implicit = I; }
369 :
370 2724: static bool classof(const Stmt *T) {
371 2724: return T->getStmtClass() == CXXThisExprClass;
372 : }
373 : static bool classof(const CXXThisExpr *) { return true; }
374 :
375 : // Iterators
376 : virtual child_iterator child_begin();
377 : virtual child_iterator child_end();
378 : };
379 :
380 : /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
381 : /// 'throw' and 'throw' assignment-expression. When
382 : /// assignment-expression isn't present, Op will be null.
383 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
384 0: class CXXThrowExpr : public Expr {
385 : Stmt *Op;
386 : SourceLocation ThrowLoc;
387 : public:
388 : // Ty is the void type which is used as the result type of the
389 : // exepression. The l is the location of the throw keyword. expr
390 : // can by null, if the optional expression to throw isn't present.
391 40: CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
392 40: Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
393 55: const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
394 12: Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
395 : void setSubExpr(Expr *E) { Op = E; }
396 :
397 3: SourceLocation getThrowLoc() const { return ThrowLoc; }
398 : void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
399 :
400 17: virtual SourceRange getSourceRange() const {
1: branch 1 taken
16: branch 2 taken
401 17: if (getSubExpr() == 0)
402 1: return SourceRange(ThrowLoc, ThrowLoc);
403 16: return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
404 : }
405 :
406 167: static bool classof(const Stmt *T) {
407 167: return T->getStmtClass() == CXXThrowExprClass;
408 : }
409 : static bool classof(const CXXThrowExpr *) { return true; }
410 :
411 : // Iterators
412 : virtual child_iterator child_begin();
413 : virtual child_iterator child_end();
414 : };
415 :
416 : /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
417 : /// function call argument that was created from the corresponding
418 : /// parameter's default argument, when the call did not explicitly
419 : /// supply arguments for all of the parameters.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
4: branch 6 taken
420 4: class CXXDefaultArgExpr : public Expr {
421 : /// \brief The parameter whose default is being used.
422 : ///
423 : /// When the bit is set, the subexpression is stored after the
424 : /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
425 : /// actual default expression is the subexpression.
426 : llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
427 :
428 : /// \brief The location where the default argument expression was used.
429 : SourceLocation Loc;
430 :
431 : protected:
432 132: CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
433 : : Expr(SC,
434 : param->hasUnparsedDefaultArg()
435 : ? param->getType().getNonReferenceType()
436 : : param->getDefaultArg()->getType(),
437 : false, false),
438 132: Param(param, false), Loc(Loc) { }
439 :
440 : CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
441 27: Expr *SubExpr)
442 27: : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc)
443 : {
444 27: *reinterpret_cast<Expr **>(this + 1) = SubExpr;
445 27: }
446 :
447 : protected:
448 : virtual void DoDestroy(ASTContext &C);
449 :
450 : public:
451 : // Param is the parameter whose default argument is used by this
452 : // expression.
453 : static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
454 132: ParmVarDecl *Param) {
455 132: return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
456 : }
457 :
458 : // Param is the parameter whose default argument is used by this
459 : // expression, and SubExpr is the expression that will actually be used.
460 : static CXXDefaultArgExpr *Create(ASTContext &C,
461 : SourceLocation Loc,
462 : ParmVarDecl *Param,
463 : Expr *SubExpr);
464 :
465 : // Retrieve the parameter that the argument was created from.
466 16: const ParmVarDecl *getParam() const { return Param.getPointer(); }
467 84: ParmVarDecl *getParam() { return Param.getPointer(); }
468 :
469 : // Retrieve the actual argument to the function call.
470 20: const Expr *getExpr() const {
4: branch 1 taken
16: branch 2 taken
471 20: if (Param.getInt())
472 4: return *reinterpret_cast<Expr const * const*> (this + 1);
473 16: return getParam()->getDefaultArg();
474 : }
475 76: Expr *getExpr() {
1: branch 1 taken
75: branch 2 taken
476 76: if (Param.getInt())
477 1: return *reinterpret_cast<Expr **> (this + 1);
478 75: return getParam()->getDefaultArg();
479 : }
480 :
481 : /// \brief Retrieve the location where this default argument was actually
482 : /// used.
483 3: SourceLocation getUsedLocation() const { return Loc; }
484 :
485 20: virtual SourceRange getSourceRange() const {
486 : // Default argument expressions have no representation in the
487 : // source, so they have an empty source range.
488 20: return SourceRange();
489 : }
490 :
491 9757: static bool classof(const Stmt *T) {
492 9757: return T->getStmtClass() == CXXDefaultArgExprClass;
493 : }
494 : static bool classof(const CXXDefaultArgExpr *) { return true; }
495 :
496 : // Iterators
497 : virtual child_iterator child_begin();
498 : virtual child_iterator child_end();
499 : };
500 :
501 : /// CXXTemporary - Represents a C++ temporary.
502 : class CXXTemporary {
503 : /// Destructor - The destructor that needs to be called.
504 : const CXXDestructorDecl *Destructor;
505 :
506 100: CXXTemporary(const CXXDestructorDecl *destructor)
507 100: : Destructor(destructor) { }
508 3: ~CXXTemporary() { }
509 :
510 : public:
511 : static CXXTemporary *Create(ASTContext &C,
512 : const CXXDestructorDecl *Destructor);
513 :
514 : void Destroy(ASTContext &Ctx);
515 :
516 63: const CXXDestructorDecl *getDestructor() const { return Destructor; }
517 : };
518 :
519 : /// CXXBindTemporaryExpr - Represents binding an expression to a temporary,
520 : /// so its destructor can be called later.
521 : class CXXBindTemporaryExpr : public Expr {
522 : CXXTemporary *Temp;
523 :
524 : Stmt *SubExpr;
525 :
526 100: CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
527 : : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
528 100: Temp(temp), SubExpr(subexpr) { }
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
3: branch 6 taken
529 3: ~CXXBindTemporaryExpr() { }
530 :
531 : protected:
532 : virtual void DoDestroy(ASTContext &C);
533 :
534 : public:
535 : static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
536 : Expr* SubExpr);
537 :
538 37: CXXTemporary *getTemporary() { return Temp; }
539 25: const CXXTemporary *getTemporary() const { return Temp; }
540 :
541 118: const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
542 71: Expr *getSubExpr() { return cast<Expr>(SubExpr); }
543 : void setSubExpr(Expr *E) { SubExpr = E; }
544 :
545 1012: virtual SourceRange getSourceRange() const {
546 1012: return SubExpr->getSourceRange();
547 : }
548 :
549 : // Implement isa/cast/dyncast/etc.
550 4571: static bool classof(const Stmt *T) {
551 4571: return T->getStmtClass() == CXXBindTemporaryExprClass;
552 : }
553 : static bool classof(const CXXBindTemporaryExpr *) { return true; }
554 :
555 : // Iterators
556 : virtual child_iterator child_begin();
557 : virtual child_iterator child_end();
558 : };
559 :
560 : /// CXXBindReferenceExpr - Represents binding an expression to a reference.
561 : /// In the example:
562 : ///
563 : /// const int &i = 10;
564 : ///
565 : /// a bind reference expression is inserted to indicate that 10 is bound to
566 : /// a reference. (Ans also that a temporary needs to be created to hold the
567 : /// value).
568 : class CXXBindReferenceExpr : public Expr {
569 : // SubExpr - The expression being bound.
570 : Stmt *SubExpr;
571 :
572 : // ExtendsLifetime - Whether binding this reference extends the lifetime of
573 : // the expression being bound. FIXME: Add C++ reference.
574 : bool ExtendsLifetime;
575 :
576 : /// RequiresTemporaryCopy - Whether binding the subexpression requires a
577 : /// temporary copy.
578 : bool RequiresTemporaryCopy;
579 :
580 : CXXBindReferenceExpr(Expr *subexpr, bool ExtendsLifetime,
581 0: bool RequiresTemporaryCopy)
582 : : Expr(CXXBindReferenceExprClass, subexpr->getType(), false, false),
583 : SubExpr(subexpr), ExtendsLifetime(ExtendsLifetime),
584 0: RequiresTemporaryCopy(RequiresTemporaryCopy) { }
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
585 0: ~CXXBindReferenceExpr() { }
586 :
587 : protected:
588 : virtual void DoDestroy(ASTContext &C);
589 :
590 : public:
591 : static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr,
592 : bool ExtendsLifetime,
593 : bool RequiresTemporaryCopy);
594 :
595 : const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
596 0: Expr *getSubExpr() { return cast<Expr>(SubExpr); }
597 : void setSubExpr(Expr *E) { SubExpr = E; }
598 :
599 0: virtual SourceRange getSourceRange() const {
600 0: return SubExpr->getSourceRange();
601 : }
602 :
603 : /// requiresTemporaryCopy - Whether binding the subexpression requires a
604 : /// temporary copy.
605 : bool requiresTemporaryCopy() const { return RequiresTemporaryCopy; }
606 :
607 : // extendsLifetime - Whether binding this reference extends the lifetime of
608 : // the expression being bound. FIXME: Add C++ reference.
609 : bool extendsLifetime() { return ExtendsLifetime; }
610 :
611 : // Implement isa/cast/dyncast/etc.
612 0: static bool classof(const Stmt *T) {
613 0: return T->getStmtClass() == CXXBindReferenceExprClass;
614 : }
615 : static bool classof(const CXXBindReferenceExpr *) { return true; }
616 :
617 : // Iterators
618 : virtual child_iterator child_begin();
619 : virtual child_iterator child_end();
620 : };
621 :
622 : /// CXXConstructExpr - Represents a call to a C++ constructor.
623 : class CXXConstructExpr : public Expr {
624 : CXXConstructorDecl *Constructor;
625 :
626 : SourceLocation Loc;
627 : bool Elidable : 1;
628 : bool ZeroInitialization : 1;
629 : bool BaseInitialization : 1;
630 : Stmt **Args;
631 : unsigned NumArgs;
632 :
633 : protected:
634 : CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
635 : SourceLocation Loc,
636 : CXXConstructorDecl *d, bool elidable,
637 : Expr **args, unsigned numargs,
638 : bool ZeroInitialization = false,
639 : bool BaseInitialization = false);
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
58: branch 6 taken
0: branch 9 not taken
0: branch 10 not taken
640 58: ~CXXConstructExpr() { }
641 :
642 : virtual void DoDestroy(ASTContext &C);
643 :
644 : public:
645 : /// \brief Construct an empty C++ construction expression that will store
646 : /// \p numargs arguments.
647 : CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs);
648 :
649 : static CXXConstructExpr *Create(ASTContext &C, QualType T,
650 : SourceLocation Loc,
651 : CXXConstructorDecl *D, bool Elidable,
652 : Expr **Args, unsigned NumArgs,
653 : bool ZeroInitialization = false,
654 : bool BaseInitialization = false);
655 :
656 :
657 988: CXXConstructorDecl* getConstructor() const { return Constructor; }
658 0: void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
659 :
660 4: SourceLocation getLocation() const { return Loc; }
661 0: void setLocation(SourceLocation Loc) { this->Loc = Loc; }
662 :
663 : /// \brief Whether this construction is elidable.
664 2148: bool isElidable() const { return Elidable; }
665 0: void setElidable(bool E) { Elidable = E; }
666 :
667 : /// \brief Whether this construction first requires
668 : /// zero-initialization before the initializer is called.
669 755: bool requiresZeroInitialization() const { return ZeroInitialization; }
670 0: void setRequiresZeroInitialization(bool ZeroInit) {
671 0: ZeroInitialization = ZeroInit;
672 0: }
673 :
674 : /// \brief Determines whether this constructor is actually constructing
675 : /// a base class (rather than a complete object).
676 668: bool isBaseInitialization() const { return BaseInitialization; }
677 : void setBaseInitialization(bool BI) { BaseInitialization = BI; }
678 :
679 : typedef ExprIterator arg_iterator;
680 : typedef ConstExprIterator const_arg_iterator;
681 :
682 56: arg_iterator arg_begin() { return Args; }
683 56: arg_iterator arg_end() { return Args + NumArgs; }
684 695: const_arg_iterator arg_begin() const { return Args; }
685 695: const_arg_iterator arg_end() const { return Args + NumArgs; }
686 :
687 8: Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
688 64: unsigned getNumArgs() const { return NumArgs; }
689 :
690 : /// getArg - Return the specified argument.
691 25: Expr *getArg(unsigned Arg) {
0: branch 1 not taken
692 25: assert(Arg < NumArgs && "Arg access out of range!");
693 25: return cast<Expr>(Args[Arg]);
694 : }
695 42: const Expr *getArg(unsigned Arg) const {
42: branch 1 taken
696 42: assert(Arg < NumArgs && "Arg access out of range!");
697 42: return cast<Expr>(Args[Arg]);
698 : }
699 :
700 : /// setArg - Set the specified argument.
701 0: void setArg(unsigned Arg, Expr *ArgExpr) {
702 0: assert(Arg < NumArgs && "Arg access out of range!");
703 0: Args[Arg] = ArgExpr;
704 0: }
705 :
706 : virtual SourceRange getSourceRange() const;
707 :
708 2656: static bool classof(const Stmt *T) {
709 : return T->getStmtClass() == CXXConstructExprClass ||
932: branch 1 taken
1724: branch 2 taken
0: branch 4 not taken
932: branch 5 taken
710 2656: T->getStmtClass() == CXXTemporaryObjectExprClass;
711 : }
712 : static bool classof(const CXXConstructExpr *) { return true; }
713 :
714 : // Iterators
715 : virtual child_iterator child_begin();
716 : virtual child_iterator child_end();
717 : };
718 :
719 : /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
720 : /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
721 : /// x = int(0.5);
722 2: class CXXFunctionalCastExpr : public ExplicitCastExpr {
723 : SourceLocation TyBeginLoc;
724 : SourceLocation RParenLoc;
725 : public:
726 : CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
727 : SourceLocation tyBeginLoc, CastKind kind,
728 145: Expr *castExpr, SourceLocation rParenLoc)
729 : : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr,
730 : writtenTy),
731 145: TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
732 :
733 1: explicit CXXFunctionalCastExpr(EmptyShell Shell)
734 1: : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell) { }
735 :
736 11: SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
737 1: void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
738 4: SourceLocation getRParenLoc() const { return RParenLoc; }
739 1: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
740 :
741 376: virtual SourceRange getSourceRange() const {
742 376: return SourceRange(TyBeginLoc, RParenLoc);
743 : }
744 477: static bool classof(const Stmt *T) {
745 477: return T->getStmtClass() == CXXFunctionalCastExprClass;
746 : }
747 : static bool classof(const CXXFunctionalCastExpr *) { return true; }
748 : };
749 :
750 : /// @brief Represents a C++ functional cast expression that builds a
751 : /// temporary object.
752 : ///
753 : /// This expression type represents a C++ "functional" cast
754 : /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
755 : /// constructor to build a temporary object. If N == 0 but no
756 : /// constructor will be called (because the functional cast is
757 : /// performing a value-initialized an object whose class type has no
758 : /// user-declared constructors), CXXZeroInitValueExpr will represent
759 : /// the functional cast. Finally, with N == 1 arguments the functional
760 : /// cast expression will be represented by CXXFunctionalCastExpr.
761 : /// Example:
762 : /// @code
763 : /// struct X { X(int, float); }
764 : ///
765 : /// X create_X() {
766 : /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
767 : /// };
768 : /// @endcode
769 : class CXXTemporaryObjectExpr : public CXXConstructExpr {
770 : SourceLocation TyBeginLoc;
771 : SourceLocation RParenLoc;
772 :
773 : public:
774 : CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
775 : QualType writtenTy, SourceLocation tyBeginLoc,
776 : Expr **Args,unsigned NumArgs,
777 : SourceLocation rParenLoc);
778 :
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
779 0: ~CXXTemporaryObjectExpr() { }
780 :
781 0: SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
782 : SourceLocation getRParenLoc() const { return RParenLoc; }
783 :
784 0: virtual SourceRange getSourceRange() const {
785 0: return SourceRange(TyBeginLoc, RParenLoc);
786 : }
787 332: static bool classof(const Stmt *T) {
788 332: return T->getStmtClass() == CXXTemporaryObjectExprClass;
789 : }
790 : static bool classof(const CXXTemporaryObjectExpr *) { return true; }
791 : };
792 :
793 : /// CXXZeroInitValueExpr - [C++ 5.2.3p2]
794 : /// Expression "T()" which creates a value-initialized rvalue of type
795 : /// T, which is either a non-class type or a class type without any
796 : /// user-defined constructors.
797 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
24: branch 6 taken
798 24: class CXXZeroInitValueExpr : public Expr {
799 : SourceLocation TyBeginLoc;
800 : SourceLocation RParenLoc;
801 :
802 : public:
803 : CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
804 260: SourceLocation rParenLoc ) :
805 : Expr(CXXZeroInitValueExprClass, ty, false, false),
806 260: TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
807 :
808 9: SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
809 0: SourceLocation getRParenLoc() const { return RParenLoc; }
810 :
811 : /// @brief Whether this initialization expression was
812 : /// implicitly-generated.
813 : bool isImplicit() const {
814 : return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
815 : }
816 :
817 8051: virtual SourceRange getSourceRange() const {
818 8051: return SourceRange(TyBeginLoc, RParenLoc);
819 : }
820 :
821 90: static bool classof(const Stmt *T) {
822 90: return T->getStmtClass() == CXXZeroInitValueExprClass;
823 : }
824 : static bool classof(const CXXZeroInitValueExpr *) { return true; }
825 :
826 : // Iterators
827 : virtual child_iterator child_begin();
828 : virtual child_iterator child_end();
829 : };
830 :
831 : /// CXXNewExpr - A new expression for memory allocation and constructor calls,
832 : /// e.g: "new CXXNewExpr(foo)".
833 : class CXXNewExpr : public Expr {
834 : // Was the usage ::new, i.e. is the global new to be used?
835 : bool GlobalNew : 1;
836 : // Was the form (type-id) used? Otherwise, it was new-type-id.
837 : bool ParenTypeId : 1;
838 : // Is there an initializer? If not, built-ins are uninitialized, else they're
839 : // value-initialized.
840 : bool Initializer : 1;
841 : // Do we allocate an array? If so, the first SubExpr is the size expression.
842 : bool Array : 1;
843 : // The number of placement new arguments.
844 : unsigned NumPlacementArgs : 14;
845 : // The number of constructor arguments. This may be 1 even for non-class
846 : // types; use the pseudo copy constructor.
847 : unsigned NumConstructorArgs : 14;
848 : // Contains an optional array size expression, any number of optional
849 : // placement arguments, and any number of optional constructor arguments,
850 : // in that order.
851 : Stmt **SubExprs;
852 : // Points to the allocation function used.
853 : FunctionDecl *OperatorNew;
854 : // Points to the deallocation function used in case of error. May be null.
855 : FunctionDecl *OperatorDelete;
856 : // Points to the constructor used. Cannot be null if AllocType is a record;
857 : // it would still point at the default constructor (even an implicit one).
858 : // Must be null for all other types.
859 : CXXConstructorDecl *Constructor;
860 :
861 : SourceLocation StartLoc;
862 : SourceLocation EndLoc;
863 :
864 : public:
865 : CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs,
866 : unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize,
867 : CXXConstructorDecl *constructor, bool initializer,
868 : Expr **constructorArgs, unsigned numConsArgs,
869 : FunctionDecl *operatorDelete, QualType ty,
870 : SourceLocation startLoc, SourceLocation endLoc);
871 0: ~CXXNewExpr() {
0: branch 0 not taken
0: branch 1 not taken
0: branch 3 not taken
0: branch 4 not taken
872 0: delete[] SubExprs;
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
873 0: }
874 :
875 229: QualType getAllocatedType() const {
0: branch 4 not taken
876 229: assert(getType()->isPointerType());
877 229: return getType()->getAs<PointerType>()->getPointeeType();
878 : }
879 :
880 96: FunctionDecl *getOperatorNew() const { return OperatorNew; }
881 0: FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
882 58: CXXConstructorDecl *getConstructor() const { return Constructor; }
883 :
884 193: bool isArray() const { return Array; }
885 19: Expr *getArraySize() {
0: branch 0 not taken
19: branch 1 taken
886 19: return Array ? cast<Expr>(SubExprs[0]) : 0;
887 : }
888 22: const Expr *getArraySize() const {
889 22: return Array ? cast<Expr>(SubExprs[0]) : 0;
890 : }
891 :
892 229: unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
893 12: Expr *getPlacementArg(unsigned i) {
0: branch 0 not taken
12: branch 1 taken
894 12: assert(i < NumPlacementArgs && "Index out of range");
895 12: return cast<Expr>(SubExprs[Array + i]);
896 : }
897 : const Expr *getPlacementArg(unsigned i) const {
898 : assert(i < NumPlacementArgs && "Index out of range");
899 : return cast<Expr>(SubExprs[Array + i]);
900 : }
901 :
902 18: bool isGlobalNew() const { return GlobalNew; }
903 18: bool isParenTypeId() const { return ParenTypeId; }
904 7: bool hasInitializer() const { return Initializer; }
905 :
906 100: unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
907 20: Expr *getConstructorArg(unsigned i) {
0: branch 0 not taken
20: branch 1 taken
908 20: assert(i < NumConstructorArgs && "Index out of range");
909 20: return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
910 : }
911 11: const Expr *getConstructorArg(unsigned i) const {
912 11: assert(i < NumConstructorArgs && "Index out of range");
913 11: return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
914 : }
915 :
916 : typedef ExprIterator arg_iterator;
917 : typedef ConstExprIterator const_arg_iterator;
918 :
919 : arg_iterator placement_arg_begin() {
920 : return SubExprs + Array;
921 : }
922 : arg_iterator placement_arg_end() {
923 : return SubExprs + Array + getNumPlacementArgs();
924 : }
925 58: const_arg_iterator placement_arg_begin() const {
926 58: return SubExprs + Array;
927 : }
928 116: const_arg_iterator placement_arg_end() const {
929 116: return SubExprs + Array + getNumPlacementArgs();
930 : }
931 :
932 : arg_iterator constructor_arg_begin() {
933 : return SubExprs + Array + getNumPlacementArgs();
934 : }
935 : arg_iterator constructor_arg_end() {
936 : return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
937 : }
938 38: const_arg_iterator constructor_arg_begin() const {
939 38: return SubExprs + Array + getNumPlacementArgs();
940 : }
941 38: const_arg_iterator constructor_arg_end() const {
942 38: return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
943 : }
944 :
945 203: virtual SourceRange getSourceRange() const {
946 203: return SourceRange(StartLoc, EndLoc);
947 : }
948 :
949 18: static bool classof(const Stmt *T) {
950 18: return T->getStmtClass() == CXXNewExprClass;
951 : }
952 : static bool classof(const CXXNewExpr *) { return true; }
953 :
954 : // Iterators
955 : virtual child_iterator child_begin();
956 : virtual child_iterator child_end();
957 : };
958 :
959 : /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
960 : /// calls, e.g. "delete[] pArray".
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
961 0: class CXXDeleteExpr : public Expr {
962 : // Is this a forced global delete, i.e. "::delete"?
963 : bool GlobalDelete : 1;
964 : // Is this the array form of delete, i.e. "delete[]"?
965 : bool ArrayForm : 1;
966 : // Points to the operator delete overload that is used. Could be a member.
967 : FunctionDecl *OperatorDelete;
968 : // The pointer expression to be deleted.
969 : Stmt *Argument;
970 : // Location of the expression.
971 : SourceLocation Loc;
972 : public:
973 : CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
974 46: FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
975 : : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
976 : ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
977 46: Loc(loc) { }
978 :
979 9: bool isGlobalDelete() const { return GlobalDelete; }
980 20: bool isArrayForm() const { return ArrayForm; }
981 :
982 20: FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
983 :
984 18: Expr *getArgument() { return cast<Expr>(Argument); }
985 20: const Expr *getArgument() const { return cast<Expr>(Argument); }
986 :
987 9: virtual SourceRange getSourceRange() const {
988 9: return SourceRange(Loc, Argument->getLocEnd());
989 : }
990 :
991 9: static bool classof(const Stmt *T) {
992 9: return T->getStmtClass() == CXXDeleteExprClass;
993 : }
994 : static bool classof(const CXXDeleteExpr *) { return true; }
995 :
996 : // Iterators
997 : virtual child_iterator child_begin();
998 : virtual child_iterator child_end();
999 : };
1000 :
1001 : /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1002 : ///
1003 : /// Example:
1004 : ///
1005 : /// \code
1006 : /// template<typename T>
1007 : /// void destroy(T* ptr) {
1008 : /// ptr->~T();
1009 : /// }
1010 : /// \endcode
1011 : ///
1012 : /// When the template is parsed, the expression \c ptr->~T will be stored as
1013 : /// a member reference expression. If it then instantiated with a scalar type
1014 : /// as a template argument for T, the resulting expression will be a
1015 : /// pseudo-destructor expression.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1016 0: class CXXPseudoDestructorExpr : public Expr {
1017 : /// \brief The base expression (that is being destroyed).
1018 : Stmt *Base;
1019 :
1020 : /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1021 : /// period ('.').
1022 : bool IsArrow : 1;
1023 :
1024 : /// \brief The location of the '.' or '->' operator.
1025 : SourceLocation OperatorLoc;
1026 :
1027 : /// \brief The nested-name-specifier that follows the operator, if present.
1028 : NestedNameSpecifier *Qualifier;
1029 :
1030 : /// \brief The source range that covers the nested-name-specifier, if
1031 : /// present.
1032 : SourceRange QualifierRange;
1033 :
1034 : /// \brief The type being destroyed.
1035 : QualType DestroyedType;
1036 :
1037 : /// \brief The location of the type after the '~'.
1038 : SourceLocation DestroyedTypeLoc;
1039 :
1040 : public:
1041 : CXXPseudoDestructorExpr(ASTContext &Context,
1042 : Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1043 : NestedNameSpecifier *Qualifier,
1044 : SourceRange QualifierRange,
1045 : QualType DestroyedType,
1046 13: SourceLocation DestroyedTypeLoc)
1047 : : Expr(CXXPseudoDestructorExprClass,
1048 : Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1049 : false, 0)),
1050 : /*isTypeDependent=*/false,
1051 : /*isValueDependent=*/Base->isValueDependent()),
1052 : Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1053 : OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1054 : QualifierRange(QualifierRange), DestroyedType(DestroyedType),
1055 13: DestroyedTypeLoc(DestroyedTypeLoc) { }
1056 :
1057 : void setBase(Expr *E) { Base = E; }
1058 4: Expr *getBase() const { return cast<Expr>(Base); }
1059 :
1060 : /// \brief Determines whether this member expression actually had
1061 : /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1062 : /// x->Base::foo.
1063 : bool hasQualifier() const { return Qualifier != 0; }
1064 :
1065 : /// \brief If the member name was qualified, retrieves the source range of
1066 : /// the nested-name-specifier that precedes the member name. Otherwise,
1067 : /// returns an empty source range.
1068 0: SourceRange getQualifierRange() const { return QualifierRange; }
1069 :
1070 : /// \brief If the member name was qualified, retrieves the
1071 : /// nested-name-specifier that precedes the member name. Otherwise, returns
1072 : /// NULL.
1073 0: NestedNameSpecifier *getQualifier() const { return Qualifier; }
1074 :
1075 : /// \brief Determine whether this pseudo-destructor expression was written
1076 : /// using an '->' (otherwise, it used a '.').
1077 0: bool isArrow() const { return IsArrow; }
1078 : void setArrow(bool A) { IsArrow = A; }
1079 :
1080 : /// \brief Retrieve the location of the '.' or '->' operator.
1081 0: SourceLocation getOperatorLoc() const { return OperatorLoc; }
1082 :
1083 : /// \brief Retrieve the type that is being destroyed.
1084 0: QualType getDestroyedType() const { return DestroyedType; }
1085 :
1086 : /// \brief Retrieve the location of the type being destroyed.
1087 0: SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; }
1088 :
1089 9: virtual SourceRange getSourceRange() const {
1090 9: return SourceRange(Base->getLocStart(), DestroyedTypeLoc);
1091 : }
1092 :
1093 3182: static bool classof(const Stmt *T) {
1094 3182: return T->getStmtClass() == CXXPseudoDestructorExprClass;
1095 : }
1096 : static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1097 :
1098 : // Iterators
1099 : virtual child_iterator child_begin();
1100 : virtual child_iterator child_end();
1101 : };
1102 :
1103 : /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1104 : /// implementation of TR1/C++0x type trait templates.
1105 : /// Example:
1106 : /// __is_pod(int) == true
1107 : /// __is_enum(std::string) == false
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1108 0: class UnaryTypeTraitExpr : public Expr {
1109 : /// UTT - The trait.
1110 : UnaryTypeTrait UTT;
1111 :
1112 : /// Loc - The location of the type trait keyword.
1113 : SourceLocation Loc;
1114 :
1115 : /// RParen - The location of the closing paren.
1116 : SourceLocation RParen;
1117 :
1118 : /// QueriedType - The type we're testing.
1119 : QualType QueriedType;
1120 :
1121 : public:
1122 : UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1123 181: SourceLocation rparen, QualType ty)
1124 : : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1125 181: UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1126 :
1127 13: virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1128 :
1129 2: UnaryTypeTrait getTrait() const { return UTT; }
1130 :
1131 4: QualType getQueriedType() const { return QueriedType; }
1132 :
1133 : bool EvaluateTrait(ASTContext&) const;
1134 :
1135 2: static bool classof(const Stmt *T) {
1136 2: return T->getStmtClass() == UnaryTypeTraitExprClass;
1137 : }
1138 : static bool classof(const UnaryTypeTraitExpr *) { return true; }
1139 :
1140 : // Iterators
1141 : virtual child_iterator child_begin();
1142 : virtual child_iterator child_end();
1143 : };
1144 :
1145 : /// \brief A reference to an overloaded function set, either an
1146 : /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
0: branch 2 not taken
160: branch 3 taken
0: branch 7 not taken
0: branch 8 not taken
0: branch 12 not taken
0: branch 13 not taken
1147 160: class OverloadExpr : public Expr {
1148 : /// The results. These are undesugared, which is to say, they may
1149 : /// include UsingShadowDecls. Access is relative to the naming
1150 : /// class.
1151 : UnresolvedSet<4> Results;
1152 :
1153 : /// The common name of these declarations.
1154 : DeclarationName Name;
1155 :
1156 : /// The scope specifier, if any.
1157 : NestedNameSpecifier *Qualifier;
1158 :
1159 : /// The source range of the scope specifier.
1160 : SourceRange QualifierRange;
1161 :
1162 : /// The location of the name.
1163 : SourceLocation NameLoc;
1164 :
1165 : /// True if the name was a template-id.
1166 : bool HasExplicitTemplateArgs;
1167 :
1168 : protected:
1169 : OverloadExpr(StmtClass K, QualType T, bool Dependent,
1170 : NestedNameSpecifier *Qualifier, SourceRange QRange,
1171 : DeclarationName Name, SourceLocation NameLoc,
1172 1752: bool HasTemplateArgs)
1173 : : Expr(K, T, Dependent, Dependent),
1174 : Name(Name), Qualifier(Qualifier), QualifierRange(QRange),
1175 1752: NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs)
1176 1752: {}
1177 :
1178 : public:
1179 : /// Computes whether an unresolved lookup on the given declarations
1180 : /// and optional template arguments is type- and value-dependent.
1181 : static bool ComputeDependence(UnresolvedSetIterator Begin,
1182 : UnresolvedSetIterator End,
1183 : const TemplateArgumentListInfo *Args);
1184 :
1185 : /// Finds the overloaded expression in the given expression of
1186 : /// OverloadTy.
1187 : ///
1188 : /// \return the expression (which must be there) and true if it is
1189 : /// within an address-of operator.
1190 426: static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) {
0: branch 3 not taken
0: branch 4 not taken
1191 426: assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1192 :
1193 426: bool op = false;
1194 426: E = E->IgnoreParens();
225: branch 2 taken
0: branch 2 not taken
1195 426: if (isa<UnaryOperator>(E))
1196 201: op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
1197 426: return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op);
1198 : }
1199 :
1200 1752: void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) {
1201 1752: Results.append(Begin, End);
1202 1752: }
1203 :
1204 : typedef UnresolvedSetImpl::iterator decls_iterator;
1205 5513: decls_iterator decls_begin() const { return Results.begin(); }
1206 4478: decls_iterator decls_end() const { return Results.end(); }
1207 :
1208 : /// Gets the decls as an unresolved set.
1209 : const UnresolvedSetImpl &getDecls() { return Results; }
1210 :
1211 : /// Gets the number of declarations in the unresolved set.
1212 168: unsigned getNumDecls() const { return Results.size(); }
1213 :
1214 : /// Gets the name looked up.
1215 1641: DeclarationName getName() const { return Name; }
1216 : void setName(DeclarationName N) { Name = N; }
1217 :
1218 : /// Gets the location of the name.
1219 5878: SourceLocation getNameLoc() const { return NameLoc; }
1220 : void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
1221 :
1222 : /// Fetches the nested-name qualifier, if one was given.
1223 6338: NestedNameSpecifier *getQualifier() const { return Qualifier; }
1224 :
1225 : /// Fetches the range of the nested-name qualifier.
1226 1654: SourceRange getQualifierRange() const { return QualifierRange; }
1227 :
1228 : /// \brief Determines whether this expression had an explicit
1229 : /// template argument list, e.g. f<int>.
1230 7987: bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1231 :
1232 : ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1233 :
1234 : const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1235 : return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1236 : }
1237 :
1238 : ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1239 : if (hasExplicitTemplateArgs())
1240 : return &getExplicitTemplateArgs();
1241 : return 0;
1242 : }
1243 :
1244 427: static bool classof(const Stmt *T) {
1245 : return T->getStmtClass() == UnresolvedLookupExprClass ||
4: branch 1 taken
423: branch 2 taken
4: branch 4 taken
0: branch 5 not taken
1246 427: T->getStmtClass() == UnresolvedMemberExprClass;
1247 : }
1248 : static bool classof(const OverloadExpr *) { return true; }
1249 : };
1250 :
1251 : /// \brief A reference to a name which we were able to look up during
1252 : /// parsing but could not resolve to a specific declaration. This
1253 : /// arises in several ways:
1254 : /// * we might be waiting for argument-dependent lookup
1255 : /// * the name might resolve to an overloaded function
1256 : /// and eventually:
1257 : /// * the lookup might have included a function template
1258 : /// These never include UnresolvedUsingValueDecls, which are always
1259 : /// class members and therefore appear only in
1260 : /// UnresolvedMemberLookupExprs.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
160: branch 6 taken
1261 160: class UnresolvedLookupExpr : public OverloadExpr {
1262 : /// True if these lookup results should be extended by
1263 : /// argument-dependent lookup if this is the operand of a function
1264 : /// call.
1265 : bool RequiresADL;
1266 :
1267 : /// True if these lookup results are overloaded. This is pretty
1268 : /// trivially rederivable if we urgently need to kill this field.
1269 : bool Overloaded;
1270 :
1271 : /// The naming class (C++ [class.access.base]p5) of the lookup, if
1272 : /// any. This can generally be recalculated from the context chain,
1273 : /// but that can be fairly expensive for unqualified lookups. If we
1274 : /// want to improve memory use here, this could go in a union
1275 : /// against the qualified-lookup bits.
1276 : CXXRecordDecl *NamingClass;
1277 :
1278 : UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass,
1279 : NestedNameSpecifier *Qualifier, SourceRange QRange,
1280 : DeclarationName Name, SourceLocation NameLoc,
1281 1572: bool RequiresADL, bool Overloaded, bool HasTemplateArgs)
1282 : : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange,
1283 : Name, NameLoc, HasTemplateArgs),
1284 1572: RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1285 1572: {}
1286 :
1287 : public:
1288 : static UnresolvedLookupExpr *Create(ASTContext &C,
1289 : bool Dependent,
1290 : CXXRecordDecl *NamingClass,
1291 : NestedNameSpecifier *Qualifier,
1292 : SourceRange QualifierRange,
1293 : DeclarationName Name,
1294 : SourceLocation NameLoc,
1295 1444: bool ADL, bool Overloaded) {
1296 : return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy,
1297 : Dependent, NamingClass,
1298 : Qualifier, QualifierRange,
0: branch 0 not taken
0: branch 1 not taken
0: branch 4 not taken
0: branch 5 not taken
1299 1444: Name, NameLoc, ADL, Overloaded, false);
1300 : }
1301 :
1302 : static UnresolvedLookupExpr *Create(ASTContext &C,
1303 : bool Dependent,
1304 : CXXRecordDecl *NamingClass,
1305 : NestedNameSpecifier *Qualifier,
1306 : SourceRange QualifierRange,
1307 : DeclarationName Name,
1308 : SourceLocation NameLoc,
1309 : bool ADL,
1310 : const TemplateArgumentListInfo &Args);
1311 :
1312 : /// True if this declaration should be extended by
1313 : /// argument-dependent lookup.
1314 3951: bool requiresADL() const { return RequiresADL; }
1315 :
1316 : /// True if this lookup is overloaded.
1317 : bool isOverloaded() const { return Overloaded; }
1318 :
1319 : /// Gets the 'naming class' (in the sense of C++0x
1320 : /// [class.access.base]p5) of the lookup. This is the scope
1321 : /// that was looked in to find these results.
1322 12: CXXRecordDecl *getNamingClass() const { return NamingClass; }
1323 :
1324 : // Note that, inconsistently with the explicit-template-argument AST
1325 : // nodes, users are *forbidden* from calling these methods on objects
1326 : // without explicit template arguments.
1327 :
1328 77: ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
0: branch 1 not taken
77: branch 2 taken
1329 77: assert(hasExplicitTemplateArgs());
1330 77: return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1331 : }
1332 :
1333 : /// Gets a reference to the explicit template argument list.
1334 555: const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
0: branch 1 not taken
555: branch 2 taken
1335 555: assert(hasExplicitTemplateArgs());
1336 555: return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1337 : }
1338 :
1339 : /// \brief Copies the template arguments (if present) into the given
1340 : /// structure.
1341 216: void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1342 216: getExplicitTemplateArgs().copyInto(List);
1343 216: }
1344 :
1345 3: SourceLocation getLAngleLoc() const {
1346 3: return getExplicitTemplateArgs().LAngleLoc;
1347 : }
1348 :
1349 330: SourceLocation getRAngleLoc() const {
1350 330: return getExplicitTemplateArgs().RAngleLoc;
1351 : }
1352 :
1353 3: TemplateArgumentLoc const *getTemplateArgs() const {
1354 3: return getExplicitTemplateArgs().getTemplateArgs();
1355 : }
1356 :
1357 3: unsigned getNumTemplateArgs() const {
1358 3: return getExplicitTemplateArgs().NumTemplateArgs;
1359 : }
1360 :
1361 3441: virtual SourceRange getSourceRange() const {
1362 3441: SourceRange Range(getNameLoc());
157: branch 1 taken
3284: branch 2 taken
1363 3441: if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
327: branch 1 taken
3114: branch 2 taken
1364 3441: if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1365 : return Range;
1366 : }
1367 :
1368 : virtual StmtIterator child_begin();
1369 : virtual StmtIterator child_end();
1370 :
1371 11758: static bool classof(const Stmt *T) {
1372 11758: return T->getStmtClass() == UnresolvedLookupExprClass;
1373 : }
1374 : static bool classof(const UnresolvedLookupExpr *) { return true; }
1375 : };
1376 :
1377 : /// \brief A qualified reference to a name whose declaration cannot
1378 : /// yet be resolved.
1379 : ///
1380 : /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1381 : /// it expresses a reference to a declaration such as
1382 : /// X<T>::value. The difference, however, is that an
1383 : /// DependentScopeDeclRefExpr node is used only within C++ templates when
1384 : /// the qualification (e.g., X<T>::) refers to a dependent type. In
1385 : /// this case, X<T>::value cannot resolve to a declaration because the
1386 : /// declaration will differ from on instantiation of X<T> to the
1387 : /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1388 : /// qualifier (X<T>::) and the name of the entity being referenced
1389 : /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1390 : /// declaration can be found.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1391 0: class DependentScopeDeclRefExpr : public Expr {
1392 : /// The name of the entity we will be referencing.
1393 : DeclarationName Name;
1394 :
1395 : /// Location of the name of the declaration we're referencing.
1396 : SourceLocation Loc;
1397 :
1398 : /// QualifierRange - The source range that covers the
1399 : /// nested-name-specifier.
1400 : SourceRange QualifierRange;
1401 :
1402 : /// \brief The nested-name-specifier that qualifies this unresolved
1403 : /// declaration name.
1404 : NestedNameSpecifier *Qualifier;
1405 :
1406 : /// \brief Whether the name includes explicit template arguments.
1407 : bool HasExplicitTemplateArgs;
1408 :
1409 : DependentScopeDeclRefExpr(QualType T,
1410 : NestedNameSpecifier *Qualifier,
1411 : SourceRange QualifierRange,
1412 : DeclarationName Name,
1413 : SourceLocation NameLoc,
1414 39: bool HasExplicitTemplateArgs)
1415 : : Expr(DependentScopeDeclRefExprClass, T, true, true),
1416 : Name(Name), Loc(NameLoc),
1417 : QualifierRange(QualifierRange), Qualifier(Qualifier),
1418 39: HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1419 39: {}
1420 :
1421 : public:
1422 : static DependentScopeDeclRefExpr *Create(ASTContext &C,
1423 : NestedNameSpecifier *Qualifier,
1424 : SourceRange QualifierRange,
1425 : DeclarationName Name,
1426 : SourceLocation NameLoc,
1427 : const TemplateArgumentListInfo *TemplateArgs = 0);
1428 :
1429 : /// \brief Retrieve the name that this expression refers to.
1430 512: DeclarationName getDeclName() const { return Name; }
1431 :
1432 : /// \brief Retrieve the location of the name within the expression.
1433 999: SourceLocation getLocation() const { return Loc; }
1434 :
1435 : /// \brief Retrieve the source range of the nested-name-specifier.
1436 975: SourceRange getQualifierRange() const { return QualifierRange; }
1437 :
1438 : /// \brief Retrieve the nested-name-specifier that qualifies this
1439 : /// declaration.
1440 991: NestedNameSpecifier *getQualifier() const { return Qualifier; }
1441 :
1442 : /// Determines whether this lookup had explicit template arguments.
1443 534: bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1444 :
1445 : // Note that, inconsistently with the explicit-template-argument AST
1446 : // nodes, users are *forbidden* from calling these methods on objects
1447 : // without explicit template arguments.
1448 :
1449 : /// Gets a reference to the explicit template argument list.
1450 4: const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
0: branch 1 not taken
4: branch 2 taken
1451 4: assert(hasExplicitTemplateArgs());
1452 4: return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1453 : }
1454 :
1455 : /// \brief Copies the template arguments (if present) into the given
1456 : /// structure.
1457 : void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1458 : getExplicitTemplateArgs().copyInto(List);
1459 : }
1460 :
1461 1: SourceLocation getLAngleLoc() const {
1462 1: return getExplicitTemplateArgs().LAngleLoc;
1463 : }
1464 :
1465 1: SourceLocation getRAngleLoc() const {
1466 1: return getExplicitTemplateArgs().RAngleLoc;
1467 : }
1468 :
1469 1: TemplateArgumentLoc const *getTemplateArgs() const {
1470 1: return getExplicitTemplateArgs().getTemplateArgs();
1471 : }
1472 :
1473 1: unsigned getNumTemplateArgs() const {
1474 1: return getExplicitTemplateArgs().NumTemplateArgs;
1475 : }
1476 :
1477 25: virtual SourceRange getSourceRange() const {
1478 25: SourceRange Range(QualifierRange.getBegin(), getLocation());
0: branch 1 not taken
25: branch 2 taken
1479 25: if (hasExplicitTemplateArgs())
1480 0: Range.setEnd(getRAngleLoc());
1481 : return Range;
1482 : }
1483 :
1484 496: static bool classof(const Stmt *T) {
1485 496: return T->getStmtClass() == DependentScopeDeclRefExprClass;
1486 : }
1487 : static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1488 :
1489 : virtual StmtIterator child_begin();
1490 : virtual StmtIterator child_end();
1491 : };
1492 :
1493 : class CXXExprWithTemporaries : public Expr {
1494 : Stmt *SubExpr;
1495 :
1496 : CXXTemporary **Temps;
1497 : unsigned NumTemps;
1498 :
1499 : CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
1500 : unsigned NumTemps);
1501 : ~CXXExprWithTemporaries();
1502 :
1503 : protected:
1504 : virtual void DoDestroy(ASTContext &C);
1505 :
1506 : public:
1507 : static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1508 : CXXTemporary **Temps,
1509 : unsigned NumTemps);
1510 :
1511 20: unsigned getNumTemporaries() const { return NumTemps; }
1512 10: CXXTemporary *getTemporary(unsigned i) {
0: branch 0 not taken
0: branch 1 not taken
1513 10: assert(i < NumTemps && "Index out of range");
1514 10: return Temps[i];
1515 : }
1516 : const CXXTemporary *getTemporary(unsigned i) const {
1517 : return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1518 : }
1519 :
1520 24: Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1521 79: const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1522 : void setSubExpr(Expr *E) { SubExpr = E; }
1523 :
1524 7: virtual SourceRange getSourceRange() const {
1525 7: return SubExpr->getSourceRange();
1526 : }
1527 :
1528 : // Implement isa/cast/dyncast/etc.
1529 1329: static bool classof(const Stmt *T) {
1530 1329: return T->getStmtClass() == CXXExprWithTemporariesClass;
1531 : }
1532 : static bool classof(const CXXExprWithTemporaries *) { return true; }
1533 :
1534 : // Iterators
1535 : virtual child_iterator child_begin();
1536 : virtual child_iterator child_end();
1537 : };
1538 :
1539 : /// \brief Describes an explicit type conversion that uses functional
1540 : /// notion but could not be resolved because one or more arguments are
1541 : /// type-dependent.
1542 : ///
1543 : /// The explicit type conversions expressed by
1544 : /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1545 : /// where \c T is some type and \c a1, a2, ..., aN are values, and
1546 : /// either \C T is a dependent type or one or more of the \c a's is
1547 : /// type-dependent. For example, this would occur in a template such
1548 : /// as:
1549 : ///
1550 : /// \code
1551 : /// template<typename T, typename A1>
1552 : /// inline T make_a(const A1& a1) {
1553 : /// return T(a1);
1554 : /// }
1555 : /// \endcode
1556 : ///
1557 : /// When the returned expression is instantiated, it may resolve to a
1558 : /// constructor call, conversion function call, or some kind of type
1559 : /// conversion.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1560 0: class CXXUnresolvedConstructExpr : public Expr {
1561 : /// \brief The starting location of the type
1562 : SourceLocation TyBeginLoc;
1563 :
1564 : /// \brief The type being constructed.
1565 : QualType Type;
1566 :
1567 : /// \brief The location of the left parentheses ('(').
1568 : SourceLocation LParenLoc;
1569 :
1570 : /// \brief The location of the right parentheses (')').
1571 : SourceLocation RParenLoc;
1572 :
1573 : /// \brief The number of arguments used to construct the type.
1574 : unsigned NumArgs;
1575 :
1576 : CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1577 : QualType T,
1578 : SourceLocation LParenLoc,
1579 : Expr **Args,
1580 : unsigned NumArgs,
1581 : SourceLocation RParenLoc);
1582 :
1583 : public:
1584 : static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1585 : SourceLocation TyBegin,
1586 : QualType T,
1587 : SourceLocation LParenLoc,
1588 : Expr **Args,
1589 : unsigned NumArgs,
1590 : SourceLocation RParenLoc);
1591 :
1592 : /// \brief Retrieve the source location where the type begins.
1593 130: SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1594 : void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1595 :
1596 : /// \brief Retrieve the type that is being constructed, as specified
1597 : /// in the source code.
1598 142: QualType getTypeAsWritten() const { return Type; }
1599 : void setTypeAsWritten(QualType T) { Type = T; }
1600 :
1601 : /// \brief Retrieve the location of the left parentheses ('(') that
1602 : /// precedes the argument list.
1603 65: SourceLocation getLParenLoc() const { return LParenLoc; }
1604 : void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1605 :
1606 : /// \brief Retrieve the location of the right parentheses (')') that
1607 : /// follows the argument list.
1608 65: SourceLocation getRParenLoc() const { return RParenLoc; }
1609 : void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1610 :
1611 : /// \brief Retrieve the number of arguments.
1612 20: unsigned arg_size() const { return NumArgs; }
1613 :
1614 : typedef Expr** arg_iterator;
1615 130: arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1616 65: arg_iterator arg_end() { return arg_begin() + NumArgs; }
1617 :
1618 : typedef const Expr* const * const_arg_iterator;
1619 0: const_arg_iterator arg_begin() const {
1620 0: return reinterpret_cast<const Expr* const *>(this + 1);
1621 : }
1622 : const_arg_iterator arg_end() const {
1623 : return arg_begin() + NumArgs;
1624 : }
1625 :
1626 : Expr *getArg(unsigned I) {
1627 : assert(I < NumArgs && "Argument index out-of-range");
1628 : return *(arg_begin() + I);
1629 : }
1630 :
1631 0: const Expr *getArg(unsigned I) const {
0: branch 0 not taken
1632 0: assert(I < NumArgs && "Argument index out-of-range");
1633 0: return *(arg_begin() + I);
1634 : }
1635 :
1636 45: virtual SourceRange getSourceRange() const {
1637 45: return SourceRange(TyBeginLoc, RParenLoc);
1638 : }
1639 85: static bool classof(const Stmt *T) {
1640 85: return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1641 : }
1642 : static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1643 :
1644 : // Iterators
1645 : virtual child_iterator child_begin();
1646 : virtual child_iterator child_end();
1647 : };
1648 :
1649 : /// \brief Represents a C++ member access expression where the actual
1650 : /// member referenced could not be resolved because the base
1651 : /// expression or the member name was dependent.
1652 : ///
1653 : /// Like UnresolvedMemberExprs, these can be either implicit or
1654 : /// explicit accesses. It is only possible to get one of these with
1655 : /// an implicit access if a qualifier is provided.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1656 0: class CXXDependentScopeMemberExpr : public Expr {
1657 : /// \brief The expression for the base pointer or class reference,
1658 : /// e.g., the \c x in x.f. Can be null in implicit accesses.
1659 : Stmt *Base;
1660 :
1661 : /// \brief The type of the base expression. Never null, even for
1662 : /// implicit accesses.
1663 : QualType BaseType;
1664 :
1665 : /// \brief Whether this member expression used the '->' operator or
1666 : /// the '.' operator.
1667 : bool IsArrow : 1;
1668 :
1669 : /// \brief Whether this member expression has explicitly-specified template
1670 : /// arguments.
1671 : bool HasExplicitTemplateArgs : 1;
1672 :
1673 : /// \brief The location of the '->' or '.' operator.
1674 : SourceLocation OperatorLoc;
1675 :
1676 : /// \brief The nested-name-specifier that precedes the member name, if any.
1677 : NestedNameSpecifier *Qualifier;
1678 :
1679 : /// \brief The source range covering the nested name specifier.
1680 : SourceRange QualifierRange;
1681 :
1682 : /// \brief In a qualified member access expression such as t->Base::f, this
1683 : /// member stores the resolves of name lookup in the context of the member
1684 : /// access expression, to be used at instantiation time.
1685 : ///
1686 : /// FIXME: This member, along with the Qualifier and QualifierRange, could
1687 : /// be stuck into a structure that is optionally allocated at the end of
1688 : /// the CXXDependentScopeMemberExpr, to save space in the common case.
1689 : NamedDecl *FirstQualifierFoundInScope;
1690 :
1691 : /// \brief The member to which this member expression refers, which
1692 : /// can be name, overloaded operator, or destructor.
1693 : /// FIXME: could also be a template-id
1694 : DeclarationName Member;
1695 :
1696 : /// \brief The location of the member name.
1697 : SourceLocation MemberLoc;
1698 :
1699 : /// \brief Retrieve the explicit template argument list that followed the
1700 : /// member template name, if any.
1701 29: ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
0: branch 0 not taken
29: branch 1 taken
1702 29: assert(HasExplicitTemplateArgs);
1703 29: return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1704 : }
1705 :
1706 : /// \brief Retrieve the explicit template argument list that followed the
1707 : /// member template name, if any.
1708 22: const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1709 : return const_cast<CXXDependentScopeMemberExpr *>(this)
1710 22: ->getExplicitTemplateArgumentList();
1711 : }
1712 :
1713 : CXXDependentScopeMemberExpr(ASTContext &C,
1714 : Expr *Base, QualType BaseType, bool IsArrow,
1715 : SourceLocation OperatorLoc,
1716 : NestedNameSpecifier *Qualifier,
1717 : SourceRange QualifierRange,
1718 : NamedDecl *FirstQualifierFoundInScope,
1719 : DeclarationName Member,
1720 : SourceLocation MemberLoc,
1721 : const TemplateArgumentListInfo *TemplateArgs);
1722 :
1723 : public:
1724 : CXXDependentScopeMemberExpr(ASTContext &C,
1725 : Expr *Base, QualType BaseType,
1726 : bool IsArrow,
1727 : SourceLocation OperatorLoc,
1728 : NestedNameSpecifier *Qualifier,
1729 : SourceRange QualifierRange,
1730 : NamedDecl *FirstQualifierFoundInScope,
1731 : DeclarationName Member,
1732 87: SourceLocation MemberLoc)
1733 : : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1734 : Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1735 : HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
1736 : Qualifier(Qualifier), QualifierRange(QualifierRange),
1737 : FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1738 87: Member(Member), MemberLoc(MemberLoc) { }
1739 :
1740 : static CXXDependentScopeMemberExpr *
1741 : Create(ASTContext &C,
1742 : Expr *Base, QualType BaseType, bool IsArrow,
1743 : SourceLocation OperatorLoc,
1744 : NestedNameSpecifier *Qualifier,
1745 : SourceRange QualifierRange,
1746 : NamedDecl *FirstQualifierFoundInScope,
1747 : DeclarationName Member,
1748 : SourceLocation MemberLoc,
1749 : const TemplateArgumentListInfo *TemplateArgs);
1750 :
1751 : /// \brief True if this is an implicit access, i.e. one in which the
1752 : /// member being accessed was not written in the source. The source
1753 : /// location of the operator is invalid in this case.
1754 217: bool isImplicitAccess() const { return Base == 0; }
1755 :
1756 : /// \brief Retrieve the base object of this member expressions,
1757 : /// e.g., the \c x in \c x.m.
1758 88: Expr *getBase() const {
0: branch 1 not taken
0: branch 2 not taken
1759 88: assert(!isImplicitAccess());
1760 88: return cast<Expr>(Base);
1761 : }
1762 : void setBase(Expr *E) { Base = E; }
1763 :
1764 25: QualType getBaseType() const { return BaseType; }
1765 :
1766 : /// \brief Determine whether this member expression used the '->'
1767 : /// operator; otherwise, it used the '.' operator.
1768 186: bool isArrow() const { return IsArrow; }
1769 : void setArrow(bool A) { IsArrow = A; }
1770 :
1771 : /// \brief Retrieve the location of the '->' or '.' operator.
1772 179: SourceLocation getOperatorLoc() const { return OperatorLoc; }
1773 : void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1774 :
1775 : /// \brief Retrieve the nested-name-specifier that qualifies the member
1776 : /// name.
1777 134: NestedNameSpecifier *getQualifier() const { return Qualifier; }
1778 :
1779 : /// \brief Retrieve the source range covering the nested-name-specifier
1780 : /// that qualifies the member name.
1781 220: SourceRange getQualifierRange() const { return QualifierRange; }
1782 :
1783 : /// \brief Retrieve the first part of the nested-name-specifier that was
1784 : /// found in the scope of the member access expression when the member access
1785 : /// was initially parsed.
1786 : ///
1787 : /// This function only returns a useful result when member access expression
1788 : /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
1789 : /// returned by this function describes what was found by unqualified name
1790 : /// lookup for the identifier "Base" within the scope of the member access
1791 : /// expression itself. At template instantiation time, this information is
1792 : /// combined with the results of name lookup into the type of the object
1793 : /// expression itself (the class type of x).
1794 96: NamedDecl *getFirstQualifierFoundInScope() const {
1795 96: return FirstQualifierFoundInScope;
1796 : }
1797 :
1798 : /// \brief Retrieve the name of the member that this expression
1799 : /// refers to.
1800 104: DeclarationName getMember() const { return Member; }
1801 : void setMember(DeclarationName N) { Member = N; }
1802 :
1803 : // \brief Retrieve the location of the name of the member that this
1804 : // expression refers to.
1805 190: SourceLocation getMemberLoc() const { return MemberLoc; }
1806 : void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1807 :
1808 : /// \brief Determines whether this member expression actually had a C++
1809 : /// template argument list explicitly specified, e.g., x.f<int>.
1810 115: bool hasExplicitTemplateArgs() const {
1811 115: return HasExplicitTemplateArgs;
1812 : }
1813 :
1814 : /// \brief Copies the template arguments (if present) into the given
1815 : /// structure.
1816 : void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1817 : assert(HasExplicitTemplateArgs);
1818 : getExplicitTemplateArgumentList()->copyInto(List);
1819 : }
1820 :
1821 : /// \brief Retrieve the location of the left angle bracket following the
1822 : /// member name ('<'), if any.
1823 5: SourceLocation getLAngleLoc() const {
0: branch 0 not taken
5: branch 1 taken
1824 5: assert(HasExplicitTemplateArgs);
1825 5: return getExplicitTemplateArgumentList()->LAngleLoc;
1826 : }
1827 :
1828 : /// \brief Retrieve the template arguments provided as part of this
1829 : /// template-id.
1830 5: const TemplateArgumentLoc *getTemplateArgs() const {
0: branch 0 not taken
5: branch 1 taken
1831 5: assert(HasExplicitTemplateArgs);
1832 5: return getExplicitTemplateArgumentList()->getTemplateArgs();
1833 : }
1834 :
1835 : /// \brief Retrieve the number of template arguments provided as part of this
1836 : /// template-id.
1837 5: unsigned getNumTemplateArgs() const {
0: branch 0 not taken
5: branch 1 taken
1838 5: assert(HasExplicitTemplateArgs);
1839 5: return getExplicitTemplateArgumentList()->NumTemplateArgs;
1840 : }
1841 :
1842 : /// \brief Retrieve the location of the right angle bracket following the
1843 : /// template arguments ('>').
1844 7: SourceLocation getRAngleLoc() const {
0: branch 0 not taken
7: branch 1 taken
1845 7: assert(HasExplicitTemplateArgs);
1846 7: return getExplicitTemplateArgumentList()->RAngleLoc;
1847 : }
1848 :
1849 14: virtual SourceRange getSourceRange() const {
1850 14: SourceRange Range;
14: branch 1 taken
0: branch 2 not taken
1851 14: if (!isImplicitAccess())
1852 14: Range.setBegin(Base->getSourceRange().getBegin());
0: branch 1 not taken
0: branch 2 not taken
1853 0: else if (getQualifier())
1854 0: Range.setBegin(getQualifierRange().getBegin());
1855 : else
1856 0: Range.setBegin(MemberLoc);
1857 :
2: branch 1 taken
12: branch 2 taken
1858 14: if (hasExplicitTemplateArgs())
1859 2: Range.setEnd(getRAngleLoc());
1860 : else
1861 12: Range.setEnd(MemberLoc);
1862 : return Range;
1863 : }
1864 :
1865 100: static bool classof(const Stmt *T) {
1866 100: return T->getStmtClass() == CXXDependentScopeMemberExprClass;
1867 : }
1868 : static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
1869 :
1870 : // Iterators
1871 : virtual child_iterator child_begin();
1872 : virtual child_iterator child_end();
1873 : };
1874 :
1875 : /// \brief Represents a C++ member access expression for which lookup
1876 : /// produced a set of overloaded functions.
1877 : ///
1878 : /// The member access may be explicit or implicit:
1879 : /// struct A {
1880 : /// int a, b;
1881 : /// int explicitAccess() { return this->a + this->A::b; }
1882 : /// int implicitAccess() { return a + A::b; }
1883 : /// };
1884 : ///
1885 : /// In the final AST, an explicit access always becomes a MemberExpr.
1886 : /// An implicit access may become either a MemberExpr or a
1887 : /// DeclRefExpr, depending on whether the member is static.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1888 0: class UnresolvedMemberExpr : public OverloadExpr {
1889 : /// \brief Whether this member expression used the '->' operator or
1890 : /// the '.' operator.
1891 : bool IsArrow : 1;
1892 :
1893 : /// \brief Whether the lookup results contain an unresolved using
1894 : /// declaration.
1895 : bool HasUnresolvedUsing : 1;
1896 :
1897 : /// \brief The expression for the base pointer or class reference,
1898 : /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
1899 : /// member expression
1900 : Stmt *Base;
1901 :
1902 : /// \brief The type of the base expression; never null.
1903 : QualType BaseType;
1904 :
1905 : /// \brief The location of the '->' or '.' operator.
1906 : SourceLocation OperatorLoc;
1907 :
1908 : UnresolvedMemberExpr(QualType T, bool Dependent,
1909 : bool HasUnresolvedUsing,
1910 : Expr *Base, QualType BaseType, bool IsArrow,
1911 : SourceLocation OperatorLoc,
1912 : NestedNameSpecifier *Qualifier,
1913 : SourceRange QualifierRange,
1914 : DeclarationName Member,
1915 : SourceLocation MemberLoc,
1916 : const TemplateArgumentListInfo *TemplateArgs);
1917 :
1918 : public:
1919 : static UnresolvedMemberExpr *
1920 : Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
1921 : Expr *Base, QualType BaseType, bool IsArrow,
1922 : SourceLocation OperatorLoc,
1923 : NestedNameSpecifier *Qualifier,
1924 : SourceRange QualifierRange,
1925 : DeclarationName Member,
1926 : SourceLocation MemberLoc,
1927 : const TemplateArgumentListInfo *TemplateArgs);
1928 :
1929 : /// \brief True if this is an implicit access, i.e. one in which the
1930 : /// member being accessed was not written in the source. The source
1931 : /// location of the operator is invalid in this case.
1932 539: bool isImplicitAccess() const { return Base == 0; }
1933 :
1934 : /// \brief Retrieve the base object of this member expressions,
1935 : /// e.g., the \c x in \c x.m.
1936 159: Expr *getBase() {
0: branch 1 not taken
0: branch 2 not taken
1937 159: assert(!isImplicitAccess());
1938 159: return cast<Expr>(Base);
1939 : }
1940 0: const Expr *getBase() const {
1941 0: assert(!isImplicitAccess());
1942 0: return cast<Expr>(Base);
1943 : }
1944 : void setBase(Expr *E) { Base = E; }
1945 :
1946 187: QualType getBaseType() const { return BaseType; }
1947 :
1948 : /// \brief Determine whether this member expression used the '->'
1949 : /// operator; otherwise, it used the '.' operator.
1950 178: bool isArrow() const { return IsArrow; }
1951 : void setArrow(bool A) { IsArrow = A; }
1952 :
1953 : /// \brief Retrieve the location of the '->' or '.' operator.
1954 10: SourceLocation getOperatorLoc() const { return OperatorLoc; }
1955 : void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1956 :
1957 : /// \brief Retrieves the naming class of this lookup.
1958 : CXXRecordDecl *getNamingClass() const;
1959 :
1960 : /// \brief Retrieve the name of the member that this expression
1961 : /// refers to.
1962 192: DeclarationName getMemberName() const { return getName(); }
1963 : void setMemberName(DeclarationName N) { setName(N); }
1964 :
1965 : // \brief Retrieve the location of the name of the member that this
1966 : // expression refers to.
1967 556: SourceLocation getMemberLoc() const { return getNameLoc(); }
1968 : void setMemberLoc(SourceLocation L) { setNameLoc(L); }
1969 :
1970 : /// \brief Retrieve the explicit template argument list that followed the
1971 : /// member template name.
1972 32: ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
0: branch 1 not taken
0: branch 2 not taken
1973 32: assert(hasExplicitTemplateArgs());
1974 32: return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1975 : }
1976 :
1977 : /// \brief Retrieve the explicit template argument list that followed the
1978 : /// member template name, if any.
1979 100: const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
0: branch 1 not taken
0: branch 2 not taken
1980 100: assert(hasExplicitTemplateArgs());
1981 100: return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
1982 : }
1983 :
1984 : /// \brief Copies the template arguments into the given structure.
1985 59: void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1986 59: getExplicitTemplateArgs().copyInto(List);
1987 59: }
1988 :
1989 : /// \brief Retrieve the location of the left angle bracket following
1990 : /// the member name ('<').
1991 1: SourceLocation getLAngleLoc() const {
1992 1: return getExplicitTemplateArgs().LAngleLoc;
1993 : }
1994 :
1995 : /// \brief Retrieve the template arguments provided as part of this
1996 : /// template-id.
1997 1: const TemplateArgumentLoc *getTemplateArgs() const {
1998 1: return getExplicitTemplateArgs().getTemplateArgs();
1999 : }
2000 :
2001 : /// \brief Retrieve the number of template arguments provided as
2002 : /// part of this template-id.
2003 1: unsigned getNumTemplateArgs() const {
2004 1: return getExplicitTemplateArgs().NumTemplateArgs;
2005 : }
2006 :
2007 : /// \brief Retrieve the location of the right angle bracket
2008 : /// following the template arguments ('>').
2009 38: SourceLocation getRAngleLoc() const {
2010 38: return getExplicitTemplateArgs().RAngleLoc;
2011 : }
2012 :
2013 208: virtual SourceRange getSourceRange() const {
2014 208: SourceRange Range;
182: branch 1 taken
26: branch 2 taken
2015 208: if (!isImplicitAccess())
2016 182: Range.setBegin(Base->getSourceRange().getBegin());
3: branch 1 taken
23: branch 2 taken
2017 26: else if (getQualifier())
2018 3: Range.setBegin(getQualifierRange().getBegin());
2019 : else
2020 23: Range.setBegin(getMemberLoc());
2021 :
37: branch 1 taken
171: branch 2 taken
2022 208: if (hasExplicitTemplateArgs())
2023 37: Range.setEnd(getRAngleLoc());
2024 : else
2025 171: Range.setEnd(getMemberLoc());
2026 : return Range;
2027 : }
2028 :
2029 2891: static bool classof(const Stmt *T) {
2030 2891: return T->getStmtClass() == UnresolvedMemberExprClass;
2031 : }
2032 : static bool classof(const UnresolvedMemberExpr *) { return true; }
2033 :
2034 : // Iterators
2035 : virtual child_iterator child_begin();
2036 : virtual child_iterator child_end();
2037 : };
2038 :
2039 77: inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2040 77: if (isa<UnresolvedLookupExpr>(this))
2041 77: return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2042 : else
2043 0: return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2044 : }
2045 :
2046 : } // end namespace clang
2047 :
2048 : #endif
Generated: 2010-02-10 01:31 by zcov