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