Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 1 | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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. |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Expr class and subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 14 | #include "clang/AST/Expr.h" |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 15 | #include "clang/AST/ExprCXX.h" |
Chris Lattner | 86ee286 | 2008-10-06 06:40:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/APValue.h" |
Chris Lattner | 5c4664e | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Chris Lattner | 86ee286 | 2008-10-06 06:40:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 9a65793 | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Anders Carlsson | 15b73de | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 21 | #include "clang/AST/RecordLayout.h" |
Chris Lattner | 5e9a878 | 2006-11-04 06:21:51 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtVisitor.h" |
Chris Lattner | 15ba949 | 2009-06-14 01:54:56 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Builtins.h" |
Chris Lattner | a7944d8 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 24 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 0840cc0 | 2009-11-01 20:32:48 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 27 | #include <algorithm> |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 28 | using namespace clang; |
| 29 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 30 | /// isKnownToHaveBooleanValue - Return true if this is an integer expression |
| 31 | /// that is known to return 0 or 1. This happens for _Bool/bool expressions |
| 32 | /// but also int expressions which are produced by things like comparisons in |
| 33 | /// C. |
| 34 | bool Expr::isKnownToHaveBooleanValue() const { |
| 35 | // If this value has _Bool type, it is obvious 0/1. |
| 36 | if (getType()->isBooleanType()) return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 37 | // If this is a non-scalar-integer type, we don't care enough to try. |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 38 | if (!getType()->isIntegralType()) return false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 40 | if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) |
| 41 | return PE->getSubExpr()->isKnownToHaveBooleanValue(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 43 | if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(this)) { |
| 44 | switch (UO->getOpcode()) { |
| 45 | case UnaryOperator::Plus: |
| 46 | case UnaryOperator::Extension: |
| 47 | return UO->getSubExpr()->isKnownToHaveBooleanValue(); |
| 48 | default: |
| 49 | return false; |
| 50 | } |
| 51 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 52 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 53 | if (const CastExpr *CE = dyn_cast<CastExpr>(this)) |
| 54 | return CE->getSubExpr()->isKnownToHaveBooleanValue(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 55 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 56 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) { |
| 57 | switch (BO->getOpcode()) { |
| 58 | default: return false; |
| 59 | case BinaryOperator::LT: // Relational operators. |
| 60 | case BinaryOperator::GT: |
| 61 | case BinaryOperator::LE: |
| 62 | case BinaryOperator::GE: |
| 63 | case BinaryOperator::EQ: // Equality operators. |
| 64 | case BinaryOperator::NE: |
| 65 | case BinaryOperator::LAnd: // AND operator. |
| 66 | case BinaryOperator::LOr: // Logical OR operator. |
| 67 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 69 | case BinaryOperator::And: // Bitwise AND operator. |
| 70 | case BinaryOperator::Xor: // Bitwise XOR operator. |
| 71 | case BinaryOperator::Or: // Bitwise OR operator. |
| 72 | // Handle things like (x==2)|(y==12). |
| 73 | return BO->getLHS()->isKnownToHaveBooleanValue() && |
| 74 | BO->getRHS()->isKnownToHaveBooleanValue(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 76 | case BinaryOperator::Comma: |
| 77 | case BinaryOperator::Assign: |
| 78 | return BO->getRHS()->isKnownToHaveBooleanValue(); |
| 79 | } |
| 80 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 82 | if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(this)) |
| 83 | return CO->getTrueExpr()->isKnownToHaveBooleanValue() && |
| 84 | CO->getFalseExpr()->isKnownToHaveBooleanValue(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 4ebae65 | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | |
Chris Lattner | 0eedafe | 2006-08-24 04:56:27 +0000 | [diff] [blame] | 89 | //===----------------------------------------------------------------------===// |
| 90 | // Primary Expressions. |
| 91 | //===----------------------------------------------------------------------===// |
| 92 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 93 | void ExplicitTemplateArgumentList::initializeFrom( |
| 94 | const TemplateArgumentListInfo &Info) { |
| 95 | LAngleLoc = Info.getLAngleLoc(); |
| 96 | RAngleLoc = Info.getRAngleLoc(); |
| 97 | NumTemplateArgs = Info.size(); |
| 98 | |
| 99 | TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); |
| 100 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 101 | new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); |
| 102 | } |
| 103 | |
| 104 | void ExplicitTemplateArgumentList::copyInto( |
| 105 | TemplateArgumentListInfo &Info) const { |
| 106 | Info.setLAngleLoc(LAngleLoc); |
| 107 | Info.setRAngleLoc(RAngleLoc); |
| 108 | for (unsigned I = 0; I != NumTemplateArgs; ++I) |
| 109 | Info.addArgument(getTemplateArgs()[I]); |
| 110 | } |
| 111 | |
| 112 | std::size_t ExplicitTemplateArgumentList::sizeFor( |
| 113 | const TemplateArgumentListInfo &Info) { |
| 114 | return sizeof(ExplicitTemplateArgumentList) + |
| 115 | sizeof(TemplateArgumentLoc) * Info.size(); |
| 116 | } |
| 117 | |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 118 | void DeclRefExpr::computeDependence() { |
| 119 | TypeDependent = false; |
| 120 | ValueDependent = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 122 | NamedDecl *D = getDecl(); |
| 123 | |
| 124 | // (TD) C++ [temp.dep.expr]p3: |
| 125 | // An id-expression is type-dependent if it contains: |
| 126 | // |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 127 | // and |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 128 | // |
| 129 | // (VD) C++ [temp.dep.constexpr]p2: |
| 130 | // An identifier is value-dependent if it is: |
| 131 | |
| 132 | // (TD) - an identifier that was declared with dependent type |
| 133 | // (VD) - a name declared with a dependent type, |
| 134 | if (getType()->isDependentType()) { |
| 135 | TypeDependent = true; |
| 136 | ValueDependent = true; |
| 137 | } |
| 138 | // (TD) - a conversion-function-id that specifies a dependent type |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 139 | else if (D->getDeclName().getNameKind() |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 140 | == DeclarationName::CXXConversionFunctionName && |
| 141 | D->getDeclName().getCXXNameType()->isDependentType()) { |
| 142 | TypeDependent = true; |
| 143 | ValueDependent = true; |
| 144 | } |
| 145 | // (TD) - a template-id that is dependent, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 146 | else if (hasExplicitTemplateArgumentList() && |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 147 | TemplateSpecializationType::anyDependentTemplateArguments( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 148 | getTemplateArgs(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 149 | getNumTemplateArgs())) { |
| 150 | TypeDependent = true; |
| 151 | ValueDependent = true; |
| 152 | } |
| 153 | // (VD) - the name of a non-type template parameter, |
| 154 | else if (isa<NonTypeTemplateParmDecl>(D)) |
| 155 | ValueDependent = true; |
| 156 | // (VD) - a constant with integral or enumeration type and is |
| 157 | // initialized with an expression that is value-dependent. |
| 158 | else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { |
| 159 | if (Var->getType()->isIntegralType() && |
Douglas Gregor | 5fcb51c | 2010-01-15 16:21:02 +0000 | [diff] [blame] | 160 | Var->getType().getCVRQualifiers() == Qualifiers::Const) { |
Sebastian Redl | 5ca7984 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 161 | if (const Expr *Init = Var->getAnyInitializer()) |
Douglas Gregor | 5fcb51c | 2010-01-15 16:21:02 +0000 | [diff] [blame] | 162 | if (Init->isValueDependent()) |
| 163 | ValueDependent = true; |
| 164 | } |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 165 | } |
| 166 | // (TD) - a nested-name-specifier or a qualified-id that names a |
| 167 | // member of an unknown specialization. |
| 168 | // (handled by DependentScopeDeclRefExpr) |
| 169 | } |
| 170 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 171 | DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 172 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 173 | ValueDecl *D, SourceLocation NameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 174 | const TemplateArgumentListInfo *TemplateArgs, |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 175 | QualType T) |
| 176 | : Expr(DeclRefExprClass, T, false, false), |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 177 | DecoratedD(D, |
| 178 | (Qualifier? HasQualifierFlag : 0) | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 179 | (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 180 | Loc(NameLoc) { |
| 181 | if (Qualifier) { |
| 182 | NameQualifier *NQ = getNameQualifier(); |
| 183 | NQ->NNS = Qualifier; |
| 184 | NQ->Range = QualifierRange; |
| 185 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 186 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 187 | if (TemplateArgs) |
| 188 | getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs); |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 189 | |
| 190 | computeDependence(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, |
| 194 | NestedNameSpecifier *Qualifier, |
| 195 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 196 | ValueDecl *D, |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 197 | SourceLocation NameLoc, |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 198 | QualType T, |
| 199 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 200 | std::size_t Size = sizeof(DeclRefExpr); |
| 201 | if (Qualifier != 0) |
| 202 | Size += sizeof(NameQualifier); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 203 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 204 | if (TemplateArgs) |
| 205 | Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 206 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 207 | void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>()); |
| 208 | return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc, |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 209 | TemplateArgs, T); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | SourceRange DeclRefExpr::getSourceRange() const { |
| 213 | // FIXME: Does not handle multi-token names well, e.g., operator[]. |
| 214 | SourceRange R(Loc); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 215 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 216 | if (hasQualifier()) |
| 217 | R.setBegin(getQualifierRange().getBegin()); |
| 218 | if (hasExplicitTemplateArgumentList()) |
| 219 | R.setEnd(getRAngleLoc()); |
| 220 | return R; |
| 221 | } |
| 222 | |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 223 | // FIXME: Maybe this should use DeclPrinter with a special "print predefined |
| 224 | // expr" policy instead. |
Anders Carlsson | 5bd8d19 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 225 | std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { |
| 226 | ASTContext &Context = CurrentDecl->getASTContext(); |
| 227 | |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 228 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { |
Anders Carlsson | 5bd8d19 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 229 | if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 230 | return FD->getNameAsString(); |
| 231 | |
| 232 | llvm::SmallString<256> Name; |
| 233 | llvm::raw_svector_ostream Out(Name); |
| 234 | |
| 235 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
Anders Carlsson | 5bd8d19 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 236 | if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 237 | Out << "virtual "; |
Sam Weinig | 4e83bd2 | 2009-12-27 01:38:20 +0000 | [diff] [blame] | 238 | if (MD->isStatic()) |
| 239 | Out << "static "; |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | PrintingPolicy Policy(Context.getLangOptions()); |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 243 | |
| 244 | std::string Proto = FD->getQualifiedNameAsString(Policy); |
| 245 | |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 246 | const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 247 | const FunctionProtoType *FT = 0; |
| 248 | if (FD->hasWrittenPrototype()) |
| 249 | FT = dyn_cast<FunctionProtoType>(AFT); |
| 250 | |
| 251 | Proto += "("; |
| 252 | if (FT) { |
| 253 | llvm::raw_string_ostream POut(Proto); |
| 254 | for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { |
| 255 | if (i) POut << ", "; |
| 256 | std::string Param; |
| 257 | FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); |
| 258 | POut << Param; |
| 259 | } |
| 260 | |
| 261 | if (FT->isVariadic()) { |
| 262 | if (FD->getNumParams()) POut << ", "; |
| 263 | POut << "..."; |
| 264 | } |
| 265 | } |
| 266 | Proto += ")"; |
| 267 | |
Sam Weinig | 4e83bd2 | 2009-12-27 01:38:20 +0000 | [diff] [blame] | 268 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
| 269 | Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); |
| 270 | if (ThisQuals.hasConst()) |
| 271 | Proto += " const"; |
| 272 | if (ThisQuals.hasVolatile()) |
| 273 | Proto += " volatile"; |
| 274 | } |
| 275 | |
Sam Weinig | d060ed4 | 2009-12-06 23:55:13 +0000 | [diff] [blame] | 276 | if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) |
| 277 | AFT->getResultType().getAsStringInternal(Proto, Policy); |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 278 | |
| 279 | Out << Proto; |
| 280 | |
| 281 | Out.flush(); |
| 282 | return Name.str().str(); |
| 283 | } |
| 284 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { |
| 285 | llvm::SmallString<256> Name; |
| 286 | llvm::raw_svector_ostream Out(Name); |
| 287 | Out << (MD->isInstanceMethod() ? '-' : '+'); |
| 288 | Out << '['; |
Ted Kremenek | 361ffd9 | 2010-03-18 21:23:08 +0000 | [diff] [blame] | 289 | |
| 290 | // For incorrect code, there might not be an ObjCInterfaceDecl. Do |
| 291 | // a null check to avoid a crash. |
| 292 | if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 293 | Out << ID; |
Ted Kremenek | 361ffd9 | 2010-03-18 21:23:08 +0000 | [diff] [blame] | 294 | |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 295 | if (const ObjCCategoryImplDecl *CID = |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 296 | dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) |
| 297 | Out << '(' << CID << ')'; |
| 298 | |
Anders Carlsson | 2fb0824 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 299 | Out << ' '; |
| 300 | Out << MD->getSelector().getAsString(); |
| 301 | Out << ']'; |
| 302 | |
| 303 | Out.flush(); |
| 304 | return Name.str().str(); |
| 305 | } |
| 306 | if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { |
| 307 | // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. |
| 308 | return "top level"; |
| 309 | } |
| 310 | return ""; |
| 311 | } |
| 312 | |
Chris Lattner | a017313 | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 313 | /// getValueAsApproximateDouble - This returns the value as an inaccurate |
| 314 | /// double. Note that this may cause loss of precision, but is useful for |
| 315 | /// debugging dumps, etc. |
| 316 | double FloatingLiteral::getValueAsApproximateDouble() const { |
| 317 | llvm::APFloat V = getValue(); |
Dale Johannesen | c48814b | 2008-10-09 23:02:32 +0000 | [diff] [blame] | 318 | bool ignored; |
| 319 | V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, |
| 320 | &ignored); |
Chris Lattner | a017313 | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 321 | return V.convertToDouble(); |
| 322 | } |
| 323 | |
Chris Lattner | f83b5af | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 324 | StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, |
| 325 | unsigned ByteLength, bool Wide, |
| 326 | QualType Ty, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | const SourceLocation *Loc, |
Anders Carlsson | a390581 | 2009-03-15 18:34:13 +0000 | [diff] [blame] | 328 | unsigned NumStrs) { |
Chris Lattner | f83b5af | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 329 | // Allocate enough space for the StringLiteral plus an array of locations for |
| 330 | // any concatenated string tokens. |
| 331 | void *Mem = C.Allocate(sizeof(StringLiteral)+ |
| 332 | sizeof(SourceLocation)*(NumStrs-1), |
| 333 | llvm::alignof<StringLiteral>()); |
| 334 | StringLiteral *SL = new (Mem) StringLiteral(Ty); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 335 | |
Steve Naroff | df7855b | 2007-02-21 23:46:25 +0000 | [diff] [blame] | 336 | // OPTIMIZE: could allocate this appended to the StringLiteral. |
Chris Lattner | f83b5af | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 337 | char *AStrData = new (C, 1) char[ByteLength]; |
| 338 | memcpy(AStrData, StrData, ByteLength); |
| 339 | SL->StrData = AStrData; |
| 340 | SL->ByteLength = ByteLength; |
| 341 | SL->IsWide = Wide; |
| 342 | SL->TokLocs[0] = Loc[0]; |
| 343 | SL->NumConcatenated = NumStrs; |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 630970d | 2009-02-18 05:49:11 +0000 | [diff] [blame] | 345 | if (NumStrs != 1) |
Chris Lattner | f83b5af | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 346 | memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); |
| 347 | return SL; |
Chris Lattner | 630970d | 2009-02-18 05:49:11 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Douglas Gregor | 958dfc9 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 350 | StringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { |
| 351 | void *Mem = C.Allocate(sizeof(StringLiteral)+ |
| 352 | sizeof(SourceLocation)*(NumStrs-1), |
| 353 | llvm::alignof<StringLiteral>()); |
| 354 | StringLiteral *SL = new (Mem) StringLiteral(QualType()); |
| 355 | SL->StrData = 0; |
| 356 | SL->ByteLength = 0; |
| 357 | SL->NumConcatenated = NumStrs; |
| 358 | return SL; |
| 359 | } |
| 360 | |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 361 | void StringLiteral::DoDestroy(ASTContext &C) { |
Ted Kremenek | 5a20195 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 362 | C.Deallocate(const_cast<char*>(StrData)); |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 363 | Expr::DoDestroy(C); |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Daniel Dunbar | 3621788 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 366 | void StringLiteral::setString(ASTContext &C, llvm::StringRef Str) { |
Douglas Gregor | 958dfc9 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 367 | if (StrData) |
| 368 | C.Deallocate(const_cast<char*>(StrData)); |
| 369 | |
Daniel Dunbar | 3621788 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 370 | char *AStrData = new (C, 1) char[Str.size()]; |
| 371 | memcpy(AStrData, Str.data(), Str.size()); |
Douglas Gregor | 958dfc9 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 372 | StrData = AStrData; |
Daniel Dunbar | 3621788 | 2009-09-22 03:27:33 +0000 | [diff] [blame] | 373 | ByteLength = Str.size(); |
Douglas Gregor | 958dfc9 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 376 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 377 | /// corresponds to, e.g. "sizeof" or "[pre]++". |
| 378 | const char *UnaryOperator::getOpcodeStr(Opcode Op) { |
| 379 | switch (Op) { |
Chris Lattner | c52b118 | 2006-10-25 05:45:55 +0000 | [diff] [blame] | 380 | default: assert(0 && "Unknown unary operator"); |
Chris Lattner | 1576870 | 2006-11-05 23:54:51 +0000 | [diff] [blame] | 381 | case PostInc: return "++"; |
| 382 | case PostDec: return "--"; |
| 383 | case PreInc: return "++"; |
| 384 | case PreDec: return "--"; |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 385 | case AddrOf: return "&"; |
| 386 | case Deref: return "*"; |
| 387 | case Plus: return "+"; |
| 388 | case Minus: return "-"; |
| 389 | case Not: return "~"; |
| 390 | case LNot: return "!"; |
| 391 | case Real: return "__real"; |
| 392 | case Imag: return "__imag"; |
Chris Lattner | c52b118 | 2006-10-25 05:45:55 +0000 | [diff] [blame] | 393 | case Extension: return "__extension__"; |
Chris Lattner | f17bd42 | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 394 | case OffsetOf: return "__builtin_offsetof"; |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | UnaryOperator::Opcode |
Douglas Gregor | 084d855 | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 399 | UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { |
| 400 | switch (OO) { |
Douglas Gregor | 084d855 | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 401 | default: assert(false && "No unary operator for overloaded function"); |
Chris Lattner | 17556b2 | 2009-03-22 00:10:22 +0000 | [diff] [blame] | 402 | case OO_PlusPlus: return Postfix ? PostInc : PreInc; |
| 403 | case OO_MinusMinus: return Postfix ? PostDec : PreDec; |
| 404 | case OO_Amp: return AddrOf; |
| 405 | case OO_Star: return Deref; |
| 406 | case OO_Plus: return Plus; |
| 407 | case OO_Minus: return Minus; |
| 408 | case OO_Tilde: return Not; |
| 409 | case OO_Exclaim: return LNot; |
Douglas Gregor | 084d855 | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { |
| 414 | switch (Opc) { |
| 415 | case PostInc: case PreInc: return OO_PlusPlus; |
| 416 | case PostDec: case PreDec: return OO_MinusMinus; |
| 417 | case AddrOf: return OO_Amp; |
| 418 | case Deref: return OO_Star; |
| 419 | case Plus: return OO_Plus; |
| 420 | case Minus: return OO_Minus; |
| 421 | case Not: return OO_Tilde; |
| 422 | case LNot: return OO_Exclaim; |
| 423 | default: return OO_None; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | |
Chris Lattner | 0eedafe | 2006-08-24 04:56:27 +0000 | [diff] [blame] | 428 | //===----------------------------------------------------------------------===// |
| 429 | // Postfix Operators. |
| 430 | //===----------------------------------------------------------------------===// |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 431 | |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 432 | CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, |
Ted Kremenek | 5a20195 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 433 | unsigned numargs, QualType t, SourceLocation rparenloc) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | : Expr(SC, t, |
Douglas Gregor | 4619e43 | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 435 | fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), |
Chris Lattner | 8ba2247 | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 436 | fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), |
Douglas Gregor | 4619e43 | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 437 | NumArgs(numargs) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 439 | SubExprs = new (C) Stmt*[numargs+1]; |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 440 | SubExprs[FN] = fn; |
| 441 | for (unsigned i = 0; i != numargs; ++i) |
| 442 | SubExprs[i+ARGS_START] = args[i]; |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 443 | |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 444 | RParenLoc = rparenloc; |
| 445 | } |
Nate Begeman | 1e36a85 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 446 | |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 447 | CallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, |
| 448 | QualType t, SourceLocation rparenloc) |
Douglas Gregor | 4619e43 | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 449 | : Expr(CallExprClass, t, |
| 450 | fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), |
Chris Lattner | 8ba2247 | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 451 | fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), |
Douglas Gregor | 4619e43 | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 452 | NumArgs(numargs) { |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 453 | |
| 454 | SubExprs = new (C) Stmt*[numargs+1]; |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 455 | SubExprs[FN] = fn; |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 456 | for (unsigned i = 0; i != numargs; ++i) |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 457 | SubExprs[i+ARGS_START] = args[i]; |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 458 | |
Chris Lattner | 9b3b9a1 | 2007-06-27 06:08:24 +0000 | [diff] [blame] | 459 | RParenLoc = rparenloc; |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 462 | CallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) |
| 463 | : Expr(SC, Empty), SubExprs(0), NumArgs(0) { |
Douglas Gregor | e20a2e5 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 464 | SubExprs = new (C) Stmt*[1]; |
| 465 | } |
| 466 | |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 467 | void CallExpr::DoDestroy(ASTContext& C) { |
Ted Kremenek | d7b4f40 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 468 | DestroyChildren(C); |
| 469 | if (SubExprs) C.Deallocate(SubExprs); |
| 470 | this->~CallExpr(); |
| 471 | C.Deallocate(this); |
| 472 | } |
| 473 | |
Nuno Lopes | 518e370 | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 474 | Decl *CallExpr::getCalleeDecl() { |
Zhongxing Xu | 3c8fa97 | 2009-07-17 07:29:51 +0000 | [diff] [blame] | 475 | Expr *CEE = getCallee()->IgnoreParenCasts(); |
Chris Lattner | 5230191 | 2009-07-17 15:46:27 +0000 | [diff] [blame] | 476 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) |
Nuno Lopes | 518e370 | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 477 | return DRE->getDecl(); |
Nuno Lopes | c095b53 | 2009-12-24 00:28:18 +0000 | [diff] [blame] | 478 | if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) |
| 479 | return ME->getMemberDecl(); |
Zhongxing Xu | 3c8fa97 | 2009-07-17 07:29:51 +0000 | [diff] [blame] | 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Nuno Lopes | 518e370 | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 484 | FunctionDecl *CallExpr::getDirectCallee() { |
Chris Lattner | 3a6af3d | 2009-12-21 01:10:56 +0000 | [diff] [blame] | 485 | return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); |
Nuno Lopes | 518e370 | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Chris Lattner | e4407ed | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 488 | /// setNumArgs - This changes the number of arguments present in this call. |
| 489 | /// Any orphaned expressions are deleted by this, and any new operands are set |
| 490 | /// to null. |
Ted Kremenek | 5a20195 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 491 | void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { |
Chris Lattner | e4407ed | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 492 | // No change, just return. |
| 493 | if (NumArgs == getNumArgs()) return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 494 | |
Chris Lattner | e4407ed | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 495 | // If shrinking # arguments, just delete the extras and forgot them. |
| 496 | if (NumArgs < getNumArgs()) { |
| 497 | for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i) |
Ted Kremenek | 5a20195 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 498 | getArg(i)->Destroy(C); |
Chris Lattner | e4407ed | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 499 | this->NumArgs = NumArgs; |
| 500 | return; |
| 501 | } |
| 502 | |
| 503 | // Otherwise, we are growing the # arguments. New an bigger argument array. |
Daniel Dunbar | ec5ae3d | 2009-07-28 06:29:46 +0000 | [diff] [blame] | 504 | Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1]; |
Chris Lattner | e4407ed | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 505 | // Copy over args. |
| 506 | for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) |
| 507 | NewSubExprs[i] = SubExprs[i]; |
| 508 | // Null out new args. |
| 509 | for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) |
| 510 | NewSubExprs[i] = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | ba6e557 | 2009-04-17 21:46:47 +0000 | [diff] [blame] | 512 | if (SubExprs) C.Deallocate(SubExprs); |
Chris Lattner | e4407ed | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 513 | SubExprs = NewSubExprs; |
| 514 | this->NumArgs = NumArgs; |
| 515 | } |
| 516 | |
Chris Lattner | 01ff98a | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 517 | /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If |
| 518 | /// not, return 0. |
Douglas Gregor | e711f70 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 519 | unsigned CallExpr::isBuiltinCall(ASTContext &Context) const { |
Steve Naroff | f6e3b329 | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 520 | // All simple function calls (e.g. func()) are implicitly cast to pointer to |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | // function. As a result, we try and obtain the DeclRefExpr from the |
Steve Naroff | f6e3b329 | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 522 | // ImplicitCastExpr. |
| 523 | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); |
| 524 | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). |
Chris Lattner | 01ff98a | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 525 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 526 | |
Steve Naroff | f6e3b329 | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 527 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); |
| 528 | if (!DRE) |
Chris Lattner | 01ff98a | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 529 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | |
Anders Carlsson | fbcf676 | 2008-01-31 02:13:57 +0000 | [diff] [blame] | 531 | const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); |
| 532 | if (!FDecl) |
Chris Lattner | 01ff98a | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 533 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 534 | |
Douglas Gregor | 9eb16ea | 2008-11-21 15:30:19 +0000 | [diff] [blame] | 535 | if (!FDecl->getIdentifier()) |
| 536 | return 0; |
| 537 | |
Douglas Gregor | 15fc956 | 2009-09-12 00:22:50 +0000 | [diff] [blame] | 538 | return FDecl->getBuiltinID(); |
Chris Lattner | 01ff98a | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 539 | } |
Anders Carlsson | fbcf676 | 2008-01-31 02:13:57 +0000 | [diff] [blame] | 540 | |
Anders Carlsson | 00a2759 | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 541 | QualType CallExpr::getCallReturnType() const { |
| 542 | QualType CalleeType = getCallee()->getType(); |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 543 | if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) |
Anders Carlsson | 00a2759 | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 544 | CalleeType = FnTypePtr->getPointeeType(); |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 545 | else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) |
Anders Carlsson | 00a2759 | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 546 | CalleeType = BPT->getPointeeType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 547 | |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 548 | const FunctionType *FnType = CalleeType->getAs<FunctionType>(); |
Anders Carlsson | 00a2759 | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 549 | return FnType->getResultType(); |
| 550 | } |
Chris Lattner | 01ff98a | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 551 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 552 | OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 553 | SourceLocation OperatorLoc, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 554 | TypeSourceInfo *tsi, |
| 555 | OffsetOfNode* compsPtr, unsigned numComps, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 556 | Expr** exprsPtr, unsigned numExprs, |
| 557 | SourceLocation RParenLoc) { |
| 558 | void *Mem = C.Allocate(sizeof(OffsetOfExpr) + |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 559 | sizeof(OffsetOfNode) * numComps + |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 560 | sizeof(Expr*) * numExprs); |
| 561 | |
| 562 | return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, |
| 563 | exprsPtr, numExprs, RParenLoc); |
| 564 | } |
| 565 | |
| 566 | OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, |
| 567 | unsigned numComps, unsigned numExprs) { |
| 568 | void *Mem = C.Allocate(sizeof(OffsetOfExpr) + |
| 569 | sizeof(OffsetOfNode) * numComps + |
| 570 | sizeof(Expr*) * numExprs); |
| 571 | return new (Mem) OffsetOfExpr(numComps, numExprs); |
| 572 | } |
| 573 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 574 | OffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 575 | SourceLocation OperatorLoc, TypeSourceInfo *tsi, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 576 | OffsetOfNode* compsPtr, unsigned numComps, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 577 | Expr** exprsPtr, unsigned numExprs, |
| 578 | SourceLocation RParenLoc) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 579 | : Expr(OffsetOfExprClass, type, /*TypeDependent=*/false, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 580 | /*ValueDependent=*/tsi->getType()->isDependentType() || |
| 581 | hasAnyTypeDependentArguments(exprsPtr, numExprs) || |
| 582 | hasAnyValueDependentArguments(exprsPtr, numExprs)), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 583 | OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), |
| 584 | NumComps(numComps), NumExprs(numExprs) |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 585 | { |
| 586 | for(unsigned i = 0; i < numComps; ++i) { |
| 587 | setComponent(i, compsPtr[i]); |
| 588 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 589 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 590 | for(unsigned i = 0; i < numExprs; ++i) { |
| 591 | setIndexExpr(i, exprsPtr[i]); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | IdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { |
| 596 | assert(getKind() == Field || getKind() == Identifier); |
| 597 | if (getKind() == Field) |
| 598 | return getField()->getIdentifier(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 599 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 600 | return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); |
| 601 | } |
| 602 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, |
| 604 | NestedNameSpecifier *qual, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 605 | SourceRange qualrange, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 606 | ValueDecl *memberdecl, |
John McCall | a8ae222 | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 607 | DeclAccessPair founddecl, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | SourceLocation l, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 609 | const TemplateArgumentListInfo *targs, |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 610 | QualType ty) { |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 611 | std::size_t Size = sizeof(MemberExpr); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 612 | |
John McCall | a8ae222 | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 613 | bool hasQualOrFound = (qual != 0 || |
| 614 | founddecl.getDecl() != memberdecl || |
| 615 | founddecl.getAccess() != memberdecl->getAccess()); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 616 | if (hasQualOrFound) |
| 617 | Size += sizeof(MemberNameQualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 619 | if (targs) |
| 620 | Size += ExplicitTemplateArgumentList::sizeFor(*targs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 622 | void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>()); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 623 | MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, l, ty); |
| 624 | |
| 625 | if (hasQualOrFound) { |
| 626 | if (qual && qual->isDependent()) { |
| 627 | E->setValueDependent(true); |
| 628 | E->setTypeDependent(true); |
| 629 | } |
| 630 | E->HasQualifierOrFoundDecl = true; |
| 631 | |
| 632 | MemberNameQualifier *NQ = E->getMemberQualifier(); |
| 633 | NQ->NNS = qual; |
| 634 | NQ->Range = qualrange; |
| 635 | NQ->FoundDecl = founddecl; |
| 636 | } |
| 637 | |
| 638 | if (targs) { |
| 639 | E->HasExplicitTemplateArgumentList = true; |
| 640 | E->getExplicitTemplateArgumentList()->initializeFrom(*targs); |
| 641 | } |
| 642 | |
| 643 | return E; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Anders Carlsson | 496335e | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 646 | const char *CastExpr::getCastKindName() const { |
| 647 | switch (getCastKind()) { |
| 648 | case CastExpr::CK_Unknown: |
| 649 | return "Unknown"; |
| 650 | case CastExpr::CK_BitCast: |
| 651 | return "BitCast"; |
| 652 | case CastExpr::CK_NoOp: |
| 653 | return "NoOp"; |
Anders Carlsson | a70ad93 | 2009-11-12 16:43:42 +0000 | [diff] [blame] | 654 | case CastExpr::CK_BaseToDerived: |
| 655 | return "BaseToDerived"; |
Anders Carlsson | 496335e | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 656 | case CastExpr::CK_DerivedToBase: |
| 657 | return "DerivedToBase"; |
John McCall | d9c7c656 | 2010-03-30 23:58:03 +0000 | [diff] [blame] | 658 | case CastExpr::CK_UncheckedDerivedToBase: |
| 659 | return "UncheckedDerivedToBase"; |
Anders Carlsson | 496335e | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 660 | case CastExpr::CK_Dynamic: |
| 661 | return "Dynamic"; |
| 662 | case CastExpr::CK_ToUnion: |
| 663 | return "ToUnion"; |
| 664 | case CastExpr::CK_ArrayToPointerDecay: |
| 665 | return "ArrayToPointerDecay"; |
| 666 | case CastExpr::CK_FunctionToPointerDecay: |
| 667 | return "FunctionToPointerDecay"; |
| 668 | case CastExpr::CK_NullToMemberPointer: |
| 669 | return "NullToMemberPointer"; |
| 670 | case CastExpr::CK_BaseToDerivedMemberPointer: |
| 671 | return "BaseToDerivedMemberPointer"; |
Anders Carlsson | 3f0db2b | 2009-10-30 00:46:35 +0000 | [diff] [blame] | 672 | case CastExpr::CK_DerivedToBaseMemberPointer: |
| 673 | return "DerivedToBaseMemberPointer"; |
Anders Carlsson | 496335e | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 674 | case CastExpr::CK_UserDefinedConversion: |
| 675 | return "UserDefinedConversion"; |
| 676 | case CastExpr::CK_ConstructorConversion: |
| 677 | return "ConstructorConversion"; |
Anders Carlsson | 7cd39e0 | 2009-09-15 04:48:33 +0000 | [diff] [blame] | 678 | case CastExpr::CK_IntegralToPointer: |
| 679 | return "IntegralToPointer"; |
| 680 | case CastExpr::CK_PointerToIntegral: |
| 681 | return "PointerToIntegral"; |
Anders Carlsson | ef918ac | 2009-10-16 02:35:04 +0000 | [diff] [blame] | 682 | case CastExpr::CK_ToVoid: |
| 683 | return "ToVoid"; |
Anders Carlsson | 43d70f8 | 2009-10-16 05:23:41 +0000 | [diff] [blame] | 684 | case CastExpr::CK_VectorSplat: |
| 685 | return "VectorSplat"; |
Anders Carlsson | 094c459 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 686 | case CastExpr::CK_IntegralCast: |
| 687 | return "IntegralCast"; |
| 688 | case CastExpr::CK_IntegralToFloating: |
| 689 | return "IntegralToFloating"; |
| 690 | case CastExpr::CK_FloatingToIntegral: |
| 691 | return "FloatingToIntegral"; |
Benjamin Kramer | beb873d | 2009-10-18 19:02:15 +0000 | [diff] [blame] | 692 | case CastExpr::CK_FloatingCast: |
| 693 | return "FloatingCast"; |
Anders Carlsson | 7fa434c | 2009-11-23 20:04:44 +0000 | [diff] [blame] | 694 | case CastExpr::CK_MemberPointerToBoolean: |
| 695 | return "MemberPointerToBoolean"; |
Fariborz Jahanian | e19122f | 2009-12-08 23:46:15 +0000 | [diff] [blame] | 696 | case CastExpr::CK_AnyPointerToObjCPointerCast: |
| 697 | return "AnyPointerToObjCPointerCast"; |
Fariborz Jahanian | ffe912c | 2009-12-11 22:40:48 +0000 | [diff] [blame] | 698 | case CastExpr::CK_AnyPointerToBlockPointerCast: |
| 699 | return "AnyPointerToBlockPointerCast"; |
Anders Carlsson | 496335e | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Anders Carlsson | 496335e | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 702 | assert(0 && "Unhandled cast kind!"); |
| 703 | return 0; |
| 704 | } |
| 705 | |
Anders Carlsson | c20f78c | 2010-04-23 21:02:34 +0000 | [diff] [blame] | 706 | void CastExpr::DoDestroy(ASTContext &C) |
| 707 | { |
Anders Carlsson | 0c509ee | 2010-04-24 16:57:13 +0000 | [diff] [blame] | 708 | BasePath.Destroy(); |
Anders Carlsson | c20f78c | 2010-04-23 21:02:34 +0000 | [diff] [blame] | 709 | Expr::DoDestroy(C); |
| 710 | } |
| 711 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 712 | Expr *CastExpr::getSubExprAsWritten() { |
| 713 | Expr *SubExpr = 0; |
| 714 | CastExpr *E = this; |
| 715 | do { |
| 716 | SubExpr = E->getSubExpr(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 717 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 718 | // Skip any temporary bindings; they're implicit. |
| 719 | if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) |
| 720 | SubExpr = Binder->getSubExpr(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 722 | // Conversions by constructor and conversion functions have a |
| 723 | // subexpression describing the call; strip it off. |
| 724 | if (E->getCastKind() == CastExpr::CK_ConstructorConversion) |
| 725 | SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); |
| 726 | else if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) |
| 727 | SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 728 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 729 | // If the subexpression we're left with is an implicit cast, look |
| 730 | // through that, too. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 731 | } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); |
| 732 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 733 | return SubExpr; |
| 734 | } |
| 735 | |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 736 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 737 | /// corresponds to, e.g. "<<=". |
| 738 | const char *BinaryOperator::getOpcodeStr(Opcode Op) { |
| 739 | switch (Op) { |
Douglas Gregor | 0f60e9a | 2009-03-12 22:51:37 +0000 | [diff] [blame] | 740 | case PtrMemD: return ".*"; |
| 741 | case PtrMemI: return "->*"; |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 742 | case Mul: return "*"; |
| 743 | case Div: return "/"; |
| 744 | case Rem: return "%"; |
| 745 | case Add: return "+"; |
| 746 | case Sub: return "-"; |
| 747 | case Shl: return "<<"; |
| 748 | case Shr: return ">>"; |
| 749 | case LT: return "<"; |
| 750 | case GT: return ">"; |
| 751 | case LE: return "<="; |
| 752 | case GE: return ">="; |
| 753 | case EQ: return "=="; |
| 754 | case NE: return "!="; |
| 755 | case And: return "&"; |
| 756 | case Xor: return "^"; |
| 757 | case Or: return "|"; |
| 758 | case LAnd: return "&&"; |
| 759 | case LOr: return "||"; |
| 760 | case Assign: return "="; |
| 761 | case MulAssign: return "*="; |
| 762 | case DivAssign: return "/="; |
| 763 | case RemAssign: return "%="; |
| 764 | case AddAssign: return "+="; |
| 765 | case SubAssign: return "-="; |
| 766 | case ShlAssign: return "<<="; |
| 767 | case ShrAssign: return ">>="; |
| 768 | case AndAssign: return "&="; |
| 769 | case XorAssign: return "^="; |
| 770 | case OrAssign: return "|="; |
| 771 | case Comma: return ","; |
| 772 | } |
Douglas Gregor | 0f60e9a | 2009-03-12 22:51:37 +0000 | [diff] [blame] | 773 | |
| 774 | return ""; |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 775 | } |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 776 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | BinaryOperator::Opcode |
Douglas Gregor | 1baf54e | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 778 | BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { |
| 779 | switch (OO) { |
Chris Lattner | 17556b2 | 2009-03-22 00:10:22 +0000 | [diff] [blame] | 780 | default: assert(false && "Not an overloadable binary operator"); |
Douglas Gregor | 1baf54e | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 781 | case OO_Plus: return Add; |
| 782 | case OO_Minus: return Sub; |
| 783 | case OO_Star: return Mul; |
| 784 | case OO_Slash: return Div; |
| 785 | case OO_Percent: return Rem; |
| 786 | case OO_Caret: return Xor; |
| 787 | case OO_Amp: return And; |
| 788 | case OO_Pipe: return Or; |
| 789 | case OO_Equal: return Assign; |
| 790 | case OO_Less: return LT; |
| 791 | case OO_Greater: return GT; |
| 792 | case OO_PlusEqual: return AddAssign; |
| 793 | case OO_MinusEqual: return SubAssign; |
| 794 | case OO_StarEqual: return MulAssign; |
| 795 | case OO_SlashEqual: return DivAssign; |
| 796 | case OO_PercentEqual: return RemAssign; |
| 797 | case OO_CaretEqual: return XorAssign; |
| 798 | case OO_AmpEqual: return AndAssign; |
| 799 | case OO_PipeEqual: return OrAssign; |
| 800 | case OO_LessLess: return Shl; |
| 801 | case OO_GreaterGreater: return Shr; |
| 802 | case OO_LessLessEqual: return ShlAssign; |
| 803 | case OO_GreaterGreaterEqual: return ShrAssign; |
| 804 | case OO_EqualEqual: return EQ; |
| 805 | case OO_ExclaimEqual: return NE; |
| 806 | case OO_LessEqual: return LE; |
| 807 | case OO_GreaterEqual: return GE; |
| 808 | case OO_AmpAmp: return LAnd; |
| 809 | case OO_PipePipe: return LOr; |
| 810 | case OO_Comma: return Comma; |
| 811 | case OO_ArrowStar: return PtrMemI; |
Douglas Gregor | 1baf54e | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | |
| 815 | OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { |
| 816 | static const OverloadedOperatorKind OverOps[] = { |
| 817 | /* .* Cannot be overloaded */OO_None, OO_ArrowStar, |
| 818 | OO_Star, OO_Slash, OO_Percent, |
| 819 | OO_Plus, OO_Minus, |
| 820 | OO_LessLess, OO_GreaterGreater, |
| 821 | OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, |
| 822 | OO_EqualEqual, OO_ExclaimEqual, |
| 823 | OO_Amp, |
| 824 | OO_Caret, |
| 825 | OO_Pipe, |
| 826 | OO_AmpAmp, |
| 827 | OO_PipePipe, |
| 828 | OO_Equal, OO_StarEqual, |
| 829 | OO_SlashEqual, OO_PercentEqual, |
| 830 | OO_PlusEqual, OO_MinusEqual, |
| 831 | OO_LessLessEqual, OO_GreaterGreaterEqual, |
| 832 | OO_AmpEqual, OO_CaretEqual, |
| 833 | OO_PipeEqual, |
| 834 | OO_Comma |
| 835 | }; |
| 836 | return OverOps[Opc]; |
| 837 | } |
| 838 | |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 839 | InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, |
Chris Lattner | 07d754a | 2008-10-26 23:43:26 +0000 | [diff] [blame] | 840 | Expr **initExprs, unsigned numInits, |
Douglas Gregor | 347f7ea | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 841 | SourceLocation rbraceloc) |
Douglas Gregor | deebf6e | 2009-11-19 23:25:22 +0000 | [diff] [blame] | 842 | : Expr(InitListExprClass, QualType(), false, false), |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 843 | InitExprs(C, numInits), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 844 | LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 845 | UnionFieldInit(0), HadArrayRangeDesignator(false) |
| 846 | { |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 847 | for (unsigned I = 0; I != numInits; ++I) { |
| 848 | if (initExprs[I]->isTypeDependent()) |
Douglas Gregor | deebf6e | 2009-11-19 23:25:22 +0000 | [diff] [blame] | 849 | TypeDependent = true; |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 850 | if (initExprs[I]->isValueDependent()) |
Douglas Gregor | deebf6e | 2009-11-19 23:25:22 +0000 | [diff] [blame] | 851 | ValueDependent = true; |
| 852 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 853 | |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 854 | InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); |
Anders Carlsson | 4692db0 | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 855 | } |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 856 | |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 857 | void InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 858 | if (NumInits > InitExprs.size()) |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 859 | InitExprs.reserve(C, NumInits); |
Douglas Gregor | 6d00c99 | 2009-03-20 23:58:33 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 862 | void InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 863 | for (unsigned Idx = NumInits, LastIdx = InitExprs.size(); |
| 864 | Idx < LastIdx; ++Idx) |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 865 | InitExprs[Idx]->Destroy(C); |
| 866 | InitExprs.resize(C, NumInits, 0); |
Douglas Gregor | 347f7ea | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 869 | Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 870 | if (Init >= InitExprs.size()) { |
Ted Kremenek | ac03461 | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 871 | InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 872 | InitExprs.back() = expr; |
| 873 | return 0; |
Douglas Gregor | 347f7ea | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 874 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 875 | |
Douglas Gregor | 347f7ea | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 876 | Expr *Result = cast_or_null<Expr>(InitExprs[Init]); |
| 877 | InitExprs[Init] = expr; |
| 878 | return Result; |
| 879 | } |
| 880 | |
Steve Naroff | 991e99d | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 881 | /// getFunctionType - Return the underlying function type for this block. |
Steve Naroff | c540d66 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 882 | /// |
| 883 | const FunctionType *BlockExpr::getFunctionType() const { |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 884 | return getType()->getAs<BlockPointerType>()-> |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 885 | getPointeeType()->getAs<FunctionType>(); |
Steve Naroff | c540d66 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 888 | SourceLocation BlockExpr::getCaretLocation() const { |
| 889 | return TheBlock->getCaretLocation(); |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 891 | const Stmt *BlockExpr::getBody() const { |
Douglas Gregor | e3dcb2d | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 892 | return TheBlock->getBody(); |
| 893 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | Stmt *BlockExpr::getBody() { |
| 895 | return TheBlock->getBody(); |
Douglas Gregor | e3dcb2d | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 896 | } |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 897 | |
| 898 | |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 899 | //===----------------------------------------------------------------------===// |
| 900 | // Generic Expression Routines |
| 901 | //===----------------------------------------------------------------------===// |
| 902 | |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 903 | /// isUnusedResultAWarning - Return true if this immediate expression should |
| 904 | /// be warned about if the result is unused. If so, fill in Loc and Ranges |
| 905 | /// with location to warn on and the source range[s] to report with the |
| 906 | /// warning. |
| 907 | bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 908 | SourceRange &R2, ASTContext &Ctx) const { |
Anders Carlsson | 789e2cc | 2009-05-15 23:10:19 +0000 | [diff] [blame] | 909 | // Don't warn if the expr is type dependent. The type could end up |
| 910 | // instantiating to void. |
| 911 | if (isTypeDependent()) |
| 912 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 914 | switch (getStmtClass()) { |
| 915 | default: |
John McCall | c493a73 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 916 | if (getType()->isVoidType()) |
| 917 | return false; |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 918 | Loc = getExprLoc(); |
| 919 | R1 = getSourceRange(); |
| 920 | return true; |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 921 | case ParenExprClass: |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 922 | return cast<ParenExpr>(this)->getSubExpr()-> |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 923 | isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 924 | case UnaryOperatorClass: { |
| 925 | const UnaryOperator *UO = cast<UnaryOperator>(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 926 | |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 927 | switch (UO->getOpcode()) { |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 928 | default: break; |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 929 | case UnaryOperator::PostInc: |
| 930 | case UnaryOperator::PostDec: |
| 931 | case UnaryOperator::PreInc: |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 932 | case UnaryOperator::PreDec: // ++/-- |
| 933 | return false; // Not a warning. |
Chris Lattner | a44d116 | 2007-06-27 05:58:59 +0000 | [diff] [blame] | 934 | case UnaryOperator::Deref: |
| 935 | // Dereferencing a volatile pointer is a side-effect. |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 936 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 937 | return false; |
| 938 | break; |
Chris Lattner | a44d116 | 2007-06-27 05:58:59 +0000 | [diff] [blame] | 939 | case UnaryOperator::Real: |
| 940 | case UnaryOperator::Imag: |
| 941 | // accessing a piece of a volatile complex is a side-effect. |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 942 | if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) |
| 943 | .isVolatileQualified()) |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 944 | return false; |
| 945 | break; |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 946 | case UnaryOperator::Extension: |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 947 | return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 948 | } |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 949 | Loc = UO->getOperatorLoc(); |
| 950 | R1 = UO->getSubExpr()->getSourceRange(); |
| 951 | return true; |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 952 | } |
Chris Lattner | ae7a834 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 953 | case BinaryOperatorClass: { |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 954 | const BinaryOperator *BO = cast<BinaryOperator>(this); |
Ted Kremenek | 43a9c96 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 955 | switch (BO->getOpcode()) { |
| 956 | default: |
| 957 | break; |
| 958 | // Consider ',', '||', '&&' to have side effects if the LHS or RHS does. |
| 959 | case BinaryOperator::Comma: |
| 960 | // ((foo = <blah>), 0) is an idiom for hiding the result (and |
| 961 | // lvalue-ness) of an assignment written in a macro. |
| 962 | if (IntegerLiteral *IE = |
| 963 | dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) |
| 964 | if (IE->getValue() == 0) |
| 965 | return false; |
| 966 | case BinaryOperator::LAnd: |
| 967 | case BinaryOperator::LOr: |
| 968 | return (BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || |
| 969 | BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
John McCall | 1e3715a | 2010-02-16 04:10:53 +0000 | [diff] [blame] | 970 | } |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 971 | if (BO->isAssignmentOp()) |
| 972 | return false; |
| 973 | Loc = BO->getOperatorLoc(); |
| 974 | R1 = BO->getLHS()->getSourceRange(); |
| 975 | R2 = BO->getRHS()->getSourceRange(); |
| 976 | return true; |
Chris Lattner | ae7a834 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 977 | } |
Chris Lattner | 8692811 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 978 | case CompoundAssignOperatorClass: |
Douglas Gregor | 0bbe94d | 2010-05-08 22:41:50 +0000 | [diff] [blame^] | 979 | case VAArgExprClass: |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 980 | return false; |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 981 | |
Fariborz Jahanian | 9fac54d | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 982 | case ConditionalOperatorClass: { |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 983 | // The condition must be evaluated, but if either the LHS or RHS is a |
| 984 | // warning, warn about them. |
Fariborz Jahanian | 9fac54d | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 985 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | if (Exp->getLHS() && |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 987 | Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 988 | return true; |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 989 | return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Fariborz Jahanian | 9fac54d | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Chris Lattner | a44d116 | 2007-06-27 05:58:59 +0000 | [diff] [blame] | 992 | case MemberExprClass: |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 993 | // If the base pointer or element is to a volatile pointer/field, accessing |
| 994 | // it is a side effect. |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 995 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 996 | return false; |
| 997 | Loc = cast<MemberExpr>(this)->getMemberLoc(); |
| 998 | R1 = SourceRange(Loc, Loc); |
| 999 | R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); |
| 1000 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 1002 | case ArraySubscriptExprClass: |
Chris Lattner | a44d116 | 2007-06-27 05:58:59 +0000 | [diff] [blame] | 1003 | // If the base pointer or element is to a volatile pointer/field, accessing |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1004 | // it is a side effect. |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1005 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1006 | return false; |
| 1007 | Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); |
| 1008 | R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); |
| 1009 | R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); |
| 1010 | return true; |
Eli Friedman | 824f8c1 | 2008-05-27 15:24:04 +0000 | [diff] [blame] | 1011 | |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 1012 | case CallExprClass: |
Eli Friedman | debdc1d | 2009-04-29 16:35:53 +0000 | [diff] [blame] | 1013 | case CXXOperatorCallExprClass: |
| 1014 | case CXXMemberCallExprClass: { |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1015 | // If this is a direct call, get the callee. |
| 1016 | const CallExpr *CE = cast<CallExpr>(this); |
Nuno Lopes | 518e370 | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 1017 | if (const Decl *FD = CE->getCalleeDecl()) { |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1018 | // If the callee has attribute pure, const, or warn_unused_result, warn |
| 1019 | // about it. void foo() { strlen("bar"); } should warn. |
Chris Lattner | 1a6babf | 2009-10-13 04:53:48 +0000 | [diff] [blame] | 1020 | // |
| 1021 | // Note: If new cases are added here, DiagnoseUnusedExprResult should be |
| 1022 | // updated to match for QoI. |
| 1023 | if (FD->getAttr<WarnUnusedResultAttr>() || |
| 1024 | FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { |
| 1025 | Loc = CE->getCallee()->getLocStart(); |
| 1026 | R1 = CE->getCallee()->getSourceRange(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | |
Chris Lattner | 1a6babf | 2009-10-13 04:53:48 +0000 | [diff] [blame] | 1028 | if (unsigned NumArgs = CE->getNumArgs()) |
| 1029 | R2 = SourceRange(CE->getArg(0)->getLocStart(), |
| 1030 | CE->getArg(NumArgs-1)->getLocEnd()); |
| 1031 | return true; |
| 1032 | } |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1033 | } |
| 1034 | return false; |
| 1035 | } |
Anders Carlsson | 6aa5039 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1036 | |
| 1037 | case CXXTemporaryObjectExprClass: |
| 1038 | case CXXConstructExprClass: |
| 1039 | return false; |
| 1040 | |
Fariborz Jahanian | 5cab26d | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1041 | case ObjCMessageExprClass: { |
| 1042 | const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); |
| 1043 | const ObjCMethodDecl *MD = ME->getMethodDecl(); |
| 1044 | if (MD && MD->getAttr<WarnUnusedResultAttr>()) { |
| 1045 | Loc = getExprLoc(); |
| 1046 | return true; |
| 1047 | } |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1048 | return false; |
Fariborz Jahanian | 5cab26d | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 1051 | case ObjCImplicitSetterGetterRefExprClass: { // Dot syntax for message send. |
Chris Lattner | d8b800a | 2009-08-16 16:45:18 +0000 | [diff] [blame] | 1052 | #if 0 |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | const ObjCImplicitSetterGetterRefExpr *Ref = |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 1054 | cast<ObjCImplicitSetterGetterRefExpr>(this); |
Chris Lattner | d8b800a | 2009-08-16 16:45:18 +0000 | [diff] [blame] | 1055 | // FIXME: We really want the location of the '.' here. |
Fariborz Jahanian | 88cc234 | 2009-08-18 20:50:23 +0000 | [diff] [blame] | 1056 | Loc = Ref->getLocation(); |
| 1057 | R1 = SourceRange(Ref->getLocation(), Ref->getLocation()); |
| 1058 | if (Ref->getBase()) |
| 1059 | R2 = Ref->getBase()->getSourceRange(); |
Chris Lattner | d37f61c | 2009-08-16 16:51:50 +0000 | [diff] [blame] | 1060 | #else |
| 1061 | Loc = getExprLoc(); |
| 1062 | R1 = getSourceRange(); |
Chris Lattner | d8b800a | 2009-08-16 16:45:18 +0000 | [diff] [blame] | 1063 | #endif |
| 1064 | return true; |
| 1065 | } |
Chris Lattner | 944d306 | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1066 | case StmtExprClass: { |
| 1067 | // Statement exprs don't logically have side effects themselves, but are |
| 1068 | // sometimes used in macros in ways that give them a type that is unused. |
| 1069 | // For example ({ blah; foo(); }) will end up with a type if foo has a type. |
| 1070 | // however, if the result of the stmt expr is dead, we don't want to emit a |
| 1071 | // warning. |
| 1072 | const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); |
| 1073 | if (!CS->body_empty()) |
| 1074 | if (const Expr *E = dyn_cast<Expr>(CS->body_back())) |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1075 | return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1076 | |
John McCall | c493a73 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1077 | if (getType()->isVoidType()) |
| 1078 | return false; |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1079 | Loc = cast<StmtExpr>(this)->getLParenLoc(); |
| 1080 | R1 = getSourceRange(); |
| 1081 | return true; |
Chris Lattner | 944d306 | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1082 | } |
Douglas Gregor | f19b231 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 1083 | case CStyleCastExprClass: |
Chris Lattner | 2706a55 | 2009-07-28 18:25:28 +0000 | [diff] [blame] | 1084 | // If this is an explicit cast to void, allow it. People do this when they |
| 1085 | // think they know what they're doing :). |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1086 | if (getType()->isVoidType()) |
Chris Lattner | 2706a55 | 2009-07-28 18:25:28 +0000 | [diff] [blame] | 1087 | return false; |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1088 | Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); |
| 1089 | R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); |
| 1090 | return true; |
Anders Carlsson | 6aa5039 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1091 | case CXXFunctionalCastExprClass: { |
John McCall | c493a73 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1092 | if (getType()->isVoidType()) |
| 1093 | return false; |
Anders Carlsson | 6aa5039 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1094 | const CastExpr *CE = cast<CastExpr>(this); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1095 | |
Anders Carlsson | 6aa5039 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1096 | // If this is a cast to void or a constructor conversion, check the operand. |
| 1097 | // Otherwise, the result of the cast is unused. |
| 1098 | if (CE->getCastKind() == CastExpr::CK_ToVoid || |
| 1099 | CE->getCastKind() == CastExpr::CK_ConstructorConversion) |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1100 | return (cast<CastExpr>(this)->getSubExpr() |
| 1101 | ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1102 | Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); |
| 1103 | R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); |
| 1104 | return true; |
Anders Carlsson | 6aa5039 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1105 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Eli Friedman | ca8da1d | 2008-05-19 21:24:43 +0000 | [diff] [blame] | 1107 | case ImplicitCastExprClass: |
| 1108 | // Check the operand, since implicit casts are inserted by Sema |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1109 | return (cast<ImplicitCastExpr>(this) |
| 1110 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Eli Friedman | ca8da1d | 2008-05-19 21:24:43 +0000 | [diff] [blame] | 1111 | |
Chris Lattner | aa9c7ae | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1112 | case CXXDefaultArgExprClass: |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1113 | return (cast<CXXDefaultArgExpr>(this) |
| 1114 | ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1115 | |
| 1116 | case CXXNewExprClass: |
| 1117 | // FIXME: In theory, there might be new expressions that don't have side |
| 1118 | // effects (e.g. a placement new with an uninitialized POD). |
| 1119 | case CXXDeleteExprClass: |
Chris Lattner | 237f275 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1120 | return false; |
Anders Carlsson | e80ccac | 2009-08-16 04:11:06 +0000 | [diff] [blame] | 1121 | case CXXBindTemporaryExprClass: |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1122 | return (cast<CXXBindTemporaryExpr>(this) |
| 1123 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Anders Carlsson | 24824e5 | 2009-05-17 21:11:30 +0000 | [diff] [blame] | 1124 | case CXXExprWithTemporariesClass: |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1125 | return (cast<CXXExprWithTemporaries>(this) |
| 1126 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1127 | } |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Douglas Gregor | 4b62ec6 | 2008-10-22 15:04:37 +0000 | [diff] [blame] | 1130 | /// DeclCanBeLvalue - Determine whether the given declaration can be |
| 1131 | /// an lvalue. This is a helper routine for isLvalue. |
| 1132 | static bool DeclCanBeLvalue(const NamedDecl *Decl, ASTContext &Ctx) { |
Douglas Gregor | 5101c24 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1133 | // C++ [temp.param]p6: |
| 1134 | // A non-type non-reference template-parameter is not an lvalue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | if (const NonTypeTemplateParmDecl *NTTParm |
Douglas Gregor | 5101c24 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1136 | = dyn_cast<NonTypeTemplateParmDecl>(Decl)) |
| 1137 | return NTTParm->getType()->isReferenceType(); |
| 1138 | |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1139 | return isa<VarDecl>(Decl) || isa<FieldDecl>(Decl) || |
Douglas Gregor | 4b62ec6 | 2008-10-22 15:04:37 +0000 | [diff] [blame] | 1140 | // C++ 3.10p2: An lvalue refers to an object or function. |
| 1141 | (Ctx.getLangOptions().CPlusPlus && |
John McCall | 3d988d9 | 2009-12-02 08:47:38 +0000 | [diff] [blame] | 1142 | (isa<FunctionDecl>(Decl) || isa<FunctionTemplateDecl>(Decl))); |
Douglas Gregor | 4b62ec6 | 2008-10-22 15:04:37 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Steve Naroff | 475cca0 | 2007-05-14 17:19:29 +0000 | [diff] [blame] | 1145 | /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an |
| 1146 | /// incomplete type other than void. Nonarray expressions that can be lvalues: |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1147 | /// - name, where name must be a variable |
| 1148 | /// - e[i] |
| 1149 | /// - (e), where e must be an lvalue |
| 1150 | /// - e.name, where e must be an lvalue |
| 1151 | /// - e->name |
Steve Naroff | 35d8515 | 2007-05-07 00:24:15 +0000 | [diff] [blame] | 1152 | /// - *e, the type of e cannot be a function type |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1153 | /// - string-constant |
Chris Lattner | 595db86 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 1154 | /// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension] |
Bill Wendling | dfc8107 | 2007-07-17 03:52:31 +0000 | [diff] [blame] | 1155 | /// - reference type [C++ [expr]] |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1156 | /// |
Chris Lattner | 6731544 | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 1157 | Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const { |
Eli Friedman | b8c4fd8 | 2009-05-03 22:36:05 +0000 | [diff] [blame] | 1158 | assert(!TR->isReferenceType() && "Expressions can't have reference type."); |
| 1159 | |
| 1160 | isLvalueResult Res = isLvalueInternal(Ctx); |
| 1161 | if (Res != LV_Valid || Ctx.getLangOptions().CPlusPlus) |
| 1162 | return Res; |
| 1163 | |
Douglas Gregor | 9a65793 | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 1164 | // first, check the type (C99 6.3.2.1). Expressions with function |
| 1165 | // type in C are not lvalues, but they can be lvalues in C++. |
Douglas Gregor | 9b14658 | 2009-07-08 20:55:45 +0000 | [diff] [blame] | 1166 | if (TR->isFunctionType() || TR == Ctx.OverloadTy) |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1167 | return LV_NotObjectType; |
Steve Naroff | e728ba3 | 2007-07-10 22:20:04 +0000 | [diff] [blame] | 1168 | |
Steve Naroff | 1018ea3 | 2008-02-10 01:39:04 +0000 | [diff] [blame] | 1169 | // Allow qualified void which is an incomplete type other than void (yuck). |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1170 | if (TR->isVoidType() && !Ctx.getCanonicalType(TR).hasQualifiers()) |
Steve Naroff | 1018ea3 | 2008-02-10 01:39:04 +0000 | [diff] [blame] | 1171 | return LV_IncompleteVoidType; |
| 1172 | |
Eli Friedman | b8c4fd8 | 2009-05-03 22:36:05 +0000 | [diff] [blame] | 1173 | return LV_Valid; |
| 1174 | } |
Bill Wendling | dfc8107 | 2007-07-17 03:52:31 +0000 | [diff] [blame] | 1175 | |
Eli Friedman | b8c4fd8 | 2009-05-03 22:36:05 +0000 | [diff] [blame] | 1176 | // Check whether the expression can be sanely treated like an l-value |
| 1177 | Expr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const { |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1178 | switch (getStmtClass()) { |
Fariborz Jahanian | 531c16f | 2009-12-09 23:35:29 +0000 | [diff] [blame] | 1179 | case ObjCIsaExprClass: |
Chris Lattner | d7e7b8e | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 1180 | case StringLiteralClass: // C99 6.5.1p4 |
| 1181 | case ObjCEncodeExprClass: // @encode behaves like its string in every way. |
Anders Carlsson | 7a9a38a | 2007-11-30 22:47:59 +0000 | [diff] [blame] | 1182 | return LV_Valid; |
Steve Naroff | 5dd642e | 2007-05-14 18:14:51 +0000 | [diff] [blame] | 1183 | case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) |
Steve Naroff | e728ba3 | 2007-07-10 22:20:04 +0000 | [diff] [blame] | 1184 | // For vectors, make sure base is an lvalue (i.e. not a function call). |
| 1185 | if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType()) |
Chris Lattner | 6731544 | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 1186 | return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx); |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1187 | return LV_Valid; |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1188 | case DeclRefExprClass: { // C99 6.5.1p2 |
Douglas Gregor | 4b62ec6 | 2008-10-22 15:04:37 +0000 | [diff] [blame] | 1189 | const NamedDecl *RefdDecl = cast<DeclRefExpr>(this)->getDecl(); |
| 1190 | if (DeclCanBeLvalue(RefdDecl, Ctx)) |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1191 | return LV_Valid; |
| 1192 | break; |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1193 | } |
Steve Naroff | 8de9c3a | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 1194 | case BlockDeclRefExprClass: { |
| 1195 | const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this); |
Steve Naroff | ba756cb | 2008-09-26 14:41:28 +0000 | [diff] [blame] | 1196 | if (isa<VarDecl>(BDR->getDecl())) |
Steve Naroff | 8de9c3a | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 1197 | return LV_Valid; |
| 1198 | break; |
| 1199 | } |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1200 | case MemberExprClass: { |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1201 | const MemberExpr *m = cast<MemberExpr>(this); |
Douglas Gregor | 2eedc3a | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 1202 | if (Ctx.getLangOptions().CPlusPlus) { // C++ [expr.ref]p4: |
| 1203 | NamedDecl *Member = m->getMemberDecl(); |
| 1204 | // C++ [expr.ref]p4: |
| 1205 | // If E2 is declared to have type "reference to T", then E1.E2 |
| 1206 | // is an lvalue. |
| 1207 | if (ValueDecl *Value = dyn_cast<ValueDecl>(Member)) |
| 1208 | if (Value->getType()->isReferenceType()) |
| 1209 | return LV_Valid; |
| 1210 | |
| 1211 | // -- If E2 is a static data member [...] then E1.E2 is an lvalue. |
Douglas Gregor | 212cab3 | 2009-03-11 20:22:50 +0000 | [diff] [blame] | 1212 | if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord()) |
Douglas Gregor | 2eedc3a | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 1213 | return LV_Valid; |
| 1214 | |
| 1215 | // -- If E2 is a non-static data member [...]. If E1 is an |
| 1216 | // lvalue, then E1.E2 is an lvalue. |
Fariborz Jahanian | e8d2890 | 2009-12-15 23:59:41 +0000 | [diff] [blame] | 1217 | if (isa<FieldDecl>(Member)) { |
| 1218 | if (m->isArrow()) |
| 1219 | return LV_Valid; |
Fariborz Jahanian | e5c118f | 2010-02-12 21:02:28 +0000 | [diff] [blame] | 1220 | return m->getBase()->isLvalue(Ctx); |
Fariborz Jahanian | e8d2890 | 2009-12-15 23:59:41 +0000 | [diff] [blame] | 1221 | } |
Douglas Gregor | 2eedc3a | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 1222 | |
| 1223 | // -- If it refers to a static member function [...], then |
| 1224 | // E1.E2 is an lvalue. |
| 1225 | // -- Otherwise, if E1.E2 refers to a non-static member |
| 1226 | // function [...], then E1.E2 is not an lvalue. |
| 1227 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member)) |
| 1228 | return Method->isStatic()? LV_Valid : LV_MemberFunction; |
| 1229 | |
| 1230 | // -- If E2 is a member enumerator [...], the expression E1.E2 |
| 1231 | // is not an lvalue. |
| 1232 | if (isa<EnumConstantDecl>(Member)) |
| 1233 | return LV_InvalidExpression; |
| 1234 | |
| 1235 | // Not an lvalue. |
| 1236 | return LV_InvalidExpression; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | 2eedc3a | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 1239 | // C99 6.5.2.3p4 |
Fariborz Jahanian | e8d2890 | 2009-12-15 23:59:41 +0000 | [diff] [blame] | 1240 | if (m->isArrow()) |
| 1241 | return LV_Valid; |
| 1242 | Expr *BaseExp = m->getBase(); |
Fariborz Jahanian | 8342e57 | 2010-03-18 18:50:41 +0000 | [diff] [blame] | 1243 | if (BaseExp->getStmtClass() == ObjCPropertyRefExprClass || |
| 1244 | BaseExp->getStmtClass() == ObjCImplicitSetterGetterRefExprClass) |
Fariborz Jahanian | 13b9782 | 2010-02-11 01:11:34 +0000 | [diff] [blame] | 1245 | return LV_SubObjCPropertySetting; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1246 | return |
| 1247 | BaseExp->isLvalue(Ctx); |
Anton Korobeynikov | b76cda0 | 2007-07-12 15:26:50 +0000 | [diff] [blame] | 1248 | } |
Chris Lattner | 595db86 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 1249 | case UnaryOperatorClass: |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1250 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref) |
Chris Lattner | 595db86 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 1251 | return LV_Valid; // C99 6.5.3p4 |
| 1252 | |
| 1253 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real || |
Chris Lattner | ec8996d | 2008-07-25 18:07:19 +0000 | [diff] [blame] | 1254 | cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag || |
| 1255 | cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension) |
Chris Lattner | 6731544 | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 1256 | return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx); // GNU. |
Douglas Gregor | d08452f | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 1257 | |
| 1258 | if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.pre.incr]p1 |
| 1259 | (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreInc || |
| 1260 | cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreDec)) |
| 1261 | return LV_Valid; |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1262 | break; |
Douglas Gregor | a11693b | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1263 | case ImplicitCastExprClass: |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1264 | if (cast<ImplicitCastExpr>(this)->isLvalueCast()) |
| 1265 | return LV_Valid; |
| 1266 | |
| 1267 | // If this is a conversion to a class temporary, make a note of |
| 1268 | // that. |
| 1269 | if (Ctx.getLangOptions().CPlusPlus && getType()->isRecordType()) |
| 1270 | return LV_ClassTemporary; |
| 1271 | |
| 1272 | break; |
Steve Naroff | 475cca0 | 2007-05-14 17:19:29 +0000 | [diff] [blame] | 1273 | case ParenExprClass: // C99 6.5.1p5 |
Chris Lattner | 6731544 | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 1274 | return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx); |
Douglas Gregor | a11693b | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1275 | case BinaryOperatorClass: |
| 1276 | case CompoundAssignOperatorClass: { |
| 1277 | const BinaryOperator *BinOp = cast<BinaryOperator>(this); |
Douglas Gregor | 40412ac | 2008-11-19 17:17:41 +0000 | [diff] [blame] | 1278 | |
| 1279 | if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.comma]p1 |
| 1280 | BinOp->getOpcode() == BinaryOperator::Comma) |
| 1281 | return BinOp->getRHS()->isLvalue(Ctx); |
| 1282 | |
Sebastian Redl | 112a9766 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 1283 | // C++ [expr.mptr.oper]p6 |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1284 | // The result of a .* expression is an lvalue only if its first operand is |
| 1285 | // an lvalue and its second operand is a pointer to data member. |
Fariborz Jahanian | 03b4f66 | 2009-10-08 18:00:39 +0000 | [diff] [blame] | 1286 | if (BinOp->getOpcode() == BinaryOperator::PtrMemD && |
Sebastian Redl | 112a9766 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 1287 | !BinOp->getType()->isFunctionType()) |
| 1288 | return BinOp->getLHS()->isLvalue(Ctx); |
| 1289 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1290 | // The result of an ->* expression is an lvalue only if its second operand |
Fariborz Jahanian | 03b4f66 | 2009-10-08 18:00:39 +0000 | [diff] [blame] | 1291 | // is a pointer to data member. |
| 1292 | if (BinOp->getOpcode() == BinaryOperator::PtrMemI && |
| 1293 | !BinOp->getType()->isFunctionType()) { |
| 1294 | QualType Ty = BinOp->getRHS()->getType(); |
| 1295 | if (Ty->isMemberPointerType() && !Ty->isMemberFunctionPointerType()) |
| 1296 | return LV_Valid; |
| 1297 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1298 | |
Douglas Gregor | 58e008d | 2008-11-13 20:12:29 +0000 | [diff] [blame] | 1299 | if (!BinOp->isAssignmentOp()) |
Douglas Gregor | a11693b | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1300 | return LV_InvalidExpression; |
| 1301 | |
Douglas Gregor | 58e008d | 2008-11-13 20:12:29 +0000 | [diff] [blame] | 1302 | if (Ctx.getLangOptions().CPlusPlus) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | // C++ [expr.ass]p1: |
Douglas Gregor | 58e008d | 2008-11-13 20:12:29 +0000 | [diff] [blame] | 1304 | // The result of an assignment operation [...] is an lvalue. |
| 1305 | return LV_Valid; |
| 1306 | |
| 1307 | |
| 1308 | // C99 6.5.16: |
| 1309 | // An assignment expression [...] is not an lvalue. |
| 1310 | return LV_InvalidExpression; |
Douglas Gregor | a11693b | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1311 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | case CallExprClass: |
Douglas Gregor | 97fd6e2 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1313 | case CXXOperatorCallExprClass: |
| 1314 | case CXXMemberCallExprClass: { |
Sebastian Redl | 0f8b23f | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1315 | // C++0x [expr.call]p10 |
Douglas Gregor | 6b75484 | 2008-10-28 00:22:11 +0000 | [diff] [blame] | 1316 | // A function call is an lvalue if and only if the result type |
Sebastian Redl | 0f8b23f | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1317 | // is an lvalue reference. |
Anders Carlsson | 00a2759 | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 1318 | QualType ReturnType = cast<CallExpr>(this)->getCallReturnType(); |
| 1319 | if (ReturnType->isLValueReferenceType()) |
| 1320 | return LV_Valid; |
Sebastian Redl | 0f8b23f | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1321 | |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1322 | // If the function is returning a class temporary, make a note of |
| 1323 | // that. |
| 1324 | if (Ctx.getLangOptions().CPlusPlus && ReturnType->isRecordType()) |
| 1325 | return LV_ClassTemporary; |
| 1326 | |
Douglas Gregor | 6b75484 | 2008-10-28 00:22:11 +0000 | [diff] [blame] | 1327 | break; |
| 1328 | } |
Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 1329 | case CompoundLiteralExprClass: // C99 6.5.2.5p5 |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1330 | // FIXME: Is this what we want in C++? |
Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 1331 | return LV_Valid; |
Chris Lattner | 053441f | 2008-12-12 05:35:08 +0000 | [diff] [blame] | 1332 | case ChooseExprClass: |
| 1333 | // __builtin_choose_expr is an lvalue if the selected operand is. |
Eli Friedman | e0a5b8b | 2009-03-04 05:52:32 +0000 | [diff] [blame] | 1334 | return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->isLvalue(Ctx); |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1335 | case ExtVectorElementExprClass: |
| 1336 | if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements()) |
Steve Naroff | 0d595ca | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1337 | return LV_DuplicateVectorComponents; |
| 1338 | return LV_Valid; |
Steve Naroff | b342361 | 2007-11-12 14:34:27 +0000 | [diff] [blame] | 1339 | case ObjCIvarRefExprClass: // ObjC instance variables are lvalues. |
| 1340 | return LV_Valid; |
Steve Naroff | 6600228 | 2008-05-30 23:23:16 +0000 | [diff] [blame] | 1341 | case ObjCPropertyRefExprClass: // FIXME: check if read-only property. |
| 1342 | return LV_Valid; |
Enea Zaffanella | f205977 | 2010-04-27 07:38:32 +0000 | [diff] [blame] | 1343 | case ObjCImplicitSetterGetterRefExprClass: |
| 1344 | // FIXME: check if read-only property. |
Chris Lattner | 053441f | 2008-12-12 05:35:08 +0000 | [diff] [blame] | 1345 | return LV_Valid; |
Chris Lattner | 6307f19 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 1346 | case PredefinedExprClass: |
Douglas Gregor | 97a9c81 | 2008-11-04 14:32:21 +0000 | [diff] [blame] | 1347 | return LV_Valid; |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 1348 | case UnresolvedLookupExprClass: |
Douglas Gregor | 980fb16 | 2010-04-29 18:24:40 +0000 | [diff] [blame] | 1349 | case UnresolvedMemberExprClass: |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 1350 | return LV_Valid; |
Chris Lattner | aa9c7ae | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1351 | case CXXDefaultArgExprClass: |
Chris Lattner | 6731544 | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 1352 | return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx); |
Douglas Gregor | f19b231 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 1353 | case CStyleCastExprClass: |
Douglas Gregor | 6b75484 | 2008-10-28 00:22:11 +0000 | [diff] [blame] | 1354 | case CXXFunctionalCastExprClass: |
| 1355 | case CXXStaticCastExprClass: |
| 1356 | case CXXDynamicCastExprClass: |
| 1357 | case CXXReinterpretCastExprClass: |
| 1358 | case CXXConstCastExprClass: |
| 1359 | // The result of an explicit cast is an lvalue if the type we are |
Sebastian Redl | 0f8b23f | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1360 | // casting to is an lvalue reference type. See C++ [expr.cast]p1, |
Douglas Gregor | 6b75484 | 2008-10-28 00:22:11 +0000 | [diff] [blame] | 1361 | // C++ [expr.static.cast]p2, C++ [expr.dynamic.cast]p2, |
| 1362 | // C++ [expr.reinterpret.cast]p1, C++ [expr.const.cast]p1. |
Sebastian Redl | 0f8b23f | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1363 | if (cast<ExplicitCastExpr>(this)->getTypeAsWritten()-> |
| 1364 | isLValueReferenceType()) |
Douglas Gregor | 6b75484 | 2008-10-28 00:22:11 +0000 | [diff] [blame] | 1365 | return LV_Valid; |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1366 | |
| 1367 | // If this is a conversion to a class temporary, make a note of |
| 1368 | // that. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1369 | if (Ctx.getLangOptions().CPlusPlus && |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1370 | cast<ExplicitCastExpr>(this)->getTypeAsWritten()->isRecordType()) |
| 1371 | return LV_ClassTemporary; |
| 1372 | |
Douglas Gregor | 6b75484 | 2008-10-28 00:22:11 +0000 | [diff] [blame] | 1373 | break; |
Sebastian Redl | c470476 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1374 | case CXXTypeidExprClass: |
| 1375 | // C++ 5.2.8p1: The result of a typeid expression is an lvalue of ... |
| 1376 | return LV_Valid; |
Anders Carlsson | 8c84c20 | 2009-08-16 03:42:12 +0000 | [diff] [blame] | 1377 | case CXXBindTemporaryExprClass: |
| 1378 | return cast<CXXBindTemporaryExpr>(this)->getSubExpr()-> |
| 1379 | isLvalueInternal(Ctx); |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 1380 | case CXXBindReferenceExprClass: |
| 1381 | // Something that's bound to a reference is always an lvalue. |
| 1382 | return LV_Valid; |
Sebastian Redl | 5775af1a | 2009-04-17 16:30:52 +0000 | [diff] [blame] | 1383 | case ConditionalOperatorClass: { |
| 1384 | // Complicated handling is only for C++. |
| 1385 | if (!Ctx.getLangOptions().CPlusPlus) |
| 1386 | return LV_InvalidExpression; |
| 1387 | |
| 1388 | // Sema should have taken care to ensure that a CXXTemporaryObjectExpr is |
| 1389 | // everywhere there's an object converted to an rvalue. Also, any other |
| 1390 | // casts should be wrapped by ImplicitCastExprs. There's just the special |
| 1391 | // case involving throws to work out. |
| 1392 | const ConditionalOperator *Cond = cast<ConditionalOperator>(this); |
Douglas Gregor | 115652d | 2009-05-19 20:13:50 +0000 | [diff] [blame] | 1393 | Expr *True = Cond->getTrueExpr(); |
| 1394 | Expr *False = Cond->getFalseExpr(); |
Sebastian Redl | 5775af1a | 2009-04-17 16:30:52 +0000 | [diff] [blame] | 1395 | // C++0x 5.16p2 |
| 1396 | // If either the second or the third operand has type (cv) void, [...] |
| 1397 | // the result [...] is an rvalue. |
Douglas Gregor | 115652d | 2009-05-19 20:13:50 +0000 | [diff] [blame] | 1398 | if (True->getType()->isVoidType() || False->getType()->isVoidType()) |
Sebastian Redl | 5775af1a | 2009-04-17 16:30:52 +0000 | [diff] [blame] | 1399 | return LV_InvalidExpression; |
| 1400 | |
| 1401 | // Both sides must be lvalues for the result to be an lvalue. |
Douglas Gregor | 115652d | 2009-05-19 20:13:50 +0000 | [diff] [blame] | 1402 | if (True->isLvalue(Ctx) != LV_Valid || False->isLvalue(Ctx) != LV_Valid) |
Sebastian Redl | 5775af1a | 2009-04-17 16:30:52 +0000 | [diff] [blame] | 1403 | return LV_InvalidExpression; |
| 1404 | |
| 1405 | // That's it. |
| 1406 | return LV_Valid; |
| 1407 | } |
| 1408 | |
Douglas Gregor | 5103eff | 2009-12-19 07:07:47 +0000 | [diff] [blame] | 1409 | case Expr::CXXExprWithTemporariesClass: |
| 1410 | return cast<CXXExprWithTemporaries>(this)->getSubExpr()->isLvalue(Ctx); |
| 1411 | |
| 1412 | case Expr::ObjCMessageExprClass: |
| 1413 | if (const ObjCMethodDecl *Method |
| 1414 | = cast<ObjCMessageExpr>(this)->getMethodDecl()) |
| 1415 | if (Method->getResultType()->isLValueReferenceType()) |
| 1416 | return LV_Valid; |
| 1417 | break; |
| 1418 | |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1419 | case Expr::CXXConstructExprClass: |
| 1420 | case Expr::CXXTemporaryObjectExprClass: |
| 1421 | case Expr::CXXZeroInitValueExprClass: |
| 1422 | return LV_ClassTemporary; |
| 1423 | |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1424 | default: |
| 1425 | break; |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1426 | } |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1427 | return LV_InvalidExpression; |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 1428 | } |
Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 1429 | |
Steve Naroff | 475cca0 | 2007-05-14 17:19:29 +0000 | [diff] [blame] | 1430 | /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, |
| 1431 | /// does not have an incomplete type, does not have a const-qualified type, and |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1432 | /// if it is a structure or union, does not have any member (including, |
Steve Naroff | 475cca0 | 2007-05-14 17:19:29 +0000 | [diff] [blame] | 1433 | /// recursively, any member or element of all contained aggregates or unions) |
| 1434 | /// with a const-qualified type. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | Expr::isModifiableLvalueResult |
Daniel Dunbar | c2223ab | 2009-04-15 00:08:05 +0000 | [diff] [blame] | 1436 | Expr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const { |
Chris Lattner | 6731544 | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 1437 | isLvalueResult lvalResult = isLvalue(Ctx); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1438 | |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1439 | switch (lvalResult) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1440 | case LV_Valid: |
Douglas Gregor | 293a3c6 | 2008-10-22 00:03:08 +0000 | [diff] [blame] | 1441 | // C++ 3.10p11: Functions cannot be modified, but pointers to |
| 1442 | // functions can be modifiable. |
| 1443 | if (Ctx.getLangOptions().CPlusPlus && TR->isFunctionType()) |
| 1444 | return MLV_NotObjectType; |
| 1445 | break; |
| 1446 | |
Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 1447 | case LV_NotObjectType: return MLV_NotObjectType; |
| 1448 | case LV_IncompleteVoidType: return MLV_IncompleteVoidType; |
Steve Naroff | 0d595ca | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1449 | case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; |
Chris Lattner | 9b3bbe9 | 2008-11-17 19:51:54 +0000 | [diff] [blame] | 1450 | case LV_InvalidExpression: |
| 1451 | // If the top level is a C-style cast, and the subexpression is a valid |
| 1452 | // lvalue, then this is probably a use of the old-school "cast as lvalue" |
| 1453 | // GCC extension. We don't support it, but we want to produce good |
| 1454 | // diagnostics when it happens so that the user knows why. |
Daniel Dunbar | c2223ab | 2009-04-15 00:08:05 +0000 | [diff] [blame] | 1455 | if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(IgnoreParens())) { |
| 1456 | if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) { |
| 1457 | if (Loc) |
| 1458 | *Loc = CE->getLParenLoc(); |
Chris Lattner | 9b3bbe9 | 2008-11-17 19:51:54 +0000 | [diff] [blame] | 1459 | return MLV_LValueCast; |
Daniel Dunbar | c2223ab | 2009-04-15 00:08:05 +0000 | [diff] [blame] | 1460 | } |
| 1461 | } |
Chris Lattner | 9b3bbe9 | 2008-11-17 19:51:54 +0000 | [diff] [blame] | 1462 | return MLV_InvalidExpression; |
Douglas Gregor | 2eedc3a | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 1463 | case LV_MemberFunction: return MLV_MemberFunction; |
Fariborz Jahanian | 13b9782 | 2010-02-11 01:11:34 +0000 | [diff] [blame] | 1464 | case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting; |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 1465 | case LV_ClassTemporary: |
| 1466 | return MLV_ClassTemporary; |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1467 | } |
Eli Friedman | e8dd7b3 | 2009-03-22 23:26:56 +0000 | [diff] [blame] | 1468 | |
| 1469 | // The following is illegal: |
| 1470 | // void takeclosure(void (^C)(void)); |
| 1471 | // void func() { int x = 1; takeclosure(^{ x = 7; }); } |
| 1472 | // |
Fariborz Jahanian | cb1c191 | 2009-09-14 16:40:48 +0000 | [diff] [blame] | 1473 | if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(this)) { |
Eli Friedman | e8dd7b3 | 2009-03-22 23:26:56 +0000 | [diff] [blame] | 1474 | if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl())) |
| 1475 | return MLV_NotBlockQualified; |
| 1476 | } |
Daniel Dunbar | 4782a6e | 2009-09-17 06:31:17 +0000 | [diff] [blame] | 1477 | |
Fariborz Jahanian | cb1c191 | 2009-09-14 16:40:48 +0000 | [diff] [blame] | 1478 | // Assigning to an 'implicit' property? |
Daniel Dunbar | 4782a6e | 2009-09-17 06:31:17 +0000 | [diff] [blame] | 1479 | if (const ObjCImplicitSetterGetterRefExpr* Expr = |
Fariborz Jahanian | cb1c191 | 2009-09-14 16:40:48 +0000 | [diff] [blame] | 1480 | dyn_cast<ObjCImplicitSetterGetterRefExpr>(this)) { |
| 1481 | if (Expr->getSetterMethod() == 0) |
| 1482 | return MLV_NoSetterProperty; |
| 1483 | } |
Daniel Dunbar | 4782a6e | 2009-09-17 06:31:17 +0000 | [diff] [blame] | 1484 | |
Chris Lattner | 7adf076 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1485 | QualType CT = Ctx.getCanonicalType(getType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1486 | |
Chris Lattner | 7adf076 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1487 | if (CT.isConstQualified()) |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1488 | return MLV_ConstQualified; |
Chris Lattner | 7adf076 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1489 | if (CT->isArrayType()) |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1490 | return MLV_ArrayType; |
Chris Lattner | 7adf076 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1491 | if (CT->isIncompleteType()) |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1492 | return MLV_IncompleteType; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1493 | |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 1494 | if (const RecordType *r = CT->getAs<RecordType>()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | if (r->hasConstFields()) |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 1496 | return MLV_ConstQualified; |
| 1497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1499 | return MLV_Valid; |
Steve Naroff | 475cca0 | 2007-05-14 17:19:29 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1502 | /// isOBJCGCCandidate - Check if an expression is objc gc'able. |
Fariborz Jahanian | 063c772 | 2009-09-08 23:38:54 +0000 | [diff] [blame] | 1503 | /// returns true, if it is; false otherwise. |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1504 | bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1505 | switch (getStmtClass()) { |
| 1506 | default: |
| 1507 | return false; |
| 1508 | case ObjCIvarRefExprClass: |
| 1509 | return true; |
Fariborz Jahanian | 392124c | 2009-02-23 18:59:50 +0000 | [diff] [blame] | 1510 | case Expr::UnaryOperatorClass: |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1511 | return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1512 | case ParenExprClass: |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1513 | return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1514 | case ImplicitCastExprClass: |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1515 | return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | a16904b | 2009-05-05 23:28:21 +0000 | [diff] [blame] | 1516 | case CStyleCastExprClass: |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1517 | return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1518 | case DeclRefExprClass: { |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1519 | const Decl *D = cast<DeclRefExpr>(this)->getDecl(); |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1520 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 1521 | if (VD->hasGlobalStorage()) |
| 1522 | return true; |
| 1523 | QualType T = VD->getType(); |
Fariborz Jahanian | cceedbf | 2009-09-16 18:09:18 +0000 | [diff] [blame] | 1524 | // dereferencing to a pointer is always a gc'able candidate, |
| 1525 | // unless it is __weak. |
Daniel Dunbar | 4782a6e | 2009-09-17 06:31:17 +0000 | [diff] [blame] | 1526 | return T->isPointerType() && |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1527 | (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1528 | } |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1531 | case MemberExprClass: { |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1532 | const MemberExpr *M = cast<MemberExpr>(this); |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1533 | return M->getBase()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1534 | } |
| 1535 | case ArraySubscriptExprClass: |
Fariborz Jahanian | c6d9800 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1536 | return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); |
Fariborz Jahanian | 0773533 | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1537 | } |
| 1538 | } |
Ted Kremenek | fff7096 | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 1539 | Expr* Expr::IgnoreParens() { |
| 1540 | Expr* E = this; |
| 1541 | while (ParenExpr* P = dyn_cast<ParenExpr>(E)) |
| 1542 | E = P->getSubExpr(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1543 | |
Ted Kremenek | fff7096 | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 1544 | return E; |
| 1545 | } |
| 1546 | |
Chris Lattner | f266096 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 1547 | /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr |
| 1548 | /// or CastExprs or ImplicitCastExprs, returning their operand. |
| 1549 | Expr *Expr::IgnoreParenCasts() { |
| 1550 | Expr *E = this; |
| 1551 | while (true) { |
| 1552 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) |
| 1553 | E = P->getSubExpr(); |
| 1554 | else if (CastExpr *P = dyn_cast<CastExpr>(E)) |
| 1555 | E = P->getSubExpr(); |
Chris Lattner | f266096 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 1556 | else |
| 1557 | return E; |
| 1558 | } |
| 1559 | } |
| 1560 | |
John McCall | eebc832 | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 1561 | Expr *Expr::IgnoreParenImpCasts() { |
| 1562 | Expr *E = this; |
| 1563 | while (true) { |
| 1564 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) |
| 1565 | E = P->getSubExpr(); |
| 1566 | else if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) |
| 1567 | E = P->getSubExpr(); |
| 1568 | else |
| 1569 | return E; |
| 1570 | } |
| 1571 | } |
| 1572 | |
Chris Lattner | ef26c77 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1573 | /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the |
| 1574 | /// value (including ptr->int casts of the same size). Strip off any |
| 1575 | /// ParenExpr or CastExprs, returning their operand. |
| 1576 | Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { |
| 1577 | Expr *E = this; |
| 1578 | while (true) { |
| 1579 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { |
| 1580 | E = P->getSubExpr(); |
| 1581 | continue; |
| 1582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | |
Chris Lattner | ef26c77 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1584 | if (CastExpr *P = dyn_cast<CastExpr>(E)) { |
| 1585 | // We ignore integer <-> casts that are of the same width, ptr<->ptr and |
| 1586 | // ptr<->int casts of the same width. We also ignore all identify casts. |
| 1587 | Expr *SE = P->getSubExpr(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1588 | |
Chris Lattner | ef26c77 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1589 | if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { |
| 1590 | E = SE; |
| 1591 | continue; |
| 1592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | |
Chris Lattner | ef26c77 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1594 | if ((E->getType()->isPointerType() || E->getType()->isIntegralType()) && |
| 1595 | (SE->getType()->isPointerType() || SE->getType()->isIntegralType()) && |
| 1596 | Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { |
| 1597 | E = SE; |
| 1598 | continue; |
| 1599 | } |
| 1600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | |
Chris Lattner | ef26c77 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1602 | return E; |
| 1603 | } |
| 1604 | } |
| 1605 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1606 | bool Expr::isDefaultArgument() const { |
| 1607 | const Expr *E = this; |
| 1608 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 1609 | E = ICE->getSubExprAsWritten(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1611 | return isa<CXXDefaultArgExpr>(E); |
| 1612 | } |
Chris Lattner | ef26c77 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 1613 | |
Douglas Gregor | 45cf7e3 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1614 | /// \brief Skip over any no-op casts and any temporary-binding |
| 1615 | /// expressions. |
| 1616 | static const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) { |
| 1617 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
| 1618 | if (ICE->getCastKind() == CastExpr::CK_NoOp) |
| 1619 | E = ICE->getSubExpr(); |
| 1620 | else |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 1625 | E = BE->getSubExpr(); |
| 1626 | |
| 1627 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
| 1628 | if (ICE->getCastKind() == CastExpr::CK_NoOp) |
| 1629 | E = ICE->getSubExpr(); |
| 1630 | else |
| 1631 | break; |
| 1632 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1633 | |
Douglas Gregor | 45cf7e3 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 1634 | return E; |
| 1635 | } |
| 1636 | |
| 1637 | const Expr *Expr::getTemporaryObject() const { |
| 1638 | const Expr *E = skipTemporaryBindingsAndNoOpCasts(this); |
| 1639 | |
| 1640 | // A cast can produce a temporary object. The object's construction |
| 1641 | // is represented as a CXXConstructExpr. |
| 1642 | if (const CastExpr *Cast = dyn_cast<CastExpr>(E)) { |
| 1643 | // Only user-defined and constructor conversions can produce |
| 1644 | // temporary objects. |
| 1645 | if (Cast->getCastKind() != CastExpr::CK_ConstructorConversion && |
| 1646 | Cast->getCastKind() != CastExpr::CK_UserDefinedConversion) |
| 1647 | return 0; |
| 1648 | |
| 1649 | // Strip off temporary bindings and no-op casts. |
| 1650 | const Expr *Sub = skipTemporaryBindingsAndNoOpCasts(Cast->getSubExpr()); |
| 1651 | |
| 1652 | // If this is a constructor conversion, see if we have an object |
| 1653 | // construction. |
| 1654 | if (Cast->getCastKind() == CastExpr::CK_ConstructorConversion) |
| 1655 | return dyn_cast<CXXConstructExpr>(Sub); |
| 1656 | |
| 1657 | // If this is a user-defined conversion, see if we have a call to |
| 1658 | // a function that itself returns a temporary object. |
| 1659 | if (Cast->getCastKind() == CastExpr::CK_UserDefinedConversion) |
| 1660 | if (const CallExpr *CE = dyn_cast<CallExpr>(Sub)) |
| 1661 | if (CE->getCallReturnType()->isRecordType()) |
| 1662 | return CE; |
| 1663 | |
| 1664 | return 0; |
| 1665 | } |
| 1666 | |
| 1667 | // A call returning a class type returns a temporary. |
| 1668 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
| 1669 | if (CE->getCallReturnType()->isRecordType()) |
| 1670 | return CE; |
| 1671 | |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
| 1675 | // Explicit temporary object constructors create temporaries. |
| 1676 | return dyn_cast<CXXTemporaryObjectExpr>(E); |
| 1677 | } |
| 1678 | |
Douglas Gregor | 4619e43 | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1679 | /// hasAnyTypeDependentArguments - Determines if any of the expressions |
| 1680 | /// in Exprs is type-dependent. |
| 1681 | bool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { |
| 1682 | for (unsigned I = 0; I < NumExprs; ++I) |
| 1683 | if (Exprs[I]->isTypeDependent()) |
| 1684 | return true; |
| 1685 | |
| 1686 | return false; |
| 1687 | } |
| 1688 | |
| 1689 | /// hasAnyValueDependentArguments - Determines if any of the expressions |
| 1690 | /// in Exprs is value-dependent. |
| 1691 | bool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { |
| 1692 | for (unsigned I = 0; I < NumExprs; ++I) |
| 1693 | if (Exprs[I]->isValueDependent()) |
| 1694 | return true; |
| 1695 | |
| 1696 | return false; |
| 1697 | } |
| 1698 | |
Eli Friedman | 7139af4 | 2009-01-25 02:32:41 +0000 | [diff] [blame] | 1699 | bool Expr::isConstantInitializer(ASTContext &Ctx) const { |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1700 | // This function is attempting whether an expression is an initializer |
| 1701 | // which can be evaluated at compile-time. isEvaluatable handles most |
| 1702 | // of the cases, but it can't deal with some initializer-specific |
| 1703 | // expressions, and it can't deal with aggregates; we deal with those here, |
| 1704 | // and fall back to isEvaluatable for the other cases. |
| 1705 | |
Eli Friedman | cf7cbe7 | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 1706 | // FIXME: This function assumes the variable being assigned to |
| 1707 | // isn't a reference type! |
| 1708 | |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1709 | switch (getStmtClass()) { |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1710 | default: break; |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1711 | case StringLiteralClass: |
Steve Naroff | 7cae42b | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 1712 | case ObjCStringLiteralClass: |
Chris Lattner | d7e7b8e | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 1713 | case ObjCEncodeExprClass: |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1714 | return true; |
Nate Begeman | 2f2bdeb | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 1715 | case CompoundLiteralExprClass: { |
Eli Friedman | cf7cbe7 | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 1716 | // This handles gcc's extension that allows global initializers like |
| 1717 | // "struct x {int x;} x = (struct x) {};". |
| 1718 | // FIXME: This accepts other cases it shouldn't! |
Nate Begeman | 2f2bdeb | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 1719 | const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); |
Eli Friedman | 7139af4 | 2009-01-25 02:32:41 +0000 | [diff] [blame] | 1720 | return Exp->isConstantInitializer(Ctx); |
Nate Begeman | 2f2bdeb | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 1721 | } |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1722 | case InitListExprClass: { |
Eli Friedman | cf7cbe7 | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 1723 | // FIXME: This doesn't deal with fields with reference types correctly. |
| 1724 | // FIXME: This incorrectly allows pointers cast to integers to be assigned |
| 1725 | // to bitfields. |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1726 | const InitListExpr *Exp = cast<InitListExpr>(this); |
| 1727 | unsigned numInits = Exp->getNumInits(); |
| 1728 | for (unsigned i = 0; i < numInits; i++) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | if (!Exp->getInit(i)->isConstantInitializer(Ctx)) |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1730 | return false; |
| 1731 | } |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1732 | return true; |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1733 | } |
Douglas Gregor | 0202cb4 | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 1734 | case ImplicitValueInitExprClass: |
| 1735 | return true; |
Chris Lattner | 3eb172a | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 1736 | case ParenExprClass: |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1737 | return cast<ParenExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1738 | case UnaryOperatorClass: { |
| 1739 | const UnaryOperator* Exp = cast<UnaryOperator>(this); |
| 1740 | if (Exp->getOpcode() == UnaryOperator::Extension) |
| 1741 | return Exp->getSubExpr()->isConstantInitializer(Ctx); |
| 1742 | break; |
| 1743 | } |
Chris Lattner | 3eb172a | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 1744 | case BinaryOperatorClass: { |
| 1745 | // Special case &&foo - &&bar. It would be nice to generalize this somehow |
| 1746 | // but this handles the common case. |
| 1747 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
| 1748 | if (Exp->getOpcode() == BinaryOperator::Sub && |
| 1749 | isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && |
| 1750 | isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) |
| 1751 | return true; |
| 1752 | break; |
| 1753 | } |
Chris Lattner | 1f02e05 | 2009-04-21 05:19:11 +0000 | [diff] [blame] | 1754 | case ImplicitCastExprClass: |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1755 | case CStyleCastExprClass: |
| 1756 | // Handle casts with a destination that's a struct or union; this |
| 1757 | // deals with both the gcc no-op struct cast extension and the |
| 1758 | // cast-to-union extension. |
| 1759 | if (getType()->isRecordType()) |
| 1760 | return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1761 | |
Chris Lattner | a2f9bd5 | 2009-10-13 22:12:09 +0000 | [diff] [blame] | 1762 | // Integer->integer casts can be handled here, which is important for |
| 1763 | // things like (int)(&&x-&&y). Scary but true. |
| 1764 | if (getType()->isIntegerType() && |
| 1765 | cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) |
| 1766 | return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1767 | |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1768 | break; |
Anders Carlsson | a7c5eb7 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 1769 | } |
Eli Friedman | 384da27 | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 1770 | return isEvaluatable(Ctx); |
Steve Naroff | b03f594 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Chris Lattner | 7eef919 | 2007-05-24 01:23:49 +0000 | [diff] [blame] | 1773 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an |
| 1774 | /// integer constant expression with the value zero, or if this is one that is |
| 1775 | /// cast to void*. |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1776 | bool Expr::isNullPointerConstant(ASTContext &Ctx, |
| 1777 | NullPointerConstantValueDependence NPC) const { |
| 1778 | if (isValueDependent()) { |
| 1779 | switch (NPC) { |
| 1780 | case NPC_NeverValueDependent: |
| 1781 | assert(false && "Unexpected value dependent expression!"); |
| 1782 | // If the unthinkable happens, fall through to the safest alternative. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1784 | case NPC_ValueDependentIsNull: |
| 1785 | return isTypeDependent() || getType()->isIntegralType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1786 | |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1787 | case NPC_ValueDependentIsNotNull: |
| 1788 | return false; |
| 1789 | } |
| 1790 | } |
Daniel Dunbar | ebc5140 | 2009-09-18 08:46:16 +0000 | [diff] [blame] | 1791 | |
Sebastian Redl | 72b8aef | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 1792 | // Strip off a cast to void*, if it exists. Except in C++. |
Argyrios Kyrtzidis | 3bab3d2 | 2008-08-18 23:01:59 +0000 | [diff] [blame] | 1793 | if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { |
Sebastian Redl | 273ce56 | 2008-11-04 11:45:54 +0000 | [diff] [blame] | 1794 | if (!Ctx.getLangOptions().CPlusPlus) { |
Sebastian Redl | 72b8aef | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 1795 | // Check that it is a cast to void*. |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 1796 | if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { |
Sebastian Redl | 72b8aef | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 1797 | QualType Pointee = PT->getPointeeType(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1798 | if (!Pointee.hasQualifiers() && |
Sebastian Redl | 72b8aef | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 1799 | Pointee->isVoidType() && // to void* |
| 1800 | CE->getSubExpr()->getType()->isIntegerType()) // from int. |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1801 | return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
Sebastian Redl | 72b8aef | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 1802 | } |
Steve Naroff | ada7d42 | 2007-05-20 17:54:12 +0000 | [diff] [blame] | 1803 | } |
Steve Naroff | 4871fe0 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 1804 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { |
| 1805 | // Ignore the ImplicitCastExpr type entirely. |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1806 | return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
Steve Naroff | 4871fe0 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 1807 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { |
| 1808 | // Accept ((void*)0) as a null pointer constant, as many other |
| 1809 | // implementations do. |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1810 | return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | } else if (const CXXDefaultArgExpr *DefaultArg |
Chris Lattner | 5825824 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 1812 | = dyn_cast<CXXDefaultArgExpr>(this)) { |
Chris Lattner | aa9c7ae | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1813 | // See through default argument expressions |
Douglas Gregor | 56751b5 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 1814 | return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); |
Douglas Gregor | 3be4b12 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 1815 | } else if (isa<GNUNullExpr>(this)) { |
| 1816 | // The GNU __null extension is always a null pointer constant. |
| 1817 | return true; |
Steve Naroff | 0903531 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 1818 | } |
Douglas Gregor | 3be4b12 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 1819 | |
Sebastian Redl | 576fd42 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 1820 | // C++0x nullptr_t is always a null pointer constant. |
| 1821 | if (getType()->isNullPtrType()) |
| 1822 | return true; |
| 1823 | |
Steve Naroff | 4871fe0 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 1824 | // This expression must be an integer type. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1825 | if (!getType()->isIntegerType() || |
Fariborz Jahanian | 333bb73 | 2009-10-06 00:09:31 +0000 | [diff] [blame] | 1826 | (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) |
Steve Naroff | 4871fe0 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 1827 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1828 | |
Chris Lattner | 1abbd41 | 2007-06-08 17:58:43 +0000 | [diff] [blame] | 1829 | // If we have an integer constant expression, we need to *evaluate* it and |
| 1830 | // test for the value 0. |
Eli Friedman | 7524de1 | 2009-04-25 22:37:12 +0000 | [diff] [blame] | 1831 | llvm::APSInt Result; |
| 1832 | return isIntegerConstantExpr(Result, Ctx) && Result == 0; |
Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 1833 | } |
Steve Naroff | f7a5da1 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | 71235ec | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 1835 | FieldDecl *Expr::getBitField() { |
Douglas Gregor | 19623dc | 2009-07-06 15:38:40 +0000 | [diff] [blame] | 1836 | Expr *E = this->IgnoreParens(); |
Douglas Gregor | 71235ec | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | 65eb86e | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 1838 | while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
| 1839 | if (ICE->isLvalueCast() && ICE->getCastKind() == CastExpr::CK_NoOp) |
| 1840 | E = ICE->getSubExpr()->IgnoreParens(); |
| 1841 | else |
| 1842 | break; |
| 1843 | } |
| 1844 | |
Douglas Gregor | 8e1cf60 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1845 | if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) |
Douglas Gregor | 2eedc3a | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 1846 | if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) |
Douglas Gregor | 71235ec | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 1847 | if (Field->isBitField()) |
| 1848 | return Field; |
| 1849 | |
| 1850 | if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) |
| 1851 | if (BinOp->isAssignmentOp() && BinOp->getLHS()) |
| 1852 | return BinOp->getLHS()->getBitField(); |
| 1853 | |
| 1854 | return 0; |
Douglas Gregor | 8e1cf60 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Anders Carlsson | 8abde4b | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 1857 | bool Expr::refersToVectorElement() const { |
| 1858 | const Expr *E = this->IgnoreParens(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1859 | |
Anders Carlsson | 8abde4b | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 1860 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
| 1861 | if (ICE->isLvalueCast() && ICE->getCastKind() == CastExpr::CK_NoOp) |
| 1862 | E = ICE->getSubExpr()->IgnoreParens(); |
| 1863 | else |
| 1864 | break; |
| 1865 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1866 | |
Anders Carlsson | 8abde4b | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 1867 | if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) |
| 1868 | return ASE->getBase()->getType()->isVectorType(); |
| 1869 | |
| 1870 | if (isa<ExtVectorElementExpr>(E)) |
| 1871 | return true; |
| 1872 | |
| 1873 | return false; |
| 1874 | } |
| 1875 | |
Chris Lattner | b8211f6 | 2009-02-16 22:14:05 +0000 | [diff] [blame] | 1876 | /// isArrow - Return true if the base expression is a pointer to vector, |
| 1877 | /// return false if the base expression is a vector. |
| 1878 | bool ExtVectorElementExpr::isArrow() const { |
| 1879 | return getBase()->getType()->isPointerType(); |
| 1880 | } |
| 1881 | |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1882 | unsigned ExtVectorElementExpr::getNumElements() const { |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1883 | if (const VectorType *VT = getType()->getAs<VectorType>()) |
Nate Begeman | f322eab | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 1884 | return VT->getNumElements(); |
| 1885 | return 1; |
Chris Lattner | 177bd45 | 2007-08-03 16:00:20 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
Nate Begeman | f322eab | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 1888 | /// containsDuplicateElements - Return true if any element access is repeated. |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1889 | bool ExtVectorElementExpr::containsDuplicateElements() const { |
Daniel Dunbar | cb2a056 | 2009-10-18 02:09:09 +0000 | [diff] [blame] | 1890 | // FIXME: Refactor this code to an accessor on the AST node which returns the |
| 1891 | // "type" of component access, and share with code below and in Sema. |
Daniel Dunbar | 07d0785 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 1892 | llvm::StringRef Comp = Accessor->getName(); |
Nate Begeman | 7e5185b | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 1893 | |
| 1894 | // Halving swizzles do not contain duplicate elements. |
Daniel Dunbar | 125c9c9 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 1895 | if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") |
Nate Begeman | 7e5185b | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 1896 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1897 | |
Nate Begeman | 7e5185b | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 1898 | // Advance past s-char prefix on hex swizzles. |
Daniel Dunbar | 125c9c9 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 1899 | if (Comp[0] == 's' || Comp[0] == 'S') |
| 1900 | Comp = Comp.substr(1); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | |
Daniel Dunbar | 125c9c9 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 1902 | for (unsigned i = 0, e = Comp.size(); i != e; ++i) |
| 1903 | if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos) |
Steve Naroff | 0d595ca | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1904 | return true; |
Daniel Dunbar | 125c9c9 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 1905 | |
Steve Naroff | 0d595ca | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1906 | return false; |
| 1907 | } |
Chris Lattner | 885b495 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 1908 | |
Nate Begeman | f322eab | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 1909 | /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. |
Nate Begeman | d386215 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 1910 | void ExtVectorElementExpr::getEncodedElementAccess( |
| 1911 | llvm::SmallVectorImpl<unsigned> &Elts) const { |
Daniel Dunbar | ce5a0b3 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 1912 | llvm::StringRef Comp = Accessor->getName(); |
| 1913 | if (Comp[0] == 's' || Comp[0] == 'S') |
| 1914 | Comp = Comp.substr(1); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1915 | |
Daniel Dunbar | ce5a0b3 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 1916 | bool isHi = Comp == "hi"; |
| 1917 | bool isLo = Comp == "lo"; |
| 1918 | bool isEven = Comp == "even"; |
| 1919 | bool isOdd = Comp == "odd"; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1920 | |
Nate Begeman | f322eab | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 1921 | for (unsigned i = 0, e = getNumElements(); i != e; ++i) { |
| 1922 | uint64_t Index; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1923 | |
Nate Begeman | f322eab | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 1924 | if (isHi) |
| 1925 | Index = e + i; |
| 1926 | else if (isLo) |
| 1927 | Index = i; |
| 1928 | else if (isEven) |
| 1929 | Index = 2 * i; |
| 1930 | else if (isOdd) |
| 1931 | Index = 2 * i + 1; |
| 1932 | else |
Daniel Dunbar | ce5a0b3 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 1933 | Index = ExtVectorType::getAccessorIdx(Comp[i]); |
Chris Lattner | 885b495 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 1934 | |
Nate Begeman | d386215 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 1935 | Elts.push_back(Index); |
Chris Lattner | 885b495 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 1936 | } |
Nate Begeman | f322eab | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1939 | ObjCMessageExpr::ObjCMessageExpr(QualType T, |
| 1940 | SourceLocation LBracLoc, |
| 1941 | SourceLocation SuperLoc, |
| 1942 | bool IsInstanceSuper, |
| 1943 | QualType SuperType, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1944 | Selector Sel, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1945 | ObjCMethodDecl *Method, |
| 1946 | Expr **Args, unsigned NumArgs, |
| 1947 | SourceLocation RBracLoc) |
| 1948 | : Expr(ObjCMessageExprClass, T, /*TypeDependent=*/false, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1949 | /*ValueDependent=*/false), |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1950 | NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass), |
| 1951 | HasMethod(Method != 0), SuperLoc(SuperLoc), |
| 1952 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method |
| 1953 | : Sel.getAsOpaquePtr())), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1954 | LBracLoc(LBracLoc), RBracLoc(RBracLoc) |
Douglas Gregor | de4827d | 2010-03-08 16:40:19 +0000 | [diff] [blame] | 1955 | { |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1956 | setReceiverPointer(SuperType.getAsOpaquePtr()); |
| 1957 | if (NumArgs) |
| 1958 | memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); |
Ted Kremenek | a3a37ae | 2008-06-24 15:50:53 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1961 | ObjCMessageExpr::ObjCMessageExpr(QualType T, |
| 1962 | SourceLocation LBracLoc, |
| 1963 | TypeSourceInfo *Receiver, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1964 | Selector Sel, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1965 | ObjCMethodDecl *Method, |
| 1966 | Expr **Args, unsigned NumArgs, |
| 1967 | SourceLocation RBracLoc) |
| 1968 | : Expr(ObjCMessageExprClass, T, T->isDependentType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1969 | (T->isDependentType() || |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1970 | hasAnyValueDependentArguments(Args, NumArgs))), |
| 1971 | NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0), |
| 1972 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method |
| 1973 | : Sel.getAsOpaquePtr())), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1974 | LBracLoc(LBracLoc), RBracLoc(RBracLoc) |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1975 | { |
| 1976 | setReceiverPointer(Receiver); |
| 1977 | if (NumArgs) |
| 1978 | memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); |
Ted Kremenek | a3a37ae | 2008-06-24 15:50:53 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1981 | ObjCMessageExpr::ObjCMessageExpr(QualType T, |
| 1982 | SourceLocation LBracLoc, |
| 1983 | Expr *Receiver, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1984 | Selector Sel, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1985 | ObjCMethodDecl *Method, |
| 1986 | Expr **Args, unsigned NumArgs, |
| 1987 | SourceLocation RBracLoc) |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1988 | : Expr(ObjCMessageExprClass, T, Receiver->isTypeDependent(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1989 | (Receiver->isTypeDependent() || |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1990 | hasAnyValueDependentArguments(Args, NumArgs))), |
| 1991 | NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0), |
| 1992 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method |
| 1993 | : Sel.getAsOpaquePtr())), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1994 | LBracLoc(LBracLoc), RBracLoc(RBracLoc) |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 1995 | { |
| 1996 | setReceiverPointer(Receiver); |
| 1997 | if (NumArgs) |
| 1998 | memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); |
Chris Lattner | 7ec71da | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2001 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, |
| 2002 | SourceLocation LBracLoc, |
| 2003 | SourceLocation SuperLoc, |
| 2004 | bool IsInstanceSuper, |
| 2005 | QualType SuperType, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2006 | Selector Sel, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2007 | ObjCMethodDecl *Method, |
| 2008 | Expr **Args, unsigned NumArgs, |
| 2009 | SourceLocation RBracLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2010 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2011 | NumArgs * sizeof(Expr *); |
| 2012 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
| 2013 | return new (Mem) ObjCMessageExpr(T, LBracLoc, SuperLoc, IsInstanceSuper, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2014 | SuperType, Sel, Method, Args, NumArgs, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2015 | RBracLoc); |
| 2016 | } |
| 2017 | |
| 2018 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, |
| 2019 | SourceLocation LBracLoc, |
| 2020 | TypeSourceInfo *Receiver, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2021 | Selector Sel, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2022 | ObjCMethodDecl *Method, |
| 2023 | Expr **Args, unsigned NumArgs, |
| 2024 | SourceLocation RBracLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2025 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2026 | NumArgs * sizeof(Expr *); |
| 2027 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2028 | return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2029 | NumArgs, RBracLoc); |
| 2030 | } |
| 2031 | |
| 2032 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, |
| 2033 | SourceLocation LBracLoc, |
| 2034 | Expr *Receiver, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2035 | Selector Sel, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2036 | ObjCMethodDecl *Method, |
| 2037 | Expr **Args, unsigned NumArgs, |
| 2038 | SourceLocation RBracLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2039 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2040 | NumArgs * sizeof(Expr *); |
| 2041 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2042 | return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2043 | NumArgs, RBracLoc); |
| 2044 | } |
| 2045 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2046 | ObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2047 | unsigned NumArgs) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2048 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2049 | NumArgs * sizeof(Expr *); |
| 2050 | void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); |
| 2051 | return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); |
| 2052 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2053 | |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2054 | Selector ObjCMessageExpr::getSelector() const { |
| 2055 | if (HasMethod) |
| 2056 | return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) |
| 2057 | ->getSelector(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2058 | return Selector(SelectorOrMethod); |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { |
| 2062 | switch (getReceiverKind()) { |
| 2063 | case Instance: |
| 2064 | if (const ObjCObjectPointerType *Ptr |
| 2065 | = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) |
| 2066 | return Ptr->getInterfaceDecl(); |
| 2067 | break; |
| 2068 | |
| 2069 | case Class: |
| 2070 | if (const ObjCInterfaceType *Iface |
| 2071 | = getClassReceiver()->getAs<ObjCInterfaceType>()) |
| 2072 | return Iface->getDecl(); |
| 2073 | break; |
| 2074 | |
| 2075 | case SuperInstance: |
| 2076 | if (const ObjCObjectPointerType *Ptr |
| 2077 | = getSuperType()->getAs<ObjCObjectPointerType>()) |
| 2078 | return Ptr->getInterfaceDecl(); |
| 2079 | break; |
| 2080 | |
| 2081 | case SuperClass: |
| 2082 | if (const ObjCObjectPointerType *Iface |
| 2083 | = getSuperType()->getAs<ObjCObjectPointerType>()) |
| 2084 | return Iface->getInterfaceDecl(); |
| 2085 | break; |
| 2086 | } |
| 2087 | |
| 2088 | return 0; |
Ted Kremenek | 2c80930 | 2010-02-11 22:41:21 +0000 | [diff] [blame] | 2089 | } |
Chris Lattner | 7ec71da | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 2090 | |
Chris Lattner | 35e564e | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 2091 | bool ChooseExpr::isConditionTrue(ASTContext &C) const { |
Eli Friedman | 1c4a175 | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 2092 | return getCond()->EvaluateAsInt(C) != 0; |
Chris Lattner | 35e564e | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
Nate Begeman | 4874592 | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 2095 | void ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, |
| 2096 | unsigned NumExprs) { |
| 2097 | if (SubExprs) C.Deallocate(SubExprs); |
| 2098 | |
| 2099 | SubExprs = new (C) Stmt* [NumExprs]; |
Douglas Gregor | a3c5590 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2100 | this->NumExprs = NumExprs; |
| 2101 | memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | } |
Nate Begeman | 4874592 | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 2103 | |
| 2104 | void ShuffleVectorExpr::DoDestroy(ASTContext& C) { |
| 2105 | DestroyChildren(C); |
| 2106 | if (SubExprs) C.Deallocate(SubExprs); |
| 2107 | this->~ShuffleVectorExpr(); |
| 2108 | C.Deallocate(this); |
Douglas Gregor | a3c5590 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 2111 | void SizeOfAlignOfExpr::DoDestroy(ASTContext& C) { |
Sebastian Redl | 6f28289 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2112 | // Override default behavior of traversing children. If this has a type |
| 2113 | // operand and the type is a variable-length array, the child iteration |
| 2114 | // will iterate over the size expression. However, this expression belongs |
| 2115 | // to the type, not to this, so we don't want to delete it. |
| 2116 | // We still want to delete this expression. |
Ted Kremenek | 5a20195 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 2117 | if (isArgumentType()) { |
| 2118 | this->~SizeOfAlignOfExpr(); |
| 2119 | C.Deallocate(this); |
| 2120 | } |
Sebastian Redl | 6f28289 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2121 | else |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 2122 | Expr::DoDestroy(C); |
Daniel Dunbar | 3e1888e | 2008-08-28 18:02:04 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2125 | //===----------------------------------------------------------------------===// |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2126 | // DesignatedInitExpr |
| 2127 | //===----------------------------------------------------------------------===// |
| 2128 | |
| 2129 | IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { |
| 2130 | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
| 2131 | if (Field.NameOrField & 0x01) |
| 2132 | return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); |
| 2133 | else |
| 2134 | return getField()->getIdentifier(); |
| 2135 | } |
| 2136 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2137 | DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2138 | unsigned NumDesignators, |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2139 | const Designator *Designators, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2140 | SourceLocation EqualOrColonLoc, |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2141 | bool GNUSyntax, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2142 | Expr **IndexExprs, |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2143 | unsigned NumIndexExprs, |
| 2144 | Expr *Init) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | : Expr(DesignatedInitExprClass, Ty, |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2146 | Init->isTypeDependent(), Init->isValueDependent()), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), |
| 2148 | NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2149 | this->Designators = new (C) Designator[NumDesignators]; |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2150 | |
| 2151 | // Record the initializer itself. |
| 2152 | child_iterator Child = child_begin(); |
| 2153 | *Child++ = Init; |
| 2154 | |
| 2155 | // Copy the designators and their subexpressions, computing |
| 2156 | // value-dependence along the way. |
| 2157 | unsigned IndexIdx = 0; |
| 2158 | for (unsigned I = 0; I != NumDesignators; ++I) { |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2159 | this->Designators[I] = Designators[I]; |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2160 | |
| 2161 | if (this->Designators[I].isArrayDesignator()) { |
| 2162 | // Compute type- and value-dependence. |
| 2163 | Expr *Index = IndexExprs[IndexIdx]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2164 | ValueDependent = ValueDependent || |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2165 | Index->isTypeDependent() || Index->isValueDependent(); |
| 2166 | |
| 2167 | // Copy the index expressions into permanent storage. |
| 2168 | *Child++ = IndexExprs[IndexIdx++]; |
| 2169 | } else if (this->Designators[I].isArrayRangeDesignator()) { |
| 2170 | // Compute type- and value-dependence. |
| 2171 | Expr *Start = IndexExprs[IndexIdx]; |
| 2172 | Expr *End = IndexExprs[IndexIdx + 1]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2173 | ValueDependent = ValueDependent || |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2174 | Start->isTypeDependent() || Start->isValueDependent() || |
| 2175 | End->isTypeDependent() || End->isValueDependent(); |
| 2176 | |
| 2177 | // Copy the start/end expressions into permanent storage. |
| 2178 | *Child++ = IndexExprs[IndexIdx++]; |
| 2179 | *Child++ = IndexExprs[IndexIdx++]; |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2186 | DesignatedInitExpr * |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2187 | DesignatedInitExpr::Create(ASTContext &C, Designator *Designators, |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2188 | unsigned NumDesignators, |
| 2189 | Expr **IndexExprs, unsigned NumIndexExprs, |
| 2190 | SourceLocation ColonOrEqualLoc, |
| 2191 | bool UsesColonSyntax, Expr *Init) { |
Steve Naroff | 99c0cdf | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 2192 | void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + |
Steve Naroff | 99c0cdf | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 2193 | sizeof(Stmt *) * (NumIndexExprs + 1), 8); |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2194 | return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, |
Douglas Gregor | ca1aeec | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 2195 | ColonOrEqualLoc, UsesColonSyntax, |
| 2196 | IndexExprs, NumIndexExprs, Init); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, |
Douglas Gregor | 38676d5 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2200 | unsigned NumIndexExprs) { |
| 2201 | void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + |
| 2202 | sizeof(Stmt *) * (NumIndexExprs + 1), 8); |
| 2203 | return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); |
| 2204 | } |
| 2205 | |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2206 | void DesignatedInitExpr::setDesignators(ASTContext &C, |
| 2207 | const Designator *Desigs, |
Douglas Gregor | 38676d5 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2208 | unsigned NumDesigs) { |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2209 | DestroyDesignators(C); |
Douglas Gregor | 38676d5 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2210 | |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2211 | Designators = new (C) Designator[NumDesigs]; |
Douglas Gregor | 38676d5 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2212 | NumDesignators = NumDesigs; |
| 2213 | for (unsigned I = 0; I != NumDesigs; ++I) |
| 2214 | Designators[I] = Desigs[I]; |
| 2215 | } |
| 2216 | |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2217 | SourceRange DesignatedInitExpr::getSourceRange() const { |
| 2218 | SourceLocation StartLoc; |
Chris Lattner | 8ba2247 | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 2219 | Designator &First = |
| 2220 | *const_cast<DesignatedInitExpr*>(this)->designators_begin(); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2221 | if (First.isFieldDesignator()) { |
Douglas Gregor | 5c7c9cb | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 2222 | if (GNUSyntax) |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2223 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); |
| 2224 | else |
| 2225 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); |
| 2226 | } else |
Chris Lattner | 8ba2247 | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 2227 | StartLoc = |
| 2228 | SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2229 | return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); |
| 2230 | } |
| 2231 | |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2232 | Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) { |
| 2233 | assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); |
| 2234 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2235 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2236 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2237 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); |
| 2238 | } |
| 2239 | |
| 2240 | Expr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2241 | assert(D.Kind == Designator::ArrayRangeDesignator && |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2242 | "Requires array range designator"); |
| 2243 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2244 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2245 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2246 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); |
| 2247 | } |
| 2248 | |
| 2249 | Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2250 | assert(D.Kind == Designator::ArrayRangeDesignator && |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2251 | "Requires array range designator"); |
| 2252 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2253 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2254 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2255 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); |
| 2256 | } |
| 2257 | |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2258 | /// \brief Replaces the designator at index @p Idx with the series |
| 2259 | /// of designators in [First, Last). |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2260 | void DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2261 | const Designator *First, |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2262 | const Designator *Last) { |
| 2263 | unsigned NumNewDesignators = Last - First; |
| 2264 | if (NumNewDesignators == 0) { |
| 2265 | std::copy_backward(Designators + Idx + 1, |
| 2266 | Designators + NumDesignators, |
| 2267 | Designators + Idx); |
| 2268 | --NumNewDesignators; |
| 2269 | return; |
| 2270 | } else if (NumNewDesignators == 1) { |
| 2271 | Designators[Idx] = *First; |
| 2272 | return; |
| 2273 | } |
| 2274 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2275 | Designator *NewDesignators |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2276 | = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2277 | std::copy(Designators, Designators + Idx, NewDesignators); |
| 2278 | std::copy(First, Last, NewDesignators + Idx); |
| 2279 | std::copy(Designators + Idx + 1, Designators + NumDesignators, |
| 2280 | NewDesignators + Idx + NumNewDesignators); |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2281 | DestroyDesignators(C); |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2282 | Designators = NewDesignators; |
| 2283 | NumDesignators = NumDesignators - 1 + NumNewDesignators; |
| 2284 | } |
| 2285 | |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 2286 | void DesignatedInitExpr::DoDestroy(ASTContext &C) { |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2287 | DestroyDesignators(C); |
Douglas Gregor | e26a285 | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 2288 | Expr::DoDestroy(C); |
Douglas Gregor | d5846a1 | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
Douglas Gregor | 03e8bdc | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 2291 | void DesignatedInitExpr::DestroyDesignators(ASTContext &C) { |
| 2292 | for (unsigned I = 0; I != NumDesignators; ++I) |
| 2293 | Designators[I].~Designator(); |
| 2294 | C.Deallocate(Designators); |
| 2295 | Designators = 0; |
| 2296 | } |
| 2297 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | ParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, |
Nate Begeman | 5ec4b31 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2299 | Expr **exprs, unsigned nexprs, |
| 2300 | SourceLocation rparenloc) |
| 2301 | : Expr(ParenListExprClass, QualType(), |
| 2302 | hasAnyTypeDependentArguments(exprs, nexprs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | hasAnyValueDependentArguments(exprs, nexprs)), |
Nate Begeman | 5ec4b31 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2304 | NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2305 | |
Nate Begeman | 5ec4b31 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2306 | Exprs = new (C) Stmt*[nexprs]; |
| 2307 | for (unsigned i = 0; i != nexprs; ++i) |
| 2308 | Exprs[i] = exprs[i]; |
| 2309 | } |
| 2310 | |
| 2311 | void ParenListExpr::DoDestroy(ASTContext& C) { |
| 2312 | DestroyChildren(C); |
| 2313 | if (Exprs) C.Deallocate(Exprs); |
| 2314 | this->~ParenListExpr(); |
| 2315 | C.Deallocate(this); |
| 2316 | } |
| 2317 | |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2318 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 2319 | // ExprIterator. |
| 2320 | //===----------------------------------------------------------------------===// |
| 2321 | |
| 2322 | Expr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } |
| 2323 | Expr* ExprIterator::operator*() const { return cast<Expr>(*I); } |
| 2324 | Expr* ExprIterator::operator->() const { return cast<Expr>(*I); } |
| 2325 | const Expr* ConstExprIterator::operator[](size_t idx) const { |
| 2326 | return cast<Expr>(I[idx]); |
| 2327 | } |
| 2328 | const Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } |
| 2329 | const Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } |
| 2330 | |
| 2331 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2332 | // Child Iterators for iterating over subexpressions/substatements |
| 2333 | //===----------------------------------------------------------------------===// |
| 2334 | |
| 2335 | // DeclRefExpr |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2336 | Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } |
| 2337 | Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2338 | |
Steve Naroff | e46504b | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 2339 | // ObjCIvarRefExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2340 | Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; } |
| 2341 | Stmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; } |
Steve Naroff | e46504b | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 2342 | |
Steve Naroff | ebf4cb4 | 2008-06-02 23:03:37 +0000 | [diff] [blame] | 2343 | // ObjCPropertyRefExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2344 | Stmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; } |
| 2345 | Stmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; } |
Steve Naroff | ec94403 | 2008-05-30 00:40:33 +0000 | [diff] [blame] | 2346 | |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 2347 | // ObjCImplicitSetterGetterRefExpr |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2348 | Stmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() { |
John McCall | eebc832 | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 2349 | // If this is accessing a class member, skip that entry. |
| 2350 | if (Base) return &Base; |
| 2351 | return &Base+1; |
Fariborz Jahanian | 88cc234 | 2009-08-18 20:50:23 +0000 | [diff] [blame] | 2352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2353 | Stmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() { |
| 2354 | return &Base+1; |
Fariborz Jahanian | 88cc234 | 2009-08-18 20:50:23 +0000 | [diff] [blame] | 2355 | } |
Fariborz Jahanian | 8a1810f | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 2356 | |
Douglas Gregor | 8ea1f53 | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 2357 | // ObjCSuperExpr |
| 2358 | Stmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); } |
| 2359 | Stmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); } |
| 2360 | |
Steve Naroff | e87026a | 2009-07-24 17:54:45 +0000 | [diff] [blame] | 2361 | // ObjCIsaExpr |
| 2362 | Stmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; } |
| 2363 | Stmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; } |
| 2364 | |
Chris Lattner | 6307f19 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 2365 | // PredefinedExpr |
| 2366 | Stmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); } |
| 2367 | Stmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2368 | |
| 2369 | // IntegerLiteral |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2370 | Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } |
| 2371 | Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2372 | |
| 2373 | // CharacterLiteral |
Chris Lattner | 8ba2247 | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 2374 | Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();} |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2375 | Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2376 | |
| 2377 | // FloatingLiteral |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2378 | Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } |
| 2379 | Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2380 | |
Chris Lattner | 1c20a17 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 2381 | // ImaginaryLiteral |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2382 | Stmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; } |
| 2383 | Stmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; } |
Chris Lattner | 1c20a17 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 2384 | |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2385 | // StringLiteral |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2386 | Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } |
| 2387 | Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2388 | |
| 2389 | // ParenExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2390 | Stmt::child_iterator ParenExpr::child_begin() { return &Val; } |
| 2391 | Stmt::child_iterator ParenExpr::child_end() { return &Val+1; } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2392 | |
| 2393 | // UnaryOperator |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2394 | Stmt::child_iterator UnaryOperator::child_begin() { return &Val; } |
| 2395 | Stmt::child_iterator UnaryOperator::child_end() { return &Val+1; } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2396 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2397 | // OffsetOfExpr |
| 2398 | Stmt::child_iterator OffsetOfExpr::child_begin() { |
| 2399 | return reinterpret_cast<Stmt **> (reinterpret_cast<OffsetOfNode *> (this + 1) |
| 2400 | + NumComps); |
| 2401 | } |
| 2402 | Stmt::child_iterator OffsetOfExpr::child_end() { |
| 2403 | return child_iterator(&*child_begin() + NumExprs); |
| 2404 | } |
| 2405 | |
Sebastian Redl | 6f28289 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2406 | // SizeOfAlignOfExpr |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2407 | Stmt::child_iterator SizeOfAlignOfExpr::child_begin() { |
Sebastian Redl | 6f28289 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2408 | // If this is of a type and the type is a VLA type (and not a typedef), the |
| 2409 | // size expression of the VLA needs to be treated as an executable expression. |
| 2410 | // Why isn't this weirdness documented better in StmtIterator? |
| 2411 | if (isArgumentType()) { |
| 2412 | if (VariableArrayType* T = dyn_cast<VariableArrayType>( |
| 2413 | getArgumentType().getTypePtr())) |
| 2414 | return child_iterator(T); |
| 2415 | return child_iterator(); |
| 2416 | } |
Sebastian Redl | ba3fdfc | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 2417 | return child_iterator(&Argument.Ex); |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2418 | } |
Sebastian Redl | 6f28289 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 2419 | Stmt::child_iterator SizeOfAlignOfExpr::child_end() { |
| 2420 | if (isArgumentType()) |
| 2421 | return child_iterator(); |
Sebastian Redl | ba3fdfc | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 2422 | return child_iterator(&Argument.Ex + 1); |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2423 | } |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2424 | |
| 2425 | // ArraySubscriptExpr |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2426 | Stmt::child_iterator ArraySubscriptExpr::child_begin() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2427 | return &SubExprs[0]; |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2428 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2429 | Stmt::child_iterator ArraySubscriptExpr::child_end() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2430 | return &SubExprs[0]+END_EXPR; |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | // CallExpr |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2434 | Stmt::child_iterator CallExpr::child_begin() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2435 | return &SubExprs[0]; |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2436 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2437 | Stmt::child_iterator CallExpr::child_end() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2438 | return &SubExprs[0]+NumArgs+ARGS_START; |
Ted Kremenek | 85e92ec | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 2439 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2440 | |
| 2441 | // MemberExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2442 | Stmt::child_iterator MemberExpr::child_begin() { return &Base; } |
| 2443 | Stmt::child_iterator MemberExpr::child_end() { return &Base+1; } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2444 | |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2445 | // ExtVectorElementExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2446 | Stmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; } |
| 2447 | Stmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2448 | |
| 2449 | // CompoundLiteralExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2450 | Stmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; } |
| 2451 | Stmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2452 | |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2453 | // CastExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2454 | Stmt::child_iterator CastExpr::child_begin() { return &Op; } |
| 2455 | Stmt::child_iterator CastExpr::child_end() { return &Op+1; } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2456 | |
| 2457 | // BinaryOperator |
| 2458 | Stmt::child_iterator BinaryOperator::child_begin() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2459 | return &SubExprs[0]; |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2460 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2461 | Stmt::child_iterator BinaryOperator::child_end() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2462 | return &SubExprs[0]+END_EXPR; |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | // ConditionalOperator |
| 2466 | Stmt::child_iterator ConditionalOperator::child_begin() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2467 | return &SubExprs[0]; |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2468 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2469 | Stmt::child_iterator ConditionalOperator::child_end() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2470 | return &SubExprs[0]+END_EXPR; |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | // AddrLabelExpr |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2474 | Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } |
| 2475 | Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2476 | |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2477 | // StmtExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2478 | Stmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } |
| 2479 | Stmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2480 | |
| 2481 | // TypesCompatibleExpr |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2482 | Stmt::child_iterator TypesCompatibleExpr::child_begin() { |
| 2483 | return child_iterator(); |
| 2484 | } |
| 2485 | |
| 2486 | Stmt::child_iterator TypesCompatibleExpr::child_end() { |
| 2487 | return child_iterator(); |
| 2488 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2489 | |
| 2490 | // ChooseExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2491 | Stmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } |
| 2492 | Stmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2493 | |
Douglas Gregor | 3be4b12 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 2494 | // GNUNullExpr |
| 2495 | Stmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); } |
| 2496 | Stmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); } |
| 2497 | |
Eli Friedman | a1b4ed8 | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 2498 | // ShuffleVectorExpr |
| 2499 | Stmt::child_iterator ShuffleVectorExpr::child_begin() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2500 | return &SubExprs[0]; |
Eli Friedman | a1b4ed8 | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 2501 | } |
| 2502 | Stmt::child_iterator ShuffleVectorExpr::child_end() { |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2503 | return &SubExprs[0]+NumExprs; |
Eli Friedman | a1b4ed8 | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
Anders Carlsson | 7e13ab8 | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 2506 | // VAArgExpr |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2507 | Stmt::child_iterator VAArgExpr::child_begin() { return &Val; } |
| 2508 | Stmt::child_iterator VAArgExpr::child_end() { return &Val+1; } |
Anders Carlsson | 7e13ab8 | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 2509 | |
Anders Carlsson | 4692db0 | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 2510 | // InitListExpr |
Ted Kremenek | 013041e | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 2511 | Stmt::child_iterator InitListExpr::child_begin() { |
| 2512 | return InitExprs.size() ? &InitExprs[0] : 0; |
| 2513 | } |
| 2514 | Stmt::child_iterator InitListExpr::child_end() { |
| 2515 | return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0; |
| 2516 | } |
Anders Carlsson | 4692db0 | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 2517 | |
Douglas Gregor | 0202cb4 | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2518 | // DesignatedInitExpr |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2519 | Stmt::child_iterator DesignatedInitExpr::child_begin() { |
| 2520 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); |
| 2521 | Ptr += sizeof(DesignatedInitExpr); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 2522 | return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); |
| 2523 | } |
| 2524 | Stmt::child_iterator DesignatedInitExpr::child_end() { |
| 2525 | return child_iterator(&*child_begin() + NumSubExprs); |
| 2526 | } |
| 2527 | |
Douglas Gregor | 0202cb4 | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2528 | // ImplicitValueInitExpr |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2529 | Stmt::child_iterator ImplicitValueInitExpr::child_begin() { |
| 2530 | return child_iterator(); |
Douglas Gregor | 0202cb4 | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2533 | Stmt::child_iterator ImplicitValueInitExpr::child_end() { |
| 2534 | return child_iterator(); |
Douglas Gregor | 0202cb4 | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
Nate Begeman | 5ec4b31 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 2537 | // ParenListExpr |
| 2538 | Stmt::child_iterator ParenListExpr::child_begin() { |
| 2539 | return &Exprs[0]; |
| 2540 | } |
| 2541 | Stmt::child_iterator ParenListExpr::child_end() { |
| 2542 | return &Exprs[0]+NumExprs; |
| 2543 | } |
| 2544 | |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2545 | // ObjCStringLiteral |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2546 | Stmt::child_iterator ObjCStringLiteral::child_begin() { |
Chris Lattner | 112c2a9 | 2009-02-18 06:53:08 +0000 | [diff] [blame] | 2547 | return &String; |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2548 | } |
| 2549 | Stmt::child_iterator ObjCStringLiteral::child_end() { |
Chris Lattner | 112c2a9 | 2009-02-18 06:53:08 +0000 | [diff] [blame] | 2550 | return &String+1; |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2551 | } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2552 | |
| 2553 | // ObjCEncodeExpr |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2554 | Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } |
| 2555 | Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 23702b6 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 2556 | |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2557 | // ObjCSelectorExpr |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | Stmt::child_iterator ObjCSelectorExpr::child_begin() { |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2559 | return child_iterator(); |
| 2560 | } |
| 2561 | Stmt::child_iterator ObjCSelectorExpr::child_end() { |
| 2562 | return child_iterator(); |
| 2563 | } |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2564 | |
Fariborz Jahanian | a32aaef | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2565 | // ObjCProtocolExpr |
Ted Kremenek | 04746ce | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 2566 | Stmt::child_iterator ObjCProtocolExpr::child_begin() { |
| 2567 | return child_iterator(); |
| 2568 | } |
| 2569 | Stmt::child_iterator ObjCProtocolExpr::child_end() { |
| 2570 | return child_iterator(); |
| 2571 | } |
Fariborz Jahanian | a32aaef | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2572 | |
Steve Naroff | d54978b | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 2573 | // ObjCMessageExpr |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | Stmt::child_iterator ObjCMessageExpr::child_begin() { |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2575 | if (getReceiverKind() == Instance) |
| 2576 | return reinterpret_cast<Stmt **>(this + 1); |
| 2577 | return getArgs(); |
Steve Naroff | d54978b | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 2578 | } |
| 2579 | Stmt::child_iterator ObjCMessageExpr::child_end() { |
Douglas Gregor | 9a12919 | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2580 | return getArgs() + getNumArgs(); |
Steve Naroff | d54978b | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
Steve Naroff | c540d66 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2583 | // Blocks |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 2584 | Stmt::child_iterator BlockExpr::child_begin() { return child_iterator(); } |
| 2585 | Stmt::child_iterator BlockExpr::child_end() { return child_iterator(); } |
Steve Naroff | c540d66 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2586 | |
Ted Kremenek | 8bafa2c | 2008-09-26 23:24:14 +0000 | [diff] [blame] | 2587 | Stmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} |
| 2588 | Stmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); } |