Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Expr class and subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 14 | #include "clang/AST/Expr.h" |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 15 | #include "clang/AST/ExprCXX.h" |
Chris Lattner | a4d55d8 | 2008-10-06 06:40:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/APValue.h" |
Chris Lattner | 2eadfb6 | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Chris Lattner | a4d55d8 | 2008-10-06 06:40:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 98cd599 | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 21 | #include "clang/AST/RecordLayout.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtVisitor.h" |
Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 23 | #include "clang/Lex/LiteralSupport.h" |
| 24 | #include "clang/Lex/Lexer.h" |
Chris Lattner | 1b63e4f | 2009-06-14 01:54:56 +0000 | [diff] [blame] | 25 | #include "clang/Basic/Builtins.h" |
Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 26 | #include "clang/Basic/SourceManager.h" |
Chris Lattner | da5a6b6 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 27 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cf3293e | 2009-11-01 20:32:48 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 30 | #include <algorithm> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | using namespace clang; |
| 32 | |
Chris Lattner | bef0efd | 2010-05-13 01:02:19 +0000 | [diff] [blame] | 33 | void Expr::ANCHOR() {} // key function for Expr class. |
| 34 | |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 35 | /// isKnownToHaveBooleanValue - Return true if this is an integer expression |
| 36 | /// that is known to return 0 or 1. This happens for _Bool/bool expressions |
| 37 | /// but also int expressions which are produced by things like comparisons in |
| 38 | /// C. |
| 39 | bool Expr::isKnownToHaveBooleanValue() const { |
| 40 | // If this value has _Bool type, it is obvious 0/1. |
| 41 | if (getType()->isBooleanType()) return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 42 | // If this is a non-scalar-integer type, we don't care enough to try. |
Douglas Gregor | 2ade35e | 2010-06-16 00:17:44 +0000 | [diff] [blame] | 43 | if (!getType()->isIntegralOrEnumerationType()) return false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 45 | if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) |
| 46 | return PE->getSubExpr()->isKnownToHaveBooleanValue(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 48 | if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(this)) { |
| 49 | switch (UO->getOpcode()) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 50 | case UO_Plus: |
| 51 | case UO_Extension: |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 52 | return UO->getSubExpr()->isKnownToHaveBooleanValue(); |
| 53 | default: |
| 54 | return false; |
| 55 | } |
| 56 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 57 | |
John McCall | 6907fbe | 2010-06-12 01:56:02 +0000 | [diff] [blame] | 58 | // Only look through implicit casts. If the user writes |
| 59 | // '(int) (a && b)' treat it as an arbitrary int. |
| 60 | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(this)) |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 61 | return CE->getSubExpr()->isKnownToHaveBooleanValue(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 62 | |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 63 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) { |
| 64 | switch (BO->getOpcode()) { |
| 65 | default: return false; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 66 | case BO_LT: // Relational operators. |
| 67 | case BO_GT: |
| 68 | case BO_LE: |
| 69 | case BO_GE: |
| 70 | case BO_EQ: // Equality operators. |
| 71 | case BO_NE: |
| 72 | case BO_LAnd: // AND operator. |
| 73 | case BO_LOr: // Logical OR operator. |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 74 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 75 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 76 | case BO_And: // Bitwise AND operator. |
| 77 | case BO_Xor: // Bitwise XOR operator. |
| 78 | case BO_Or: // Bitwise OR operator. |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 79 | // Handle things like (x==2)|(y==12). |
| 80 | return BO->getLHS()->isKnownToHaveBooleanValue() && |
| 81 | BO->getRHS()->isKnownToHaveBooleanValue(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 82 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 83 | case BO_Comma: |
| 84 | case BO_Assign: |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 85 | return BO->getRHS()->isKnownToHaveBooleanValue(); |
| 86 | } |
| 87 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 89 | if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(this)) |
| 90 | return CO->getTrueExpr()->isKnownToHaveBooleanValue() && |
| 91 | CO->getFalseExpr()->isKnownToHaveBooleanValue(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 92 | |
Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 93 | return false; |
| 94 | } |
| 95 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 96 | //===----------------------------------------------------------------------===// |
| 97 | // Primary Expressions. |
| 98 | //===----------------------------------------------------------------------===// |
| 99 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 100 | void ExplicitTemplateArgumentList::initializeFrom( |
| 101 | const TemplateArgumentListInfo &Info) { |
| 102 | LAngleLoc = Info.getLAngleLoc(); |
| 103 | RAngleLoc = Info.getRAngleLoc(); |
| 104 | NumTemplateArgs = Info.size(); |
| 105 | |
| 106 | TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); |
| 107 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 108 | new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); |
| 109 | } |
| 110 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 111 | void ExplicitTemplateArgumentList::initializeFrom( |
| 112 | const TemplateArgumentListInfo &Info, |
| 113 | bool &Dependent, |
| 114 | bool &ContainsUnexpandedParameterPack) { |
| 115 | LAngleLoc = Info.getLAngleLoc(); |
| 116 | RAngleLoc = Info.getRAngleLoc(); |
| 117 | NumTemplateArgs = Info.size(); |
| 118 | |
| 119 | TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); |
| 120 | for (unsigned i = 0; i != NumTemplateArgs; ++i) { |
| 121 | Dependent = Dependent || Info[i].getArgument().isDependent(); |
| 122 | ContainsUnexpandedParameterPack |
| 123 | = ContainsUnexpandedParameterPack || |
| 124 | Info[i].getArgument().containsUnexpandedParameterPack(); |
| 125 | |
| 126 | new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); |
| 127 | } |
| 128 | } |
| 129 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 130 | void ExplicitTemplateArgumentList::copyInto( |
| 131 | TemplateArgumentListInfo &Info) const { |
| 132 | Info.setLAngleLoc(LAngleLoc); |
| 133 | Info.setRAngleLoc(RAngleLoc); |
| 134 | for (unsigned I = 0; I != NumTemplateArgs; ++I) |
| 135 | Info.addArgument(getTemplateArgs()[I]); |
| 136 | } |
| 137 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 138 | std::size_t ExplicitTemplateArgumentList::sizeFor(unsigned NumTemplateArgs) { |
| 139 | return sizeof(ExplicitTemplateArgumentList) + |
| 140 | sizeof(TemplateArgumentLoc) * NumTemplateArgs; |
| 141 | } |
| 142 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 143 | std::size_t ExplicitTemplateArgumentList::sizeFor( |
| 144 | const TemplateArgumentListInfo &Info) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 145 | return sizeFor(Info.size()); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 148 | void DeclRefExpr::computeDependence() { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 149 | ExprBits.TypeDependent = false; |
| 150 | ExprBits.ValueDependent = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 151 | |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 152 | NamedDecl *D = getDecl(); |
| 153 | |
| 154 | // (TD) C++ [temp.dep.expr]p3: |
| 155 | // An id-expression is type-dependent if it contains: |
| 156 | // |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 157 | // and |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 158 | // |
| 159 | // (VD) C++ [temp.dep.constexpr]p2: |
| 160 | // An identifier is value-dependent if it is: |
| 161 | |
| 162 | // (TD) - an identifier that was declared with dependent type |
| 163 | // (VD) - a name declared with a dependent type, |
| 164 | if (getType()->isDependentType()) { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 165 | ExprBits.TypeDependent = true; |
| 166 | ExprBits.ValueDependent = true; |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 167 | } |
| 168 | // (TD) - a conversion-function-id that specifies a dependent type |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 169 | else if (D->getDeclName().getNameKind() |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 170 | == DeclarationName::CXXConversionFunctionName && |
| 171 | D->getDeclName().getCXXNameType()->isDependentType()) { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 172 | ExprBits.TypeDependent = true; |
| 173 | ExprBits.ValueDependent = true; |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 174 | } |
| 175 | // (TD) - a template-id that is dependent, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 176 | else if (hasExplicitTemplateArgs() && |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 177 | TemplateSpecializationType::anyDependentTemplateArguments( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 178 | getTemplateArgs(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 179 | getNumTemplateArgs())) { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 180 | ExprBits.TypeDependent = true; |
| 181 | ExprBits.ValueDependent = true; |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 182 | } |
| 183 | // (VD) - the name of a non-type template parameter, |
| 184 | else if (isa<NonTypeTemplateParmDecl>(D)) |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 185 | ExprBits.ValueDependent = true; |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 186 | // (VD) - a constant with integral or enumeration type and is |
| 187 | // initialized with an expression that is value-dependent. |
| 188 | else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { |
Douglas Gregor | 2ade35e | 2010-06-16 00:17:44 +0000 | [diff] [blame] | 189 | if (Var->getType()->isIntegralOrEnumerationType() && |
Douglas Gregor | 501edb6 | 2010-01-15 16:21:02 +0000 | [diff] [blame] | 190 | Var->getType().getCVRQualifiers() == Qualifiers::Const) { |
Sebastian Redl | 31310a2 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 191 | if (const Expr *Init = Var->getAnyInitializer()) |
Douglas Gregor | 501edb6 | 2010-01-15 16:21:02 +0000 | [diff] [blame] | 192 | if (Init->isValueDependent()) |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 193 | ExprBits.ValueDependent = true; |
Douglas Gregor | bb6e73f | 2010-05-11 08:41:30 +0000 | [diff] [blame] | 194 | } |
| 195 | // (VD) - FIXME: Missing from the standard: |
| 196 | // - a member function or a static data member of the current |
| 197 | // instantiation |
| 198 | else if (Var->isStaticDataMember() && |
Douglas Gregor | 7ed5bd3 | 2010-05-11 08:44:04 +0000 | [diff] [blame] | 199 | Var->getDeclContext()->isDependentContext()) |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 200 | ExprBits.ValueDependent = true; |
Douglas Gregor | bb6e73f | 2010-05-11 08:41:30 +0000 | [diff] [blame] | 201 | } |
| 202 | // (VD) - FIXME: Missing from the standard: |
| 203 | // - a member function or a static data member of the current |
| 204 | // instantiation |
| 205 | else if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 206 | ExprBits.ValueDependent = true; |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 207 | // (TD) - a nested-name-specifier or a qualified-id that names a |
| 208 | // member of an unknown specialization. |
| 209 | // (handled by DependentScopeDeclRefExpr) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 210 | |
| 211 | // FIXME: Variadic templates require that we compute whether this |
| 212 | // declaration reference contains an unexpanded parameter pack. |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 215 | DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 216 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 217 | ValueDecl *D, SourceLocation NameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 218 | const TemplateArgumentListInfo *TemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 219 | QualType T, ExprValueKind VK) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 220 | : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 221 | DecoratedD(D, |
| 222 | (Qualifier? HasQualifierFlag : 0) | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 223 | (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 224 | Loc(NameLoc) { |
| 225 | if (Qualifier) { |
| 226 | NameQualifier *NQ = getNameQualifier(); |
| 227 | NQ->NNS = Qualifier; |
| 228 | NQ->Range = QualifierRange; |
| 229 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 230 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 231 | if (TemplateArgs) |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 232 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs); |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 233 | |
| 234 | computeDependence(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 237 | DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, |
| 238 | SourceRange QualifierRange, |
| 239 | ValueDecl *D, const DeclarationNameInfo &NameInfo, |
| 240 | const TemplateArgumentListInfo *TemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 241 | QualType T, ExprValueKind VK) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 242 | : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 243 | DecoratedD(D, |
| 244 | (Qualifier? HasQualifierFlag : 0) | |
| 245 | (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), |
| 246 | Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { |
| 247 | if (Qualifier) { |
| 248 | NameQualifier *NQ = getNameQualifier(); |
| 249 | NQ->NNS = Qualifier; |
| 250 | NQ->Range = QualifierRange; |
| 251 | } |
| 252 | |
| 253 | if (TemplateArgs) |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 254 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 255 | |
| 256 | computeDependence(); |
| 257 | } |
| 258 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 259 | DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, |
| 260 | NestedNameSpecifier *Qualifier, |
| 261 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 262 | ValueDecl *D, |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 263 | SourceLocation NameLoc, |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 264 | QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 265 | ExprValueKind VK, |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 266 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 267 | return Create(Context, Qualifier, QualifierRange, D, |
| 268 | DeclarationNameInfo(D->getDeclName(), NameLoc), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 269 | T, VK, TemplateArgs); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, |
| 273 | NestedNameSpecifier *Qualifier, |
| 274 | SourceRange QualifierRange, |
| 275 | ValueDecl *D, |
| 276 | const DeclarationNameInfo &NameInfo, |
| 277 | QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 278 | ExprValueKind VK, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 279 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 280 | std::size_t Size = sizeof(DeclRefExpr); |
| 281 | if (Qualifier != 0) |
| 282 | Size += sizeof(NameQualifier); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 283 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 284 | if (TemplateArgs) |
| 285 | Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 286 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 287 | void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 288 | return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 289 | TemplateArgs, T, VK); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Argyrios Kyrtzidis | 663e380 | 2010-07-08 13:09:47 +0000 | [diff] [blame] | 292 | DeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, bool HasQualifier, |
| 293 | unsigned NumTemplateArgs) { |
| 294 | std::size_t Size = sizeof(DeclRefExpr); |
| 295 | if (HasQualifier) |
| 296 | Size += sizeof(NameQualifier); |
| 297 | |
| 298 | if (NumTemplateArgs) |
| 299 | Size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 300 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 301 | void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); |
Argyrios Kyrtzidis | 663e380 | 2010-07-08 13:09:47 +0000 | [diff] [blame] | 302 | return new (Mem) DeclRefExpr(EmptyShell()); |
| 303 | } |
| 304 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 305 | SourceRange DeclRefExpr::getSourceRange() const { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 306 | SourceRange R = getNameInfo().getSourceRange(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 307 | if (hasQualifier()) |
| 308 | R.setBegin(getQualifierRange().getBegin()); |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 309 | if (hasExplicitTemplateArgs()) |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 310 | R.setEnd(getRAngleLoc()); |
| 311 | return R; |
| 312 | } |
| 313 | |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 314 | // FIXME: Maybe this should use DeclPrinter with a special "print predefined |
| 315 | // expr" policy instead. |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 316 | std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { |
| 317 | ASTContext &Context = CurrentDecl->getASTContext(); |
| 318 | |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 319 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 320 | if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 321 | return FD->getNameAsString(); |
| 322 | |
| 323 | llvm::SmallString<256> Name; |
| 324 | llvm::raw_svector_ostream Out(Name); |
| 325 | |
| 326 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 327 | if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 328 | Out << "virtual "; |
Sam Weinig | 4eadcc5 | 2009-12-27 01:38:20 +0000 | [diff] [blame] | 329 | if (MD->isStatic()) |
| 330 | Out << "static "; |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | PrintingPolicy Policy(Context.getLangOptions()); |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 334 | |
| 335 | std::string Proto = FD->getQualifiedNameAsString(Policy); |
| 336 | |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 337 | const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 338 | const FunctionProtoType *FT = 0; |
| 339 | if (FD->hasWrittenPrototype()) |
| 340 | FT = dyn_cast<FunctionProtoType>(AFT); |
| 341 | |
| 342 | Proto += "("; |
| 343 | if (FT) { |
| 344 | llvm::raw_string_ostream POut(Proto); |
| 345 | for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { |
| 346 | if (i) POut << ", "; |
| 347 | std::string Param; |
| 348 | FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); |
| 349 | POut << Param; |
| 350 | } |
| 351 | |
| 352 | if (FT->isVariadic()) { |
| 353 | if (FD->getNumParams()) POut << ", "; |
| 354 | POut << "..."; |
| 355 | } |
| 356 | } |
| 357 | Proto += ")"; |
| 358 | |
Sam Weinig | 4eadcc5 | 2009-12-27 01:38:20 +0000 | [diff] [blame] | 359 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
| 360 | Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); |
| 361 | if (ThisQuals.hasConst()) |
| 362 | Proto += " const"; |
| 363 | if (ThisQuals.hasVolatile()) |
| 364 | Proto += " volatile"; |
| 365 | } |
| 366 | |
Sam Weinig | 3a1ce1e | 2009-12-06 23:55:13 +0000 | [diff] [blame] | 367 | if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) |
| 368 | AFT->getResultType().getAsStringInternal(Proto, Policy); |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 369 | |
| 370 | Out << Proto; |
| 371 | |
| 372 | Out.flush(); |
| 373 | return Name.str().str(); |
| 374 | } |
| 375 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { |
| 376 | llvm::SmallString<256> Name; |
| 377 | llvm::raw_svector_ostream Out(Name); |
| 378 | Out << (MD->isInstanceMethod() ? '-' : '+'); |
| 379 | Out << '['; |
Ted Kremenek | b03d33e | 2010-03-18 21:23:08 +0000 | [diff] [blame] | 380 | |
| 381 | // For incorrect code, there might not be an ObjCInterfaceDecl. Do |
| 382 | // a null check to avoid a crash. |
| 383 | if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 384 | Out << ID; |
Ted Kremenek | b03d33e | 2010-03-18 21:23:08 +0000 | [diff] [blame] | 385 | |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 386 | if (const ObjCCategoryImplDecl *CID = |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 387 | dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) |
| 388 | Out << '(' << CID << ')'; |
| 389 | |
Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 390 | Out << ' '; |
| 391 | Out << MD->getSelector().getAsString(); |
| 392 | Out << ']'; |
| 393 | |
| 394 | Out.flush(); |
| 395 | return Name.str().str(); |
| 396 | } |
| 397 | if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { |
| 398 | // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. |
| 399 | return "top level"; |
| 400 | } |
| 401 | return ""; |
| 402 | } |
| 403 | |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 404 | void APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { |
| 405 | if (hasAllocation()) |
| 406 | C.Deallocate(pVal); |
| 407 | |
| 408 | BitWidth = Val.getBitWidth(); |
| 409 | unsigned NumWords = Val.getNumWords(); |
| 410 | const uint64_t* Words = Val.getRawData(); |
| 411 | if (NumWords > 1) { |
| 412 | pVal = new (C) uint64_t[NumWords]; |
| 413 | std::copy(Words, Words + NumWords, pVal); |
| 414 | } else if (NumWords == 1) |
| 415 | VAL = Words[0]; |
| 416 | else |
| 417 | VAL = 0; |
| 418 | } |
| 419 | |
| 420 | IntegerLiteral * |
| 421 | IntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, |
| 422 | QualType type, SourceLocation l) { |
| 423 | return new (C) IntegerLiteral(C, V, type, l); |
| 424 | } |
| 425 | |
| 426 | IntegerLiteral * |
| 427 | IntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { |
| 428 | return new (C) IntegerLiteral(Empty); |
| 429 | } |
| 430 | |
| 431 | FloatingLiteral * |
| 432 | FloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, |
| 433 | bool isexact, QualType Type, SourceLocation L) { |
| 434 | return new (C) FloatingLiteral(C, V, isexact, Type, L); |
| 435 | } |
| 436 | |
| 437 | FloatingLiteral * |
| 438 | FloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { |
| 439 | return new (C) FloatingLiteral(Empty); |
| 440 | } |
| 441 | |
Chris Lattner | da8249e | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 442 | /// getValueAsApproximateDouble - This returns the value as an inaccurate |
| 443 | /// double. Note that this may cause loss of precision, but is useful for |
| 444 | /// debugging dumps, etc. |
| 445 | double FloatingLiteral::getValueAsApproximateDouble() const { |
| 446 | llvm::APFloat V = getValue(); |
Dale Johannesen | ee5a700 | 2008-10-09 23:02:32 +0000 | [diff] [blame] | 447 | bool ignored; |
| 448 | V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, |
| 449 | &ignored); |
Chris Lattner | da8249e | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 450 | return V.convertToDouble(); |
| 451 | } |
| 452 | |
Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 453 | StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, |
| 454 | unsigned ByteLength, bool Wide, |
| 455 | QualType Ty, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | const SourceLocation *Loc, |
Anders Carlsson | a135fb4 | 2009-03-15 18:34:13 +0000 | [diff] [blame] | 457 | unsigned NumStrs) { |
Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 458 | // Allocate enough space for the StringLiteral plus an array of locations for |
| 459 | // any concatenated string tokens. |
| 460 | void *Mem = C.Allocate(sizeof(StringLiteral)+ |
| 461 | sizeof(SourceLocation)*(NumStrs-1), |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 462 | llvm::alignOf<StringLiteral>()); |
Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 463 | StringLiteral *SL = new (Mem) StringLiteral(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 464 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 465 | // OPTIMIZE: could allocate this appended to the StringLiteral. |
Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 466 | char *AStrData = new (C, 1) char[ByteLength]; |
| 467 | memcpy(AStrData, StrData, ByteLength); |
| 468 | SL->StrData = AStrData; |
| 469 | SL->ByteLength = ByteLength; |
| 470 | SL->IsWide = Wide; |
| 471 | SL->TokLocs[0] = Loc[0]; |
| 472 | SL->NumConcatenated = NumStrs; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 473 | |
Chris Lattner | 726e168 | 2009-02-18 05:49:11 +0000 | [diff] [blame] | 474 | if (NumStrs != 1) |
Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 475 | memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); |
| 476 | return SL; |
Chris Lattner | 726e168 | 2009-02-18 05:49:11 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 479 | StringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { |
| 480 | void *Mem = C.Allocate(sizeof(StringLiteral)+ |
| 481 | sizeof(SourceLocation)*(NumStrs-1), |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 482 | llvm::alignOf<StringLiteral>()); |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 483 | StringLiteral *SL = new (Mem) StringLiteral(QualType()); |
| 484 | SL->StrData = 0; |
| 485 | SL->ByteLength = 0; |
| 486 | SL->NumConcatenated = NumStrs; |
| 487 | return SL; |
| 488 | } |
| 489 | |
Daniel Dunbar | b648023 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 490 | void StringLiteral::setString(ASTContext &C, llvm::StringRef Str) { |
Daniel Dunbar | b648023 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 491 | char *AStrData = new (C, 1) char[Str.size()]; |
| 492 | memcpy(AStrData, Str.data(), Str.size()); |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 493 | StrData = AStrData; |
Daniel Dunbar | b648023 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 494 | ByteLength = Str.size(); |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 497 | /// getLocationOfByte - Return a source location that points to the specified |
| 498 | /// byte of this string literal. |
| 499 | /// |
| 500 | /// Strings are amazingly complex. They can be formed from multiple tokens and |
| 501 | /// can have escape sequences in them in addition to the usual trigraph and |
| 502 | /// escaped newline business. This routine handles this complexity. |
| 503 | /// |
| 504 | SourceLocation StringLiteral:: |
| 505 | getLocationOfByte(unsigned ByteNo, const SourceManager &SM, |
| 506 | const LangOptions &Features, const TargetInfo &Target) const { |
| 507 | assert(!isWide() && "This doesn't work for wide strings yet"); |
| 508 | |
| 509 | // Loop over all of the tokens in this string until we find the one that |
| 510 | // contains the byte we're looking for. |
| 511 | unsigned TokNo = 0; |
| 512 | while (1) { |
| 513 | assert(TokNo < getNumConcatenated() && "Invalid byte number!"); |
| 514 | SourceLocation StrTokLoc = getStrTokenLoc(TokNo); |
| 515 | |
| 516 | // Get the spelling of the string so that we can get the data that makes up |
| 517 | // the string literal, not the identifier for the macro it is potentially |
| 518 | // expanded through. |
| 519 | SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); |
| 520 | |
| 521 | // Re-lex the token to get its length and original spelling. |
| 522 | std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); |
| 523 | bool Invalid = false; |
| 524 | llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); |
| 525 | if (Invalid) |
| 526 | return StrTokSpellingLoc; |
| 527 | |
| 528 | const char *StrData = Buffer.data()+LocInfo.second; |
| 529 | |
| 530 | // Create a langops struct and enable trigraphs. This is sufficient for |
| 531 | // relexing tokens. |
| 532 | LangOptions LangOpts; |
| 533 | LangOpts.Trigraphs = true; |
| 534 | |
| 535 | // Create a lexer starting at the beginning of this token. |
| 536 | Lexer TheLexer(StrTokSpellingLoc, Features, Buffer.begin(), StrData, |
| 537 | Buffer.end()); |
| 538 | Token TheTok; |
| 539 | TheLexer.LexFromRawLexer(TheTok); |
| 540 | |
| 541 | // Use the StringLiteralParser to compute the length of the string in bytes. |
| 542 | StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); |
| 543 | unsigned TokNumBytes = SLP.GetStringLength(); |
| 544 | |
| 545 | // If the byte is in this token, return the location of the byte. |
| 546 | if (ByteNo < TokNumBytes || |
| 547 | (ByteNo == TokNumBytes && TokNo == getNumConcatenated())) { |
| 548 | unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); |
| 549 | |
| 550 | // Now that we know the offset of the token in the spelling, use the |
| 551 | // preprocessor to get the offset in the original source. |
| 552 | return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); |
| 553 | } |
| 554 | |
| 555 | // Move to the next string token. |
| 556 | ++TokNo; |
| 557 | ByteNo -= TokNumBytes; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | |
| 562 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 563 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 564 | /// corresponds to, e.g. "sizeof" or "[pre]++". |
| 565 | const char *UnaryOperator::getOpcodeStr(Opcode Op) { |
| 566 | switch (Op) { |
| 567 | default: assert(0 && "Unknown unary operator"); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 568 | case UO_PostInc: return "++"; |
| 569 | case UO_PostDec: return "--"; |
| 570 | case UO_PreInc: return "++"; |
| 571 | case UO_PreDec: return "--"; |
| 572 | case UO_AddrOf: return "&"; |
| 573 | case UO_Deref: return "*"; |
| 574 | case UO_Plus: return "+"; |
| 575 | case UO_Minus: return "-"; |
| 576 | case UO_Not: return "~"; |
| 577 | case UO_LNot: return "!"; |
| 578 | case UO_Real: return "__real"; |
| 579 | case UO_Imag: return "__imag"; |
| 580 | case UO_Extension: return "__extension__"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 584 | UnaryOperatorKind |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 585 | UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { |
| 586 | switch (OO) { |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 587 | default: assert(false && "No unary operator for overloaded function"); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 588 | case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; |
| 589 | case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; |
| 590 | case OO_Amp: return UO_AddrOf; |
| 591 | case OO_Star: return UO_Deref; |
| 592 | case OO_Plus: return UO_Plus; |
| 593 | case OO_Minus: return UO_Minus; |
| 594 | case OO_Tilde: return UO_Not; |
| 595 | case OO_Exclaim: return UO_LNot; |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
| 599 | OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { |
| 600 | switch (Opc) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 601 | case UO_PostInc: case UO_PreInc: return OO_PlusPlus; |
| 602 | case UO_PostDec: case UO_PreDec: return OO_MinusMinus; |
| 603 | case UO_AddrOf: return OO_Amp; |
| 604 | case UO_Deref: return OO_Star; |
| 605 | case UO_Plus: return OO_Plus; |
| 606 | case UO_Minus: return OO_Minus; |
| 607 | case UO_Not: return OO_Tilde; |
| 608 | case UO_LNot: return OO_Exclaim; |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 609 | default: return OO_None; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 614 | //===----------------------------------------------------------------------===// |
| 615 | // Postfix Operators. |
| 616 | //===----------------------------------------------------------------------===// |
| 617 | |
Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 618 | CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 619 | unsigned numargs, QualType t, ExprValueKind VK, |
| 620 | SourceLocation rparenloc) |
| 621 | : Expr(SC, t, VK, OK_Ordinary, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 622 | fn->isTypeDependent(), |
| 623 | fn->isValueDependent(), |
| 624 | fn->containsUnexpandedParameterPack()), |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 625 | NumArgs(numargs) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | |
Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 627 | SubExprs = new (C) Stmt*[numargs+1]; |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 628 | SubExprs[FN] = fn; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 629 | for (unsigned i = 0; i != numargs; ++i) { |
| 630 | if (args[i]->isTypeDependent()) |
| 631 | ExprBits.TypeDependent = true; |
| 632 | if (args[i]->isValueDependent()) |
| 633 | ExprBits.ValueDependent = true; |
| 634 | if (args[i]->containsUnexpandedParameterPack()) |
| 635 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 636 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 637 | SubExprs[i+ARGS_START] = args[i]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 638 | } |
Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 639 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 640 | RParenLoc = rparenloc; |
| 641 | } |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 642 | |
Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 643 | CallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 644 | QualType t, ExprValueKind VK, SourceLocation rparenloc) |
| 645 | : Expr(CallExprClass, t, VK, OK_Ordinary, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 646 | fn->isTypeDependent(), |
| 647 | fn->isValueDependent(), |
| 648 | fn->containsUnexpandedParameterPack()), |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 649 | NumArgs(numargs) { |
Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 650 | |
| 651 | SubExprs = new (C) Stmt*[numargs+1]; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 652 | SubExprs[FN] = fn; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 653 | for (unsigned i = 0; i != numargs; ++i) { |
| 654 | if (args[i]->isTypeDependent()) |
| 655 | ExprBits.TypeDependent = true; |
| 656 | if (args[i]->isValueDependent()) |
| 657 | ExprBits.ValueDependent = true; |
| 658 | if (args[i]->containsUnexpandedParameterPack()) |
| 659 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 660 | |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 661 | SubExprs[i+ARGS_START] = args[i]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 662 | } |
Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 663 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 664 | RParenLoc = rparenloc; |
| 665 | } |
| 666 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 667 | CallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) |
| 668 | : Expr(SC, Empty), SubExprs(0), NumArgs(0) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 669 | // FIXME: Why do we allocate this? |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 670 | SubExprs = new (C) Stmt*[1]; |
| 671 | } |
| 672 | |
Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 673 | Decl *CallExpr::getCalleeDecl() { |
Zhongxing Xu | a004254 | 2009-07-17 07:29:51 +0000 | [diff] [blame] | 674 | Expr *CEE = getCallee()->IgnoreParenCasts(); |
Sebastian Redl | 2001215 | 2010-09-10 20:55:30 +0000 | [diff] [blame] | 675 | // If we're calling a dereference, look at the pointer instead. |
| 676 | if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { |
| 677 | if (BO->isPtrMemOp()) |
| 678 | CEE = BO->getRHS()->IgnoreParenCasts(); |
| 679 | } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { |
| 680 | if (UO->getOpcode() == UO_Deref) |
| 681 | CEE = UO->getSubExpr()->IgnoreParenCasts(); |
| 682 | } |
Chris Lattner | 6346f96 | 2009-07-17 15:46:27 +0000 | [diff] [blame] | 683 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) |
Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 684 | return DRE->getDecl(); |
Nuno Lopes | cb1c77f | 2009-12-24 00:28:18 +0000 | [diff] [blame] | 685 | if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) |
| 686 | return ME->getMemberDecl(); |
Zhongxing Xu | a004254 | 2009-07-17 07:29:51 +0000 | [diff] [blame] | 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 691 | FunctionDecl *CallExpr::getDirectCallee() { |
Chris Lattner | caabf9b | 2009-12-21 01:10:56 +0000 | [diff] [blame] | 692 | return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); |
Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 695 | /// setNumArgs - This changes the number of arguments present in this call. |
| 696 | /// Any orphaned expressions are deleted by this, and any new operands are set |
| 697 | /// to null. |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 698 | void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 699 | // No change, just return. |
| 700 | if (NumArgs == getNumArgs()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 702 | // If shrinking # arguments, just delete the extras and forgot them. |
| 703 | if (NumArgs < getNumArgs()) { |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 704 | this->NumArgs = NumArgs; |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | // Otherwise, we are growing the # arguments. New an bigger argument array. |
Daniel Dunbar | 68a049c | 2009-07-28 06:29:46 +0000 | [diff] [blame] | 709 | Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1]; |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 710 | // Copy over args. |
| 711 | for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) |
| 712 | NewSubExprs[i] = SubExprs[i]; |
| 713 | // Null out new args. |
| 714 | for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) |
| 715 | NewSubExprs[i] = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | |
Douglas Gregor | 88c9a46 | 2009-04-17 21:46:47 +0000 | [diff] [blame] | 717 | if (SubExprs) C.Deallocate(SubExprs); |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 718 | SubExprs = NewSubExprs; |
| 719 | this->NumArgs = NumArgs; |
| 720 | } |
| 721 | |
Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 722 | /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If |
| 723 | /// not, return 0. |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 724 | unsigned CallExpr::isBuiltinCall(ASTContext &Context) const { |
Steve Naroff | c4f8e8b | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 725 | // All simple function calls (e.g. func()) are implicitly cast to pointer to |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | // function. As a result, we try and obtain the DeclRefExpr from the |
Steve Naroff | c4f8e8b | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 727 | // ImplicitCastExpr. |
| 728 | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); |
| 729 | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). |
Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 730 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Steve Naroff | c4f8e8b | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 732 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); |
| 733 | if (!DRE) |
Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 734 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Anders Carlsson | bcba201 | 2008-01-31 02:13:57 +0000 | [diff] [blame] | 736 | const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); |
| 737 | if (!FDecl) |
Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 738 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Douglas Gregor | 4fcd399 | 2008-11-21 15:30:19 +0000 | [diff] [blame] | 740 | if (!FDecl->getIdentifier()) |
| 741 | return 0; |
| 742 | |
Douglas Gregor | 7814e6d | 2009-09-12 00:22:50 +0000 | [diff] [blame] | 743 | return FDecl->getBuiltinID(); |
Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 744 | } |
Anders Carlsson | bcba201 | 2008-01-31 02:13:57 +0000 | [diff] [blame] | 745 | |
Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 746 | QualType CallExpr::getCallReturnType() const { |
| 747 | QualType CalleeType = getCallee()->getType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 748 | if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) |
Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 749 | CalleeType = FnTypePtr->getPointeeType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 750 | else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) |
Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 751 | CalleeType = BPT->getPointeeType(); |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 752 | else if (const MemberPointerType *MPT |
| 753 | = CalleeType->getAs<MemberPointerType>()) |
| 754 | CalleeType = MPT->getPointeeType(); |
| 755 | |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 756 | const FunctionType *FnType = CalleeType->getAs<FunctionType>(); |
Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 757 | return FnType->getResultType(); |
| 758 | } |
Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 759 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 760 | OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 761 | SourceLocation OperatorLoc, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 762 | TypeSourceInfo *tsi, |
| 763 | OffsetOfNode* compsPtr, unsigned numComps, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 764 | Expr** exprsPtr, unsigned numExprs, |
| 765 | SourceLocation RParenLoc) { |
| 766 | void *Mem = C.Allocate(sizeof(OffsetOfExpr) + |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 767 | sizeof(OffsetOfNode) * numComps + |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 768 | sizeof(Expr*) * numExprs); |
| 769 | |
| 770 | return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, |
| 771 | exprsPtr, numExprs, RParenLoc); |
| 772 | } |
| 773 | |
| 774 | OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, |
| 775 | unsigned numComps, unsigned numExprs) { |
| 776 | void *Mem = C.Allocate(sizeof(OffsetOfExpr) + |
| 777 | sizeof(OffsetOfNode) * numComps + |
| 778 | sizeof(Expr*) * numExprs); |
| 779 | return new (Mem) OffsetOfExpr(numComps, numExprs); |
| 780 | } |
| 781 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 782 | OffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 783 | SourceLocation OperatorLoc, TypeSourceInfo *tsi, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 784 | OffsetOfNode* compsPtr, unsigned numComps, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 785 | Expr** exprsPtr, unsigned numExprs, |
| 786 | SourceLocation RParenLoc) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 787 | : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, |
| 788 | /*TypeDependent=*/false, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 789 | /*ValueDependent=*/tsi->getType()->isDependentType(), |
| 790 | tsi->getType()->containsUnexpandedParameterPack()), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 791 | OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), |
| 792 | NumComps(numComps), NumExprs(numExprs) |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 793 | { |
| 794 | for(unsigned i = 0; i < numComps; ++i) { |
| 795 | setComponent(i, compsPtr[i]); |
| 796 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 797 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 798 | for(unsigned i = 0; i < numExprs; ++i) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 799 | if (exprsPtr[i]->isTypeDependent() || exprsPtr[i]->isValueDependent()) |
| 800 | ExprBits.ValueDependent = true; |
| 801 | if (exprsPtr[i]->containsUnexpandedParameterPack()) |
| 802 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 803 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 804 | setIndexExpr(i, exprsPtr[i]); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | IdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { |
| 809 | assert(getKind() == Field || getKind() == Identifier); |
| 810 | if (getKind() == Field) |
| 811 | return getField()->getIdentifier(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 812 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 813 | return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); |
| 814 | } |
| 815 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, |
| 817 | NestedNameSpecifier *qual, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 818 | SourceRange qualrange, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 819 | ValueDecl *memberdecl, |
John McCall | 161755a | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 820 | DeclAccessPair founddecl, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 821 | DeclarationNameInfo nameinfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 822 | const TemplateArgumentListInfo *targs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 823 | QualType ty, |
| 824 | ExprValueKind vk, |
| 825 | ExprObjectKind ok) { |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 826 | std::size_t Size = sizeof(MemberExpr); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 827 | |
John McCall | 161755a | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 828 | bool hasQualOrFound = (qual != 0 || |
| 829 | founddecl.getDecl() != memberdecl || |
| 830 | founddecl.getAccess() != memberdecl->getAccess()); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 831 | if (hasQualOrFound) |
| 832 | Size += sizeof(MemberNameQualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 834 | if (targs) |
| 835 | Size += ExplicitTemplateArgumentList::sizeFor(*targs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 836 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 837 | void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 838 | MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, |
| 839 | ty, vk, ok); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 840 | |
| 841 | if (hasQualOrFound) { |
| 842 | if (qual && qual->isDependent()) { |
| 843 | E->setValueDependent(true); |
| 844 | E->setTypeDependent(true); |
| 845 | } |
| 846 | E->HasQualifierOrFoundDecl = true; |
| 847 | |
| 848 | MemberNameQualifier *NQ = E->getMemberQualifier(); |
| 849 | NQ->NNS = qual; |
| 850 | NQ->Range = qualrange; |
| 851 | NQ->FoundDecl = founddecl; |
| 852 | } |
| 853 | |
| 854 | if (targs) { |
| 855 | E->HasExplicitTemplateArgumentList = true; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 856 | E->getExplicitTemplateArgs().initializeFrom(*targs); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | return E; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 862 | const char *CastExpr::getCastKindName() const { |
| 863 | switch (getCastKind()) { |
John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 864 | case CK_Dependent: |
| 865 | return "Dependent"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 866 | case CK_BitCast: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 867 | return "BitCast"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 868 | case CK_LValueBitCast: |
Douglas Gregor | e39a389 | 2010-07-13 23:17:26 +0000 | [diff] [blame] | 869 | return "LValueBitCast"; |
John McCall | 0ae287a | 2010-12-01 04:43:34 +0000 | [diff] [blame] | 870 | case CK_LValueToRValue: |
| 871 | return "LValueToRValue"; |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 872 | case CK_GetObjCProperty: |
| 873 | return "GetObjCProperty"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 874 | case CK_NoOp: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 875 | return "NoOp"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 876 | case CK_BaseToDerived: |
Anders Carlsson | 11de6de | 2009-11-12 16:43:42 +0000 | [diff] [blame] | 877 | return "BaseToDerived"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 878 | case CK_DerivedToBase: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 879 | return "DerivedToBase"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 880 | case CK_UncheckedDerivedToBase: |
John McCall | 23cba80 | 2010-03-30 23:58:03 +0000 | [diff] [blame] | 881 | return "UncheckedDerivedToBase"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 882 | case CK_Dynamic: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 883 | return "Dynamic"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 884 | case CK_ToUnion: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 885 | return "ToUnion"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 886 | case CK_ArrayToPointerDecay: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 887 | return "ArrayToPointerDecay"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 888 | case CK_FunctionToPointerDecay: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 889 | return "FunctionToPointerDecay"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 890 | case CK_NullToMemberPointer: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 891 | return "NullToMemberPointer"; |
John McCall | 404cd16 | 2010-11-13 01:35:44 +0000 | [diff] [blame] | 892 | case CK_NullToPointer: |
| 893 | return "NullToPointer"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 894 | case CK_BaseToDerivedMemberPointer: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 895 | return "BaseToDerivedMemberPointer"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 896 | case CK_DerivedToBaseMemberPointer: |
Anders Carlsson | 1a31a18 | 2009-10-30 00:46:35 +0000 | [diff] [blame] | 897 | return "DerivedToBaseMemberPointer"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 898 | case CK_UserDefinedConversion: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 899 | return "UserDefinedConversion"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 900 | case CK_ConstructorConversion: |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 901 | return "ConstructorConversion"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 902 | case CK_IntegralToPointer: |
Anders Carlsson | 7f9e646 | 2009-09-15 04:48:33 +0000 | [diff] [blame] | 903 | return "IntegralToPointer"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 904 | case CK_PointerToIntegral: |
Anders Carlsson | 7f9e646 | 2009-09-15 04:48:33 +0000 | [diff] [blame] | 905 | return "PointerToIntegral"; |
John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 906 | case CK_PointerToBoolean: |
| 907 | return "PointerToBoolean"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 908 | case CK_ToVoid: |
Anders Carlsson | ebeaf20 | 2009-10-16 02:35:04 +0000 | [diff] [blame] | 909 | return "ToVoid"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 910 | case CK_VectorSplat: |
Anders Carlsson | 16a8904 | 2009-10-16 05:23:41 +0000 | [diff] [blame] | 911 | return "VectorSplat"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 912 | case CK_IntegralCast: |
Anders Carlsson | 82debc7 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 913 | return "IntegralCast"; |
John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 914 | case CK_IntegralToBoolean: |
| 915 | return "IntegralToBoolean"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 916 | case CK_IntegralToFloating: |
Anders Carlsson | 82debc7 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 917 | return "IntegralToFloating"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 918 | case CK_FloatingToIntegral: |
Anders Carlsson | 82debc7 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 919 | return "FloatingToIntegral"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 920 | case CK_FloatingCast: |
Benjamin Kramer | c6b2916 | 2009-10-18 19:02:15 +0000 | [diff] [blame] | 921 | return "FloatingCast"; |
John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 922 | case CK_FloatingToBoolean: |
| 923 | return "FloatingToBoolean"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 924 | case CK_MemberPointerToBoolean: |
Anders Carlsson | bc0e078 | 2009-11-23 20:04:44 +0000 | [diff] [blame] | 925 | return "MemberPointerToBoolean"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 926 | case CK_AnyPointerToObjCPointerCast: |
Fariborz Jahanian | 4cbf9d4 | 2009-12-08 23:46:15 +0000 | [diff] [blame] | 927 | return "AnyPointerToObjCPointerCast"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 928 | case CK_AnyPointerToBlockPointerCast: |
Fariborz Jahanian | 3b27f1a | 2009-12-11 22:40:48 +0000 | [diff] [blame] | 929 | return "AnyPointerToBlockPointerCast"; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 930 | case CK_ObjCObjectLValueCast: |
Douglas Gregor | 569c316 | 2010-08-07 11:51:51 +0000 | [diff] [blame] | 931 | return "ObjCObjectLValueCast"; |
John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 932 | case CK_FloatingRealToComplex: |
| 933 | return "FloatingRealToComplex"; |
John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 934 | case CK_FloatingComplexToReal: |
| 935 | return "FloatingComplexToReal"; |
| 936 | case CK_FloatingComplexToBoolean: |
| 937 | return "FloatingComplexToBoolean"; |
John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 938 | case CK_FloatingComplexCast: |
| 939 | return "FloatingComplexCast"; |
John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 940 | case CK_FloatingComplexToIntegralComplex: |
| 941 | return "FloatingComplexToIntegralComplex"; |
John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 942 | case CK_IntegralRealToComplex: |
| 943 | return "IntegralRealToComplex"; |
John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 944 | case CK_IntegralComplexToReal: |
| 945 | return "IntegralComplexToReal"; |
| 946 | case CK_IntegralComplexToBoolean: |
| 947 | return "IntegralComplexToBoolean"; |
John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 948 | case CK_IntegralComplexCast: |
| 949 | return "IntegralComplexCast"; |
John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 950 | case CK_IntegralComplexToFloatingComplex: |
| 951 | return "IntegralComplexToFloatingComplex"; |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 952 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | |
John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 954 | llvm_unreachable("Unhandled cast kind!"); |
Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 955 | return 0; |
| 956 | } |
| 957 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 958 | Expr *CastExpr::getSubExprAsWritten() { |
| 959 | Expr *SubExpr = 0; |
| 960 | CastExpr *E = this; |
| 961 | do { |
| 962 | SubExpr = E->getSubExpr(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 963 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 964 | // Skip any temporary bindings; they're implicit. |
| 965 | if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) |
| 966 | SubExpr = Binder->getSubExpr(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 967 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 968 | // Conversions by constructor and conversion functions have a |
| 969 | // subexpression describing the call; strip it off. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 970 | if (E->getCastKind() == CK_ConstructorConversion) |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 971 | SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 972 | else if (E->getCastKind() == CK_UserDefinedConversion) |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 973 | SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 974 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 975 | // If the subexpression we're left with is an implicit cast, look |
| 976 | // through that, too. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 977 | } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); |
| 978 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 979 | return SubExpr; |
| 980 | } |
| 981 | |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 982 | CXXBaseSpecifier **CastExpr::path_buffer() { |
| 983 | switch (getStmtClass()) { |
| 984 | #define ABSTRACT_STMT(x) |
| 985 | #define CASTEXPR(Type, Base) \ |
| 986 | case Stmt::Type##Class: \ |
| 987 | return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); |
| 988 | #define STMT(Type, Base) |
| 989 | #include "clang/AST/StmtNodes.inc" |
| 990 | default: |
| 991 | llvm_unreachable("non-cast expressions not possible here"); |
| 992 | return 0; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | void CastExpr::setCastPath(const CXXCastPath &Path) { |
| 997 | assert(Path.size() == path_size()); |
| 998 | memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); |
| 999 | } |
| 1000 | |
| 1001 | ImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, |
| 1002 | CastKind Kind, Expr *Operand, |
| 1003 | const CXXCastPath *BasePath, |
John McCall | 5baba9d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 1004 | ExprValueKind VK) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1005 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 1006 | void *Buffer = |
| 1007 | C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 1008 | ImplicitCastExpr *E = |
John McCall | 5baba9d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 1009 | new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1010 | if (PathSize) E->setCastPath(*BasePath); |
| 1011 | return E; |
| 1012 | } |
| 1013 | |
| 1014 | ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, |
| 1015 | unsigned PathSize) { |
| 1016 | void *Buffer = |
| 1017 | C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 1018 | return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | CStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1023 | ExprValueKind VK, CastKind K, Expr *Op, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1024 | const CXXCastPath *BasePath, |
| 1025 | TypeSourceInfo *WrittenTy, |
| 1026 | SourceLocation L, SourceLocation R) { |
| 1027 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 1028 | void *Buffer = |
| 1029 | C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 1030 | CStyleCastExpr *E = |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1031 | new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1032 | if (PathSize) E->setCastPath(*BasePath); |
| 1033 | return E; |
| 1034 | } |
| 1035 | |
| 1036 | CStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 1037 | void *Buffer = |
| 1038 | C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 1039 | return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); |
| 1040 | } |
| 1041 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1042 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 1043 | /// corresponds to, e.g. "<<=". |
| 1044 | const char *BinaryOperator::getOpcodeStr(Opcode Op) { |
| 1045 | switch (Op) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1046 | case BO_PtrMemD: return ".*"; |
| 1047 | case BO_PtrMemI: return "->*"; |
| 1048 | case BO_Mul: return "*"; |
| 1049 | case BO_Div: return "/"; |
| 1050 | case BO_Rem: return "%"; |
| 1051 | case BO_Add: return "+"; |
| 1052 | case BO_Sub: return "-"; |
| 1053 | case BO_Shl: return "<<"; |
| 1054 | case BO_Shr: return ">>"; |
| 1055 | case BO_LT: return "<"; |
| 1056 | case BO_GT: return ">"; |
| 1057 | case BO_LE: return "<="; |
| 1058 | case BO_GE: return ">="; |
| 1059 | case BO_EQ: return "=="; |
| 1060 | case BO_NE: return "!="; |
| 1061 | case BO_And: return "&"; |
| 1062 | case BO_Xor: return "^"; |
| 1063 | case BO_Or: return "|"; |
| 1064 | case BO_LAnd: return "&&"; |
| 1065 | case BO_LOr: return "||"; |
| 1066 | case BO_Assign: return "="; |
| 1067 | case BO_MulAssign: return "*="; |
| 1068 | case BO_DivAssign: return "/="; |
| 1069 | case BO_RemAssign: return "%="; |
| 1070 | case BO_AddAssign: return "+="; |
| 1071 | case BO_SubAssign: return "-="; |
| 1072 | case BO_ShlAssign: return "<<="; |
| 1073 | case BO_ShrAssign: return ">>="; |
| 1074 | case BO_AndAssign: return "&="; |
| 1075 | case BO_XorAssign: return "^="; |
| 1076 | case BO_OrAssign: return "|="; |
| 1077 | case BO_Comma: return ","; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1078 | } |
Douglas Gregor | baf5348 | 2009-03-12 22:51:37 +0000 | [diff] [blame] | 1079 | |
| 1080 | return ""; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1083 | BinaryOperatorKind |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 1084 | BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { |
| 1085 | switch (OO) { |
Chris Lattner | b7beee9 | 2009-03-22 00:10:22 +0000 | [diff] [blame] | 1086 | default: assert(false && "Not an overloadable binary operator"); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1087 | case OO_Plus: return BO_Add; |
| 1088 | case OO_Minus: return BO_Sub; |
| 1089 | case OO_Star: return BO_Mul; |
| 1090 | case OO_Slash: return BO_Div; |
| 1091 | case OO_Percent: return BO_Rem; |
| 1092 | case OO_Caret: return BO_Xor; |
| 1093 | case OO_Amp: return BO_And; |
| 1094 | case OO_Pipe: return BO_Or; |
| 1095 | case OO_Equal: return BO_Assign; |
| 1096 | case OO_Less: return BO_LT; |
| 1097 | case OO_Greater: return BO_GT; |
| 1098 | case OO_PlusEqual: return BO_AddAssign; |
| 1099 | case OO_MinusEqual: return BO_SubAssign; |
| 1100 | case OO_StarEqual: return BO_MulAssign; |
| 1101 | case OO_SlashEqual: return BO_DivAssign; |
| 1102 | case OO_PercentEqual: return BO_RemAssign; |
| 1103 | case OO_CaretEqual: return BO_XorAssign; |
| 1104 | case OO_AmpEqual: return BO_AndAssign; |
| 1105 | case OO_PipeEqual: return BO_OrAssign; |
| 1106 | case OO_LessLess: return BO_Shl; |
| 1107 | case OO_GreaterGreater: return BO_Shr; |
| 1108 | case OO_LessLessEqual: return BO_ShlAssign; |
| 1109 | case OO_GreaterGreaterEqual: return BO_ShrAssign; |
| 1110 | case OO_EqualEqual: return BO_EQ; |
| 1111 | case OO_ExclaimEqual: return BO_NE; |
| 1112 | case OO_LessEqual: return BO_LE; |
| 1113 | case OO_GreaterEqual: return BO_GE; |
| 1114 | case OO_AmpAmp: return BO_LAnd; |
| 1115 | case OO_PipePipe: return BO_LOr; |
| 1116 | case OO_Comma: return BO_Comma; |
| 1117 | case OO_ArrowStar: return BO_PtrMemI; |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { |
| 1122 | static const OverloadedOperatorKind OverOps[] = { |
| 1123 | /* .* Cannot be overloaded */OO_None, OO_ArrowStar, |
| 1124 | OO_Star, OO_Slash, OO_Percent, |
| 1125 | OO_Plus, OO_Minus, |
| 1126 | OO_LessLess, OO_GreaterGreater, |
| 1127 | OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, |
| 1128 | OO_EqualEqual, OO_ExclaimEqual, |
| 1129 | OO_Amp, |
| 1130 | OO_Caret, |
| 1131 | OO_Pipe, |
| 1132 | OO_AmpAmp, |
| 1133 | OO_PipePipe, |
| 1134 | OO_Equal, OO_StarEqual, |
| 1135 | OO_SlashEqual, OO_PercentEqual, |
| 1136 | OO_PlusEqual, OO_MinusEqual, |
| 1137 | OO_LessLessEqual, OO_GreaterGreaterEqual, |
| 1138 | OO_AmpEqual, OO_CaretEqual, |
| 1139 | OO_PipeEqual, |
| 1140 | OO_Comma |
| 1141 | }; |
| 1142 | return OverOps[Opc]; |
| 1143 | } |
| 1144 | |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1145 | InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, |
Chris Lattner | 418f6c7 | 2008-10-26 23:43:26 +0000 | [diff] [blame] | 1146 | Expr **initExprs, unsigned numInits, |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1147 | SourceLocation rbraceloc) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 1148 | : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, |
| 1149 | false), |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1150 | InitExprs(C, numInits), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1152 | UnionFieldInit(0), HadArrayRangeDesignator(false) |
| 1153 | { |
Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1154 | for (unsigned I = 0; I != numInits; ++I) { |
| 1155 | if (initExprs[I]->isTypeDependent()) |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 1156 | ExprBits.TypeDependent = true; |
Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1157 | if (initExprs[I]->isValueDependent()) |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 1158 | ExprBits.ValueDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 1159 | if (initExprs[I]->containsUnexpandedParameterPack()) |
| 1160 | ExprBits.ContainsUnexpandedParameterPack = true; |
Douglas Gregor | 73460a3 | 2009-11-19 23:25:22 +0000 | [diff] [blame] | 1161 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1162 | |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1163 | InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 1164 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1165 | |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1166 | void InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { |
Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1167 | if (NumInits > InitExprs.size()) |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1168 | InitExprs.reserve(C, NumInits); |
Douglas Gregor | fa21920 | 2009-03-20 23:58:33 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1171 | void InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1172 | InitExprs.resize(C, NumInits, 0); |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1175 | Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { |
Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1176 | if (Init >= InitExprs.size()) { |
Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1177 | InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); |
Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1178 | InitExprs.back() = expr; |
| 1179 | return 0; |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1182 | Expr *Result = cast_or_null<Expr>(InitExprs[Init]); |
| 1183 | InitExprs[Init] = expr; |
| 1184 | return Result; |
| 1185 | } |
| 1186 | |
Ted Kremenek | c4ba51f | 2010-11-09 02:11:40 +0000 | [diff] [blame] | 1187 | SourceRange InitListExpr::getSourceRange() const { |
| 1188 | if (SyntacticForm) |
| 1189 | return SyntacticForm->getSourceRange(); |
| 1190 | SourceLocation Beg = LBraceLoc, End = RBraceLoc; |
| 1191 | if (Beg.isInvalid()) { |
| 1192 | // Find the first non-null initializer. |
| 1193 | for (InitExprsTy::const_iterator I = InitExprs.begin(), |
| 1194 | E = InitExprs.end(); |
| 1195 | I != E; ++I) { |
| 1196 | if (Stmt *S = *I) { |
| 1197 | Beg = S->getLocStart(); |
| 1198 | break; |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | if (End.isInvalid()) { |
| 1203 | // Find the first non-null initializer from the end. |
| 1204 | for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), |
| 1205 | E = InitExprs.rend(); |
| 1206 | I != E; ++I) { |
| 1207 | if (Stmt *S = *I) { |
| 1208 | End = S->getSourceRange().getEnd(); |
| 1209 | break; |
| 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | return SourceRange(Beg, End); |
| 1214 | } |
| 1215 | |
Steve Naroff | bfdcae6 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 1216 | /// getFunctionType - Return the underlying function type for this block. |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1217 | /// |
| 1218 | const FunctionType *BlockExpr::getFunctionType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 1219 | return getType()->getAs<BlockPointerType>()-> |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1220 | getPointeeType()->getAs<FunctionType>(); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | SourceLocation BlockExpr::getCaretLocation() const { |
| 1224 | return TheBlock->getCaretLocation(); |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1225 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | const Stmt *BlockExpr::getBody() const { |
Douglas Gregor | 7297134 | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 1227 | return TheBlock->getBody(); |
| 1228 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | Stmt *BlockExpr::getBody() { |
| 1230 | return TheBlock->getBody(); |
Douglas Gregor | 7297134 | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 1231 | } |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1232 | |
| 1233 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1234 | //===----------------------------------------------------------------------===// |
| 1235 | // Generic Expression Routines |
| 1236 | //===----------------------------------------------------------------------===// |
| 1237 | |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1238 | /// isUnusedResultAWarning - Return true if this immediate expression should |
| 1239 | /// be warned about if the result is unused. If so, fill in Loc and Ranges |
| 1240 | /// with location to warn on and the source range[s] to report with the |
| 1241 | /// warning. |
| 1242 | bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1243 | SourceRange &R2, ASTContext &Ctx) const { |
Anders Carlsson | ffce2df | 2009-05-15 23:10:19 +0000 | [diff] [blame] | 1244 | // Don't warn if the expr is type dependent. The type could end up |
| 1245 | // instantiating to void. |
| 1246 | if (isTypeDependent()) |
| 1247 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1248 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1249 | switch (getStmtClass()) { |
| 1250 | default: |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1251 | if (getType()->isVoidType()) |
| 1252 | return false; |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1253 | Loc = getExprLoc(); |
| 1254 | R1 = getSourceRange(); |
| 1255 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1256 | case ParenExprClass: |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1257 | return cast<ParenExpr>(this)->getSubExpr()-> |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1258 | isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1259 | case UnaryOperatorClass: { |
| 1260 | const UnaryOperator *UO = cast<UnaryOperator>(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1261 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1262 | switch (UO->getOpcode()) { |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1263 | default: break; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1264 | case UO_PostInc: |
| 1265 | case UO_PostDec: |
| 1266 | case UO_PreInc: |
| 1267 | case UO_PreDec: // ++/-- |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1268 | return false; // Not a warning. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1269 | case UO_Deref: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1270 | // Dereferencing a volatile pointer is a side-effect. |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1271 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1272 | return false; |
| 1273 | break; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1274 | case UO_Real: |
| 1275 | case UO_Imag: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1276 | // accessing a piece of a volatile complex is a side-effect. |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1277 | if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) |
| 1278 | .isVolatileQualified()) |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1279 | return false; |
| 1280 | break; |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1281 | case UO_Extension: |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1282 | return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1283 | } |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1284 | Loc = UO->getOperatorLoc(); |
| 1285 | R1 = UO->getSubExpr()->getSourceRange(); |
| 1286 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1287 | } |
Chris Lattner | e7716e6 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 1288 | case BinaryOperatorClass: { |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1289 | const BinaryOperator *BO = cast<BinaryOperator>(this); |
Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 1290 | switch (BO->getOpcode()) { |
| 1291 | default: |
| 1292 | break; |
Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 1293 | // Consider the RHS of comma for side effects. LHS was checked by |
| 1294 | // Sema::CheckCommaOperands. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1295 | case BO_Comma: |
Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 1296 | // ((foo = <blah>), 0) is an idiom for hiding the result (and |
| 1297 | // lvalue-ness) of an assignment written in a macro. |
| 1298 | if (IntegerLiteral *IE = |
| 1299 | dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) |
| 1300 | if (IE->getValue() == 0) |
| 1301 | return false; |
Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 1302 | return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
| 1303 | // Consider '||', '&&' to have side effects if the LHS or RHS does. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1304 | case BO_LAnd: |
| 1305 | case BO_LOr: |
Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 1306 | if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || |
| 1307 | !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) |
| 1308 | return false; |
| 1309 | break; |
John McCall | bf0ee35 | 2010-02-16 04:10:53 +0000 | [diff] [blame] | 1310 | } |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1311 | if (BO->isAssignmentOp()) |
| 1312 | return false; |
| 1313 | Loc = BO->getOperatorLoc(); |
| 1314 | R1 = BO->getLHS()->getSourceRange(); |
| 1315 | R2 = BO->getRHS()->getSourceRange(); |
| 1316 | return true; |
Chris Lattner | e7716e6 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 1317 | } |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 1318 | case CompoundAssignOperatorClass: |
Douglas Gregor | c6dfe19 | 2010-05-08 22:41:50 +0000 | [diff] [blame] | 1319 | case VAArgExprClass: |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1320 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1321 | |
Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 1322 | case ConditionalOperatorClass: { |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1323 | // The condition must be evaluated, but if either the LHS or RHS is a |
| 1324 | // warning, warn about them. |
Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 1325 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | if (Exp->getLHS() && |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1327 | Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1328 | return true; |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1329 | return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1332 | case MemberExprClass: |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1333 | // If the base pointer or element is to a volatile pointer/field, accessing |
| 1334 | // it is a side effect. |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1335 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1336 | return false; |
| 1337 | Loc = cast<MemberExpr>(this)->getMemberLoc(); |
| 1338 | R1 = SourceRange(Loc, Loc); |
| 1339 | R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); |
| 1340 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1342 | case ArraySubscriptExprClass: |
| 1343 | // If the base pointer or element is to a volatile pointer/field, accessing |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1344 | // it is a side effect. |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1345 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1346 | return false; |
| 1347 | Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); |
| 1348 | R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); |
| 1349 | R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); |
| 1350 | return true; |
Eli Friedman | 211f6ad | 2008-05-27 15:24:04 +0000 | [diff] [blame] | 1351 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1352 | case CallExprClass: |
Eli Friedman | 852871a | 2009-04-29 16:35:53 +0000 | [diff] [blame] | 1353 | case CXXOperatorCallExprClass: |
| 1354 | case CXXMemberCallExprClass: { |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1355 | // If this is a direct call, get the callee. |
| 1356 | const CallExpr *CE = cast<CallExpr>(this); |
Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 1357 | if (const Decl *FD = CE->getCalleeDecl()) { |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1358 | // If the callee has attribute pure, const, or warn_unused_result, warn |
| 1359 | // about it. void foo() { strlen("bar"); } should warn. |
Chris Lattner | bc8d42c | 2009-10-13 04:53:48 +0000 | [diff] [blame] | 1360 | // |
| 1361 | // Note: If new cases are added here, DiagnoseUnusedExprResult should be |
| 1362 | // updated to match for QoI. |
| 1363 | if (FD->getAttr<WarnUnusedResultAttr>() || |
| 1364 | FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { |
| 1365 | Loc = CE->getCallee()->getLocStart(); |
| 1366 | R1 = CE->getCallee()->getSourceRange(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Chris Lattner | bc8d42c | 2009-10-13 04:53:48 +0000 | [diff] [blame] | 1368 | if (unsigned NumArgs = CE->getNumArgs()) |
| 1369 | R2 = SourceRange(CE->getArg(0)->getLocStart(), |
| 1370 | CE->getArg(NumArgs-1)->getLocEnd()); |
| 1371 | return true; |
| 1372 | } |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1373 | } |
| 1374 | return false; |
| 1375 | } |
Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1376 | |
| 1377 | case CXXTemporaryObjectExprClass: |
| 1378 | case CXXConstructExprClass: |
| 1379 | return false; |
| 1380 | |
Fariborz Jahanian | f031774 | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1381 | case ObjCMessageExprClass: { |
| 1382 | const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); |
| 1383 | const ObjCMethodDecl *MD = ME->getMethodDecl(); |
| 1384 | if (MD && MD->getAttr<WarnUnusedResultAttr>()) { |
| 1385 | Loc = getExprLoc(); |
| 1386 | return true; |
| 1387 | } |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1388 | return false; |
Fariborz Jahanian | f031774 | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1391 | case ObjCPropertyRefExprClass: |
Chris Lattner | 5e94a0d | 2009-08-16 16:51:50 +0000 | [diff] [blame] | 1392 | Loc = getExprLoc(); |
| 1393 | R1 = getSourceRange(); |
Chris Lattner | a50089e | 2009-08-16 16:45:18 +0000 | [diff] [blame] | 1394 | return true; |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1395 | |
Chris Lattner | 611b2ec | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1396 | case StmtExprClass: { |
| 1397 | // Statement exprs don't logically have side effects themselves, but are |
| 1398 | // sometimes used in macros in ways that give them a type that is unused. |
| 1399 | // For example ({ blah; foo(); }) will end up with a type if foo has a type. |
| 1400 | // however, if the result of the stmt expr is dead, we don't want to emit a |
| 1401 | // warning. |
| 1402 | const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); |
Argyrios Kyrtzidis | d2827af | 2010-09-19 21:21:10 +0000 | [diff] [blame] | 1403 | if (!CS->body_empty()) { |
Chris Lattner | 611b2ec | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1404 | if (const Expr *E = dyn_cast<Expr>(CS->body_back())) |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1405 | return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Argyrios Kyrtzidis | d2827af | 2010-09-19 21:21:10 +0000 | [diff] [blame] | 1406 | if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) |
| 1407 | if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) |
| 1408 | return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
| 1409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1411 | if (getType()->isVoidType()) |
| 1412 | return false; |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1413 | Loc = cast<StmtExpr>(this)->getLParenLoc(); |
| 1414 | R1 = getSourceRange(); |
| 1415 | return true; |
Chris Lattner | 611b2ec | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1416 | } |
Douglas Gregor | 6eec8e8 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 1417 | case CStyleCastExprClass: |
Chris Lattner | fb84664 | 2009-07-28 18:25:28 +0000 | [diff] [blame] | 1418 | // If this is an explicit cast to void, allow it. People do this when they |
| 1419 | // think they know what they're doing :). |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1420 | if (getType()->isVoidType()) |
Chris Lattner | fb84664 | 2009-07-28 18:25:28 +0000 | [diff] [blame] | 1421 | return false; |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1422 | Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); |
| 1423 | R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); |
| 1424 | return true; |
Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1425 | case CXXFunctionalCastExprClass: { |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1426 | if (getType()->isVoidType()) |
| 1427 | return false; |
Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1428 | const CastExpr *CE = cast<CastExpr>(this); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1429 | |
Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1430 | // If this is a cast to void or a constructor conversion, check the operand. |
| 1431 | // Otherwise, the result of the cast is unused. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1432 | if (CE->getCastKind() == CK_ToVoid || |
| 1433 | CE->getCastKind() == CK_ConstructorConversion) |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1434 | return (cast<CastExpr>(this)->getSubExpr() |
| 1435 | ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1436 | Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); |
| 1437 | R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); |
| 1438 | return true; |
Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1440 | |
Eli Friedman | 4be1f47 | 2008-05-19 21:24:43 +0000 | [diff] [blame] | 1441 | case ImplicitCastExprClass: |
| 1442 | // Check the operand, since implicit casts are inserted by Sema |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1443 | return (cast<ImplicitCastExpr>(this) |
| 1444 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Eli Friedman | 4be1f47 | 2008-05-19 21:24:43 +0000 | [diff] [blame] | 1445 | |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1446 | case CXXDefaultArgExprClass: |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1447 | return (cast<CXXDefaultArgExpr>(this) |
| 1448 | ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1449 | |
| 1450 | case CXXNewExprClass: |
| 1451 | // FIXME: In theory, there might be new expressions that don't have side |
| 1452 | // effects (e.g. a placement new with an uninitialized POD). |
| 1453 | case CXXDeleteExprClass: |
Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1454 | return false; |
Anders Carlsson | 2d46eb2 | 2009-08-16 04:11:06 +0000 | [diff] [blame] | 1455 | case CXXBindTemporaryExprClass: |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1456 | return (cast<CXXBindTemporaryExpr>(this) |
| 1457 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 1458 | case ExprWithCleanupsClass: |
| 1459 | return (cast<ExprWithCleanups>(this) |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1460 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1461 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1464 | /// isOBJCGCCandidate - Check if an expression is objc gc'able. |
Fariborz Jahanian | 7f4f86a | 2009-09-08 23:38:54 +0000 | [diff] [blame] | 1465 | /// returns true, if it is; false otherwise. |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1466 | bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1467 | switch (getStmtClass()) { |
| 1468 | default: |
| 1469 | return false; |
| 1470 | case ObjCIvarRefExprClass: |
| 1471 | return true; |
Fariborz Jahanian | 207c521 | 2009-02-23 18:59:50 +0000 | [diff] [blame] | 1472 | case Expr::UnaryOperatorClass: |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1473 | return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1474 | case ParenExprClass: |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1475 | return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1476 | case ImplicitCastExprClass: |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1477 | return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 06b8912 | 2009-05-05 23:28:21 +0000 | [diff] [blame] | 1478 | case CStyleCastExprClass: |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1479 | return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1480 | case DeclRefExprClass: { |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1481 | const Decl *D = cast<DeclRefExpr>(this)->getDecl(); |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1482 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 1483 | if (VD->hasGlobalStorage()) |
| 1484 | return true; |
| 1485 | QualType T = VD->getType(); |
Fariborz Jahanian | 59a53fa | 2009-09-16 18:09:18 +0000 | [diff] [blame] | 1486 | // dereferencing to a pointer is always a gc'able candidate, |
| 1487 | // unless it is __weak. |
Daniel Dunbar | 7e88a60 | 2009-09-17 06:31:17 +0000 | [diff] [blame] | 1488 | return T->isPointerType() && |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1489 | (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1490 | } |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1491 | return false; |
| 1492 | } |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1493 | case MemberExprClass: { |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1494 | const MemberExpr *M = cast<MemberExpr>(this); |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1495 | return M->getBase()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1496 | } |
| 1497 | case ArraySubscriptExprClass: |
Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1498 | return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1499 | } |
| 1500 | } |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1501 | |
Argyrios Kyrtzidis | 11ab790 | 2010-11-01 18:49:26 +0000 | [diff] [blame] | 1502 | bool Expr::isBoundMemberFunction(ASTContext &Ctx) const { |
| 1503 | if (isTypeDependent()) |
| 1504 | return false; |
John McCall | 7eb0a9e | 2010-11-24 05:12:34 +0000 | [diff] [blame] | 1505 | return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; |
Argyrios Kyrtzidis | 11ab790 | 2010-11-01 18:49:26 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1508 | static Expr::CanThrowResult MergeCanThrow(Expr::CanThrowResult CT1, |
| 1509 | Expr::CanThrowResult CT2) { |
| 1510 | // CanThrowResult constants are ordered so that the maximum is the correct |
| 1511 | // merge result. |
| 1512 | return CT1 > CT2 ? CT1 : CT2; |
| 1513 | } |
| 1514 | |
| 1515 | static Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) { |
| 1516 | Expr *E = const_cast<Expr*>(CE); |
| 1517 | Expr::CanThrowResult R = Expr::CT_Cannot; |
| 1518 | for (Expr::child_iterator I = E->child_begin(), IE = E->child_end(); |
| 1519 | I != IE && R != Expr::CT_Can; ++I) { |
| 1520 | R = MergeCanThrow(R, cast<Expr>(*I)->CanThrow(C)); |
| 1521 | } |
| 1522 | return R; |
| 1523 | } |
| 1524 | |
| 1525 | static Expr::CanThrowResult CanCalleeThrow(const Decl *D, |
| 1526 | bool NullThrows = true) { |
| 1527 | if (!D) |
| 1528 | return NullThrows ? Expr::CT_Can : Expr::CT_Cannot; |
| 1529 | |
| 1530 | // See if we can get a function type from the decl somehow. |
| 1531 | const ValueDecl *VD = dyn_cast<ValueDecl>(D); |
| 1532 | if (!VD) // If we have no clue what we're calling, assume the worst. |
| 1533 | return Expr::CT_Can; |
| 1534 | |
Sebastian Redl | 5221d8f | 2010-09-10 22:34:40 +0000 | [diff] [blame] | 1535 | // As an extension, we assume that __attribute__((nothrow)) functions don't |
| 1536 | // throw. |
| 1537 | if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>()) |
| 1538 | return Expr::CT_Cannot; |
| 1539 | |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1540 | QualType T = VD->getType(); |
| 1541 | const FunctionProtoType *FT; |
| 1542 | if ((FT = T->getAs<FunctionProtoType>())) { |
| 1543 | } else if (const PointerType *PT = T->getAs<PointerType>()) |
| 1544 | FT = PT->getPointeeType()->getAs<FunctionProtoType>(); |
| 1545 | else if (const ReferenceType *RT = T->getAs<ReferenceType>()) |
| 1546 | FT = RT->getPointeeType()->getAs<FunctionProtoType>(); |
| 1547 | else if (const MemberPointerType *MT = T->getAs<MemberPointerType>()) |
| 1548 | FT = MT->getPointeeType()->getAs<FunctionProtoType>(); |
| 1549 | else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) |
| 1550 | FT = BT->getPointeeType()->getAs<FunctionProtoType>(); |
| 1551 | |
| 1552 | if (!FT) |
| 1553 | return Expr::CT_Can; |
| 1554 | |
| 1555 | return FT->hasEmptyExceptionSpec() ? Expr::CT_Cannot : Expr::CT_Can; |
| 1556 | } |
| 1557 | |
| 1558 | static Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) { |
| 1559 | if (DC->isTypeDependent()) |
| 1560 | return Expr::CT_Dependent; |
| 1561 | |
Sebastian Redl | 295995c | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 1562 | if (!DC->getTypeAsWritten()->isReferenceType()) |
| 1563 | return Expr::CT_Cannot; |
| 1564 | |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1565 | return DC->getCastKind() == clang::CK_Dynamic? Expr::CT_Can : Expr::CT_Cannot; |
| 1566 | } |
| 1567 | |
| 1568 | static Expr::CanThrowResult CanTypeidThrow(ASTContext &C, |
| 1569 | const CXXTypeidExpr *DC) { |
| 1570 | if (DC->isTypeOperand()) |
| 1571 | return Expr::CT_Cannot; |
| 1572 | |
| 1573 | Expr *Op = DC->getExprOperand(); |
| 1574 | if (Op->isTypeDependent()) |
| 1575 | return Expr::CT_Dependent; |
| 1576 | |
| 1577 | const RecordType *RT = Op->getType()->getAs<RecordType>(); |
| 1578 | if (!RT) |
| 1579 | return Expr::CT_Cannot; |
| 1580 | |
| 1581 | if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic()) |
| 1582 | return Expr::CT_Cannot; |
| 1583 | |
| 1584 | if (Op->Classify(C).isPRValue()) |
| 1585 | return Expr::CT_Cannot; |
| 1586 | |
| 1587 | return Expr::CT_Can; |
| 1588 | } |
| 1589 | |
| 1590 | Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { |
| 1591 | // C++ [expr.unary.noexcept]p3: |
| 1592 | // [Can throw] if in a potentially-evaluated context the expression would |
| 1593 | // contain: |
| 1594 | switch (getStmtClass()) { |
| 1595 | case CXXThrowExprClass: |
| 1596 | // - a potentially evaluated throw-expression |
| 1597 | return CT_Can; |
| 1598 | |
| 1599 | case CXXDynamicCastExprClass: { |
| 1600 | // - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), |
| 1601 | // where T is a reference type, that requires a run-time check |
| 1602 | CanThrowResult CT = CanDynamicCastThrow(cast<CXXDynamicCastExpr>(this)); |
| 1603 | if (CT == CT_Can) |
| 1604 | return CT; |
| 1605 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1606 | } |
| 1607 | |
| 1608 | case CXXTypeidExprClass: |
| 1609 | // - a potentially evaluated typeid expression applied to a glvalue |
| 1610 | // expression whose type is a polymorphic class type |
| 1611 | return CanTypeidThrow(C, cast<CXXTypeidExpr>(this)); |
| 1612 | |
| 1613 | // - a potentially evaluated call to a function, member function, function |
| 1614 | // pointer, or member function pointer that does not have a non-throwing |
| 1615 | // exception-specification |
| 1616 | case CallExprClass: |
| 1617 | case CXXOperatorCallExprClass: |
| 1618 | case CXXMemberCallExprClass: { |
| 1619 | CanThrowResult CT = CanCalleeThrow(cast<CallExpr>(this)->getCalleeDecl()); |
| 1620 | if (CT == CT_Can) |
| 1621 | return CT; |
| 1622 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1623 | } |
| 1624 | |
Sebastian Redl | 295995c | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 1625 | case CXXConstructExprClass: |
| 1626 | case CXXTemporaryObjectExprClass: { |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1627 | CanThrowResult CT = CanCalleeThrow( |
| 1628 | cast<CXXConstructExpr>(this)->getConstructor()); |
| 1629 | if (CT == CT_Can) |
| 1630 | return CT; |
| 1631 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1632 | } |
| 1633 | |
| 1634 | case CXXNewExprClass: { |
| 1635 | CanThrowResult CT = MergeCanThrow( |
| 1636 | CanCalleeThrow(cast<CXXNewExpr>(this)->getOperatorNew()), |
| 1637 | CanCalleeThrow(cast<CXXNewExpr>(this)->getConstructor(), |
| 1638 | /*NullThrows*/false)); |
| 1639 | if (CT == CT_Can) |
| 1640 | return CT; |
| 1641 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1642 | } |
| 1643 | |
| 1644 | case CXXDeleteExprClass: { |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1645 | CanThrowResult CT = CanCalleeThrow( |
| 1646 | cast<CXXDeleteExpr>(this)->getOperatorDelete()); |
| 1647 | if (CT == CT_Can) |
| 1648 | return CT; |
Sebastian Redl | 0b34cf7 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 1649 | const Expr *Arg = cast<CXXDeleteExpr>(this)->getArgument(); |
| 1650 | // Unwrap exactly one implicit cast, which converts all pointers to void*. |
| 1651 | if (const ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(Arg)) |
| 1652 | Arg = Cast->getSubExpr(); |
| 1653 | if (const PointerType *PT = Arg->getType()->getAs<PointerType>()) { |
| 1654 | if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) { |
| 1655 | CanThrowResult CT2 = CanCalleeThrow( |
| 1656 | cast<CXXRecordDecl>(RT->getDecl())->getDestructor()); |
| 1657 | if (CT2 == CT_Can) |
| 1658 | return CT2; |
| 1659 | CT = MergeCanThrow(CT, CT2); |
| 1660 | } |
| 1661 | } |
| 1662 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1663 | } |
| 1664 | |
| 1665 | case CXXBindTemporaryExprClass: { |
| 1666 | // The bound temporary has to be destroyed again, which might throw. |
| 1667 | CanThrowResult CT = CanCalleeThrow( |
| 1668 | cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor()); |
| 1669 | if (CT == CT_Can) |
| 1670 | return CT; |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1671 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1672 | } |
| 1673 | |
| 1674 | // ObjC message sends are like function calls, but never have exception |
| 1675 | // specs. |
| 1676 | case ObjCMessageExprClass: |
| 1677 | case ObjCPropertyRefExprClass: |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1678 | return CT_Can; |
| 1679 | |
| 1680 | // Many other things have subexpressions, so we have to test those. |
| 1681 | // Some are simple: |
| 1682 | case ParenExprClass: |
| 1683 | case MemberExprClass: |
| 1684 | case CXXReinterpretCastExprClass: |
| 1685 | case CXXConstCastExprClass: |
| 1686 | case ConditionalOperatorClass: |
| 1687 | case CompoundLiteralExprClass: |
| 1688 | case ExtVectorElementExprClass: |
| 1689 | case InitListExprClass: |
| 1690 | case DesignatedInitExprClass: |
| 1691 | case ParenListExprClass: |
| 1692 | case VAArgExprClass: |
| 1693 | case CXXDefaultArgExprClass: |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 1694 | case ExprWithCleanupsClass: |
Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1695 | case ObjCIvarRefExprClass: |
| 1696 | case ObjCIsaExprClass: |
| 1697 | case ShuffleVectorExprClass: |
| 1698 | return CanSubExprsThrow(C, this); |
| 1699 | |
| 1700 | // Some might be dependent for other reasons. |
| 1701 | case UnaryOperatorClass: |
| 1702 | case ArraySubscriptExprClass: |
| 1703 | case ImplicitCastExprClass: |
| 1704 | case CStyleCastExprClass: |
| 1705 | case CXXStaticCastExprClass: |
| 1706 | case CXXFunctionalCastExprClass: |
| 1707 | case BinaryOperatorClass: |
| 1708 | case CompoundAssignOperatorClass: { |
| 1709 | CanThrowResult CT = isTypeDependent() ? CT_Dependent : CT_Cannot; |
| 1710 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); |
| 1711 | } |
| 1712 | |
| 1713 | // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms. |
| 1714 | case StmtExprClass: |
| 1715 | return CT_Can; |
| 1716 | |
| 1717 | case ChooseExprClass: |
| 1718 | if (isTypeDependent() || isValueDependent()) |
| 1719 | return CT_Dependent; |
| 1720 | return cast<ChooseExpr>(this)->getChosenSubExpr(C)->CanThrow(C); |
| 1721 | |
| 1722 | // Some expressions are always dependent. |
| 1723 | case DependentScopeDeclRefExprClass: |
| 1724 | case CXXUnresolvedConstructExprClass: |
| 1725 | case CXXDependentScopeMemberExprClass: |
| 1726 | return CT_Dependent; |
| 1727 | |
| 1728 | default: |
| 1729 | // All other expressions don't have subexpressions, or else they are |
| 1730 | // unevaluated. |
| 1731 | return CT_Cannot; |
| 1732 | } |
| 1733 | } |
| 1734 | |
Ted Kremenek | 4e99a5f | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 1735 | Expr* Expr::IgnoreParens() { |
| 1736 | Expr* E = this; |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1737 | while (true) { |
| 1738 | if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { |
| 1739 | E = P->getSubExpr(); |
| 1740 | continue; |
| 1741 | } |
| 1742 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { |
| 1743 | if (P->getOpcode() == UO_Extension) { |
| 1744 | E = P->getSubExpr(); |
| 1745 | continue; |
| 1746 | } |
| 1747 | } |
| 1748 | return E; |
| 1749 | } |
Ted Kremenek | 4e99a5f | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 1752 | /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr |
| 1753 | /// or CastExprs or ImplicitCastExprs, returning their operand. |
| 1754 | Expr *Expr::IgnoreParenCasts() { |
| 1755 | Expr *E = this; |
| 1756 | while (true) { |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1757 | if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { |
Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 1758 | E = P->getSubExpr(); |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1759 | continue; |
| 1760 | } |
| 1761 | if (CastExpr *P = dyn_cast<CastExpr>(E)) { |
Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 1762 | E = P->getSubExpr(); |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1763 | continue; |
| 1764 | } |
| 1765 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { |
| 1766 | if (P->getOpcode() == UO_Extension) { |
| 1767 | E = P->getSubExpr(); |
| 1768 | continue; |
| 1769 | } |
| 1770 | } |
| 1771 | return E; |
Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 1775 | /// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue |
| 1776 | /// casts. This is intended purely as a temporary workaround for code |
| 1777 | /// that hasn't yet been rewritten to do the right thing about those |
| 1778 | /// casts, and may disappear along with the last internal use. |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 1779 | Expr *Expr::IgnoreParenLValueCasts() { |
| 1780 | Expr *E = this; |
John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 1781 | while (true) { |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 1782 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { |
| 1783 | E = P->getSubExpr(); |
| 1784 | continue; |
John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 1785 | } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 1786 | if (P->getCastKind() == CK_LValueToRValue) { |
| 1787 | E = P->getSubExpr(); |
| 1788 | continue; |
| 1789 | } |
John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 1790 | } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { |
| 1791 | if (P->getOpcode() == UO_Extension) { |
| 1792 | E = P->getSubExpr(); |
| 1793 | continue; |
| 1794 | } |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 1795 | } |
| 1796 | break; |
| 1797 | } |
| 1798 | return E; |
| 1799 | } |
| 1800 | |
John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 1801 | Expr *Expr::IgnoreParenImpCasts() { |
| 1802 | Expr *E = this; |
| 1803 | while (true) { |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1804 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { |
John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 1805 | E = P->getSubExpr(); |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1806 | continue; |
| 1807 | } |
| 1808 | if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { |
John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 1809 | E = P->getSubExpr(); |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1810 | continue; |
| 1811 | } |
| 1812 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { |
| 1813 | if (P->getOpcode() == UO_Extension) { |
| 1814 | E = P->getSubExpr(); |
| 1815 | continue; |
| 1816 | } |
| 1817 | } |
| 1818 | return E; |
John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 1819 | } |
| 1820 | } |
| 1821 | |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1822 | /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the |
| 1823 | /// value (including ptr->int casts of the same size). Strip off any |
| 1824 | /// ParenExpr or CastExprs, returning their operand. |
| 1825 | Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { |
| 1826 | Expr *E = this; |
| 1827 | while (true) { |
| 1828 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { |
| 1829 | E = P->getSubExpr(); |
| 1830 | continue; |
| 1831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1833 | if (CastExpr *P = dyn_cast<CastExpr>(E)) { |
| 1834 | // We ignore integer <-> casts that are of the same width, ptr<->ptr and |
Douglas Gregor | 2ade35e | 2010-06-16 00:17:44 +0000 | [diff] [blame] | 1835 | // ptr<->int casts of the same width. We also ignore all identity casts. |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1836 | Expr *SE = P->getSubExpr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1838 | if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { |
| 1839 | E = SE; |
| 1840 | continue; |
| 1841 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1843 | if ((E->getType()->isPointerType() || |
Douglas Gregor | 9d3347a | 2010-06-16 00:35:25 +0000 | [diff] [blame] | 1844 | E->getType()->isIntegralType(Ctx)) && |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1845 | (SE->getType()->isPointerType() || |
Douglas Gregor | 9d3347a | 2010-06-16 00:35:25 +0000 | [diff] [blame] | 1846 | SE->getType()->isIntegralType(Ctx)) && |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1847 | Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { |
| 1848 | E = SE; |
| 1849 | continue; |
| 1850 | } |
| 1851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 1853 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { |
| 1854 | if (P->getOpcode() == UO_Extension) { |
| 1855 | E = P->getSubExpr(); |
| 1856 | continue; |
| 1857 | } |
| 1858 | } |
| 1859 | |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1860 | return E; |
| 1861 | } |
| 1862 | } |
| 1863 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1864 | bool Expr::isDefaultArgument() const { |
| 1865 | const Expr *E = this; |
| 1866 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 1867 | E = ICE->getSubExprAsWritten(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1869 | return isa<CXXDefaultArgExpr>(E); |
| 1870 | } |
Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1872 | /// \brief Skip over any no-op casts and any temporary-binding |
| 1873 | /// expressions. |
Anders Carlsson | f8b3015 | 2010-11-28 16:40:49 +0000 | [diff] [blame] | 1874 | static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1875 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1876 | if (ICE->getCastKind() == CK_NoOp) |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1877 | E = ICE->getSubExpr(); |
| 1878 | else |
| 1879 | break; |
| 1880 | } |
| 1881 | |
| 1882 | while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 1883 | E = BE->getSubExpr(); |
| 1884 | |
| 1885 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1886 | if (ICE->getCastKind() == CK_NoOp) |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1887 | E = ICE->getSubExpr(); |
| 1888 | else |
| 1889 | break; |
| 1890 | } |
Anders Carlsson | f8b3015 | 2010-11-28 16:40:49 +0000 | [diff] [blame] | 1891 | |
| 1892 | return E->IgnoreParens(); |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1895 | /// isTemporaryObject - Determines if this expression produces a |
| 1896 | /// temporary of the given class type. |
| 1897 | bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { |
| 1898 | if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) |
| 1899 | return false; |
| 1900 | |
Anders Carlsson | f8b3015 | 2010-11-28 16:40:49 +0000 | [diff] [blame] | 1901 | const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1902 | |
John McCall | 58277b5 | 2010-09-15 20:59:13 +0000 | [diff] [blame] | 1903 | // Temporaries are by definition pr-values of class type. |
Fariborz Jahanian | db148be | 2010-09-27 17:30:38 +0000 | [diff] [blame] | 1904 | if (!E->Classify(C).isPRValue()) { |
| 1905 | // In this context, property reference is a message call and is pr-value. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1906 | if (!isa<ObjCPropertyRefExpr>(E)) |
Fariborz Jahanian | db148be | 2010-09-27 17:30:38 +0000 | [diff] [blame] | 1907 | return false; |
| 1908 | } |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1909 | |
John McCall | 19e60ad | 2010-09-16 06:57:56 +0000 | [diff] [blame] | 1910 | // Black-list a few cases which yield pr-values of class type that don't |
| 1911 | // refer to temporaries of that type: |
| 1912 | |
| 1913 | // - implicit derived-to-base conversions |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1914 | if (isa<ImplicitCastExpr>(E)) { |
| 1915 | switch (cast<ImplicitCastExpr>(E)->getCastKind()) { |
| 1916 | case CK_DerivedToBase: |
| 1917 | case CK_UncheckedDerivedToBase: |
| 1918 | return false; |
| 1919 | default: |
| 1920 | break; |
| 1921 | } |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
John McCall | 19e60ad | 2010-09-16 06:57:56 +0000 | [diff] [blame] | 1924 | // - member expressions (all) |
| 1925 | if (isa<MemberExpr>(E)) |
| 1926 | return false; |
| 1927 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1928 | return true; |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1931 | /// hasAnyTypeDependentArguments - Determines if any of the expressions |
| 1932 | /// in Exprs is type-dependent. |
| 1933 | bool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { |
| 1934 | for (unsigned I = 0; I < NumExprs; ++I) |
| 1935 | if (Exprs[I]->isTypeDependent()) |
| 1936 | return true; |
| 1937 | |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | /// hasAnyValueDependentArguments - Determines if any of the expressions |
| 1942 | /// in Exprs is value-dependent. |
| 1943 | bool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { |
| 1944 | for (unsigned I = 0; I < NumExprs; ++I) |
| 1945 | if (Exprs[I]->isValueDependent()) |
| 1946 | return true; |
| 1947 | |
| 1948 | return false; |
| 1949 | } |
| 1950 | |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 1951 | bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1952 | // This function is attempting whether an expression is an initializer |
| 1953 | // which can be evaluated at compile-time. isEvaluatable handles most |
| 1954 | // of the cases, but it can't deal with some initializer-specific |
| 1955 | // expressions, and it can't deal with aggregates; we deal with those here, |
| 1956 | // and fall back to isEvaluatable for the other cases. |
| 1957 | |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 1958 | // If we ever capture reference-binding directly in the AST, we can |
| 1959 | // kill the second parameter. |
| 1960 | |
| 1961 | if (IsForRef) { |
| 1962 | EvalResult Result; |
| 1963 | return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; |
| 1964 | } |
Eli Friedman | 1f4a6db | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 1965 | |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1966 | switch (getStmtClass()) { |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1967 | default: break; |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1968 | case StringLiteralClass: |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 1969 | case ObjCStringLiteralClass: |
Chris Lattner | eaf2bb8 | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 1970 | case ObjCEncodeExprClass: |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1971 | return true; |
John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 1972 | case CXXTemporaryObjectExprClass: |
| 1973 | case CXXConstructExprClass: { |
| 1974 | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 1975 | |
| 1976 | // Only if it's |
| 1977 | // 1) an application of the trivial default constructor or |
John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 1978 | if (!CE->getConstructor()->isTrivial()) return false; |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 1979 | if (!CE->getNumArgs()) return true; |
| 1980 | |
| 1981 | // 2) an elidable trivial copy construction of an operand which is |
| 1982 | // itself a constant initializer. Note that we consider the |
| 1983 | // operand on its own, *not* as a reference binding. |
| 1984 | return CE->isElidable() && |
| 1985 | CE->getArg(0)->isConstantInitializer(Ctx, false); |
John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 1986 | } |
Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 1987 | case CompoundLiteralExprClass: { |
Eli Friedman | 1f4a6db | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 1988 | // This handles gcc's extension that allows global initializers like |
| 1989 | // "struct x {int x;} x = (struct x) {};". |
| 1990 | // FIXME: This accepts other cases it shouldn't! |
Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 1991 | const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 1992 | return Exp->isConstantInitializer(Ctx, false); |
Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 1993 | } |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1994 | case InitListExprClass: { |
Eli Friedman | 1f4a6db | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 1995 | // FIXME: This doesn't deal with fields with reference types correctly. |
| 1996 | // FIXME: This incorrectly allows pointers cast to integers to be assigned |
| 1997 | // to bitfields. |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1998 | const InitListExpr *Exp = cast<InitListExpr>(this); |
| 1999 | unsigned numInits = Exp->getNumInits(); |
| 2000 | for (unsigned i = 0; i < numInits; i++) { |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2001 | if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2002 | return false; |
| 2003 | } |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2004 | return true; |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2005 | } |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2006 | case ImplicitValueInitExprClass: |
| 2007 | return true; |
Chris Lattner | 3ae9f48 | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 2008 | case ParenExprClass: |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2009 | return cast<ParenExpr>(this)->getSubExpr() |
| 2010 | ->isConstantInitializer(Ctx, IsForRef); |
Abramo Bagnara | 5cadfab | 2010-09-27 07:13:32 +0000 | [diff] [blame] | 2011 | case ChooseExprClass: |
| 2012 | return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) |
| 2013 | ->isConstantInitializer(Ctx, IsForRef); |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2014 | case UnaryOperatorClass: { |
| 2015 | const UnaryOperator* Exp = cast<UnaryOperator>(this); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2016 | if (Exp->getOpcode() == UO_Extension) |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2017 | return Exp->getSubExpr()->isConstantInitializer(Ctx, false); |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2018 | break; |
| 2019 | } |
Chris Lattner | 3ae9f48 | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 2020 | case BinaryOperatorClass: { |
| 2021 | // Special case &&foo - &&bar. It would be nice to generalize this somehow |
| 2022 | // but this handles the common case. |
| 2023 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2024 | if (Exp->getOpcode() == BO_Sub && |
Chris Lattner | 3ae9f48 | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 2025 | isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && |
| 2026 | isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) |
| 2027 | return true; |
| 2028 | break; |
| 2029 | } |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2030 | case CXXFunctionalCastExprClass: |
John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 2031 | case CXXStaticCastExprClass: |
Chris Lattner | 81045d8 | 2009-04-21 05:19:11 +0000 | [diff] [blame] | 2032 | case ImplicitCastExprClass: |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2033 | case CStyleCastExprClass: |
| 2034 | // Handle casts with a destination that's a struct or union; this |
| 2035 | // deals with both the gcc no-op struct cast extension and the |
| 2036 | // cast-to-union extension. |
| 2037 | if (getType()->isRecordType()) |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2038 | return cast<CastExpr>(this)->getSubExpr() |
| 2039 | ->isConstantInitializer(Ctx, false); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2040 | |
Chris Lattner | 430656e | 2009-10-13 22:12:09 +0000 | [diff] [blame] | 2041 | // Integer->integer casts can be handled here, which is important for |
| 2042 | // things like (int)(&&x-&&y). Scary but true. |
| 2043 | if (getType()->isIntegerType() && |
| 2044 | cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) |
John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2045 | return cast<CastExpr>(this)->getSubExpr() |
| 2046 | ->isConstantInitializer(Ctx, false); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2047 | |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2048 | break; |
Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2049 | } |
Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2050 | return isEvaluatable(Ctx); |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2053 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an |
| 2054 | /// integer constant expression with the value zero, or if this is one that is |
| 2055 | /// cast to void*. |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2056 | bool Expr::isNullPointerConstant(ASTContext &Ctx, |
| 2057 | NullPointerConstantValueDependence NPC) const { |
| 2058 | if (isValueDependent()) { |
| 2059 | switch (NPC) { |
| 2060 | case NPC_NeverValueDependent: |
| 2061 | assert(false && "Unexpected value dependent expression!"); |
| 2062 | // If the unthinkable happens, fall through to the safest alternative. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2063 | |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2064 | case NPC_ValueDependentIsNull: |
Douglas Gregor | 9d3347a | 2010-06-16 00:35:25 +0000 | [diff] [blame] | 2065 | return isTypeDependent() || getType()->isIntegralType(Ctx); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2066 | |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2067 | case NPC_ValueDependentIsNotNull: |
| 2068 | return false; |
| 2069 | } |
| 2070 | } |
Daniel Dunbar | f515b22 | 2009-09-18 08:46:16 +0000 | [diff] [blame] | 2071 | |
Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2072 | // Strip off a cast to void*, if it exists. Except in C++. |
Argyrios Kyrtzidis | 0835a3c | 2008-08-18 23:01:59 +0000 | [diff] [blame] | 2073 | if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { |
Sebastian Redl | 6215dee | 2008-11-04 11:45:54 +0000 | [diff] [blame] | 2074 | if (!Ctx.getLangOptions().CPlusPlus) { |
Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2075 | // Check that it is a cast to void*. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2076 | if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { |
Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2077 | QualType Pointee = PT->getPointeeType(); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2078 | if (!Pointee.hasQualifiers() && |
Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2079 | Pointee->isVoidType() && // to void* |
| 2080 | CE->getSubExpr()->getType()->isIntegerType()) // from int. |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2081 | return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2082 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2083 | } |
Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2084 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { |
| 2085 | // Ignore the ImplicitCastExpr type entirely. |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2086 | return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2087 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { |
| 2088 | // Accept ((void*)0) as a null pointer constant, as many other |
| 2089 | // implementations do. |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2090 | return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2091 | } else if (const CXXDefaultArgExpr *DefaultArg |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 2092 | = dyn_cast<CXXDefaultArgExpr>(this)) { |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 2093 | // See through default argument expressions |
Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2094 | return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 2095 | } else if (isa<GNUNullExpr>(this)) { |
| 2096 | // The GNU __null extension is always a null pointer constant. |
| 2097 | return true; |
Steve Naroff | aaffbf7 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 2098 | } |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 2099 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 2100 | // C++0x nullptr_t is always a null pointer constant. |
| 2101 | if (getType()->isNullPtrType()) |
| 2102 | return true; |
| 2103 | |
Fariborz Jahanian | ff3a078 | 2010-09-27 22:42:37 +0000 | [diff] [blame] | 2104 | if (const RecordType *UT = getType()->getAsUnionType()) |
| 2105 | if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) |
| 2106 | if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ |
| 2107 | const Expr *InitExpr = CLE->getInitializer(); |
| 2108 | if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) |
| 2109 | return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); |
| 2110 | } |
Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2111 | // This expression must be an integer type. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2112 | if (!getType()->isIntegerType() || |
Fariborz Jahanian | 56fc0d1 | 2009-10-06 00:09:31 +0000 | [diff] [blame] | 2113 | (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) |
Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2114 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2115 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2116 | // If we have an integer constant expression, we need to *evaluate* it and |
| 2117 | // test for the value 0. |
Eli Friedman | 09de176 | 2009-04-25 22:37:12 +0000 | [diff] [blame] | 2118 | llvm::APSInt Result; |
| 2119 | return isIntegerConstantExpr(Result, Ctx) && Result == 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2120 | } |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 2121 | |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2122 | /// \brief If this expression is an l-value for an Objective C |
| 2123 | /// property, find the underlying property reference expression. |
| 2124 | const ObjCPropertyRefExpr *Expr::getObjCProperty() const { |
| 2125 | const Expr *E = this; |
| 2126 | while (true) { |
| 2127 | assert((E->getValueKind() == VK_LValue && |
| 2128 | E->getObjectKind() == OK_ObjCProperty) && |
| 2129 | "expression is not a property reference"); |
| 2130 | E = E->IgnoreParenCasts(); |
| 2131 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { |
| 2132 | if (BO->getOpcode() == BO_Comma) { |
| 2133 | E = BO->getRHS(); |
| 2134 | continue; |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | break; |
| 2139 | } |
| 2140 | |
| 2141 | return cast<ObjCPropertyRefExpr>(E); |
| 2142 | } |
| 2143 | |
Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2144 | FieldDecl *Expr::getBitField() { |
Douglas Gregor | 6f4a69a | 2009-07-06 15:38:40 +0000 | [diff] [blame] | 2145 | Expr *E = this->IgnoreParens(); |
Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2146 | |
Douglas Gregor | de4b1d8 | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 2147 | while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2148 | if (ICE->getCastKind() == CK_LValueToRValue || |
| 2149 | (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) |
Douglas Gregor | de4b1d8 | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 2150 | E = ICE->getSubExpr()->IgnoreParens(); |
| 2151 | else |
| 2152 | break; |
| 2153 | } |
| 2154 | |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2155 | if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) |
Douglas Gregor | 86f1940 | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 2156 | if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) |
Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2157 | if (Field->isBitField()) |
| 2158 | return Field; |
| 2159 | |
Argyrios Kyrtzidis | 0f279e7 | 2010-10-30 19:52:22 +0000 | [diff] [blame] | 2160 | if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) |
| 2161 | if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) |
| 2162 | if (Field->isBitField()) |
| 2163 | return Field; |
| 2164 | |
Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2165 | if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) |
| 2166 | if (BinOp->isAssignmentOp() && BinOp->getLHS()) |
| 2167 | return BinOp->getLHS()->getBitField(); |
| 2168 | |
| 2169 | return 0; |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2172 | bool Expr::refersToVectorElement() const { |
| 2173 | const Expr *E = this->IgnoreParens(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2174 | |
Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2175 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
John McCall | 5baba9d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 2176 | if (ICE->getValueKind() != VK_RValue && |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2177 | ICE->getCastKind() == CK_NoOp) |
Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2178 | E = ICE->getSubExpr()->IgnoreParens(); |
| 2179 | else |
| 2180 | break; |
| 2181 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2182 | |
Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2183 | if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) |
| 2184 | return ASE->getBase()->getType()->isVectorType(); |
| 2185 | |
| 2186 | if (isa<ExtVectorElementExpr>(E)) |
| 2187 | return true; |
| 2188 | |
| 2189 | return false; |
| 2190 | } |
| 2191 | |
Chris Lattner | 2140e90 | 2009-02-16 22:14:05 +0000 | [diff] [blame] | 2192 | /// isArrow - Return true if the base expression is a pointer to vector, |
| 2193 | /// return false if the base expression is a vector. |
| 2194 | bool ExtVectorElementExpr::isArrow() const { |
| 2195 | return getBase()->getType()->isPointerType(); |
| 2196 | } |
| 2197 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2198 | unsigned ExtVectorElementExpr::getNumElements() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2199 | if (const VectorType *VT = getType()->getAs<VectorType>()) |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2200 | return VT->getNumElements(); |
| 2201 | return 1; |
Chris Lattner | 4d0ac88 | 2007-08-03 16:00:20 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2204 | /// containsDuplicateElements - Return true if any element access is repeated. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2205 | bool ExtVectorElementExpr::containsDuplicateElements() const { |
Daniel Dunbar | a2b34eb | 2009-10-18 02:09:09 +0000 | [diff] [blame] | 2206 | // FIXME: Refactor this code to an accessor on the AST node which returns the |
| 2207 | // "type" of component access, and share with code below and in Sema. |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 2208 | llvm::StringRef Comp = Accessor->getName(); |
Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 2209 | |
| 2210 | // Halving swizzles do not contain duplicate elements. |
Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2211 | if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") |
Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 2212 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2213 | |
Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 2214 | // Advance past s-char prefix on hex swizzles. |
Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2215 | if (Comp[0] == 's' || Comp[0] == 'S') |
| 2216 | Comp = Comp.substr(1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2217 | |
Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2218 | for (unsigned i = 0, e = Comp.size(); i != e; ++i) |
| 2219 | if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos) |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 2220 | return true; |
Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2221 | |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 2222 | return false; |
| 2223 | } |
Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 2224 | |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2225 | /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. |
Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 2226 | void ExtVectorElementExpr::getEncodedElementAccess( |
| 2227 | llvm::SmallVectorImpl<unsigned> &Elts) const { |
Daniel Dunbar | 4b55b24 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 2228 | llvm::StringRef Comp = Accessor->getName(); |
| 2229 | if (Comp[0] == 's' || Comp[0] == 'S') |
| 2230 | Comp = Comp.substr(1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2231 | |
Daniel Dunbar | 4b55b24 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 2232 | bool isHi = Comp == "hi"; |
| 2233 | bool isLo = Comp == "lo"; |
| 2234 | bool isEven = Comp == "even"; |
| 2235 | bool isOdd = Comp == "odd"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2236 | |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2237 | for (unsigned i = 0, e = getNumElements(); i != e; ++i) { |
| 2238 | uint64_t Index; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2239 | |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2240 | if (isHi) |
| 2241 | Index = e + i; |
| 2242 | else if (isLo) |
| 2243 | Index = i; |
| 2244 | else if (isEven) |
| 2245 | Index = 2 * i; |
| 2246 | else if (isOdd) |
| 2247 | Index = 2 * i + 1; |
| 2248 | else |
Daniel Dunbar | 4b55b24 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 2249 | Index = ExtVectorType::getAccessorIdx(Comp[i]); |
Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 2250 | |
Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 2251 | Elts.push_back(Index); |
Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 2252 | } |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2255 | ObjCMessageExpr::ObjCMessageExpr(QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2256 | ExprValueKind VK, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2257 | SourceLocation LBracLoc, |
| 2258 | SourceLocation SuperLoc, |
| 2259 | bool IsInstanceSuper, |
| 2260 | QualType SuperType, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2261 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2262 | SourceLocation SelLoc, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2263 | ObjCMethodDecl *Method, |
| 2264 | Expr **Args, unsigned NumArgs, |
| 2265 | SourceLocation RBracLoc) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2266 | : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2267 | /*TypeDependent=*/false, /*ValueDependent=*/false, |
| 2268 | /*ContainsUnexpandedParameterPack=*/false), |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2269 | NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass), |
| 2270 | HasMethod(Method != 0), SuperLoc(SuperLoc), |
| 2271 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method |
| 2272 | : Sel.getAsOpaquePtr())), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2273 | SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) |
Douglas Gregor | c2350e5 | 2010-03-08 16:40:19 +0000 | [diff] [blame] | 2274 | { |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2275 | setReceiverPointer(SuperType.getAsOpaquePtr()); |
| 2276 | if (NumArgs) |
| 2277 | memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); |
Ted Kremenek | 4df728e | 2008-06-24 15:50:53 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2280 | ObjCMessageExpr::ObjCMessageExpr(QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2281 | ExprValueKind VK, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2282 | SourceLocation LBracLoc, |
| 2283 | TypeSourceInfo *Receiver, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2284 | Selector Sel, |
| 2285 | SourceLocation SelLoc, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2286 | ObjCMethodDecl *Method, |
| 2287 | Expr **Args, unsigned NumArgs, |
| 2288 | SourceLocation RBracLoc) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2289 | : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2290 | T->isDependentType(), T->containsUnexpandedParameterPack()), |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2291 | NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0), |
| 2292 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method |
| 2293 | : Sel.getAsOpaquePtr())), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2294 | SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2295 | { |
| 2296 | setReceiverPointer(Receiver); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2297 | Stmt **MyArgs = getArgs(); |
| 2298 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 2299 | if (Args[I]->isTypeDependent()) |
| 2300 | ExprBits.TypeDependent = true; |
| 2301 | if (Args[I]->isValueDependent()) |
| 2302 | ExprBits.ValueDependent = true; |
| 2303 | if (Args[I]->containsUnexpandedParameterPack()) |
| 2304 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 2305 | |
| 2306 | MyArgs[I] = Args[I]; |
| 2307 | } |
Ted Kremenek | 4df728e | 2008-06-24 15:50:53 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2310 | ObjCMessageExpr::ObjCMessageExpr(QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2311 | ExprValueKind VK, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2312 | SourceLocation LBracLoc, |
| 2313 | Expr *Receiver, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2314 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2315 | SourceLocation SelLoc, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2316 | ObjCMethodDecl *Method, |
| 2317 | Expr **Args, unsigned NumArgs, |
| 2318 | SourceLocation RBracLoc) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2319 | : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2320 | Receiver->isTypeDependent(), |
| 2321 | Receiver->containsUnexpandedParameterPack()), |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2322 | NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0), |
| 2323 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method |
| 2324 | : Sel.getAsOpaquePtr())), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2325 | SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2326 | { |
| 2327 | setReceiverPointer(Receiver); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2328 | Stmt **MyArgs = getArgs(); |
| 2329 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 2330 | if (Args[I]->isTypeDependent()) |
| 2331 | ExprBits.TypeDependent = true; |
| 2332 | if (Args[I]->isValueDependent()) |
| 2333 | ExprBits.ValueDependent = true; |
| 2334 | if (Args[I]->containsUnexpandedParameterPack()) |
| 2335 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 2336 | |
| 2337 | MyArgs[I] = Args[I]; |
| 2338 | } |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2341 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2342 | ExprValueKind VK, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2343 | SourceLocation LBracLoc, |
| 2344 | SourceLocation SuperLoc, |
| 2345 | bool IsInstanceSuper, |
| 2346 | QualType SuperType, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2347 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2348 | SourceLocation SelLoc, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2349 | ObjCMethodDecl *Method, |
| 2350 | Expr **Args, unsigned NumArgs, |
| 2351 | SourceLocation RBracLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2352 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2353 | NumArgs * sizeof(Expr *); |
| 2354 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2355 | return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2356 | SuperType, Sel, SelLoc, Method, Args,NumArgs, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2357 | RBracLoc); |
| 2358 | } |
| 2359 | |
| 2360 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2361 | ExprValueKind VK, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2362 | SourceLocation LBracLoc, |
| 2363 | TypeSourceInfo *Receiver, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2364 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2365 | SourceLocation SelLoc, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2366 | ObjCMethodDecl *Method, |
| 2367 | Expr **Args, unsigned NumArgs, |
| 2368 | SourceLocation RBracLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2369 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2370 | NumArgs * sizeof(Expr *); |
| 2371 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2372 | return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLoc, |
| 2373 | Method, Args, NumArgs, RBracLoc); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2377 | ExprValueKind VK, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2378 | SourceLocation LBracLoc, |
| 2379 | Expr *Receiver, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2380 | Selector Sel, |
| 2381 | SourceLocation SelLoc, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2382 | ObjCMethodDecl *Method, |
| 2383 | Expr **Args, unsigned NumArgs, |
| 2384 | SourceLocation RBracLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2385 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2386 | NumArgs * sizeof(Expr *); |
| 2387 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2388 | return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLoc, |
| 2389 | Method, Args, NumArgs, RBracLoc); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2392 | ObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2393 | unsigned NumArgs) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2394 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2395 | NumArgs * sizeof(Expr *); |
| 2396 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
| 2397 | return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); |
| 2398 | } |
Argyrios Kyrtzidis | e005d19 | 2010-12-10 20:08:30 +0000 | [diff] [blame] | 2399 | |
| 2400 | SourceRange ObjCMessageExpr::getReceiverRange() const { |
| 2401 | switch (getReceiverKind()) { |
| 2402 | case Instance: |
| 2403 | return getInstanceReceiver()->getSourceRange(); |
| 2404 | |
| 2405 | case Class: |
| 2406 | return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); |
| 2407 | |
| 2408 | case SuperInstance: |
| 2409 | case SuperClass: |
| 2410 | return getSuperLoc(); |
| 2411 | } |
| 2412 | |
| 2413 | return SourceLocation(); |
| 2414 | } |
| 2415 | |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2416 | Selector ObjCMessageExpr::getSelector() const { |
| 2417 | if (HasMethod) |
| 2418 | return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) |
| 2419 | ->getSelector(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2420 | return Selector(SelectorOrMethod); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { |
| 2424 | switch (getReceiverKind()) { |
| 2425 | case Instance: |
| 2426 | if (const ObjCObjectPointerType *Ptr |
| 2427 | = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) |
| 2428 | return Ptr->getInterfaceDecl(); |
| 2429 | break; |
| 2430 | |
| 2431 | case Class: |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2432 | if (const ObjCObjectType *Ty |
| 2433 | = getClassReceiver()->getAs<ObjCObjectType>()) |
| 2434 | return Ty->getInterface(); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2435 | break; |
| 2436 | |
| 2437 | case SuperInstance: |
| 2438 | if (const ObjCObjectPointerType *Ptr |
| 2439 | = getSuperType()->getAs<ObjCObjectPointerType>()) |
| 2440 | return Ptr->getInterfaceDecl(); |
| 2441 | break; |
| 2442 | |
| 2443 | case SuperClass: |
| 2444 | if (const ObjCObjectPointerType *Iface |
| 2445 | = getSuperType()->getAs<ObjCObjectPointerType>()) |
| 2446 | return Iface->getInterfaceDecl(); |
| 2447 | break; |
| 2448 | } |
| 2449 | |
| 2450 | return 0; |
Ted Kremenek | eb3b324 | 2010-02-11 22:41:21 +0000 | [diff] [blame] | 2451 | } |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 2452 | |
Chris Lattner | 27437ca | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 2453 | bool ChooseExpr::isConditionTrue(ASTContext &C) const { |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 2454 | return getCond()->EvaluateAsInt(C) != 0; |
Chris Lattner | 27437ca | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2457 | ShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, |
| 2458 | QualType Type, SourceLocation BLoc, |
| 2459 | SourceLocation RP) |
| 2460 | : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, |
| 2461 | Type->isDependentType(), Type->isDependentType(), |
| 2462 | Type->containsUnexpandedParameterPack()), |
| 2463 | BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) |
| 2464 | { |
| 2465 | SubExprs = new (C) Stmt*[nexpr]; |
| 2466 | for (unsigned i = 0; i < nexpr; i++) { |
| 2467 | if (args[i]->isTypeDependent()) |
| 2468 | ExprBits.TypeDependent = true; |
| 2469 | if (args[i]->isValueDependent()) |
| 2470 | ExprBits.ValueDependent = true; |
| 2471 | if (args[i]->containsUnexpandedParameterPack()) |
| 2472 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 2473 | |
| 2474 | SubExprs[i] = args[i]; |
| 2475 | } |
| 2476 | } |
| 2477 | |
Nate Begeman | 888376a | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 2478 | void ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, |
| 2479 | unsigned NumExprs) { |
| 2480 | if (SubExprs) C.Deallocate(SubExprs); |
| 2481 | |
| 2482 | SubExprs = new (C) Stmt* [NumExprs]; |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2483 | this->NumExprs = NumExprs; |
| 2484 | memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2485 | } |
Nate Begeman | 888376a | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 2486 | |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2487 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2488 | // DesignatedInitExpr |
| 2489 | //===----------------------------------------------------------------------===// |
| 2490 | |
| 2491 | IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { |
| 2492 | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
| 2493 | if (Field.NameOrField & 0x01) |
| 2494 | return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); |
| 2495 | else |
| 2496 | return getField()->getIdentifier(); |
| 2497 | } |
| 2498 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2499 | DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2500 | unsigned NumDesignators, |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2501 | const Designator *Designators, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2502 | SourceLocation EqualOrColonLoc, |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2503 | bool GNUSyntax, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2504 | Expr **IndexExprs, |
Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2505 | unsigned NumIndexExprs, |
| 2506 | Expr *Init) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2507 | : Expr(DesignatedInitExprClass, Ty, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2508 | Init->getValueKind(), Init->getObjectKind(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2509 | Init->isTypeDependent(), Init->isValueDependent(), |
| 2510 | Init->containsUnexpandedParameterPack()), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2511 | EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), |
| 2512 | NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2513 | this->Designators = new (C) Designator[NumDesignators]; |
Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2514 | |
| 2515 | // Record the initializer itself. |
| 2516 | child_iterator Child = child_begin(); |
| 2517 | *Child++ = Init; |
| 2518 | |
| 2519 | // Copy the designators and their subexpressions, computing |
| 2520 | // value-dependence along the way. |
| 2521 | unsigned IndexIdx = 0; |
| 2522 | for (unsigned I = 0; I != NumDesignators; ++I) { |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2523 | this->Designators[I] = Designators[I]; |
Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2524 | |
| 2525 | if (this->Designators[I].isArrayDesignator()) { |
| 2526 | // Compute type- and value-dependence. |
| 2527 | Expr *Index = IndexExprs[IndexIdx]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2528 | if (Index->isTypeDependent() || Index->isValueDependent()) |
| 2529 | ExprBits.ValueDependent = true; |
| 2530 | |
| 2531 | // Propagate unexpanded parameter packs. |
| 2532 | if (Index->containsUnexpandedParameterPack()) |
| 2533 | ExprBits.ContainsUnexpandedParameterPack = true; |
Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2534 | |
| 2535 | // Copy the index expressions into permanent storage. |
| 2536 | *Child++ = IndexExprs[IndexIdx++]; |
| 2537 | } else if (this->Designators[I].isArrayRangeDesignator()) { |
| 2538 | // Compute type- and value-dependence. |
| 2539 | Expr *Start = IndexExprs[IndexIdx]; |
| 2540 | Expr *End = IndexExprs[IndexIdx + 1]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2541 | if (Start->isTypeDependent() || Start->isValueDependent() || |
| 2542 | End->isTypeDependent() || End->isValueDependent()) |
| 2543 | ExprBits.ValueDependent = true; |
| 2544 | |
| 2545 | // Propagate unexpanded parameter packs. |
| 2546 | if (Start->containsUnexpandedParameterPack() || |
| 2547 | End->containsUnexpandedParameterPack()) |
| 2548 | ExprBits.ContainsUnexpandedParameterPack = true; |
Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2549 | |
| 2550 | // Copy the start/end expressions into permanent storage. |
| 2551 | *Child++ = IndexExprs[IndexIdx++]; |
| 2552 | *Child++ = IndexExprs[IndexIdx++]; |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2559 | DesignatedInitExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2560 | DesignatedInitExpr::Create(ASTContext &C, Designator *Designators, |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2561 | unsigned NumDesignators, |
| 2562 | Expr **IndexExprs, unsigned NumIndexExprs, |
| 2563 | SourceLocation ColonOrEqualLoc, |
| 2564 | bool UsesColonSyntax, Expr *Init) { |
Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 2565 | void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + |
Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 2566 | sizeof(Stmt *) * (NumIndexExprs + 1), 8); |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2567 | return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, |
Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2568 | ColonOrEqualLoc, UsesColonSyntax, |
| 2569 | IndexExprs, NumIndexExprs, Init); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2572 | DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2573 | unsigned NumIndexExprs) { |
| 2574 | void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + |
| 2575 | sizeof(Stmt *) * (NumIndexExprs + 1), 8); |
| 2576 | return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); |
| 2577 | } |
| 2578 | |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2579 | void DesignatedInitExpr::setDesignators(ASTContext &C, |
| 2580 | const Designator *Desigs, |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2581 | unsigned NumDesigs) { |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2582 | Designators = new (C) Designator[NumDesigs]; |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2583 | NumDesignators = NumDesigs; |
| 2584 | for (unsigned I = 0; I != NumDesigs; ++I) |
| 2585 | Designators[I] = Desigs[I]; |
| 2586 | } |
| 2587 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2588 | SourceRange DesignatedInitExpr::getSourceRange() const { |
| 2589 | SourceLocation StartLoc; |
Chris Lattner | d603eaa | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 2590 | Designator &First = |
| 2591 | *const_cast<DesignatedInitExpr*>(this)->designators_begin(); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2592 | if (First.isFieldDesignator()) { |
Douglas Gregor | eeae8f0 | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 2593 | if (GNUSyntax) |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2594 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); |
| 2595 | else |
| 2596 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); |
| 2597 | } else |
Chris Lattner | d603eaa | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 2598 | StartLoc = |
| 2599 | SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2600 | return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); |
| 2601 | } |
| 2602 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2603 | Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) { |
| 2604 | assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); |
| 2605 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2606 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2607 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2608 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); |
| 2609 | } |
| 2610 | |
| 2611 | Expr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2612 | assert(D.Kind == Designator::ArrayRangeDesignator && |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2613 | "Requires array range designator"); |
| 2614 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2615 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2616 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2617 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); |
| 2618 | } |
| 2619 | |
| 2620 | Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2621 | assert(D.Kind == Designator::ArrayRangeDesignator && |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2622 | "Requires array range designator"); |
| 2623 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2624 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2625 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2626 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); |
| 2627 | } |
| 2628 | |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2629 | /// \brief Replaces the designator at index @p Idx with the series |
| 2630 | /// of designators in [First, Last). |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2631 | void DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2632 | const Designator *First, |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2633 | const Designator *Last) { |
| 2634 | unsigned NumNewDesignators = Last - First; |
| 2635 | if (NumNewDesignators == 0) { |
| 2636 | std::copy_backward(Designators + Idx + 1, |
| 2637 | Designators + NumDesignators, |
| 2638 | Designators + Idx); |
| 2639 | --NumNewDesignators; |
| 2640 | return; |
| 2641 | } else if (NumNewDesignators == 1) { |
| 2642 | Designators[Idx] = *First; |
| 2643 | return; |
| 2644 | } |
| 2645 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2646 | Designator *NewDesignators |
Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2647 | = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2648 | std::copy(Designators, Designators + Idx, NewDesignators); |
| 2649 | std::copy(First, Last, NewDesignators + Idx); |
| 2650 | std::copy(Designators + Idx + 1, Designators + NumDesignators, |
| 2651 | NewDesignators + Idx + NumNewDesignators); |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2652 | Designators = NewDesignators; |
| 2653 | NumDesignators = NumDesignators - 1 + NumNewDesignators; |
| 2654 | } |
| 2655 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | ParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2657 | Expr **exprs, unsigned nexprs, |
| 2658 | SourceLocation rparenloc) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2659 | : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, |
| 2660 | false, false, false), |
| 2661 | NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2662 | |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2663 | Exprs = new (C) Stmt*[nexprs]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2664 | for (unsigned i = 0; i != nexprs; ++i) { |
| 2665 | if (exprs[i]->isTypeDependent()) |
| 2666 | ExprBits.TypeDependent = true; |
| 2667 | if (exprs[i]->isValueDependent()) |
| 2668 | ExprBits.ValueDependent = true; |
| 2669 | if (exprs[i]->containsUnexpandedParameterPack()) |
| 2670 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 2671 | |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2672 | Exprs[i] = exprs[i]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame^] | 2673 | } |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2676 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 2677 | // ExprIterator. |
| 2678 | //===----------------------------------------------------------------------===// |
| 2679 | |
| 2680 | Expr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } |
| 2681 | Expr* ExprIterator::operator*() const { return cast<Expr>(*I); } |
| 2682 | Expr* ExprIterator::operator->() const { return cast<Expr>(*I); } |
| 2683 | const Expr* ConstExprIterator::operator[](size_t idx) const { |
| 2684 | return cast<Expr>(I[idx]); |
| 2685 | } |
| 2686 | const Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } |
| 2687 | const Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } |
| 2688 | |
| 2689 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2690 | // Child Iterators for iterating over subexpressions/substatements |
| 2691 | //===----------------------------------------------------------------------===// |
| 2692 | |
| 2693 | // DeclRefExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2694 | Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } |
| 2695 | Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2696 | |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 2697 | // ObjCIvarRefExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2698 | Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; } |
| 2699 | Stmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; } |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 2700 | |
Steve Naroff | e3e9add | 2008-06-02 23:03:37 +0000 | [diff] [blame] | 2701 | // ObjCPropertyRefExpr |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 2702 | Stmt::child_iterator ObjCPropertyRefExpr::child_begin() |
| 2703 | { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2704 | if (Receiver.is<Stmt*>()) { |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 2705 | // Hack alert! |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2706 | return reinterpret_cast<Stmt**> (&Receiver); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 2707 | } |
| 2708 | return child_iterator(); |
| 2709 | } |
| 2710 | |
| 2711 | Stmt::child_iterator ObjCPropertyRefExpr::child_end() |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2712 | { return Receiver.is<Stmt*>() ? |
| 2713 | reinterpret_cast<Stmt**> (&Receiver)+1 : |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 2714 | child_iterator(); |
| 2715 | } |
Steve Naroff | ae78407 | 2008-05-30 00:40:33 +0000 | [diff] [blame] | 2716 | |
Steve Naroff | f242b1b | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 2717 | // ObjCIsaExpr |
| 2718 | Stmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; } |
| 2719 | Stmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; } |
| 2720 | |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 2721 | // PredefinedExpr |
| 2722 | Stmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); } |
| 2723 | Stmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2724 | |
| 2725 | // IntegerLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2726 | Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } |
| 2727 | Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2728 | |
| 2729 | // CharacterLiteral |
Chris Lattner | d603eaa | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 2730 | Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();} |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2731 | Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2732 | |
| 2733 | // FloatingLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2734 | Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } |
| 2735 | Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2736 | |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 2737 | // ImaginaryLiteral |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2738 | Stmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; } |
| 2739 | Stmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 2740 | |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2741 | // StringLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2742 | Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } |
| 2743 | Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2744 | |
| 2745 | // ParenExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2746 | Stmt::child_iterator ParenExpr::child_begin() { return &Val; } |
| 2747 | Stmt::child_iterator ParenExpr::child_end() { return &Val+1; } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2748 | |
| 2749 | // UnaryOperator |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2750 | Stmt::child_iterator UnaryOperator::child_begin() { return &Val; } |
| 2751 | Stmt::child_iterator UnaryOperator::child_end() { return &Val+1; } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2752 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2753 | // OffsetOfExpr |
| 2754 | Stmt::child_iterator OffsetOfExpr::child_begin() { |
| 2755 | return reinterpret_cast<Stmt **> (reinterpret_cast<OffsetOfNode *> (this + 1) |
| 2756 | + NumComps); |
| 2757 | } |
| 2758 | Stmt::child_iterator OffsetOfExpr::child_end() { |
| 2759 | return child_iterator(&*child_begin() + NumExprs); |
| 2760 | } |
| 2761 | |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2762 | // SizeOfAlignOfExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2763 | Stmt::child_iterator SizeOfAlignOfExpr::child_begin() { |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2764 | // If this is of a type and the type is a VLA type (and not a typedef), the |
| 2765 | // size expression of the VLA needs to be treated as an executable expression. |
| 2766 | // Why isn't this weirdness documented better in StmtIterator? |
| 2767 | if (isArgumentType()) { |
| 2768 | if (VariableArrayType* T = dyn_cast<VariableArrayType>( |
| 2769 | getArgumentType().getTypePtr())) |
| 2770 | return child_iterator(T); |
| 2771 | return child_iterator(); |
| 2772 | } |
Sebastian Redl | d457589 | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 2773 | return child_iterator(&Argument.Ex); |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2774 | } |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2775 | Stmt::child_iterator SizeOfAlignOfExpr::child_end() { |
| 2776 | if (isArgumentType()) |
| 2777 | return child_iterator(); |
Sebastian Redl | d457589 | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 2778 | return child_iterator(&Argument.Ex + 1); |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2779 | } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2780 | |
| 2781 | // ArraySubscriptExpr |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2782 | Stmt::child_iterator ArraySubscriptExpr::child_begin() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2783 | return &SubExprs[0]; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2784 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2785 | Stmt::child_iterator ArraySubscriptExpr::child_end() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2786 | return &SubExprs[0]+END_EXPR; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | // CallExpr |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2790 | Stmt::child_iterator CallExpr::child_begin() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2791 | return &SubExprs[0]; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2792 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2793 | Stmt::child_iterator CallExpr::child_end() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2794 | return &SubExprs[0]+NumArgs+ARGS_START; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2795 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2796 | |
| 2797 | // MemberExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2798 | Stmt::child_iterator MemberExpr::child_begin() { return &Base; } |
| 2799 | Stmt::child_iterator MemberExpr::child_end() { return &Base+1; } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2800 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2801 | // ExtVectorElementExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2802 | Stmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; } |
| 2803 | Stmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2804 | |
| 2805 | // CompoundLiteralExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2806 | Stmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; } |
| 2807 | Stmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2808 | |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2809 | // CastExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2810 | Stmt::child_iterator CastExpr::child_begin() { return &Op; } |
| 2811 | Stmt::child_iterator CastExpr::child_end() { return &Op+1; } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2812 | |
| 2813 | // BinaryOperator |
| 2814 | Stmt::child_iterator BinaryOperator::child_begin() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2815 | return &SubExprs[0]; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2816 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2817 | Stmt::child_iterator BinaryOperator::child_end() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2818 | return &SubExprs[0]+END_EXPR; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | // ConditionalOperator |
| 2822 | Stmt::child_iterator ConditionalOperator::child_begin() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2823 | return &SubExprs[0]; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2824 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2825 | Stmt::child_iterator ConditionalOperator::child_end() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2826 | return &SubExprs[0]+END_EXPR; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | // AddrLabelExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2830 | Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } |
| 2831 | Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2832 | |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2833 | // StmtExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2834 | Stmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } |
| 2835 | Stmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2836 | |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2837 | |
| 2838 | // ChooseExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2839 | Stmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } |
| 2840 | Stmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2841 | |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 2842 | // GNUNullExpr |
| 2843 | Stmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); } |
| 2844 | Stmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); } |
| 2845 | |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 2846 | // ShuffleVectorExpr |
| 2847 | Stmt::child_iterator ShuffleVectorExpr::child_begin() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2848 | return &SubExprs[0]; |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 2849 | } |
| 2850 | Stmt::child_iterator ShuffleVectorExpr::child_end() { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2851 | return &SubExprs[0]+NumExprs; |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 2854 | // VAArgExpr |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2855 | Stmt::child_iterator VAArgExpr::child_begin() { return &Val; } |
| 2856 | Stmt::child_iterator VAArgExpr::child_end() { return &Val+1; } |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 2857 | |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 2858 | // InitListExpr |
Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 2859 | Stmt::child_iterator InitListExpr::child_begin() { |
| 2860 | return InitExprs.size() ? &InitExprs[0] : 0; |
| 2861 | } |
| 2862 | Stmt::child_iterator InitListExpr::child_end() { |
| 2863 | return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0; |
| 2864 | } |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 2865 | |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2866 | // DesignatedInitExpr |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2867 | Stmt::child_iterator DesignatedInitExpr::child_begin() { |
| 2868 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2869 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2870 | return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2871 | } |
| 2872 | Stmt::child_iterator DesignatedInitExpr::child_end() { |
| 2873 | return child_iterator(&*child_begin() + NumSubExprs); |
| 2874 | } |
| 2875 | |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2876 | // ImplicitValueInitExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | Stmt::child_iterator ImplicitValueInitExpr::child_begin() { |
| 2878 | return child_iterator(); |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | Stmt::child_iterator ImplicitValueInitExpr::child_end() { |
| 2882 | return child_iterator(); |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2885 | // ParenListExpr |
| 2886 | Stmt::child_iterator ParenListExpr::child_begin() { |
| 2887 | return &Exprs[0]; |
| 2888 | } |
| 2889 | Stmt::child_iterator ParenListExpr::child_end() { |
| 2890 | return &Exprs[0]+NumExprs; |
| 2891 | } |
| 2892 | |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2893 | // ObjCStringLiteral |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2894 | Stmt::child_iterator ObjCStringLiteral::child_begin() { |
Chris Lattner | c6c16af | 2009-02-18 06:53:08 +0000 | [diff] [blame] | 2895 | return &String; |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2896 | } |
| 2897 | Stmt::child_iterator ObjCStringLiteral::child_end() { |
Chris Lattner | c6c16af | 2009-02-18 06:53:08 +0000 | [diff] [blame] | 2898 | return &String+1; |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2899 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2900 | |
| 2901 | // ObjCEncodeExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2902 | Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } |
| 2903 | Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2904 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2905 | // ObjCSelectorExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2906 | Stmt::child_iterator ObjCSelectorExpr::child_begin() { |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2907 | return child_iterator(); |
| 2908 | } |
| 2909 | Stmt::child_iterator ObjCSelectorExpr::child_end() { |
| 2910 | return child_iterator(); |
| 2911 | } |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2912 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2913 | // ObjCProtocolExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2914 | Stmt::child_iterator ObjCProtocolExpr::child_begin() { |
| 2915 | return child_iterator(); |
| 2916 | } |
| 2917 | Stmt::child_iterator ObjCProtocolExpr::child_end() { |
| 2918 | return child_iterator(); |
| 2919 | } |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2920 | |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 2921 | // ObjCMessageExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | Stmt::child_iterator ObjCMessageExpr::child_begin() { |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2923 | if (getReceiverKind() == Instance) |
| 2924 | return reinterpret_cast<Stmt **>(this + 1); |
| 2925 | return getArgs(); |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 2926 | } |
| 2927 | Stmt::child_iterator ObjCMessageExpr::child_end() { |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2928 | return getArgs() + getNumArgs(); |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2931 | // Blocks |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 2932 | Stmt::child_iterator BlockExpr::child_begin() { return child_iterator(); } |
| 2933 | Stmt::child_iterator BlockExpr::child_end() { return child_iterator(); } |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2934 | |
Ted Kremenek | 9da13f9 | 2008-09-26 23:24:14 +0000 | [diff] [blame] | 2935 | Stmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} |
| 2936 | Stmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); } |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 2937 | |
| 2938 | // OpaqueValueExpr |
| 2939 | SourceRange OpaqueValueExpr::getSourceRange() const { return SourceRange(); } |
| 2940 | Stmt::child_iterator OpaqueValueExpr::child_begin() { return child_iterator(); } |
| 2941 | Stmt::child_iterator OpaqueValueExpr::child_end() { return child_iterator(); } |
| 2942 | |