 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
36.1% |
120 / 332 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
48.8% |
162 / 332 |
| |
|
Line Coverage: |
95.9% |
817 / 852 |
| |
 |
|
 |
 |
|
 |
|
| Programs: |
147 |
|
Runs |
306491 |
| |
 |
|
 |
1 : //===--- Expr.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.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_AST_EXPR_H
15 : #define LLVM_CLANG_AST_EXPR_H
16 :
17 : #include "clang/AST/APValue.h"
18 : #include "clang/AST/Stmt.h"
19 : #include "clang/AST/Type.h"
20 : #include "llvm/ADT/APSInt.h"
21 : #include "llvm/ADT/APFloat.h"
22 : #include "llvm/ADT/SmallVector.h"
23 : #include "llvm/ADT/StringRef.h"
24 : #include <vector>
25 :
26 : namespace clang {
27 : class ASTContext;
28 : class APValue;
29 : class Decl;
30 : class IdentifierInfo;
31 : class ParmVarDecl;
32 : class NamedDecl;
33 : class ValueDecl;
34 : class BlockDecl;
35 : class CXXOperatorCallExpr;
36 : class CXXMemberCallExpr;
37 : class TemplateArgumentLoc;
38 : class TemplateArgumentListInfo;
39 :
40 : /// Expr - This represents one expression. Note that Expr's are subclasses of
41 : /// Stmt. This allows an expression to be transparently used any place a Stmt
42 : /// is required.
43 : ///
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
31539: branch 10 taken
44 31539: class Expr : public Stmt {
45 : QualType TR;
46 :
47 : protected:
48 : /// TypeDependent - Whether this expression is type-dependent
49 : /// (C++ [temp.dep.expr]).
50 : bool TypeDependent : 1;
51 :
52 : /// ValueDependent - Whether this expression is value-dependent
53 : /// (C++ [temp.dep.constexpr]).
54 : bool ValueDependent : 1;
55 :
56 149743: Expr(StmtClass SC, QualType T, bool TD, bool VD)
57 149743: : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
58 149743: setType(T);
59 149743: }
60 :
61 : /// \brief Construct an empty expression.
62 401: explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
63 :
64 : public:
65 : /// \brief Increases the reference count for this expression.
66 : ///
67 : /// Invoke the Retain() operation when this expression
68 : /// is being shared by another owner.
69 22775: Expr *Retain() {
70 22775: Stmt::Retain();
71 22775: return this;
72 : }
73 :
74 1073330: QualType getType() const { return TR; }
75 159961: void setType(QualType t) {
76 : // In C++, the type of an expression is always adjusted so that it
77 : // will not have reference type an expression will never have
78 : // reference type (C++ [expr]p6). Use
79 : // QualType::getNonReferenceType() to retrieve the non-reference
80 : // type. Additionally, inspect Expr::isLvalue to determine whether
81 : // an expression that is adjusted in this manner should be
82 : // considered an lvalue.
83 : assert((t.isNull() || !t->isReferenceType()) &&
157842: branch 1 taken
2119: branch 2 taken
157842: branch 5 taken
0: branch 6 not taken
84 159961: "Expressions can't have reference type");
85 :
86 159961: TR = t;
87 159961: }
88 :
89 : /// isValueDependent - Determines whether this expression is
90 : /// value-dependent (C++ [temp.dep.constexpr]). For example, the
91 : /// array bound of "Chars" in the following example is
92 : /// value-dependent.
93 : /// @code
94 : /// template<int Size, char (&Chars)[Size]> struct meta_string;
95 : /// @endcode
96 173419: bool isValueDependent() const { return ValueDependent; }
97 :
98 : /// \brief Set whether this expression is value-dependent or not.
99 426: void setValueDependent(bool VD) { ValueDependent = VD; }
100 :
101 : /// isTypeDependent - Determines whether this expression is
102 : /// type-dependent (C++ [temp.dep.expr]), which means that its type
103 : /// could change from one template instantiation to the next. For
104 : /// example, the expressions "x" and "x + y" are type-dependent in
105 : /// the following code, but "y" is not type-dependent:
106 : /// @code
107 : /// template<typename T>
108 : /// void add(T x, int y) {
109 : /// x + y;
110 : /// }
111 : /// @endcode
112 123864: bool isTypeDependent() const { return TypeDependent; }
113 :
114 : /// \brief Set whether this expression is type-dependent or not.
115 426: void setTypeDependent(bool TD) { TypeDependent = TD; }
116 :
117 : /// SourceLocation tokens are not useful in isolation - they are low level
118 : /// value objects created/interpreted by SourceManager. We assume AST
119 : /// clients will have a pointer to the respective SourceManager.
120 : virtual SourceRange getSourceRange() const = 0;
121 :
122 : /// getExprLoc - Return the preferred location for the arrow when diagnosing
123 : /// a problem with a generic expression.
124 18485: virtual SourceLocation getExprLoc() const { return getLocStart(); }
125 :
126 : /// isUnusedResultAWarning - Return true if this immediate expression should
127 : /// be warned about if the result is unused. If so, fill in Loc and Ranges
128 : /// with location to warn on and the source range[s] to report with the
129 : /// warning.
130 : bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
131 : SourceRange &R2, ASTContext &Ctx) const;
132 :
133 : /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
134 : /// incomplete type other than void. Nonarray expressions that can be lvalues:
135 : /// - name, where name must be a variable
136 : /// - e[i]
137 : /// - (e), where e must be an lvalue
138 : /// - e.name, where e must be an lvalue
139 : /// - e->name
140 : /// - *e, the type of e cannot be a function type
141 : /// - string-constant
142 : /// - reference type [C++ [expr]]
143 : /// - b ? x : y, where x and y are lvalues of suitable types [C++]
144 : ///
145 : enum isLvalueResult {
146 : LV_Valid,
147 : LV_NotObjectType,
148 : LV_IncompleteVoidType,
149 : LV_DuplicateVectorComponents,
150 : LV_InvalidExpression,
151 : LV_MemberFunction,
152 : LV_SubObjCPropertySetting
153 : };
154 : isLvalueResult isLvalue(ASTContext &Ctx) const;
155 :
156 : // Same as above, but excluding checks for non-object and void types in C
157 : isLvalueResult isLvalueInternal(ASTContext &Ctx) const;
158 :
159 : /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
160 : /// does not have an incomplete type, does not have a const-qualified type,
161 : /// and if it is a structure or union, does not have any member (including,
162 : /// recursively, any member or element of all contained aggregates or unions)
163 : /// with a const-qualified type.
164 : ///
165 : /// \param Loc [in] [out] - A source location which *may* be filled
166 : /// in with the location of the expression making this a
167 : /// non-modifiable lvalue, if specified.
168 : enum isModifiableLvalueResult {
169 : MLV_Valid,
170 : MLV_NotObjectType,
171 : MLV_IncompleteVoidType,
172 : MLV_DuplicateVectorComponents,
173 : MLV_InvalidExpression,
174 : MLV_LValueCast, // Specialized form of MLV_InvalidExpression.
175 : MLV_IncompleteType,
176 : MLV_ConstQualified,
177 : MLV_ArrayType,
178 : MLV_NotBlockQualified,
179 : MLV_ReadonlyProperty,
180 : MLV_NoSetterProperty,
181 : MLV_MemberFunction,
182 : MLV_SubObjCPropertySetting
183 : };
184 : isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
185 : SourceLocation *Loc = 0) const;
186 :
187 : /// \brief If this expression refers to a bit-field, retrieve the
188 : /// declaration of that bit-field.
189 : FieldDecl *getBitField();
190 :
191 : const FieldDecl *getBitField() const {
192 : return const_cast<Expr*>(this)->getBitField();
193 : }
194 :
195 : /// \brief Returns whether this expression refers to a vector element.
196 : bool refersToVectorElement() const;
197 :
198 : /// isIntegerConstantExpr - Return true if this expression is a valid integer
199 : /// constant expression, and, if so, return its value in Result. If not a
200 : /// valid i-c-e, return false and fill in Loc (if specified) with the location
201 : /// of the invalid expression.
202 : bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
203 : SourceLocation *Loc = 0,
204 : bool isEvaluated = true) const;
205 799: bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
206 799: llvm::APSInt X;
207 799: return isIntegerConstantExpr(X, Ctx, Loc);
208 : }
209 : /// isConstantInitializer - Returns true if this expression is a constant
210 : /// initializer, which can be emitted at compile-time.
211 : bool isConstantInitializer(ASTContext &Ctx) const;
212 :
213 : /// EvalResult is a struct with detailed info about an evaluated expression.
214 26365: struct EvalResult {
215 : /// Val - This is the value the expression can be folded to.
216 : APValue Val;
217 :
218 : /// HasSideEffects - Whether the evaluated expression has side effects.
219 : /// For example, (f() && 0) can be folded, but it still has side effects.
220 : bool HasSideEffects;
221 :
222 : /// Diag - If the expression is unfoldable, then Diag contains a note
223 : /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
224 : /// position for the error, and DiagExpr is the expression that caused
225 : /// the error.
226 : /// If the expression is foldable, but not an integer constant expression,
227 : /// Diag contains a note diagnostic that describes why it isn't an integer
228 : /// constant expression. If the expression *is* an integer constant
229 : /// expression, then Diag will be zero.
230 : unsigned Diag;
231 : const Expr *DiagExpr;
232 : SourceLocation DiagLoc;
233 :
234 26275: EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
235 : };
236 :
237 : /// Evaluate - Return true if this is a constant which we can fold using
238 : /// any crazy technique (that has nothing to do with language standards) that
239 : /// we want to. If this function returns true, it returns the folded constant
240 : /// in Result.
241 : bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
242 :
243 : /// EvaluateAsAny - The same as Evaluate, except that it also succeeds on
244 : /// stack based objects.
245 : bool EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const;
246 :
247 : /// EvaluateAsBooleanCondition - Return true if this is a constant
248 : /// which we we can fold and convert to a boolean condition using
249 : /// any crazy technique that we want to.
250 : bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
251 :
252 : /// isEvaluatable - Call Evaluate to see if this expression can be constant
253 : /// folded, but discard the result.
254 : bool isEvaluatable(ASTContext &Ctx) const;
255 :
256 : /// HasSideEffects - This routine returns true for all those expressions
257 : /// which must be evaluated each time and must not be optimization away
258 : /// or evaluated at compile time. Example is a function call, volatile
259 : /// variable read.
260 : bool HasSideEffects(ASTContext &Ctx) const;
261 :
262 : /// EvaluateAsInt - Call Evaluate and return the folded integer. This
263 : /// must be called on an expression that constant folds to an integer.
264 : llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
265 :
266 : /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
267 : /// with link time known address.
268 : bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
269 :
270 : /// EvaluateAsAnyLValue - The same as EvaluateAsLValue, except that it
271 : /// also succeeds on stack based, immutable address lvalues.
272 : bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
273 :
274 : /// \brief Enumeration used to describe how \c isNullPointerConstant()
275 : /// should cope with value-dependent expressions.
276 : enum NullPointerConstantValueDependence {
277 : /// \brief Specifies that the expression should never be value-dependent.
278 : NPC_NeverValueDependent = 0,
279 :
280 : /// \brief Specifies that a value-dependent expression of integral or
281 : /// dependent type should be considered a null pointer constant.
282 : NPC_ValueDependentIsNull,
283 :
284 : /// \brief Specifies that a value-dependent expression should be considered
285 : /// to never be a null pointer constant.
286 : NPC_ValueDependentIsNotNull
287 : };
288 :
289 : /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an
290 : /// integer constant expression with the value zero, or if this is one that is
291 : /// cast to void*.
292 : bool isNullPointerConstant(ASTContext &Ctx,
293 : NullPointerConstantValueDependence NPC) const;
294 :
295 : /// isOBJCGCCandidate - Return true if this expression may be used in a read/
296 : /// write barrier.
297 : bool isOBJCGCCandidate(ASTContext &Ctx) const;
298 :
299 : /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return
300 : /// its subexpression. If that subexpression is also a ParenExpr,
301 : /// then this method recursively returns its subexpression, and so forth.
302 : /// Otherwise, the method returns the current Expr.
303 : Expr* IgnoreParens();
304 :
305 : /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr
306 : /// or CastExprs, returning their operand.
307 : Expr *IgnoreParenCasts();
308 :
309 : /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
310 : /// value (including ptr->int casts of the same size). Strip off any
311 : /// ParenExpr or CastExprs, returning their operand.
312 : Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
313 :
314 : /// \brief Determine whether this expression is a default function argument.
315 : ///
316 : /// Default arguments are implicitly generated in the abstract syntax tree
317 : /// by semantic analysis for function calls, object constructions, etc. in
318 : /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
319 : /// this routine also looks through any implicit casts to determine whether
320 : /// the expression is a default argument.
321 : bool isDefaultArgument() const;
322 :
323 6093: const Expr* IgnoreParens() const {
324 6093: return const_cast<Expr*>(this)->IgnoreParens();
325 : }
326 1677: const Expr *IgnoreParenCasts() const {
327 1677: return const_cast<Expr*>(this)->IgnoreParenCasts();
328 : }
329 82: const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
330 82: return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
331 : }
332 :
333 : static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
334 : static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
335 :
336 528455: static bool classof(const Stmt *T) {
337 : return T->getStmtClass() >= firstExprConstant &&
43101: branch 5 taken
485354: branch 5 taken
4791: branch 5 taken
0: branch 5 not taken
338 528455: T->getStmtClass() <= lastExprConstant;
339 : }
340 5327: static bool classof(const Expr *) { return true; }
341 : };
342 :
343 :
344 : //===----------------------------------------------------------------------===//
345 : // Primary Expressions.
346 : //===----------------------------------------------------------------------===//
347 :
348 : /// \brief Represents the qualifier that may precede a C++ name, e.g., the
349 : /// "std::" in "std::sort".
350 : struct NameQualifier {
351 : /// \brief The nested name specifier.
352 : NestedNameSpecifier *NNS;
353 :
354 : /// \brief The source range covered by the nested name specifier.
355 : SourceRange Range;
356 : };
357 :
358 : /// \brief Represents an explicit template argument list in C++, e.g.,
359 : /// the "<int>" in "sort<int>".
360 : struct ExplicitTemplateArgumentList {
361 : /// \brief The source location of the left angle bracket ('<');
362 : SourceLocation LAngleLoc;
363 :
364 : /// \brief The source location of the right angle bracket ('>');
365 : SourceLocation RAngleLoc;
366 :
367 : /// \brief The number of template arguments in TemplateArgs.
368 : /// The actual template arguments (if any) are stored after the
369 : /// ExplicitTemplateArgumentList structure.
370 : unsigned NumTemplateArgs;
371 :
372 : /// \brief Retrieve the template arguments
373 315: TemplateArgumentLoc *getTemplateArgs() {
374 315: return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
375 : }
376 :
377 : /// \brief Retrieve the template arguments
378 478: const TemplateArgumentLoc *getTemplateArgs() const {
379 478: return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
380 : }
381 :
382 : void initializeFrom(const TemplateArgumentListInfo &List);
383 : void copyInto(TemplateArgumentListInfo &List) const;
384 : static std::size_t sizeFor(const TemplateArgumentListInfo &List);
385 : };
386 :
387 : /// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
388 : /// enum, etc.
0: branch 5 not taken
0: branch 6 not taken
389 10182: class DeclRefExpr : public Expr {
390 : enum {
391 : // Flag on DecoratedD that specifies when this declaration reference
392 : // expression has a C++ nested-name-specifier.
393 : HasQualifierFlag = 0x01,
394 : // Flag on DecoratedD that specifies when this declaration reference
395 : // expression has an explicit C++ template argument list.
396 : HasExplicitTemplateArgumentListFlag = 0x02
397 : };
398 :
399 : // DecoratedD - The declaration that we are referencing, plus two bits to
400 : // indicate whether (1) the declaration's name was explicitly qualified and
401 : // (2) the declaration's name was followed by an explicit template
402 : // argument list.
403 : llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
404 :
405 : // Loc - The location of the declaration name itself.
406 : SourceLocation Loc;
407 :
408 : /// \brief Retrieve the qualifier that preceded the declaration name, if any.
409 2895: NameQualifier *getNameQualifier() {
0: branch 1 not taken
0: branch 2 not taken
410 2895: if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
411 0: return 0;
412 :
413 2895: return reinterpret_cast<NameQualifier *> (this + 1);
414 : }
415 :
416 : /// \brief Retrieve the qualifier that preceded the member name, if any.
417 1937: const NameQualifier *getNameQualifier() const {
418 1937: return const_cast<DeclRefExpr *>(this)->getNameQualifier();
419 : }
420 :
421 : /// \brief Retrieve the explicit template argument list that followed the
422 : /// member template name, if any.
423 839: ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
839: branch 2 taken
0: branch 2 not taken
424 839: if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0)
425 0: return 0;
426 :
785: branch 1 taken
54: branch 2 taken
427 839: if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
428 785: return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
429 :
430 : return reinterpret_cast<ExplicitTemplateArgumentList *>(
431 54: getNameQualifier() + 1);
432 : }
433 :
434 : /// \brief Retrieve the explicit template argument list that followed the
435 : /// member template name, if any.
436 721: const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
437 721: return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList();
438 : }
439 :
440 : DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
441 : ValueDecl *D, SourceLocation NameLoc,
442 : const TemplateArgumentListInfo *TemplateArgs,
443 : QualType T);
444 :
445 : protected:
446 : /// \brief Computes the type- and value-dependence flags for this
447 : /// declaration reference expression.
448 : void computeDependence();
449 :
450 : DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) :
451 : Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) {
452 : computeDependence();
453 : }
454 :
455 : public:
456 9848: DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
457 9848: Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
458 9848: computeDependence();
459 9848: }
460 :
461 : /// \brief Construct an empty declaration reference expression.
462 107: explicit DeclRefExpr(EmptyShell Empty)
463 107: : Expr(DeclRefExprClass, Empty) { }
464 :
465 : static DeclRefExpr *Create(ASTContext &Context,
466 : NestedNameSpecifier *Qualifier,
467 : SourceRange QualifierRange,
468 : ValueDecl *D,
469 : SourceLocation NameLoc,
470 : QualType T,
471 : const TemplateArgumentListInfo *TemplateArgs = 0);
472 :
473 99802: ValueDecl *getDecl() { return DecoratedD.getPointer(); }
474 48850: const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
475 125: void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
476 :
477 783: SourceLocation getLocation() const { return Loc; }
478 107: void setLocation(SourceLocation L) { Loc = L; }
479 : virtual SourceRange getSourceRange() const;
480 :
481 : /// \brief Determine whether this declaration reference was preceded by a
482 : /// C++ nested-name-specifier, e.g., \c N::foo.
483 191362: bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
484 :
485 : /// \brief If the name was qualified, retrieves the source range of
486 : /// the nested-name-specifier that precedes the name. Otherwise,
487 : /// returns an empty source range.
488 2275: SourceRange getQualifierRange() const {
523: branch 1 taken
1752: branch 2 taken
489 2275: if (!hasQualifier())
490 523: return SourceRange();
491 :
492 1752: return getNameQualifier()->Range;
493 : }
494 :
495 : /// \brief If the name was qualified, retrieves the nested-name-specifier
496 : /// that precedes the name. Otherwise, returns NULL.
497 2043: NestedNameSpecifier *getQualifier() const {
185: branch 2 taken
0: branch 2 not taken
498 2043: if (!hasQualifier())
499 1858: return 0;
500 :
501 185: return getNameQualifier()->NNS;
502 : }
503 :
504 : /// \brief Determines whether this member expression actually had a C++
505 : /// template argument list explicitly specified, e.g., x.f<int>.
506 228192: bool hasExplicitTemplateArgumentList() const {
507 228192: return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag;
508 : }
509 :
510 : /// \brief Copies the template arguments (if present) into the given
511 : /// structure.
512 : void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
513 : if (hasExplicitTemplateArgumentList())
514 : getExplicitTemplateArgumentList()->copyInto(List);
515 : }
516 :
517 : /// \brief Retrieve the location of the left angle bracket following the
518 : /// member name ('<'), if any.
519 1: SourceLocation getLAngleLoc() const {
1: branch 2 taken
520 1: if (!hasExplicitTemplateArgumentList())
521 0: return SourceLocation();
522 :
523 1: return getExplicitTemplateArgumentList()->LAngleLoc;
524 : }
525 :
526 : /// \brief Retrieve the template arguments provided as part of this
527 : /// template-id.
528 399: const TemplateArgumentLoc *getTemplateArgs() const {
278: branch 1 taken
121: branch 2 taken
529 399: if (!hasExplicitTemplateArgumentList())
530 278: return 0;
531 :
532 121: return getExplicitTemplateArgumentList()->getTemplateArgs();
533 : }
534 :
535 : /// \brief Retrieve the number of template arguments provided as part of this
536 : /// template-id.
537 399: unsigned getNumTemplateArgs() const {
278: branch 1 taken
121: branch 2 taken
538 399: if (!hasExplicitTemplateArgumentList())
539 278: return 0;
540 :
541 121: return getExplicitTemplateArgumentList()->NumTemplateArgs;
542 : }
543 :
544 : /// \brief Retrieve the location of the right angle bracket following the
545 : /// template arguments ('>').
546 478: SourceLocation getRAngleLoc() const {
0: branch 1 not taken
478: branch 2 taken
547 478: if (!hasExplicitTemplateArgumentList())
548 0: return SourceLocation();
549 :
550 478: return getExplicitTemplateArgumentList()->RAngleLoc;
551 : }
552 :
553 99741: static bool classof(const Stmt *T) {
554 99741: return T->getStmtClass() == DeclRefExprClass;
555 : }
556 : static bool classof(const DeclRefExpr *) { return true; }
557 :
558 : // Iterators
559 : virtual child_iterator child_begin();
560 : virtual child_iterator child_end();
561 : };
562 :
563 : /// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
564 0: class PredefinedExpr : public Expr {
565 : public:
566 : enum IdentType {
567 : Func,
568 : Function,
569 : PrettyFunction
570 : };
571 :
572 : private:
573 : SourceLocation Loc;
574 : IdentType Type;
575 : public:
576 245: PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
577 : : Expr(PredefinedExprClass, type, type->isDependentType(),
578 245: type->isDependentType()), Loc(l), Type(IT) {}
579 :
580 : /// \brief Construct an empty predefined expression.
581 1: explicit PredefinedExpr(EmptyShell Empty)
582 1: : Expr(PredefinedExprClass, Empty) { }
583 :
584 395: IdentType getIdentType() const { return Type; }
585 1: void setIdentType(IdentType IT) { Type = IT; }
586 :
587 18: SourceLocation getLocation() const { return Loc; }
588 1: void setLocation(SourceLocation L) { Loc = L; }
589 :
590 : static std::string ComputeName(ASTContext &Context, IdentType IT,
591 : const Decl *CurrentDecl);
592 :
593 247: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
594 :
595 197: static bool classof(const Stmt *T) {
596 197: return T->getStmtClass() == PredefinedExprClass;
597 : }
598 : static bool classof(const PredefinedExpr *) { return true; }
599 :
600 : // Iterators
601 : virtual child_iterator child_begin();
602 : virtual child_iterator child_end();
603 : };
604 :
0: branch 2 not taken
553: branch 3 taken
0: branch 7 not taken
0: branch 8 not taken
605 553: class IntegerLiteral : public Expr {
606 : llvm::APInt Value;
607 : SourceLocation Loc;
608 : public:
609 : // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
610 : // or UnsignedLongLongTy
611 17880: IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
612 17880: : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
17880: branch 2 taken
0: branch 3 not taken
613 17880: assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
614 17880: }
615 :
616 : /// \brief Construct an empty integer literal.
617 75: explicit IntegerLiteral(EmptyShell Empty)
618 75: : Expr(IntegerLiteralClass, Empty) { }
619 :
620 23707: const llvm::APInt &getValue() const { return Value; }
621 31713: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
622 :
623 : /// \brief Retrieve the location of the literal.
624 78: SourceLocation getLocation() const { return Loc; }
625 :
626 75: void setValue(const llvm::APInt &Val) { Value = Val; }
627 75: void setLocation(SourceLocation Location) { Loc = Location; }
628 :
629 6229: static bool classof(const Stmt *T) {
630 6229: return T->getStmtClass() == IntegerLiteralClass;
631 : }
632 : static bool classof(const IntegerLiteral *) { return true; }
633 :
634 : // Iterators
635 : virtual child_iterator child_begin();
636 : virtual child_iterator child_end();
637 : };
638 :
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
639 0: class CharacterLiteral : public Expr {
640 : unsigned Value;
641 : SourceLocation Loc;
642 : bool IsWide;
643 : public:
644 : // type should be IntTy
645 192: CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
646 : : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
647 192: IsWide(iswide) {
648 192: }
649 :
650 : /// \brief Construct an empty character literal.
651 1: CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
652 :
653 1: SourceLocation getLocation() const { return Loc; }
654 33: bool isWide() const { return IsWide; }
655 :
656 410: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
657 :
658 301: unsigned getValue() const { return Value; }
659 :
660 1: void setLocation(SourceLocation Location) { Loc = Location; }
661 1: void setWide(bool W) { IsWide = W; }
662 1: void setValue(unsigned Val) { Value = Val; }
663 :
664 111: static bool classof(const Stmt *T) {
665 111: return T->getStmtClass() == CharacterLiteralClass;
666 : }
667 : static bool classof(const CharacterLiteral *) { return true; }
668 :
669 : // Iterators
670 : virtual child_iterator child_begin();
671 : virtual child_iterator child_end();
672 : };
673 :
0: branch 2 not taken
0: branch 3 not taken
0: branch 7 not taken
36: branch 8 taken
674 36: class FloatingLiteral : public Expr {
675 : llvm::APFloat Value;
676 : bool IsExact : 1;
677 : SourceLocation Loc;
678 : public:
679 : FloatingLiteral(const llvm::APFloat &V, bool isexact,
680 771: QualType Type, SourceLocation L)
681 : : Expr(FloatingLiteralClass, Type, false, false), Value(V),
682 771: IsExact(isexact), Loc(L) {}
683 :
684 : /// \brief Construct an empty floating-point literal.
685 12: explicit FloatingLiteral(EmptyShell Empty)
686 12: : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
687 :
688 596: const llvm::APFloat &getValue() const { return Value; }
689 12: void setValue(const llvm::APFloat &Val) { Value = Val; }
690 :
691 17: bool isExact() const { return IsExact; }
692 12: void setExact(bool E) { IsExact = E; }
693 :
694 : /// getValueAsApproximateDouble - This returns the value as an inaccurate
695 : /// double. Note that this may cause loss of precision, but is useful for
696 : /// debugging dumps, etc.
697 : double getValueAsApproximateDouble() const;
698 :
699 12: SourceLocation getLocation() const { return Loc; }
700 12: void setLocation(SourceLocation L) { Loc = L; }
701 :
702 1953: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
703 :
704 158: static bool classof(const Stmt *T) {
705 158: return T->getStmtClass() == FloatingLiteralClass;
706 : }
707 : static bool classof(const FloatingLiteral *) { return true; }
708 :
709 : // Iterators
710 : virtual child_iterator child_begin();
711 : virtual child_iterator child_end();
712 : };
713 :
714 : /// ImaginaryLiteral - We support imaginary integer and floating point literals,
715 : /// like "1.0i". We represent these as a wrapper around FloatingLiteral and
716 : /// IntegerLiteral classes. Instances of this class always have a Complex type
717 : /// whose element type matches the subexpression.
718 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
2: branch 6 taken
719 2: class ImaginaryLiteral : public Expr {
720 : Stmt *Val;
721 : public:
722 55: ImaginaryLiteral(Expr *val, QualType Ty)
723 55: : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
724 :
725 : /// \brief Build an empty imaginary literal.
726 1: explicit ImaginaryLiteral(EmptyShell Empty)
727 1: : Expr(ImaginaryLiteralClass, Empty) { }
728 :
729 19: const Expr *getSubExpr() const { return cast<Expr>(Val); }
730 51: Expr *getSubExpr() { return cast<Expr>(Val); }
731 1: void setSubExpr(Expr *E) { Val = E; }
732 :
733 67: virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
734 2: static bool classof(const Stmt *T) {
735 2: return T->getStmtClass() == ImaginaryLiteralClass;
736 : }
737 : static bool classof(const ImaginaryLiteral *) { return true; }
738 :
739 : // Iterators
740 : virtual child_iterator child_begin();
741 : virtual child_iterator child_end();
742 : };
743 :
744 : /// StringLiteral - This represents a string literal expression, e.g. "foo"
745 : /// or L"bar" (wide strings). The actual string is returned by getStrData()
746 : /// is NOT null-terminated, and the length of the string is determined by
747 : /// calling getByteLength(). The C type for a string is always a
748 : /// ConstantArrayType. In C++, the char type is const qualified, in C it is
749 : /// not.
750 : ///
751 : /// Note that strings in C can be formed by concatenation of multiple string
752 : /// literal pptokens in translation phase #6. This keeps track of the locations
753 : /// of each of these pieces.
754 : ///
755 : /// Strings in C can also be truncated and extended by assigning into arrays,
756 : /// e.g. with constructs like:
757 : /// char X[2] = "foobar";
758 : /// In this case, getByteLength() will return 6, but the string literal will
759 : /// have type "char[2]".
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
50: branch 6 taken
760 50: class StringLiteral : public Expr {
761 : const char *StrData;
762 : unsigned ByteLength;
763 : bool IsWide;
764 : unsigned NumConcatenated;
765 : SourceLocation TokLocs[1];
766 :
1869: branch 2 taken
1869: branch 3 taken
767 1869: StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
768 :
769 : protected:
770 : virtual void DoDestroy(ASTContext &C);
771 :
772 : public:
773 : /// This is the "fully general" constructor that allows representation of
774 : /// strings formed from multiple concatenated tokens.
775 : static StringLiteral *Create(ASTContext &C, const char *StrData,
776 : unsigned ByteLength, bool Wide, QualType Ty,
777 : const SourceLocation *Loc, unsigned NumStrs);
778 :
779 : /// Simple constructor for string literals made from one token.
780 : static StringLiteral *Create(ASTContext &C, const char *StrData,
781 : unsigned ByteLength,
782 56: bool Wide, QualType Ty, SourceLocation Loc) {
783 56: return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
784 : }
785 :
786 : /// \brief Construct an empty string literal.
787 : static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
788 :
789 488: llvm::StringRef getString() const {
790 488: return llvm::StringRef(StrData, ByteLength);
791 : }
792 : // FIXME: These are deprecated, replace with StringRef.
793 2119: const char *getStrData() const { return StrData; }
794 1784: unsigned getByteLength() const { return ByteLength; }
795 :
796 : /// \brief Sets the string data to the given string data.
797 : void setString(ASTContext &C, llvm::StringRef Str);
798 :
799 2677: bool isWide() const { return IsWide; }
800 25: void setWide(bool W) { IsWide = W; }
801 :
802 79: bool containsNonAsciiOrNull() const {
803 79: llvm::StringRef Str = getString();
1008: branch 1 taken
75: branch 2 taken
804 1083: for (unsigned i = 0, e = Str.size(); i != e; ++i)
1004: branch 1 taken
4: branch 2 taken
0: branch 4 not taken
1004: branch 5 taken
4: branch 6 taken
1004: branch 7 taken
805 1008: if (!isascii(Str[i]) || !Str[i])
806 4: return true;
807 75: return false;
808 : }
809 : /// getNumConcatenated - Get the number of string literal tokens that were
810 : /// concatenated in translation phase #6 to form this string literal.
811 217: unsigned getNumConcatenated() const { return NumConcatenated; }
812 :
813 144: SourceLocation getStrTokenLoc(unsigned TokNum) const {
0: branch 0 not taken
144: branch 1 taken
814 144: assert(TokNum < NumConcatenated && "Invalid tok number");
815 144: return TokLocs[TokNum];
816 : }
817 28: void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
818 28: assert(TokNum < NumConcatenated && "Invalid tok number");
819 28: TokLocs[TokNum] = L;
820 28: }
821 :
822 : typedef const SourceLocation *tokloc_iterator;
823 15: tokloc_iterator tokloc_begin() const { return TokLocs; }
824 15: tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
825 :
826 4482: virtual SourceRange getSourceRange() const {
827 4482: return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
828 : }
829 8343: static bool classof(const Stmt *T) {
830 8343: return T->getStmtClass() == StringLiteralClass;
831 : }
832 : static bool classof(const StringLiteral *) { return true; }
833 :
834 : // Iterators
835 : virtual child_iterator child_begin();
836 : virtual child_iterator child_end();
837 : };
838 :
839 : /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
840 : /// AST node is only formed if full location information is requested.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
91: branch 6 taken
841 91: class ParenExpr : public Expr {
842 : SourceLocation L, R;
843 : Stmt *Val;
844 : public:
845 3998: ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
846 : : Expr(ParenExprClass, val->getType(),
847 : val->isTypeDependent(), val->isValueDependent()),
848 3998: L(l), R(r), Val(val) {}
849 :
850 : /// \brief Construct an empty parenthesized expression.
851 42: explicit ParenExpr(EmptyShell Empty)
852 42: : Expr(ParenExprClass, Empty) { }
853 :
854 3644: const Expr *getSubExpr() const { return cast<Expr>(Val); }
855 9138: Expr *getSubExpr() { return cast<Expr>(Val); }
856 42: void setSubExpr(Expr *E) { Val = E; }
857 :
858 8275: virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
859 :
860 : /// \brief Get the location of the left parentheses '('.
861 126: SourceLocation getLParen() const { return L; }
862 42: void setLParen(SourceLocation Loc) { L = Loc; }
863 :
864 : /// \brief Get the location of the right parentheses ')'.
865 126: SourceLocation getRParen() const { return R; }
866 42: void setRParen(SourceLocation Loc) { R = Loc; }
867 :
868 159344: static bool classof(const Stmt *T) {
869 159344: return T->getStmtClass() == ParenExprClass;
870 : }
871 : static bool classof(const ParenExpr *) { return true; }
872 :
873 : // Iterators
874 : virtual child_iterator child_begin();
875 : virtual child_iterator child_end();
876 : };
877 :
878 :
879 : /// UnaryOperator - This represents the unary-expression's (except sizeof and
880 : /// alignof), the postinc/postdec operators from postfix-expression, and various
881 : /// extensions.
882 : ///
883 : /// Notes on various nodes:
884 : ///
885 : /// Real/Imag - These return the real/imag part of a complex operand. If
886 : /// applied to a non-complex value, the former returns its operand and the
887 : /// later returns zero in the type of the operand.
888 : ///
889 : /// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
890 : /// subexpression is a compound literal with the various MemberExpr and
891 : /// ArraySubscriptExpr's applied to it.
892 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
77: branch 6 taken
893 77: class UnaryOperator : public Expr {
894 : public:
895 : // Note that additions to this should also update the StmtVisitor class.
896 : enum Opcode {
897 : PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
898 : PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators.
899 : AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators.
900 : Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators.
901 : Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators.
902 : Real, Imag, // "__real expr"/"__imag expr" Extension.
903 : Extension, // __extension__ marker.
904 : OffsetOf // __builtin_offsetof
905 : };
906 : private:
907 : Stmt *Val;
908 : Opcode Opc;
909 : SourceLocation Loc;
910 : public:
911 :
912 4684: UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
913 : : Expr(UnaryOperatorClass, type,
914 : input->isTypeDependent() && opc != OffsetOf,
915 : input->isValueDependent()),
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
916 4684: Val(input), Opc(opc), Loc(l) {}
917 :
918 : /// \brief Build an empty unary operator.
919 8: explicit UnaryOperator(EmptyShell Empty)
920 8: : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
921 :
922 31789: Opcode getOpcode() const { return Opc; }
923 8: void setOpcode(Opcode O) { Opc = O; }
924 :
925 14033: Expr *getSubExpr() const { return cast<Expr>(Val); }
926 8: void setSubExpr(Expr *E) { Val = E; }
927 :
928 : /// getOperatorLoc - Return the location of the operator.
929 137: SourceLocation getOperatorLoc() const { return Loc; }
930 8: void setOperatorLoc(SourceLocation L) { Loc = L; }
931 :
932 : /// isPostfix - Return true if this is a postfix operation, like x++.
933 15730: static bool isPostfix(Opcode Op) {
1750: branch 1 taken
18: branch 2 taken
13962: branch 3 taken
29: branch 3 taken
934 15730: return Op == PostInc || Op == PostDec;
935 : }
936 :
937 : /// isPostfix - Return true if this is a prefix operation, like --x.
938 150: static bool isPrefix(Opcode Op) {
939 150: return Op == PreInc || Op == PreDec;
940 : }
941 :
942 150: bool isPrefix() const { return isPrefix(Opc); }
943 15730: bool isPostfix() const { return isPostfix(Opc); }
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
944 981: bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
866: branch 0 taken
0: branch 1 not taken
866: branch 2 taken
0: branch 3 not taken
945 866: bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
946 1055: bool isOffsetOfOp() const { return Opc == OffsetOf; }
947 : static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
948 : bool isArithmeticOp() const { return isArithmeticOp(Opc); }
949 :
950 : /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
951 : /// corresponds to, e.g. "sizeof" or "[pre]++"
952 : static const char *getOpcodeStr(Opcode Op);
953 :
954 : /// \brief Retrieve the unary opcode that corresponds to the given
955 : /// overloaded operator.
956 : static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
957 :
958 : /// \brief Retrieve the overloaded operator kind that corresponds to
959 : /// the given unary opcode.
960 : static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
961 :
962 14629: virtual SourceRange getSourceRange() const {
1318: branch 1 taken
13311: branch 2 taken
963 14629: if (isPostfix())
964 1318: return SourceRange(Val->getLocStart(), Loc);
965 : else
966 13311: return SourceRange(Loc, Val->getLocEnd());
967 : }
968 400: virtual SourceLocation getExprLoc() const { return Loc; }
969 :
970 204051: static bool classof(const Stmt *T) {
971 204051: return T->getStmtClass() == UnaryOperatorClass;
972 : }
973 : static bool classof(const UnaryOperator *) { return true; }
974 :
975 : // Iterators
976 : virtual child_iterator child_begin();
977 : virtual child_iterator child_end();
978 : };
979 :
980 : /// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
981 : /// types and expressions.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
9: branch 6 taken
982 9: class SizeOfAlignOfExpr : public Expr {
983 : bool isSizeof : 1; // true if sizeof, false if alignof.
984 : bool isType : 1; // true if operand is a type, false if an expression
985 : union {
986 : TypeSourceInfo *Ty;
987 : Stmt *Ex;
988 : } Argument;
989 : SourceLocation OpLoc, RParenLoc;
990 :
991 : protected:
992 : virtual void DoDestroy(ASTContext& C);
993 :
994 : public:
995 : SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
996 : QualType resultType, SourceLocation op,
997 428: SourceLocation rp) :
998 : Expr(SizeOfAlignOfExprClass, resultType,
999 : false, // Never type-dependent (C++ [temp.dep.expr]p3).
1000 : // Value-dependent if the argument is type-dependent.
1001 : TInfo->getType()->isDependentType()),
1002 428: isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1003 428: Argument.Ty = TInfo;
1004 428: }
1005 :
1006 : SizeOfAlignOfExpr(bool issizeof, Expr *E,
1007 : QualType resultType, SourceLocation op,
1008 222: SourceLocation rp) :
1009 : Expr(SizeOfAlignOfExprClass, resultType,
1010 : false, // Never type-dependent (C++ [temp.dep.expr]p3).
1011 : // Value-dependent if the argument is type-dependent.
1012 : E->isTypeDependent()),
1013 222: isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1014 222: Argument.Ex = E;
1015 222: }
1016 :
1017 : /// \brief Construct an empty sizeof/alignof expression.
1018 2: explicit SizeOfAlignOfExpr(EmptyShell Empty)
1019 2: : Expr(SizeOfAlignOfExprClass, Empty) { }
1020 :
1021 1587: bool isSizeOf() const { return isSizeof; }
1022 2: void setSizeof(bool S) { isSizeof = S; }
1023 :
1024 4232: bool isArgumentType() const { return isType; }
1025 1106: QualType getArgumentType() const {
1026 1106: return getArgumentTypeInfo()->getType();
1027 : }
1028 1151: TypeSourceInfo *getArgumentTypeInfo() const {
1151: branch 1 taken
0: branch 2 not taken
1029 1151: assert(isArgumentType() && "calling getArgumentType() when arg is expr");
1030 1151: return Argument.Ty;
1031 : }
1032 599: Expr *getArgumentExpr() {
599: branch 1 taken
0: branch 2 not taken
1033 599: assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1034 599: return static_cast<Expr*>(Argument.Ex);
1035 : }
1036 537: const Expr *getArgumentExpr() const {
1037 537: return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1038 : }
1039 :
1040 1: void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1041 1: void setArgument(TypeSourceInfo *TInfo) {
1042 1: Argument.Ty = TInfo;
1043 1: isType = true;
1044 1: }
1045 :
1046 : /// Gets the argument type, or the type of the argument expression, whichever
1047 : /// is appropriate.
1048 1340: QualType getTypeOfArgument() const {
0: branch 1 not taken
0: branch 2 not taken
1049 1340: return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
1050 : }
1051 :
1052 62: SourceLocation getOperatorLoc() const { return OpLoc; }
1053 2: void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1054 :
1055 3: SourceLocation getRParenLoc() const { return RParenLoc; }
1056 2: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1057 :
1058 882: virtual SourceRange getSourceRange() const {
1059 882: return SourceRange(OpLoc, RParenLoc);
1060 : }
1061 :
1062 771: static bool classof(const Stmt *T) {
1063 771: return T->getStmtClass() == SizeOfAlignOfExprClass;
1064 : }
1065 : static bool classof(const SizeOfAlignOfExpr *) { return true; }
1066 :
1067 : // Iterators
1068 : virtual child_iterator child_begin();
1069 : virtual child_iterator child_end();
1070 : };
1071 :
1072 : //===----------------------------------------------------------------------===//
1073 : // Postfix Operators.
1074 : //===----------------------------------------------------------------------===//
1075 :
1076 : /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
7: branch 6 taken
1077 7: class ArraySubscriptExpr : public Expr {
1078 : enum { LHS, RHS, END_EXPR=2 };
1079 : Stmt* SubExprs[END_EXPR];
1080 : SourceLocation RBracketLoc;
1081 : public:
1082 : ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1083 841: SourceLocation rbracketloc)
1084 : : Expr(ArraySubscriptExprClass, t,
1085 : lhs->isTypeDependent() || rhs->isTypeDependent(),
1086 : lhs->isValueDependent() || rhs->isValueDependent()),
1087 841: RBracketLoc(rbracketloc) {
1088 841: SubExprs[LHS] = lhs;
1089 841: SubExprs[RHS] = rhs;
1090 841: }
1091 :
1092 : /// \brief Create an empty array subscript expression.
1093 1: explicit ArraySubscriptExpr(EmptyShell Shell)
1094 1: : Expr(ArraySubscriptExprClass, Shell) { }
1095 :
1096 : /// An array access can be written A[4] or 4[A] (both are equivalent).
1097 : /// - getBase() and getIdx() always present the normalized view: A[4].
1098 : /// In this case getBase() returns "A" and getIdx() returns "4".
1099 : /// - getLHS() and getRHS() present the syntactic view. e.g. for
1100 : /// 4[A] getLHS() returns "4".
1101 : /// Note: Because vector element access is also written A[4] we must
1102 : /// predicate the format conversion in getBase and getIdx only on the
1103 : /// the type of the RHS, as it is possible for the LHS to be a vector of
1104 : /// integer type
1105 795: Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
1106 5876: const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1107 1: void setLHS(Expr *E) { SubExprs[LHS] = E; }
1108 :
1109 1783: Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
1110 4297: const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1111 1: void setRHS(Expr *E) { SubExprs[RHS] = E; }
1112 :
1113 735: Expr *getBase() {
0: branch 4 not taken
0: branch 5 not taken
1114 735: return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1115 : }
1116 :
1117 2299: const Expr *getBase() const {
2287: branch 4 taken
12: branch 5 taken
1118 2299: return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1119 : }
1120 :
1121 511: Expr *getIdx() {
0: branch 4 not taken
0: branch 5 not taken
1122 511: return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1123 : }
1124 :
1125 991: const Expr *getIdx() const {
991: branch 4 taken
0: branch 5 not taken
1126 991: return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1127 : }
1128 :
1129 3585: virtual SourceRange getSourceRange() const {
1130 3585: return SourceRange(getLHS()->getLocStart(), RBracketLoc);
1131 : }
1132 :
1133 24: SourceLocation getRBracketLoc() const { return RBracketLoc; }
1134 1: void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1135 :
1136 23: virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
1137 :
1138 4804: static bool classof(const Stmt *T) {
1139 4804: return T->getStmtClass() == ArraySubscriptExprClass;
1140 : }
1141 : static bool classof(const ArraySubscriptExpr *) { return true; }
1142 :
1143 : // Iterators
1144 : virtual child_iterator child_begin();
1145 : virtual child_iterator child_end();
1146 : };
1147 :
1148 :
1149 : /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
1150 : /// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1151 : /// while its subclasses may represent alternative syntax that (semantically)
1152 : /// results in a function call. For example, CXXOperatorCallExpr is
1153 : /// a subclass for overloaded operator calls that use operator syntax, e.g.,
1154 : /// "str1 + str2" to resolve to a function call.
1155 : class CallExpr : public Expr {
1156 : enum { FN=0, ARGS_START=1 };
1157 : Stmt **SubExprs;
1158 : unsigned NumArgs;
1159 : SourceLocation RParenLoc;
1160 :
1161 : protected:
1162 : // This version of the constructor is for derived classes.
1163 : CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1164 : QualType t, SourceLocation rparenloc);
1165 :
1166 : virtual void DoDestroy(ASTContext& C);
1167 :
1168 : public:
1169 : CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
1170 : SourceLocation rparenloc);
1171 :
1172 : /// \brief Build an empty call expression.
1173 : CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
1174 :
9377: branch 2 taken
42: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
1175 9419: ~CallExpr() {}
1176 :
1177 62937: const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
1178 15159: Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
1179 29: void setCallee(Expr *F) { SubExprs[FN] = F; }
1180 :
1181 : Decl *getCalleeDecl();
1182 1051: const Decl *getCalleeDecl() const {
1183 1051: return const_cast<CallExpr*>(this)->getCalleeDecl();
1184 : }
1185 :
1186 : /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1187 : FunctionDecl *getDirectCallee();
1188 : const FunctionDecl *getDirectCallee() const {
1189 : return const_cast<CallExpr*>(this)->getDirectCallee();
1190 : }
1191 :
1192 : /// getNumArgs - Return the number of actual arguments to this call.
1193 : ///
1194 12701: unsigned getNumArgs() const { return NumArgs; }
1195 :
1196 : /// getArg - Return the specified argument.
1197 3802: Expr *getArg(unsigned Arg) {
0: branch 0 not taken
0: branch 1 not taken
1198 3802: assert(Arg < NumArgs && "Arg access out of range!");
1199 3802: return cast<Expr>(SubExprs[Arg+ARGS_START]);
1200 : }
1201 3791: const Expr *getArg(unsigned Arg) const {
0: branch 0 not taken
3791: branch 1 taken
1202 3791: assert(Arg < NumArgs && "Arg access out of range!");
1203 3791: return cast<Expr>(SubExprs[Arg+ARGS_START]);
1204 : }
1205 :
1206 : /// setArg - Set the specified argument.
1207 9819: void setArg(unsigned Arg, Expr *ArgExpr) {
1208 9819: assert(Arg < NumArgs && "Arg access out of range!");
1209 9819: SubExprs[Arg+ARGS_START] = ArgExpr;
1210 9819: }
1211 :
1212 : /// setNumArgs - This changes the number of arguments present in this call.
1213 : /// Any orphaned expressions are deleted by this, and any new operands are set
1214 : /// to null.
1215 : void setNumArgs(ASTContext& C, unsigned NumArgs);
1216 :
1217 : typedef ExprIterator arg_iterator;
1218 : typedef ConstExprIterator const_arg_iterator;
1219 :
1220 3232: arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1221 3236: arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
1222 3326: const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
1223 3311: const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
1224 :
1225 : /// getNumCommas - Return the number of commas that must have been present in
1226 : /// this function call.
1227 : unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
1228 :
1229 : /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If
1230 : /// not, return 0.
1231 : unsigned isBuiltinCall(ASTContext &Context) const;
1232 :
1233 : /// getCallReturnType - Get the return type of the call expr. This is not
1234 : /// always the type of the expr itself, if the return type is a reference
1235 : /// type.
1236 : QualType getCallReturnType() const;
1237 :
1238 2068: SourceLocation getRParenLoc() const { return RParenLoc; }
1239 11: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1240 :
1241 26499: virtual SourceRange getSourceRange() const {
1242 26499: return SourceRange(getCallee()->getLocStart(), RParenLoc);
1243 : }
1244 :
1245 26616: static bool classof(const Stmt *T) {
1246 : return T->getStmtClass() == CallExprClass ||
1247 : T->getStmtClass() == CXXOperatorCallExprClass ||
16: branch 2 taken
114: branch 4 taken
0: branch 5 not taken
0: branch 7 not taken
114: branch 8 taken
1248 26616: T->getStmtClass() == CXXMemberCallExprClass;
1249 : }
1250 : static bool classof(const CallExpr *) { return true; }
1251 : static bool classof(const CXXOperatorCallExpr *) { return true; }
1252 2: static bool classof(const CXXMemberCallExpr *) { return true; }
1253 :
1254 : // Iterators
1255 : virtual child_iterator child_begin();
1256 : virtual child_iterator child_end();
1257 : };
1258 :
1259 : /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
1260 : ///
0: branch 5 not taken
43: branch 6 taken
1261 43: class MemberExpr : public Expr {
1262 : /// Base - the expression for the base pointer or structure references. In
1263 : /// X.F, this is "X".
1264 : Stmt *Base;
1265 :
1266 : /// MemberDecl - This is the decl being referenced by the field/member name.
1267 : /// In X.F, this is the decl referenced by F.
1268 : ValueDecl *MemberDecl;
1269 :
1270 : /// MemberLoc - This is the location of the member name.
1271 : SourceLocation MemberLoc;
1272 :
1273 : /// IsArrow - True if this is "X->F", false if this is "X.F".
1274 : bool IsArrow : 1;
1275 :
1276 : /// \brief True if this member expression used a nested-name-specifier to
1277 : /// refer to the member, e.g., "x->Base::f". When true, a NameQualifier
1278 : /// structure is allocated immediately after the MemberExpr.
1279 : bool HasQualifier : 1;
1280 :
1281 : /// \brief True if this member expression specified a template argument list
1282 : /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1283 : /// structure (and its TemplateArguments) are allocated immediately after
1284 : /// the MemberExpr or, if the member expression also has a qualifier, after
1285 : /// the NameQualifier structure.
1286 : bool HasExplicitTemplateArgumentList : 1;
1287 :
1288 : /// \brief Retrieve the qualifier that preceded the member name, if any.
1289 102: NameQualifier *getMemberQualifier() {
102: branch 1 taken
0: branch 1 not taken
1290 102: if (!HasQualifier)
1291 0: return 0;
1292 :
1293 102: return reinterpret_cast<NameQualifier *> (this + 1);
1294 : }
1295 :
1296 : /// \brief Retrieve the qualifier that preceded the member name, if any.
1297 5: const NameQualifier *getMemberQualifier() const {
1298 5: return const_cast<MemberExpr *>(this)->getMemberQualifier();
1299 : }
1300 :
1301 : /// \brief Retrieve the explicit template argument list that followed the
1302 : /// member template name, if any.
1303 232: ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
0: branch 0 not taken
232: branch 1 taken
1304 232: if (!HasExplicitTemplateArgumentList)
1305 0: return 0;
1306 :
223: branch 0 taken
9: branch 1 taken
1307 232: if (!HasQualifier)
1308 223: return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1309 :
1310 : return reinterpret_cast<ExplicitTemplateArgumentList *>(
1311 9: getMemberQualifier() + 1);
1312 : }
1313 :
1314 : /// \brief Retrieve the explicit template argument list that followed the
1315 : /// member template name, if any.
1316 203: const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1317 203: return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList();
1318 : }
1319 :
1320 : MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual,
1321 : SourceRange qualrange, ValueDecl *memberdecl, SourceLocation l,
1322 : const TemplateArgumentListInfo *targs, QualType ty);
1323 :
1324 : public:
1325 : MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1326 599: SourceLocation l, QualType ty)
1327 : : Expr(MemberExprClass, ty,
1328 : base->isTypeDependent(), base->isValueDependent()),
1329 : Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
1330 599: HasQualifier(false), HasExplicitTemplateArgumentList(false) {}
1331 :
1332 : /// \brief Build an empty member reference expression.
1333 1: explicit MemberExpr(EmptyShell Empty)
1334 : : Expr(MemberExprClass, Empty), HasQualifier(false),
1335 1: HasExplicitTemplateArgumentList(false) { }
1336 :
1337 : static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
1338 : NestedNameSpecifier *qual, SourceRange qualrange,
1339 : ValueDecl *memberdecl,
1340 : SourceLocation l,
1341 : const TemplateArgumentListInfo *targs,
1342 : QualType ty);
1343 :
1344 563: void setBase(Expr *E) { Base = E; }
1345 10614: Expr *getBase() const { return cast<Expr>(Base); }
1346 :
1347 : /// \brief Retrieve the member declaration to which this expression refers.
1348 : ///
1349 : /// The returned declaration will either be a FieldDecl or (in C++)
1350 : /// a CXXMethodDecl.
1351 6296: ValueDecl *getMemberDecl() const { return MemberDecl; }
1352 1: void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
1353 :
1354 : /// \brief Determines whether this member expression actually had
1355 : /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1356 : /// x->Base::foo.
1357 138: bool hasQualifier() const { return HasQualifier; }
1358 :
1359 : /// \brief If the member name was qualified, retrieves the source range of
1360 : /// the nested-name-specifier that precedes the member name. Otherwise,
1361 : /// returns an empty source range.
1362 104: SourceRange getQualifierRange() const {
102: branch 0 taken
2: branch 1 taken
1363 104: if (!HasQualifier)
1364 102: return SourceRange();
1365 :
1366 2: return getMemberQualifier()->Range;
1367 : }
1368 :
1369 : /// \brief If the member name was qualified, retrieves the
1370 : /// nested-name-specifier that precedes the member name. Otherwise, returns
1371 : /// NULL.
1372 97: NestedNameSpecifier *getQualifier() const {
94: branch 0 taken
3: branch 1 taken
1373 97: if (!HasQualifier)
1374 94: return 0;
1375 :
1376 3: return getMemberQualifier()->NNS;
1377 : }
1378 :
1379 : /// \brief Determines whether this member expression actually had a C++
1380 : /// template argument list explicitly specified, e.g., x.f<int>.
1381 300: bool hasExplicitTemplateArgumentList() const {
1382 300: return HasExplicitTemplateArgumentList;
1383 : }
1384 :
1385 : /// \brief Copies the template arguments (if present) into the given
1386 : /// structure.
1387 : void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1388 : if (hasExplicitTemplateArgumentList())
1389 : getExplicitTemplateArgumentList()->copyInto(List);
1390 : }
1391 :
1392 : /// \brief Retrieve the location of the left angle bracket following the
1393 : /// member name ('<'), if any.
1394 0: SourceLocation getLAngleLoc() const {
0: branch 0 not taken
0: branch 1 not taken
1395 0: if (!HasExplicitTemplateArgumentList)
1396 0: return SourceLocation();
1397 :
1398 0: return getExplicitTemplateArgumentList()->LAngleLoc;
1399 : }
1400 :
1401 : /// \brief Retrieve the template arguments provided as part of this
1402 : /// template-id.
1403 0: const TemplateArgumentLoc *getTemplateArgs() const {
0: branch 0 not taken
0: branch 1 not taken
1404 0: if (!HasExplicitTemplateArgumentList)
1405 0: return 0;
1406 :
1407 0: return getExplicitTemplateArgumentList()->getTemplateArgs();
1408 : }
1409 :
1410 : /// \brief Retrieve the number of template arguments provided as part of this
1411 : /// template-id.
1412 0: unsigned getNumTemplateArgs() const {
0: branch 0 not taken
0: branch 1 not taken
1413 0: if (!HasExplicitTemplateArgumentList)
1414 0: return 0;
1415 :
1416 0: return getExplicitTemplateArgumentList()->NumTemplateArgs;
1417 : }
1418 :
1419 : /// \brief Retrieve the location of the right angle bracket following the
1420 : /// template arguments ('>').
1421 203: SourceLocation getRAngleLoc() const {
0: branch 0 not taken
203: branch 1 taken
1422 203: if (!HasExplicitTemplateArgumentList)
1423 0: return SourceLocation();
1424 :
1425 203: return getExplicitTemplateArgumentList()->RAngleLoc;
1426 : }
1427 :
1428 3842: bool isArrow() const { return IsArrow; }
1429 1: void setArrow(bool A) { IsArrow = A; }
1430 :
1431 : /// getMemberLoc - Return the location of the "member", in X->F, it is the
1432 : /// location of 'F'.
1433 702: SourceLocation getMemberLoc() const { return MemberLoc; }
1434 1: void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1435 :
1436 6325: virtual SourceRange getSourceRange() const {
1437 : // If we have an implicit base (like a C++ implicit this),
1438 : // make sure not to return its location
1439 6325: SourceLocation EndLoc = MemberLoc;
203: branch 0 taken
6122: branch 1 taken
1440 6325: if (HasExplicitTemplateArgumentList)
1441 203: EndLoc = getRAngleLoc();
1442 :
1443 6325: SourceLocation BaseLoc = getBase()->getLocStart();
475: branch 1 taken
5850: branch 2 taken
1444 6325: if (BaseLoc.isInvalid())
1445 475: return SourceRange(MemberLoc, EndLoc);
1446 5850: return SourceRange(BaseLoc, EndLoc);
1447 : }
1448 :
1449 25: virtual SourceLocation getExprLoc() const { return MemberLoc; }
1450 :
1451 65744: static bool classof(const Stmt *T) {
1452 65744: return T->getStmtClass() == MemberExprClass;
1453 : }
1454 : static bool classof(const MemberExpr *) { return true; }
1455 :
1456 : // Iterators
1457 : virtual child_iterator child_begin();
1458 : virtual child_iterator child_end();
1459 : };
1460 :
1461 : /// CompoundLiteralExpr - [C99 6.5.2.5]
1462 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
2: branch 6 taken
1463 2: class CompoundLiteralExpr : public Expr {
1464 : /// LParenLoc - If non-null, this is the location of the left paren in a
1465 : /// compound literal like "(int){4}". This can be null if this is a
1466 : /// synthesized compound expression.
1467 : SourceLocation LParenLoc;
1468 :
1469 : /// The type as written. This can be an incomplete array type, in
1470 : /// which case the actual expression type will be different.
1471 : TypeSourceInfo *TInfo;
1472 : Stmt *Init;
1473 : bool FileScope;
1474 : public:
1475 : // FIXME: Can compound literals be value-dependent?
1476 : CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
1477 288: QualType T, Expr *init, bool fileScope)
1478 : : Expr(CompoundLiteralExprClass, T,
1479 : tinfo->getType()->isDependentType(), false),
1480 288: LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
1481 :
1482 : /// \brief Construct an empty compound literal.
1483 1: explicit CompoundLiteralExpr(EmptyShell Empty)
1484 1: : Expr(CompoundLiteralExprClass, Empty) { }
1485 :
1486 50: const Expr *getInitializer() const { return cast<Expr>(Init); }
1487 50: Expr *getInitializer() { return cast<Expr>(Init); }
1488 1: void setInitializer(Expr *E) { Init = E; }
1489 :
1490 45: bool isFileScope() const { return FileScope; }
1491 1: void setFileScope(bool FS) { FileScope = FS; }
1492 :
1493 2: SourceLocation getLParenLoc() const { return LParenLoc; }
1494 1: void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1495 :
1496 4: TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
1497 1: void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
1498 :
1499 762: virtual SourceRange getSourceRange() const {
1500 : // FIXME: Init should never be null.
0: branch 0 not taken
762: branch 1 taken
1501 762: if (!Init)
1502 0: return SourceRange();
0: branch 1 not taken
762: branch 2 taken
1503 762: if (LParenLoc.isInvalid())
1504 0: return Init->getSourceRange();
1505 762: return SourceRange(LParenLoc, Init->getLocEnd());
1506 : }
1507 :
1508 86: static bool classof(const Stmt *T) {
1509 86: return T->getStmtClass() == CompoundLiteralExprClass;
1510 : }
1511 : static bool classof(const CompoundLiteralExpr *) { return true; }
1512 :
1513 : // Iterators
1514 : virtual child_iterator child_begin();
1515 : virtual child_iterator child_end();
1516 : };
1517 :
1518 : /// CastExpr - Base class for type casts, including both implicit
1519 : /// casts (ImplicitCastExpr) and explicit casts that have some
1520 : /// representation in the source code (ExplicitCastExpr's derived
1521 : /// classes).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1522 9578: class CastExpr : public Expr {
1523 : public:
1524 : /// CastKind - the kind of cast this represents.
1525 : enum CastKind {
1526 : /// CK_Unknown - Unknown cast kind.
1527 : /// FIXME: The goal is to get rid of this and make all casts have a
1528 : /// kind so that the AST client doesn't have to try to figure out what's
1529 : /// going on.
1530 : CK_Unknown,
1531 :
1532 : /// CK_BitCast - Used for reinterpret_cast.
1533 : CK_BitCast,
1534 :
1535 : /// CK_NoOp - Used for const_cast.
1536 : CK_NoOp,
1537 :
1538 : /// CK_BaseToDerived - Base to derived class casts.
1539 : CK_BaseToDerived,
1540 :
1541 : /// CK_DerivedToBase - Derived to base class casts.
1542 : CK_DerivedToBase,
1543 :
1544 : /// CK_Dynamic - Dynamic cast.
1545 : CK_Dynamic,
1546 :
1547 : /// CK_ToUnion - Cast to union (GCC extension).
1548 : CK_ToUnion,
1549 :
1550 : /// CK_ArrayToPointerDecay - Array to pointer decay.
1551 : CK_ArrayToPointerDecay,
1552 :
1553 : // CK_FunctionToPointerDecay - Function to pointer decay.
1554 : CK_FunctionToPointerDecay,
1555 :
1556 : /// CK_NullToMemberPointer - Null pointer to member pointer.
1557 : CK_NullToMemberPointer,
1558 :
1559 : /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
1560 : /// member pointer in derived class.
1561 : CK_BaseToDerivedMemberPointer,
1562 :
1563 : /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
1564 : /// member pointer in base class.
1565 : CK_DerivedToBaseMemberPointer,
1566 :
1567 : /// CK_UserDefinedConversion - Conversion using a user defined type
1568 : /// conversion function.
1569 : CK_UserDefinedConversion,
1570 :
1571 : /// CK_ConstructorConversion - Conversion by constructor
1572 : CK_ConstructorConversion,
1573 :
1574 : /// CK_IntegralToPointer - Integral to pointer
1575 : CK_IntegralToPointer,
1576 :
1577 : /// CK_PointerToIntegral - Pointer to integral
1578 : CK_PointerToIntegral,
1579 :
1580 : /// CK_ToVoid - Cast to void.
1581 : CK_ToVoid,
1582 :
1583 : /// CK_VectorSplat - Casting from an integer/floating type to an extended
1584 : /// vector type with the same element type as the src type. Splats the
1585 : /// src expression into the destination expression.
1586 : CK_VectorSplat,
1587 :
1588 : /// CK_IntegralCast - Casting between integral types of different size.
1589 : CK_IntegralCast,
1590 :
1591 : /// CK_IntegralToFloating - Integral to floating point.
1592 : CK_IntegralToFloating,
1593 :
1594 : /// CK_FloatingToIntegral - Floating point to integral.
1595 : CK_FloatingToIntegral,
1596 :
1597 : /// CK_FloatingCast - Casting between floating types of different size.
1598 : CK_FloatingCast,
1599 :
1600 : /// CK_MemberPointerToBoolean - Member pointer to boolean
1601 : CK_MemberPointerToBoolean,
1602 :
1603 : /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
1604 : /// pointer
1605 : CK_AnyPointerToObjCPointerCast,
1606 : /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
1607 : /// pointer
1608 : CK_AnyPointerToBlockPointerCast
1609 :
1610 : };
1611 :
1612 : private:
1613 : CastKind Kind;
1614 : Stmt *Op;
1615 : protected:
1616 36507: CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op) :
1617 : Expr(SC, ty,
1618 : // Cast expressions are type-dependent if the type is
1619 : // dependent (C++ [temp.dep.expr]p3).
1620 : ty->isDependentType(),
1621 : // Cast expressions are value-dependent if the type is
1622 : // dependent or if the subexpression is value-dependent.
1623 : ty->isDependentType() || (op && op->isValueDependent())),
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 7 not taken
0: branch 8 not taken
1624 36507: Kind(kind), Op(op) {}
1625 :
1626 : /// \brief Construct an empty cast.
1627 52: CastExpr(StmtClass SC, EmptyShell Empty)
1628 52: : Expr(SC, Empty) { }
1629 :
1630 : public:
1631 16017: CastKind getCastKind() const { return Kind; }
1632 52: void setCastKind(CastKind K) { Kind = K; }
1633 : const char *getCastKindName() const;
1634 :
1635 27409: Expr *getSubExpr() { return cast<Expr>(Op); }
1636 73274: const Expr *getSubExpr() const { return cast<Expr>(Op); }
1637 52: void setSubExpr(Expr *E) { Op = E; }
1638 :
1639 : /// \brief Retrieve the cast subexpression as it was written in the source
1640 : /// code, looking through any implicit casts or other intermediate nodes
1641 : /// introduced by semantic analysis.
1642 : Expr *getSubExprAsWritten();
1643 2: const Expr *getSubExprAsWritten() const {
1644 2: return const_cast<CastExpr *>(this)->getSubExprAsWritten();
1645 : }
1646 :
1647 63696: static bool classof(const Stmt *T) {
1648 63696: StmtClass SC = T->getStmtClass();
1332: branch 0 taken
62364: branch 1 taken
81: branch 2 taken
1251: branch 3 taken
1649 63696: if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1650 81: return true;
1651 :
49390: branch 0 taken
14225: branch 1 taken
48057: branch 2 taken
1333: branch 3 taken
1652 63615: if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
1653 48057: return true;
1654 :
1655 15558: return false;
1656 : }
1657 : static bool classof(const CastExpr *) { return true; }
1658 :
1659 : // Iterators
1660 : virtual child_iterator child_begin();
1661 : virtual child_iterator child_end();
1662 : };
1663 :
1664 : /// ImplicitCastExpr - Allows us to explicitly represent implicit type
1665 : /// conversions, which have no direct representation in the original
1666 : /// source code. For example: converting T[]->T*, void f()->void
1667 : /// (*f)(), float->double, short->int, etc.
1668 : ///
1669 : /// In C, implicit casts always produce rvalues. However, in C++, an
1670 : /// implicit cast whose result is being bound to a reference will be
1671 : /// an lvalue. For example:
1672 : ///
1673 : /// @code
1674 : /// class Base { };
1675 : /// class Derived : public Base { };
1676 : /// void f(Derived d) {
1677 : /// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1678 : /// }
1679 : /// @endcode
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1680 9503: class ImplicitCastExpr : public CastExpr {
1681 : /// LvalueCast - Whether this cast produces an lvalue.
1682 : bool LvalueCast;
1683 :
1684 : public:
1685 31109: ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, bool Lvalue) :
1686 31109: CastExpr(ImplicitCastExprClass, ty, kind, op), LvalueCast(Lvalue) { }
1687 :
1688 : /// \brief Construct an empty implicit cast.
1689 43: explicit ImplicitCastExpr(EmptyShell Shell)
1690 43: : CastExpr(ImplicitCastExprClass, Shell) { }
1691 :
1692 :
1693 52310: virtual SourceRange getSourceRange() const {
1694 52310: return getSubExpr()->getSourceRange();
1695 : }
1696 :
1697 : /// isLvalueCast - Whether this cast produces an lvalue.
1698 2154: bool isLvalueCast() const { return LvalueCast; }
1699 :
1700 : /// setLvalueCast - Set whether this cast produces an lvalue.
1701 43: void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1702 :
1703 103263: static bool classof(const Stmt *T) {
1704 103263: return T->getStmtClass() == ImplicitCastExprClass;
1705 : }
1706 : static bool classof(const ImplicitCastExpr *) { return true; }
1707 : };
1708 :
1709 : /// ExplicitCastExpr - An explicit cast written in the source
1710 : /// code.
1711 : ///
1712 : /// This class is effectively an abstract class, because it provides
1713 : /// the basic representation of an explicitly-written cast without
1714 : /// specifying which kind of cast (C cast, functional cast, static
1715 : /// cast, etc.) was written; specific derived classes represent the
1716 : /// particular style of cast and its location information.
1717 : ///
1718 : /// Unlike implicit casts, explicit cast nodes have two different
1719 : /// types: the type that was written into the source code, and the
1720 : /// actual type of the expression as determined by semantic
1721 : /// analysis. These types may differ slightly. For example, in C++ one
1722 : /// can cast to a reference type, which indicates that the resulting
1723 : /// expression will be an lvalue. The reference type, however, will
1724 : /// not be used as the type of the expression.
1725 75: class ExplicitCastExpr : public CastExpr {
1726 : /// TInfo - Source type info for the (written) type
1727 : /// this expression is casting to.
1728 : TypeSourceInfo *TInfo;
1729 :
1730 : protected:
1731 : ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
1732 5398: Expr *op, TypeSourceInfo *writtenTy)
1733 5398: : CastExpr(SC, exprTy, kind, op), TInfo(writtenTy) {}
1734 :
1735 : /// \brief Construct an empty explicit cast.
1736 9: ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1737 9: : CastExpr(SC, Shell) { }
1738 :
1739 : public:
1740 : /// getTypeInfoAsWritten - Returns the type source info for the type
1741 : /// that this expression is casting to.
1742 115: TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
1743 9: void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
1744 :
1745 : /// getTypeAsWritten - Returns the type that this expression is
1746 : /// casting to, as written in the source code.
1747 5726: QualType getTypeAsWritten() const { return TInfo->getType(); }
1748 :
1749 23026: static bool classof(const Stmt *T) {
1750 23026: StmtClass SC = T->getStmtClass();
9384: branch 0 taken
13642: branch 1 taken
7827: branch 2 taken
1557: branch 3 taken
1751 23026: if (SC >= CStyleCastExprClass && SC <= CStyleCastExprClass)
1752 7827: return true;
1487: branch 0 taken
13712: branch 1 taken
554: branch 2 taken
947: branch 3 taken
1753 15199: if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1754 547: return true;
1755 :
1756 14652: return false;
1757 : }
1758 : static bool classof(const ExplicitCastExpr *) { return true; }
1759 : };
1760 :
1761 : /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
1762 : /// cast in C++ (C++ [expr.cast]), which uses the syntax
1763 : /// (Type)expr. For example: @c (int)f.
1764 73: class CStyleCastExpr : public ExplicitCastExpr {
1765 : SourceLocation LPLoc; // the location of the left paren
1766 : SourceLocation RPLoc; // the location of the right paren
1767 : public:
1768 : CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op,
1769 : TypeSourceInfo *writtenTy,
1770 4985: SourceLocation l, SourceLocation r) :
1771 : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, writtenTy),
1772 4985: LPLoc(l), RPLoc(r) {}
1773 :
1774 : /// \brief Construct an empty C-style explicit cast.
1775 4: explicit CStyleCastExpr(EmptyShell Shell)
1776 4: : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1777 :
1778 177: SourceLocation getLParenLoc() const { return LPLoc; }
1779 4: void setLParenLoc(SourceLocation L) { LPLoc = L; }
1780 :
1781 89: SourceLocation getRParenLoc() const { return RPLoc; }
1782 4: void setRParenLoc(SourceLocation L) { RPLoc = L; }
1783 :
1784 8649: virtual SourceRange getSourceRange() const {
1785 8649: return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
1786 : }
1787 2361: static bool classof(const Stmt *T) {
1788 2361: return T->getStmtClass() == CStyleCastExprClass;
1789 : }
1790 : static bool classof(const CStyleCastExpr *) { return true; }
1791 : };
1792 :
1793 : /// \brief A builtin binary operation expression such as "x + y" or "x <= y".
1794 : ///
1795 : /// This expression node kind describes a builtin binary operation,
1796 : /// such as "x + y" for integer values "x" and "y". The operands will
1797 : /// already have been converted to appropriate types (e.g., by
1798 : /// performing promotions or conversions).
1799 : ///
1800 : /// In C++, where operators may be overloaded, a different kind of
1801 : /// expression node (CXXOperatorCallExpr) is used to express the
1802 : /// invocation of an overloaded operator with operator syntax. Within
1803 : /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
1804 : /// used to store an expression "x + y" depends on the subexpressions
1805 : /// for x and y. If neither x or y is type-dependent, and the "+"
1806 : /// operator resolves to a built-in operation, BinaryOperator will be
1807 : /// used to express the computation (x and y may still be
1808 : /// value-dependent). If either x or y is type-dependent, or if the
1809 : /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
1810 : /// be used to express the computation.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1811 155: class BinaryOperator : public Expr {
1812 : public:
1813 : enum Opcode {
1814 : // Operators listed in order of precedence.
1815 : // Note that additions to this should also update the StmtVisitor class.
1816 : PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
1817 : Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators.
1818 : Add, Sub, // [C99 6.5.6] Additive operators.
1819 : Shl, Shr, // [C99 6.5.7] Bitwise shift operators.
1820 : LT, GT, LE, GE, // [C99 6.5.8] Relational operators.
1821 : EQ, NE, // [C99 6.5.9] Equality operators.
1822 : And, // [C99 6.5.10] Bitwise AND operator.
1823 : Xor, // [C99 6.5.11] Bitwise XOR operator.
1824 : Or, // [C99 6.5.12] Bitwise OR operator.
1825 : LAnd, // [C99 6.5.13] Logical AND operator.
1826 : LOr, // [C99 6.5.14] Logical OR operator.
1827 : Assign, MulAssign,// [C99 6.5.16] Assignment operators.
1828 : DivAssign, RemAssign,
1829 : AddAssign, SubAssign,
1830 : ShlAssign, ShrAssign,
1831 : AndAssign, XorAssign,
1832 : OrAssign,
1833 : Comma // [C99 6.5.17] Comma operator.
1834 : };
1835 : private:
1836 : enum { LHS, RHS, END_EXPR };
1837 : Stmt* SubExprs[END_EXPR];
1838 : Opcode Opc;
1839 : SourceLocation OpLoc;
1840 : public:
1841 :
1842 : BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1843 9141: SourceLocation opLoc)
1844 : : Expr(BinaryOperatorClass, ResTy,
1845 : lhs->isTypeDependent() || rhs->isTypeDependent(),
1846 : lhs->isValueDependent() || rhs->isValueDependent()),
0: branch 1 not taken
0: branch 2 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 7 not taken
0: branch 8 not taken
0: branch 10 not taken
0: branch 11 not taken
1847 9141: Opc(opc), OpLoc(opLoc) {
1848 9141: SubExprs[LHS] = lhs;
1849 9141: SubExprs[RHS] = rhs;
1850 : assert(!isCompoundAssignmentOp() &&
0: branch 1 not taken
0: branch 2 not taken
1851 9141: "Use ArithAssignBinaryOperator for compound assignments");
1852 9141: }
1853 :
1854 : /// \brief Construct an empty binary operator.
1855 36: explicit BinaryOperator(EmptyShell Empty)
1856 36: : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1857 :
1858 1007: SourceLocation getOperatorLoc() const { return OpLoc; }
1859 38: void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1860 :
1861 87758: Opcode getOpcode() const { return Opc; }
1862 38: void setOpcode(Opcode O) { Opc = O; }
1863 :
1864 35783: Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1865 38: void setLHS(Expr *E) { SubExprs[LHS] = E; }
1866 33760: Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1867 38: void setRHS(Expr *E) { SubExprs[RHS] = E; }
1868 :
1869 13260: virtual SourceRange getSourceRange() const {
1870 13260: return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
1871 : }
1872 :
1873 : /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1874 : /// corresponds to, e.g. "<<=".
1875 : static const char *getOpcodeStr(Opcode Op);
1876 :
1877 : /// \brief Retrieve the binary opcode that corresponds to the given
1878 : /// overloaded operator.
1879 : static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1880 :
1881 : /// \brief Retrieve the overloaded operator kind that corresponds to
1882 : /// the given binary opcode.
1883 : static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1884 :
1885 : /// predicates to categorize the respective opcodes.
1886 : bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
1700: branch 0 taken
436: branch 1 taken
500: branch 2 taken
1200: branch 3 taken
1887 2136: bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
113: branch 0 taken
40: branch 1 taken
0: branch 2 not taken
113: branch 3 taken
1888 153: static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; }
1889 : bool isShiftOp() const { return isShiftOp(Opc); }
1890 :
1891 9054: static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; }
1892 : bool isBitwiseOp() const { return isBitwiseOp(Opc); }
1893 :
19: branch 0 taken
0: branch 1 not taken
10: branch 2 taken
9: branch 3 taken
1894 19: static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1895 19: bool isRelationalOp() const { return isRelationalOp(Opc); }
1896 :
339: branch 0 taken
175: branch 1 taken
82: branch 2 taken
257: branch 3 taken
1897 514: static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1898 272: bool isEqualityOp() const { return isEqualityOp(Opc); }
1899 :
1900 351: static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; }
1901 : bool isComparisonOp() const { return isComparisonOp(Opc); }
1902 :
440: branch 1 taken
216: branch 2 taken
20401: branch 3 taken
1903 21060: static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1904 21060: bool isLogicalOp() const { return isLogicalOp(Opc); }
1905 :
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
1906 23442: bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
1907 9693: bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
1908 : bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
1909 :
1910 345548: static bool classof(const Stmt *S) {
1911 : return S->getStmtClass() == BinaryOperatorClass ||
688: branch 1 taken
29: branch 2 taken
0: branch 4 not taken
688: branch 5 taken
1912 345548: S->getStmtClass() == CompoundAssignOperatorClass;
1913 : }
1914 : static bool classof(const BinaryOperator *) { return true; }
1915 :
1916 : // Iterators
1917 : virtual child_iterator child_begin();
1918 : virtual child_iterator child_end();
1919 :
1920 : protected:
1921 : BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1922 327: SourceLocation opLoc, bool dead)
1923 : : Expr(CompoundAssignOperatorClass, ResTy,
1924 : lhs->isTypeDependent() || rhs->isTypeDependent(),
1925 : lhs->isValueDependent() || rhs->isValueDependent()),
0: branch 10 not taken
0: branch 11 not taken
1926 327: Opc(opc), OpLoc(opLoc) {
1927 327: SubExprs[LHS] = lhs;
1928 327: SubExprs[RHS] = rhs;
1929 327: }
1930 :
1931 2: BinaryOperator(StmtClass SC, EmptyShell Empty)
1932 2: : Expr(SC, Empty), Opc(MulAssign) { }
1933 : };
1934 :
1935 : /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
1936 : /// track of the type the operation is performed in. Due to the semantics of
1937 : /// these operators, the operands are promoted, the aritmetic performed, an
1938 : /// implicit conversion back to the result type done, then the assignment takes
1939 : /// place. This captures the intermediate type which the computation is done
1940 : /// in.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
1941 0: class CompoundAssignOperator : public BinaryOperator {
1942 : QualType ComputationLHSType;
1943 : QualType ComputationResultType;
1944 : public:
1945 : CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1946 : QualType ResType, QualType CompLHSType,
1947 : QualType CompResultType,
1948 327: SourceLocation OpLoc)
1949 : : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1950 : ComputationLHSType(CompLHSType),
1951 327: ComputationResultType(CompResultType) {
1952 : assert(isCompoundAssignmentOp() &&
0: branch 1 not taken
0: branch 2 not taken
1953 327: "Only should be used for compound assignments");
1954 327: }
1955 :
1956 : /// \brief Build an empty compound assignment operator expression.
1957 2: explicit CompoundAssignOperator(EmptyShell Empty)
1958 2: : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
1959 :
1960 : // The two computation types are the type the LHS is converted
1961 : // to for the computation and the type of the result; the two are
1962 : // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1963 270: QualType getComputationLHSType() const { return ComputationLHSType; }
1964 2: void setComputationLHSType(QualType T) { ComputationLHSType = T; }
1965 :
1966 528: QualType getComputationResultType() const { return ComputationResultType; }
1967 2: void setComputationResultType(QualType T) { ComputationResultType = T; }
1968 :
1969 : static bool classof(const CompoundAssignOperator *) { return true; }
1970 284: static bool classof(const Stmt *S) {
1971 284: return S->getStmtClass() == CompoundAssignOperatorClass;
1972 : }
1973 : };
1974 :
1975 : /// ConditionalOperator - The ?: operator. Note that LHS may be null when the
1976 : /// GNU "missing LHS" extension is in use.
1977 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
34: branch 6 taken
1978 34: class ConditionalOperator : public Expr {
1979 : enum { COND, LHS, RHS, END_EXPR };
1980 : Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1981 : SourceLocation QuestionLoc, ColonLoc;
1982 : public:
1983 : ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
1984 1005: SourceLocation CLoc, Expr *rhs, QualType t)
1985 : : Expr(ConditionalOperatorClass, t,
1986 : // FIXME: the type of the conditional operator doesn't
1987 : // depend on the type of the conditional, but the standard
1988 : // seems to imply that it could. File a bug!
1989 : ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1990 : (cond->isValueDependent() ||
1991 : (lhs && lhs->isValueDependent()) ||
1992 : (rhs && rhs->isValueDependent()))),
1993 : QuestionLoc(QLoc),
1994 1005: ColonLoc(CLoc) {
1995 1005: SubExprs[COND] = cond;
1996 1005: SubExprs[LHS] = lhs;
1997 1005: SubExprs[RHS] = rhs;
1998 1005: }
1999 :
2000 : /// \brief Build an empty conditional operator.
2001 2: explicit ConditionalOperator(EmptyShell Empty)
2002 2: : Expr(ConditionalOperatorClass, Empty) { }
2003 :
2004 : // getCond - Return the expression representing the condition for
2005 : // the ?: operator.
2006 5609: Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2007 2: void setCond(Expr *E) { SubExprs[COND] = E; }
2008 :
2009 : // getTrueExpr - Return the subexpression representing the value of the ?:
2010 : // expression if the condition evaluates to true. In most cases this value
2011 : // will be the same as getLHS() except a GCC extension allows the left
2012 : // subexpression to be omitted, and instead of the condition be returned.
2013 : // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
2014 : // is only evaluated once.
2015 1637: Expr *getTrueExpr() const {
0: branch 1 not taken
0: branch 1 not taken
2016 1637: return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
2017 : }
2018 :
2019 : // getTrueExpr - Return the subexpression representing the value of the ?:
2020 : // expression if the condition evaluates to false. This is the same as getRHS.
2021 1208: Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
2022 :
2023 1267: Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
2024 2: void setLHS(Expr *E) { SubExprs[LHS] = E; }
2025 :
2026 2212: Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2027 2: void setRHS(Expr *E) { SubExprs[RHS] = E; }
2028 :
2029 24: SourceLocation getQuestionLoc() const { return QuestionLoc; }
2030 2: void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
2031 :
2032 22: SourceLocation getColonLoc() const { return ColonLoc; }
2033 2: void setColonLoc(SourceLocation L) { ColonLoc = L; }
2034 :
2035 1444: virtual SourceRange getSourceRange() const {
2036 1444: return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
2037 : }
2038 7321: static bool classof(const Stmt *T) {
2039 7321: return T->getStmtClass() == ConditionalOperatorClass;
2040 : }
2041 : static bool classof(const ConditionalOperator *) { return true; }
2042 :
2043 : // Iterators
2044 : virtual child_iterator child_begin();
2045 : virtual child_iterator child_end();
2046 : };
2047 :
2048 : /// AddrLabelExpr - The GNU address of label extension, representing &&label.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2049 0: class AddrLabelExpr : public Expr {
2050 : SourceLocation AmpAmpLoc, LabelLoc;
2051 : LabelStmt *Label;
2052 : public:
2053 : AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
2054 39: QualType t)
2055 : : Expr(AddrLabelExprClass, t, false, false),
2056 39: AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
2057 :
2058 : /// \brief Build an empty address of a label expression.
2059 2: explicit AddrLabelExpr(EmptyShell Empty)
2060 2: : Expr(AddrLabelExprClass, Empty) { }
2061 :
2062 4: SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
2063 2: void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
2064 4: SourceLocation getLabelLoc() const { return LabelLoc; }
2065 2: void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2066 :
2067 60: virtual SourceRange getSourceRange() const {
2068 60: return SourceRange(AmpAmpLoc, LabelLoc);
2069 : }
2070 :
2071 50: LabelStmt *getLabel() const { return Label; }
2072 2: void setLabel(LabelStmt *S) { Label = S; }
2073 :
2074 2926: static bool classof(const Stmt *T) {
2075 2926: return T->getStmtClass() == AddrLabelExprClass;
2076 : }
2077 : static bool classof(const AddrLabelExpr *) { return true; }
2078 :
2079 : // Iterators
2080 : virtual child_iterator child_begin();
2081 : virtual child_iterator child_end();
2082 : };
2083 :
2084 : /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2085 : /// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2086 : /// takes the value of the last subexpression.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
1: branch 6 taken
2087 1: class StmtExpr : public Expr {
2088 : Stmt *SubStmt;
2089 : SourceLocation LParenLoc, RParenLoc;
2090 : public:
2091 : // FIXME: Does type-dependence need to be computed differently?
2092 : StmtExpr(CompoundStmt *substmt, QualType T,
2093 65: SourceLocation lp, SourceLocation rp) :
2094 : Expr(StmtExprClass, T, T->isDependentType(), false),
2095 65: SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
2096 :
2097 : /// \brief Build an empty statement expression.
2098 1: explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
2099 :
2100 266: CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
2101 48: const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
2102 1: void setSubStmt(CompoundStmt *S) { SubStmt = S; }
2103 :
2104 129: virtual SourceRange getSourceRange() const {
2105 129: return SourceRange(LParenLoc, RParenLoc);
2106 : }
2107 :
2108 2: SourceLocation getLParenLoc() const { return LParenLoc; }
2109 1: void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2110 2: SourceLocation getRParenLoc() const { return RParenLoc; }
2111 1: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2112 :
2113 4402: static bool classof(const Stmt *T) {
2114 4402: return T->getStmtClass() == StmtExprClass;
2115 : }
2116 : static bool classof(const StmtExpr *) { return true; }
2117 :
2118 : // Iterators
2119 : virtual child_iterator child_begin();
2120 : virtual child_iterator child_end();
2121 : };
2122 :
2123 : /// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
2124 : /// This AST node represents a function that returns 1 if two *types* (not
2125 : /// expressions) are compatible. The result of this built-in function can be
2126 : /// used in integer constant expressions.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2127 0: class TypesCompatibleExpr : public Expr {
2128 : QualType Type1;
2129 : QualType Type2;
2130 : SourceLocation BuiltinLoc, RParenLoc;
2131 : public:
2132 : TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
2133 35: QualType t1, QualType t2, SourceLocation RP) :
2134 : Expr(TypesCompatibleExprClass, ReturnType, false, false),
2135 35: Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
2136 :
2137 : /// \brief Build an empty __builtin_type_compatible_p expression.
2138 1: explicit TypesCompatibleExpr(EmptyShell Empty)
2139 1: : Expr(TypesCompatibleExprClass, Empty) { }
2140 :
2141 22: QualType getArgType1() const { return Type1; }
2142 1: void setArgType1(QualType T) { Type1 = T; }
2143 22: QualType getArgType2() const { return Type2; }
2144 1: void setArgType2(QualType T) { Type2 = T; }
2145 :
2146 1: SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2147 1: void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2148 :
2149 1: SourceLocation getRParenLoc() const { return RParenLoc; }
2150 1: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2151 :
2152 19: virtual SourceRange getSourceRange() const {
2153 19: return SourceRange(BuiltinLoc, RParenLoc);
2154 : }
2155 0: static bool classof(const Stmt *T) {
2156 0: return T->getStmtClass() == TypesCompatibleExprClass;
2157 : }
2158 : static bool classof(const TypesCompatibleExpr *) { return true; }
2159 :
2160 : // Iterators
2161 : virtual child_iterator child_begin();
2162 : virtual child_iterator child_end();
2163 : };
2164 :
2165 : /// ShuffleVectorExpr - clang-specific builtin-in function
2166 : /// __builtin_shufflevector.
2167 : /// This AST node represents a operator that does a constant
2168 : /// shuffle, similar to LLVM's shufflevector instruction. It takes
2169 : /// two vectors and a variable number of constant indices,
2170 : /// and returns the appropriately shuffled vector.
2171 : class ShuffleVectorExpr : public Expr {
2172 : SourceLocation BuiltinLoc, RParenLoc;
2173 :
2174 : // SubExprs - the list of values passed to the __builtin_shufflevector
2175 : // function. The first two are vectors, and the rest are constant
2176 : // indices. The number of values in this list is always
2177 : // 2+the number of indices in the vector type.
2178 : Stmt **SubExprs;
2179 : unsigned NumExprs;
2180 :
2181 : protected:
2182 : virtual void DoDestroy(ASTContext &C);
2183 :
2184 : public:
2185 : // FIXME: Can a shufflevector be value-dependent? Does type-dependence need
2186 : // to be computed differently?
2187 : ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
2188 : QualType Type, SourceLocation BLoc,
2189 101: SourceLocation RP) :
2190 : Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
2191 101: BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
2192 :
2193 101: SubExprs = new (C) Stmt*[nexpr];
2194 763: for (unsigned i = 0; i < nexpr; i++)
2195 662: SubExprs[i] = args[i];
2196 101: }
2197 :
2198 : /// \brief Build an empty vector-shuffle expression.
2199 1: explicit ShuffleVectorExpr(EmptyShell Empty)
2200 1: : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
2201 :
2202 3: SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2203 1: void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2204 :
2205 3: SourceLocation getRParenLoc() const { return RParenLoc; }
2206 1: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2207 :
2208 224: virtual SourceRange getSourceRange() const {
2209 224: return SourceRange(BuiltinLoc, RParenLoc);
2210 : }
2211 2: static bool classof(const Stmt *T) {
2212 2: return T->getStmtClass() == ShuffleVectorExprClass;
2213 : }
2214 : static bool classof(const ShuffleVectorExpr *) { return true; }
2215 :
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2216 0: ~ShuffleVectorExpr() {}
2217 :
2218 : /// getNumSubExprs - Return the size of the SubExprs array. This includes the
2219 : /// constant expression, the actual arguments passed in, and the function
2220 : /// pointers.
2221 12: unsigned getNumSubExprs() const { return NumExprs; }
2222 :
2223 : /// getExpr - Return the Expr at the specified index.
2224 24: Expr *getExpr(unsigned Index) {
0: branch 0 not taken
0: branch 1 not taken
2225 24: assert((Index < NumExprs) && "Arg access out of range!");
2226 24: return cast<Expr>(SubExprs[Index]);
2227 : }
2228 : const Expr *getExpr(unsigned Index) const {
2229 : assert((Index < NumExprs) && "Arg access out of range!");
2230 : return cast<Expr>(SubExprs[Index]);
2231 : }
2232 :
2233 : void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
2234 :
2235 : unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2236 : assert((N < NumExprs - 2) && "Shuffle idx out of range!");
2237 : return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2238 : }
2239 :
2240 : // Iterators
2241 : virtual child_iterator child_begin();
2242 : virtual child_iterator child_end();
2243 : };
2244 :
2245 : /// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
2246 : /// This AST node is similar to the conditional operator (?:) in C, with
2247 : /// the following exceptions:
2248 : /// - the test expression must be a integer constant expression.
2249 : /// - the expression returned acts like the chosen subexpression in every
2250 : /// visible way: the type is the same as that of the chosen subexpression,
2251 : /// and all predicates (whether it's an l-value, whether it's an integer
2252 : /// constant expression, etc.) return the same result as for the chosen
2253 : /// sub-expression.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2254 0: class ChooseExpr : public Expr {
2255 : enum { COND, LHS, RHS, END_EXPR };
2256 : Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2257 : SourceLocation BuiltinLoc, RParenLoc;
2258 : public:
2259 : ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2260 35: SourceLocation RP, bool TypeDependent, bool ValueDependent)
2261 : : Expr(ChooseExprClass, t, TypeDependent, ValueDependent),
2262 35: BuiltinLoc(BLoc), RParenLoc(RP) {
2263 35: SubExprs[COND] = cond;
2264 35: SubExprs[LHS] = lhs;
2265 35: SubExprs[RHS] = rhs;
2266 35: }
2267 :
2268 : /// \brief Build an empty __builtin_choose_expr.
2269 1: explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
2270 :
2271 : /// isConditionTrue - Return whether the condition is true (i.e. not
2272 : /// equal to zero).
2273 : bool isConditionTrue(ASTContext &C) const;
2274 :
2275 : /// getChosenSubExpr - Return the subexpression chosen according to the
2276 : /// condition.
2277 10: Expr *getChosenSubExpr(ASTContext &C) const {
0: branch 1 not taken
0: branch 2 not taken
2278 10: return isConditionTrue(C) ? getLHS() : getRHS();
2279 : }
2280 :
2281 88: Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2282 1: void setCond(Expr *E) { SubExprs[COND] = E; }
2283 24: Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2284 1: void setLHS(Expr *E) { SubExprs[LHS] = E; }
2285 22: Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2286 1: void setRHS(Expr *E) { SubExprs[RHS] = E; }
2287 :
2288 4: SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2289 1: void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2290 :
2291 4: SourceLocation getRParenLoc() const { return RParenLoc; }
2292 1: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2293 :
2294 27: virtual SourceRange getSourceRange() const {
2295 27: return SourceRange(BuiltinLoc, RParenLoc);
2296 : }
2297 77: static bool classof(const Stmt *T) {
2298 77: return T->getStmtClass() == ChooseExprClass;
2299 : }
2300 : static bool classof(const ChooseExpr *) { return true; }
2301 :
2302 : // Iterators
2303 : virtual child_iterator child_begin();
2304 : virtual child_iterator child_end();
2305 : };
2306 :
2307 : /// GNUNullExpr - Implements the GNU __null extension, which is a name
2308 : /// for a null pointer constant that has integral type (e.g., int or
2309 : /// long) and is the same size and alignment as a pointer. The __null
2310 : /// extension is typically only used by system headers, which define
2311 : /// NULL as __null in C++ rather than using 0 (which is an integer
2312 : /// that may not match the size of a pointer).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2313 0: class GNUNullExpr : public Expr {
2314 : /// TokenLoc - The location of the __null keyword.
2315 : SourceLocation TokenLoc;
2316 :
2317 : public:
2318 18: GNUNullExpr(QualType Ty, SourceLocation Loc)
2319 18: : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
2320 :
2321 : /// \brief Build an empty GNU __null expression.
2322 0: explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
2323 :
2324 : /// getTokenLocation - The location of the __null token.
2325 0: SourceLocation getTokenLocation() const { return TokenLoc; }
2326 0: void setTokenLocation(SourceLocation L) { TokenLoc = L; }
2327 :
2328 13: virtual SourceRange getSourceRange() const {
2329 13: return SourceRange(TokenLoc);
2330 : }
2331 8422: static bool classof(const Stmt *T) {
2332 8422: return T->getStmtClass() == GNUNullExprClass;
2333 : }
2334 : static bool classof(const GNUNullExpr *) { return true; }
2335 :
2336 : // Iterators
2337 : virtual child_iterator child_begin();
2338 : virtual child_iterator child_end();
2339 : };
2340 :
2341 : /// VAArgExpr, used for the builtin function __builtin_va_start.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
2: branch 6 taken
2342 2: class VAArgExpr : public Expr {
2343 : Stmt *Val;
2344 : SourceLocation BuiltinLoc, RParenLoc;
2345 : public:
2346 31: VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
2347 : : Expr(VAArgExprClass, t, t->isDependentType(), false),
2348 : Val(e),
2349 : BuiltinLoc(BLoc),
2350 31: RParenLoc(RPLoc) { }
2351 :
2352 : /// \brief Create an empty __builtin_va_start expression.
2353 1: explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2354 :
2355 : const Expr *getSubExpr() const { return cast<Expr>(Val); }
2356 13: Expr *getSubExpr() { return cast<Expr>(Val); }
2357 1: void setSubExpr(Expr *E) { Val = E; }
2358 :
2359 5: SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2360 1: void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2361 :
2362 3: SourceLocation getRParenLoc() const { return RParenLoc; }
2363 1: void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2364 :
2365 38: virtual SourceRange getSourceRange() const {
2366 38: return SourceRange(BuiltinLoc, RParenLoc);
2367 : }
2368 3: static bool classof(const Stmt *T) {
2369 3: return T->getStmtClass() == VAArgExprClass;
2370 : }
2371 : static bool classof(const VAArgExpr *) { return true; }
2372 :
2373 : // Iterators
2374 : virtual child_iterator child_begin();
2375 : virtual child_iterator child_end();
2376 : };
2377 :
2378 : /// @brief Describes an C or C++ initializer list.
2379 : ///
2380 : /// InitListExpr describes an initializer list, which can be used to
2381 : /// initialize objects of different types, including
2382 : /// struct/class/union types, arrays, and vectors. For example:
2383 : ///
2384 : /// @code
2385 : /// struct foo x = { 1, { 2, 3 } };
2386 : /// @endcode
2387 : ///
2388 : /// Prior to semantic analysis, an initializer list will represent the
2389 : /// initializer list as written by the user, but will have the
2390 : /// placeholder type "void". This initializer list is called the
2391 : /// syntactic form of the initializer, and may contain C99 designated
2392 : /// initializers (represented as DesignatedInitExprs), initializations
2393 : /// of subobject members without explicit braces, and so on. Clients
2394 : /// interested in the original syntax of the initializer list should
2395 : /// use the syntactic form of the initializer list.
2396 : ///
2397 : /// After semantic analysis, the initializer list will represent the
2398 : /// semantic form of the initializer, where the initializations of all
2399 : /// subobjects are made explicit with nested InitListExpr nodes and
2400 : /// C99 designators have been eliminated by placing the designated
2401 : /// initializations into the subobject they initialize. Additionally,
2402 : /// any "holes" in the initialization, where no initializer has been
2403 : /// specified for a particular subobject, will be replaced with
2404 : /// implicitly-generated ImplicitValueInitExpr expressions that
2405 : /// value-initialize the subobjects. Note, however, that the
2406 : /// initializer lists may still have fewer initializers than there are
2407 : /// elements to initialize within the object.
2408 : ///
2409 : /// Given the semantic form of the initializer list, one can retrieve
2410 : /// the original syntactic form of that initializer list (if it
2411 : /// exists) using getSyntacticForm(). Since many initializer lists
2412 : /// have the same syntactic and semantic forms, getSyntacticForm() may
2413 : /// return NULL, indicating that the current initializer list also
2414 : /// serves as its syntactic form.
0: branch 2 not taken
0: branch 3 not taken
0: branch 7 not taken
9: branch 8 taken
2415 9: class InitListExpr : public Expr {
2416 : // FIXME: Eliminate this vector in favor of ASTContext allocation
2417 : std::vector<Stmt *> InitExprs;
2418 : SourceLocation LBraceLoc, RBraceLoc;
2419 :
2420 : /// Contains the initializer list that describes the syntactic form
2421 : /// written in the source code.
2422 : InitListExpr *SyntacticForm;
2423 :
2424 : /// If this initializer list initializes a union, specifies which
2425 : /// field within the union will be initialized.
2426 : FieldDecl *UnionFieldInit;
2427 :
2428 : /// Whether this initializer list originally had a GNU array-range
2429 : /// designator in it. This is a temporary marker used by CodeGen.
2430 : bool HadArrayRangeDesignator;
2431 :
2432 : public:
2433 : InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
2434 : SourceLocation rbraceloc);
2435 :
2436 : /// \brief Build an empty initializer list.
2437 10: explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { }
2438 :
2439 25861: unsigned getNumInits() const { return InitExprs.size(); }
2440 :
2441 913: const Expr* getInit(unsigned Init) const {
913: branch 1 taken
0: branch 2 not taken
2442 913: assert(Init < getNumInits() && "Initializer access out of range!");
2443 913: return cast_or_null<Expr>(InitExprs[Init]);
2444 : }
2445 :
2446 13024: Expr* getInit(unsigned Init) {
0: branch 1 not taken
0: branch 2 not taken
2447 13024: assert(Init < getNumInits() && "Initializer access out of range!");
2448 13024: return cast_or_null<Expr>(InitExprs[Init]);
2449 : }
2450 :
2451 938: void setInit(unsigned Init, Expr *expr) {
2452 938: assert(Init < getNumInits() && "Initializer access out of range!");
2453 938: InitExprs[Init] = expr;
2454 938: }
2455 :
2456 : /// \brief Reserve space for some number of initializers.
2457 : void reserveInits(unsigned NumInits);
2458 :
2459 : /// @brief Specify the number of initializers
2460 : ///
2461 : /// If there are more than @p NumInits initializers, the remaining
2462 : /// initializers will be destroyed. If there are fewer than @p
2463 : /// NumInits initializers, NULL expressions will be added for the
2464 : /// unknown initializers.
2465 : void resizeInits(ASTContext &Context, unsigned NumInits);
2466 :
2467 : /// @brief Updates the initializer at index @p Init with the new
2468 : /// expression @p expr, and returns the old expression at that
2469 : /// location.
2470 : ///
2471 : /// When @p Init is out of range for this initializer list, the
2472 : /// initializer list will be extended with NULL expressions to
2473 : /// accomodate the new entry.
2474 : Expr *updateInit(unsigned Init, Expr *expr);
2475 :
2476 : /// \brief If this initializes a union, specifies which field in the
2477 : /// union to initialize.
2478 : ///
2479 : /// Typically, this field is the first named field within the
2480 : /// union. However, a designated initializer can specify the
2481 : /// initialization of a different field within the union.
2482 88: FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
2483 50: void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
2484 :
2485 : // Explicit InitListExpr's originate from source code (and have valid source
2486 : // locations). Implicit InitListExpr's are created by the semantic analyzer.
2487 882: bool isExplicit() {
2488 882: return LBraceLoc.isValid() && RBraceLoc.isValid();
2489 : }
2490 :
2491 26: SourceLocation getLBraceLoc() const { return LBraceLoc; }
2492 10: void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2493 26: SourceLocation getRBraceLoc() const { return RBraceLoc; }
2494 90: void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
2495 :
2496 : /// @brief Retrieve the initializer list that describes the
2497 : /// syntactic form of the initializer.
2498 : ///
2499 : ///
2500 1815: InitListExpr *getSyntacticForm() const { return SyntacticForm; }
2501 1639: void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
2502 :
2503 60: bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
2504 16: void sawArrayRangeDesignator(bool ARD = true) {
2505 16: HadArrayRangeDesignator = ARD;
2506 16: }
2507 :
2508 5256: virtual SourceRange getSourceRange() const {
2509 5256: return SourceRange(LBraceLoc, RBraceLoc);
2510 : }
2511 50687: static bool classof(const Stmt *T) {
2512 50687: return T->getStmtClass() == InitListExprClass;
2513 : }
2514 : static bool classof(const InitListExpr *) { return true; }
2515 :
2516 : // Iterators
2517 : virtual child_iterator child_begin();
2518 : virtual child_iterator child_end();
2519 :
2520 : typedef std::vector<Stmt *>::iterator iterator;
2521 : typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
2522 :
2523 : iterator begin() { return InitExprs.begin(); }
2524 : iterator end() { return InitExprs.end(); }
2525 214: reverse_iterator rbegin() { return InitExprs.rbegin(); }
2526 214: reverse_iterator rend() { return InitExprs.rend(); }
2527 : };
2528 :
2529 : /// @brief Represents a C99 designated initializer expression.
2530 : ///
2531 : /// A designated initializer expression (C99 6.7.8) contains one or
2532 : /// more designators (which can be field designators, array
2533 : /// designators, or GNU array-range designators) followed by an
2534 : /// expression that initializes the field or element(s) that the
2535 : /// designators refer to. For example, given:
2536 : ///
2537 : /// @code
2538 : /// struct point {
2539 : /// double x;
2540 : /// double y;
2541 : /// };
2542 : /// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
2543 : /// @endcode
2544 : ///
2545 : /// The InitListExpr contains three DesignatedInitExprs, the first of
2546 : /// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
2547 : /// designators, one array designator for @c [2] followed by one field
2548 : /// designator for @c .y. The initalization expression will be 1.0.
0: branch 2 not taken
0: branch 5 not taken
5: branch 6 taken
2549 5: class DesignatedInitExpr : public Expr {
2550 : public:
2551 : /// \brief Forward declaration of the Designator class.
2552 : class Designator;
2553 :
2554 : private:
2555 : /// The location of the '=' or ':' prior to the actual initializer
2556 : /// expression.
2557 : SourceLocation EqualOrColonLoc;
2558 :
2559 : /// Whether this designated initializer used the GNU deprecated
2560 : /// syntax rather than the C99 '=' syntax.
2561 : bool GNUSyntax : 1;
2562 :
2563 : /// The number of designators in this initializer expression.
2564 : unsigned NumDesignators : 15;
2565 :
2566 : /// \brief The designators in this designated initialization
2567 : /// expression.
2568 : Designator *Designators;
2569 :
2570 : /// The number of subexpressions of this initializer expression,
2571 : /// which contains both the initializer and any additional
2572 : /// expressions used by array and array-range designators.
2573 : unsigned NumSubExprs : 16;
2574 :
2575 :
2576 : DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
2577 : const Designator *Designators,
2578 : SourceLocation EqualOrColonLoc, bool GNUSyntax,
2579 : Expr **IndexExprs, unsigned NumIndexExprs,
2580 : Expr *Init);
2581 :
2582 3: explicit DesignatedInitExpr(unsigned NumSubExprs)
2583 : : Expr(DesignatedInitExprClass, EmptyShell()),
2584 3: NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2585 :
2586 : protected:
2587 : virtual void DoDestroy(ASTContext &C);
2588 :
2589 : void DestroyDesignators(ASTContext &C);
2590 :
2591 : public:
2592 : /// A field designator, e.g., ".x".
2593 : struct FieldDesignator {
2594 : /// Refers to the field that is being initialized. The low bit
2595 : /// of this field determines whether this is actually a pointer
2596 : /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
2597 : /// initially constructed, a field designator will store an
2598 : /// IdentifierInfo*. After semantic analysis has resolved that
2599 : /// name, the field designator will instead store a FieldDecl*.
2600 : uintptr_t NameOrField;
2601 :
2602 : /// The location of the '.' in the designated initializer.
2603 : unsigned DotLoc;
2604 :
2605 : /// The location of the field name in the designated initializer.
2606 : unsigned FieldLoc;
2607 : };
2608 :
2609 : /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2610 : struct ArrayOrRangeDesignator {
2611 : /// Location of the first index expression within the designated
2612 : /// initializer expression's list of subexpressions.
2613 : unsigned Index;
2614 : /// The location of the '[' starting the array range designator.
2615 : unsigned LBracketLoc;
2616 : /// The location of the ellipsis separating the start and end
2617 : /// indices. Only valid for GNU array-range designators.
2618 : unsigned EllipsisLoc;
2619 : /// The location of the ']' terminating the array range designator.
2620 : unsigned RBracketLoc;
2621 : };
2622 :
2623 : /// @brief Represents a single C99 designator.
2624 : ///
2625 : /// @todo This class is infuriatingly similar to clang::Designator,
2626 : /// but minor differences (storing indices vs. storing pointers)
2627 : /// keep us from reusing it. Try harder, later, to rectify these
2628 : /// differences.
2629 243: class Designator {
2630 : /// @brief The kind of designator this describes.
2631 : enum {
2632 : FieldDesignator,
2633 : ArrayDesignator,
2634 : ArrayRangeDesignator
2635 : } Kind;
2636 :
2637 : union {
2638 : /// A field designator, e.g., ".x".
2639 : struct FieldDesignator Field;
2640 : /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2641 : struct ArrayOrRangeDesignator ArrayOrRange;
2642 : };
2643 : friend class DesignatedInitExpr;
2644 :
2645 : public:
2646 231: Designator() {}
2647 :
2648 : /// @brief Initializes a field designator.
2649 : Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
2650 158: SourceLocation FieldLoc)
2651 158: : Kind(FieldDesignator) {
2652 158: Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
2653 158: Field.DotLoc = DotLoc.getRawEncoding();
2654 158: Field.FieldLoc = FieldLoc.getRawEncoding();
2655 158: }
2656 :
2657 : /// @brief Initializes an array designator.
2658 : Designator(unsigned Index, SourceLocation LBracketLoc,
2659 66: SourceLocation RBracketLoc)
2660 66: : Kind(ArrayDesignator) {
2661 66: ArrayOrRange.Index = Index;
2662 66: ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2663 66: ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
2664 66: ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2665 66: }
2666 :
2667 : /// @brief Initializes a GNU array-range designator.
2668 : Designator(unsigned Index, SourceLocation LBracketLoc,
2669 9: SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
2670 9: : Kind(ArrayRangeDesignator) {
2671 9: ArrayOrRange.Index = Index;
2672 9: ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2673 9: ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
2674 9: ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2675 9: }
2676 :
2677 295: bool isFieldDesignator() const { return Kind == FieldDesignator; }
2678 287: bool isArrayDesignator() const { return Kind == ArrayDesignator; }
2679 161: bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
2680 :
2681 : IdentifierInfo * getFieldName();
2682 :
2683 165: FieldDecl *getField() {
0: branch 0 not taken
0: branch 1 not taken
2684 165: assert(Kind == FieldDesignator && "Only valid on a field designator");
0: branch 0 not taken
0: branch 1 not taken
2685 165: if (Field.NameOrField & 0x01)
2686 138: return 0;
2687 : else
2688 27: return reinterpret_cast<FieldDecl *>(Field.NameOrField);
2689 : }
2690 :
2691 157: void setField(FieldDecl *FD) {
2692 157: assert(Kind == FieldDesignator && "Only valid on a field designator");
2693 157: Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
2694 157: }
2695 :
2696 112: SourceLocation getDotLoc() const {
0: branch 0 not taken
0: branch 1 not taken
2697 112: assert(Kind == FieldDesignator && "Only valid on a field designator");
2698 112: return SourceLocation::getFromRawEncoding(Field.DotLoc);
2699 : }
2700 :
2701 37: SourceLocation getFieldLoc() const {
0: branch 0 not taken
0: branch 1 not taken
2702 37: assert(Kind == FieldDesignator && "Only valid on a field designator");
2703 37: return SourceLocation::getFromRawEncoding(Field.FieldLoc);
2704 : }
2705 :
2706 18: SourceLocation getLBracketLoc() const {
2707 : assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
2708 18: "Only valid on an array or array-range designator");
2709 18: return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
2710 : }
2711 :
2712 2: SourceLocation getRBracketLoc() const {
2713 : assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2714 2: "Only valid on an array or array-range designator");
2715 2: return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
2716 : }
2717 :
2718 2: SourceLocation getEllipsisLoc() const {
2719 : assert(Kind == ArrayRangeDesignator &&
0: branch 0 not taken
0: branch 1 not taken
2720 2: "Only valid on an array-range designator");
2721 2: return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
2722 : }
2723 :
2724 2: unsigned getFirstExprIndex() const {
2725 : assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2726 2: "Only valid on an array or array-range designator");
2727 2: return ArrayOrRange.Index;
2728 : }
2729 :
2730 58: SourceLocation getStartLocation() const {
2731 58: if (Kind == FieldDesignator)
2732 49: return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
2733 : else
2734 9: return getLBracketLoc();
2735 : }
2736 : };
2737 :
2738 : static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
2739 : unsigned NumDesignators,
2740 : Expr **IndexExprs, unsigned NumIndexExprs,
2741 : SourceLocation EqualOrColonLoc,
2742 : bool GNUSyntax, Expr *Init);
2743 :
2744 : static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
2745 :
2746 : /// @brief Returns the number of designators in this initializer.
2747 368: unsigned size() const { return NumDesignators; }
2748 :
2749 : // Iterator access to the designators.
2750 : typedef Designator* designators_iterator;
2751 303: designators_iterator designators_begin() { return Designators; }
2752 19: designators_iterator designators_end() {
2753 19: return Designators + NumDesignators;
2754 : }
2755 :
2756 223: Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
2757 :
2758 : void setDesignators(ASTContext &C, const Designator *Desigs,
2759 : unsigned NumDesigs);
2760 :
2761 : Expr *getArrayIndex(const Designator& D);
2762 : Expr *getArrayRangeStart(const Designator& D);
2763 : Expr *getArrayRangeEnd(const Designator& D);
2764 :
2765 : /// @brief Retrieve the location of the '=' that precedes the
2766 : /// initializer value itself, if present.
2767 17: SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2768 3: void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
2769 :
2770 : /// @brief Determines whether this designated initializer used the
2771 : /// deprecated GNU syntax for designated initializers.
2772 17: bool usesGNUSyntax() const { return GNUSyntax; }
2773 3: void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
2774 :
2775 : /// @brief Retrieve the initializer value.
2776 402: Expr *getInit() const {
2777 402: return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
2778 : }
2779 :
2780 31: void setInit(Expr *init) {
2781 31: *child_begin() = init;
2782 31: }
2783 :
2784 : /// \brief Retrieve the total number of subexpressions in this
2785 : /// designated initializer expression, including the actual
2786 : /// initialized value and any expressions that occur within array
2787 : /// and array-range designators.
2788 9: unsigned getNumSubExprs() const { return NumSubExprs; }
2789 :
2790 5: Expr *getSubExpr(unsigned Idx) {
2791 5: assert(Idx < NumSubExprs && "Subscript out of range");
2792 5: char* Ptr = static_cast<char*>(static_cast<void *>(this));
2793 5: Ptr += sizeof(DesignatedInitExpr);
2794 5: return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
2795 : }
2796 :
2797 5: void setSubExpr(unsigned Idx, Expr *E) {
2798 5: assert(Idx < NumSubExprs && "Subscript out of range");
2799 5: char* Ptr = static_cast<char*>(static_cast<void *>(this));
2800 5: Ptr += sizeof(DesignatedInitExpr);
2801 5: reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
2802 5: }
2803 :
2804 : /// \brief Replaces the designator at index @p Idx with the series
2805 : /// of designators in [First, Last).
2806 : void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
2807 : const Designator *Last);
2808 :
2809 : virtual SourceRange getSourceRange() const;
2810 :
2811 4013: static bool classof(const Stmt *T) {
2812 4013: return T->getStmtClass() == DesignatedInitExprClass;
2813 : }
2814 : static bool classof(const DesignatedInitExpr *) { return true; }
2815 :
2816 : // Iterators
2817 : virtual child_iterator child_begin();
2818 : virtual child_iterator child_end();
2819 : };
2820 :
2821 : /// \brief Represents an implicitly-generated value initialization of
2822 : /// an object of a given type.
2823 : ///
2824 : /// Implicit value initializations occur within semantic initializer
2825 : /// list expressions (InitListExpr) as placeholders for subobject
2826 : /// initializations not explicitly specified by the user.
2827 : ///
2828 : /// \see InitListExpr
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
883: branch 6 taken
2829 883: class ImplicitValueInitExpr : public Expr {
2830 : public:
2831 1141: explicit ImplicitValueInitExpr(QualType ty)
2832 1141: : Expr(ImplicitValueInitExprClass, ty, false, false) { }
2833 :
2834 : /// \brief Construct an empty implicit value initialization.
2835 2: explicit ImplicitValueInitExpr(EmptyShell Empty)
2836 2: : Expr(ImplicitValueInitExprClass, Empty) { }
2837 :
2838 79: static bool classof(const Stmt *T) {
2839 79: return T->getStmtClass() == ImplicitValueInitExprClass;
2840 : }
2841 : static bool classof(const ImplicitValueInitExpr *) { return true; }
2842 :
2843 532: virtual SourceRange getSourceRange() const {
2844 532: return SourceRange();
2845 : }
2846 :
2847 : // Iterators
2848 : virtual child_iterator child_begin();
2849 : virtual child_iterator child_end();
2850 : };
2851 :
2852 :
2853 : class ParenListExpr : public Expr {
2854 : Stmt **Exprs;
2855 : unsigned NumExprs;
2856 : SourceLocation LParenLoc, RParenLoc;
2857 :
2858 : protected:
2859 : virtual void DoDestroy(ASTContext& C);
2860 :
2861 : public:
2862 : ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
2863 : unsigned numexprs, SourceLocation rparenloc);
2864 :
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2865 0: ~ParenListExpr() {}
2866 :
2867 : /// \brief Build an empty paren list.
2868 : //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
2869 :
2870 288: unsigned getNumExprs() const { return NumExprs; }
2871 :
2872 : const Expr* getExpr(unsigned Init) const {
2873 : assert(Init < getNumExprs() && "Initializer access out of range!");
2874 : return cast_or_null<Expr>(Exprs[Init]);
2875 : }
2876 :
2877 134: Expr* getExpr(unsigned Init) {
0: branch 1 not taken
0: branch 2 not taken
2878 134: assert(Init < getNumExprs() && "Initializer access out of range!");
2879 134: return cast_or_null<Expr>(Exprs[Init]);
2880 : }
2881 :
2882 26: Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
2883 :
2884 122: SourceLocation getLParenLoc() const { return LParenLoc; }
2885 122: SourceLocation getRParenLoc() const { return RParenLoc; }
2886 :
2887 1: virtual SourceRange getSourceRange() const {
2888 1: return SourceRange(LParenLoc, RParenLoc);
2889 : }
2890 15975: static bool classof(const Stmt *T) {
2891 15975: return T->getStmtClass() == ParenListExprClass;
2892 : }
2893 : static bool classof(const ParenListExpr *) { return true; }
2894 :
2895 : // Iterators
2896 : virtual child_iterator child_begin();
2897 : virtual child_iterator child_end();
2898 : };
2899 :
2900 :
2901 : //===----------------------------------------------------------------------===//
2902 : // Clang Extensions
2903 : //===----------------------------------------------------------------------===//
2904 :
2905 :
2906 : /// ExtVectorElementExpr - This represents access to specific elements of a
2907 : /// vector, and may occur on the left hand side or right hand side. For example
2908 : /// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
2909 : ///
2910 : /// Note that the base may have either vector or pointer to vector type, just
2911 : /// like a struct field reference.
2912 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
2: branch 6 taken
2913 2: class ExtVectorElementExpr : public Expr {
2914 : Stmt *Base;
2915 : IdentifierInfo *Accessor;
2916 : SourceLocation AccessorLoc;
2917 : public:
2918 : ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2919 125: SourceLocation loc)
2920 : : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
2921 : base->isValueDependent()),
2922 125: Base(base), Accessor(&accessor), AccessorLoc(loc) {}
2923 :
2924 : /// \brief Build an empty vector element expression.
2925 1: explicit ExtVectorElementExpr(EmptyShell Empty)
2926 1: : Expr(ExtVectorElementExprClass, Empty) { }
2927 :
2928 315: const Expr *getBase() const { return cast<Expr>(Base); }
2929 11: Expr *getBase() { return cast<Expr>(Base); }
2930 1: void setBase(Expr *E) { Base = E; }
2931 :
2932 11: IdentifierInfo &getAccessor() const { return *Accessor; }
2933 1: void setAccessor(IdentifierInfo *II) { Accessor = II; }
2934 :
2935 3: SourceLocation getAccessorLoc() const { return AccessorLoc; }
2936 1: void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
2937 :
2938 : /// getNumElements - Get the number of components being selected.
2939 : unsigned getNumElements() const;
2940 :
2941 : /// containsDuplicateElements - Return true if any element access is
2942 : /// repeated.
2943 : bool containsDuplicateElements() const;
2944 :
2945 : /// getEncodedElementAccess - Encode the elements accessed into an llvm
2946 : /// aggregate Constant of ConstantInt(s).
2947 : void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2948 :
2949 90: virtual SourceRange getSourceRange() const {
2950 90: return SourceRange(getBase()->getLocStart(), AccessorLoc);
2951 : }
2952 :
2953 : /// isArrow - Return true if the base expression is a pointer to vector,
2954 : /// return false if the base expression is a vector.
2955 : bool isArrow() const;
2956 :
2957 2490: static bool classof(const Stmt *T) {
2958 2490: return T->getStmtClass() == ExtVectorElementExprClass;
2959 : }
2960 : static bool classof(const ExtVectorElementExpr *) { return true; }
2961 :
2962 : // Iterators
2963 : virtual child_iterator child_begin();
2964 : virtual child_iterator child_end();
2965 : };
2966 :
2967 :
2968 : /// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
2969 : /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
3: branch 6 taken
2970 3: class BlockExpr : public Expr {
2971 : protected:
2972 : BlockDecl *TheBlock;
2973 : bool HasBlockDeclRefExprs;
2974 : public:
2975 260: BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2976 : : Expr(BlockExprClass, ty, ty->isDependentType(), false),
2977 260: TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
2978 :
2979 : /// \brief Build an empty block expression.
2980 2: explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
2981 :
2982 70: const BlockDecl *getBlockDecl() const { return TheBlock; }
2983 294: BlockDecl *getBlockDecl() { return TheBlock; }
2984 2: void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
2985 :
2986 : // Convenience functions for probing the underlying BlockDecl.
2987 : SourceLocation getCaretLocation() const;
2988 : const Stmt *getBody() const;
2989 : Stmt *getBody();
2990 :
2991 832: virtual SourceRange getSourceRange() const {
2992 832: return SourceRange(getCaretLocation(), getBody()->getLocEnd());
2993 : }
2994 :
2995 : /// getFunctionType - Return the underlying function type for this block.
2996 : const FunctionType *getFunctionType() const;
2997 :
2998 : /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
2999 : /// inside of the block that reference values outside the block.
3000 96: bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
3001 2: void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3002 :
3003 2398: static bool classof(const Stmt *T) {
3004 2398: return T->getStmtClass() == BlockExprClass;
3005 : }
3006 : static bool classof(const BlockExpr *) { return true; }
3007 :
3008 : // Iterators
3009 : virtual child_iterator child_begin();
3010 : virtual child_iterator child_end();
3011 : };
3012 :
3013 : /// BlockDeclRefExpr - A reference to a declared variable, function,
3014 : /// enum, etc.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
2: branch 6 taken
3015 2: class BlockDeclRefExpr : public Expr {
3016 : ValueDecl *D;
3017 : SourceLocation Loc;
3018 : bool IsByRef : 1;
3019 : bool ConstQualAdded : 1;
3020 : public:
3021 : // FIXME: Fix type/value dependence!
3022 : BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
3023 179: bool constAdded = false)
3024 : : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
3025 179: ConstQualAdded(constAdded) {}
3026 :
3027 : // \brief Build an empty reference to a declared variable in a
3028 : // block.
3029 1: explicit BlockDeclRefExpr(EmptyShell Empty)
3030 1: : Expr(BlockDeclRefExprClass, Empty) { }
3031 :
3032 318: ValueDecl *getDecl() { return D; }
3033 423: const ValueDecl *getDecl() const { return D; }
3034 1: void setDecl(ValueDecl *VD) { D = VD; }
3035 :
3036 1: SourceLocation getLocation() const { return Loc; }
3037 1: void setLocation(SourceLocation L) { Loc = L; }
3038 :
3039 304: virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3040 :
3041 446: bool isByRef() const { return IsByRef; }
3042 1: void setByRef(bool BR) { IsByRef = BR; }
3043 :
3044 2: bool isConstQualAdded() const { return ConstQualAdded; }
3045 1: void setConstQualAdded(bool C) { ConstQualAdded = C; }
3046 :
3047 6809: static bool classof(const Stmt *T) {
3048 6809: return T->getStmtClass() == BlockDeclRefExprClass;
3049 : }
3050 : static bool classof(const BlockDeclRefExpr *) { return true; }
3051 :
3052 : // Iterators
3053 : virtual child_iterator child_begin();
3054 : virtual child_iterator child_end();
3055 : };
3056 :
3057 : } // end namespace clang
3058 :
3059 : #endif
Generated: 2010-02-10 01:31 by zcov