Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame^] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Expr class and subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Expr.h" |
Chris Lattner | 2eadfb6 | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/AST/StmtVisitor.h" |
Chris Lattner | c7229c3 | 2007-10-07 08:58:51 +0000 | [diff] [blame] | 17 | #include "clang/Basic/IdentifierTable.h" |
Chris Lattner | da5a6b6 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | // Primary Expressions. |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
| 25 | StringLiteral::StringLiteral(const char *strData, unsigned byteLength, |
| 26 | bool Wide, QualType t, SourceLocation firstLoc, |
| 27 | SourceLocation lastLoc) : |
| 28 | Expr(StringLiteralClass, t) { |
| 29 | // OPTIMIZE: could allocate this appended to the StringLiteral. |
| 30 | char *AStrData = new char[byteLength]; |
| 31 | memcpy(AStrData, strData, byteLength); |
| 32 | StrData = AStrData; |
| 33 | ByteLength = byteLength; |
| 34 | IsWide = Wide; |
| 35 | firstTokLoc = firstLoc; |
| 36 | lastTokLoc = lastLoc; |
| 37 | } |
| 38 | |
| 39 | StringLiteral::~StringLiteral() { |
| 40 | delete[] StrData; |
| 41 | } |
| 42 | |
| 43 | bool UnaryOperator::isPostfix(Opcode Op) { |
| 44 | switch (Op) { |
| 45 | case PostInc: |
| 46 | case PostDec: |
| 47 | return true; |
| 48 | default: |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 54 | /// corresponds to, e.g. "sizeof" or "[pre]++". |
| 55 | const char *UnaryOperator::getOpcodeStr(Opcode Op) { |
| 56 | switch (Op) { |
| 57 | default: assert(0 && "Unknown unary operator"); |
| 58 | case PostInc: return "++"; |
| 59 | case PostDec: return "--"; |
| 60 | case PreInc: return "++"; |
| 61 | case PreDec: return "--"; |
| 62 | case AddrOf: return "&"; |
| 63 | case Deref: return "*"; |
| 64 | case Plus: return "+"; |
| 65 | case Minus: return "-"; |
| 66 | case Not: return "~"; |
| 67 | case LNot: return "!"; |
| 68 | case Real: return "__real"; |
| 69 | case Imag: return "__imag"; |
| 70 | case SizeOf: return "sizeof"; |
| 71 | case AlignOf: return "alignof"; |
| 72 | case Extension: return "__extension__"; |
Chris Lattner | 73d0d4f | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 73 | case OffsetOf: return "__builtin_offsetof"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | //===----------------------------------------------------------------------===// |
| 78 | // Postfix Operators. |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | |
| 81 | CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, |
| 82 | SourceLocation rparenloc) |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 83 | : Expr(CallExprClass, t), NumArgs(numargs) { |
| 84 | SubExprs = new Expr*[numargs+1]; |
| 85 | SubExprs[FN] = fn; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 86 | for (unsigned i = 0; i != numargs; ++i) |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 87 | SubExprs[i+ARGS_START] = args[i]; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | RParenLoc = rparenloc; |
| 89 | } |
| 90 | |
Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 91 | /// setNumArgs - This changes the number of arguments present in this call. |
| 92 | /// Any orphaned expressions are deleted by this, and any new operands are set |
| 93 | /// to null. |
| 94 | void CallExpr::setNumArgs(unsigned NumArgs) { |
| 95 | // No change, just return. |
| 96 | if (NumArgs == getNumArgs()) return; |
| 97 | |
| 98 | // If shrinking # arguments, just delete the extras and forgot them. |
| 99 | if (NumArgs < getNumArgs()) { |
| 100 | for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i) |
| 101 | delete getArg(i); |
| 102 | this->NumArgs = NumArgs; |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | // Otherwise, we are growing the # arguments. New an bigger argument array. |
| 107 | Expr **NewSubExprs = new Expr*[NumArgs+1]; |
| 108 | // Copy over args. |
| 109 | for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) |
| 110 | NewSubExprs[i] = SubExprs[i]; |
| 111 | // Null out new args. |
| 112 | for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) |
| 113 | NewSubExprs[i] = 0; |
| 114 | |
| 115 | delete[] SubExprs; |
| 116 | SubExprs = NewSubExprs; |
| 117 | this->NumArgs = NumArgs; |
| 118 | } |
| 119 | |
| 120 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 121 | bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const { |
| 122 | // The following enum mimics gcc's internal "typeclass.h" file. |
| 123 | enum gcc_type_class { |
| 124 | no_type_class = -1, |
| 125 | void_type_class, integer_type_class, char_type_class, |
| 126 | enumeral_type_class, boolean_type_class, |
| 127 | pointer_type_class, reference_type_class, offset_type_class, |
| 128 | real_type_class, complex_type_class, |
| 129 | function_type_class, method_type_class, |
| 130 | record_type_class, union_type_class, |
| 131 | array_type_class, string_type_class, |
| 132 | lang_type_class |
| 133 | }; |
| 134 | Result.setIsSigned(true); |
| 135 | |
| 136 | // All simple function calls (e.g. func()) are implicitly cast to pointer to |
| 137 | // function. As a result, we try and obtain the DeclRefExpr from the |
| 138 | // ImplicitCastExpr. |
| 139 | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); |
| 140 | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). |
| 141 | return false; |
| 142 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); |
| 143 | if (!DRE) |
| 144 | return false; |
| 145 | |
| 146 | // We have a DeclRefExpr. |
| 147 | if (strcmp(DRE->getDecl()->getName(), "__builtin_classify_type") == 0) { |
| 148 | // If no argument was supplied, default to "no_type_class". This isn't |
| 149 | // ideal, however it's what gcc does. |
| 150 | Result = static_cast<uint64_t>(no_type_class); |
| 151 | if (NumArgs >= 1) { |
| 152 | QualType argType = getArg(0)->getType(); |
| 153 | |
| 154 | if (argType->isVoidType()) |
| 155 | Result = void_type_class; |
| 156 | else if (argType->isEnumeralType()) |
| 157 | Result = enumeral_type_class; |
| 158 | else if (argType->isBooleanType()) |
| 159 | Result = boolean_type_class; |
| 160 | else if (argType->isCharType()) |
| 161 | Result = string_type_class; // gcc doesn't appear to use char_type_class |
| 162 | else if (argType->isIntegerType()) |
| 163 | Result = integer_type_class; |
| 164 | else if (argType->isPointerType()) |
| 165 | Result = pointer_type_class; |
| 166 | else if (argType->isReferenceType()) |
| 167 | Result = reference_type_class; |
| 168 | else if (argType->isRealType()) |
| 169 | Result = real_type_class; |
| 170 | else if (argType->isComplexType()) |
| 171 | Result = complex_type_class; |
| 172 | else if (argType->isFunctionType()) |
| 173 | Result = function_type_class; |
| 174 | else if (argType->isStructureType()) |
| 175 | Result = record_type_class; |
| 176 | else if (argType->isUnionType()) |
| 177 | Result = union_type_class; |
| 178 | else if (argType->isArrayType()) |
| 179 | Result = array_type_class; |
| 180 | else if (argType->isUnionType()) |
| 181 | Result = union_type_class; |
| 182 | else // FIXME: offset_type_class, method_type_class, & lang_type_class? |
Chris Lattner | 3ef5bc0 | 2007-11-08 17:56:40 +0000 | [diff] [blame] | 183 | assert(0 && "CallExpr::isBuiltinClassifyType(): unimplemented type"); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 184 | } |
| 185 | return true; |
| 186 | } |
| 187 | return false; |
| 188 | } |
| 189 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 190 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 191 | /// corresponds to, e.g. "<<=". |
| 192 | const char *BinaryOperator::getOpcodeStr(Opcode Op) { |
| 193 | switch (Op) { |
| 194 | default: assert(0 && "Unknown binary operator"); |
| 195 | case Mul: return "*"; |
| 196 | case Div: return "/"; |
| 197 | case Rem: return "%"; |
| 198 | case Add: return "+"; |
| 199 | case Sub: return "-"; |
| 200 | case Shl: return "<<"; |
| 201 | case Shr: return ">>"; |
| 202 | case LT: return "<"; |
| 203 | case GT: return ">"; |
| 204 | case LE: return "<="; |
| 205 | case GE: return ">="; |
| 206 | case EQ: return "=="; |
| 207 | case NE: return "!="; |
| 208 | case And: return "&"; |
| 209 | case Xor: return "^"; |
| 210 | case Or: return "|"; |
| 211 | case LAnd: return "&&"; |
| 212 | case LOr: return "||"; |
| 213 | case Assign: return "="; |
| 214 | case MulAssign: return "*="; |
| 215 | case DivAssign: return "/="; |
| 216 | case RemAssign: return "%="; |
| 217 | case AddAssign: return "+="; |
| 218 | case SubAssign: return "-="; |
| 219 | case ShlAssign: return "<<="; |
| 220 | case ShrAssign: return ">>="; |
| 221 | case AndAssign: return "&="; |
| 222 | case XorAssign: return "^="; |
| 223 | case OrAssign: return "|="; |
| 224 | case Comma: return ","; |
| 225 | } |
| 226 | } |
| 227 | |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 228 | InitListExpr::InitListExpr(SourceLocation lbraceloc, |
| 229 | Expr **initexprs, unsigned numinits, |
| 230 | SourceLocation rbraceloc) |
| 231 | : Expr(InitListExprClass, QualType()) |
| 232 | , NumInits(numinits) |
| 233 | , LBraceLoc(lbraceloc) |
| 234 | , RBraceLoc(rbraceloc) |
| 235 | { |
| 236 | InitExprs = new Expr*[numinits]; |
| 237 | for (unsigned i = 0; i != numinits; i++) |
| 238 | InitExprs[i] = initexprs[i]; |
| 239 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 240 | |
| 241 | //===----------------------------------------------------------------------===// |
| 242 | // Generic Expression Routines |
| 243 | //===----------------------------------------------------------------------===// |
| 244 | |
| 245 | /// hasLocalSideEffect - Return true if this immediate expression has side |
| 246 | /// effects, not counting any sub-expressions. |
| 247 | bool Expr::hasLocalSideEffect() const { |
| 248 | switch (getStmtClass()) { |
| 249 | default: |
| 250 | return false; |
| 251 | case ParenExprClass: |
| 252 | return cast<ParenExpr>(this)->getSubExpr()->hasLocalSideEffect(); |
| 253 | case UnaryOperatorClass: { |
| 254 | const UnaryOperator *UO = cast<UnaryOperator>(this); |
| 255 | |
| 256 | switch (UO->getOpcode()) { |
| 257 | default: return false; |
| 258 | case UnaryOperator::PostInc: |
| 259 | case UnaryOperator::PostDec: |
| 260 | case UnaryOperator::PreInc: |
| 261 | case UnaryOperator::PreDec: |
| 262 | return true; // ++/-- |
| 263 | |
| 264 | case UnaryOperator::Deref: |
| 265 | // Dereferencing a volatile pointer is a side-effect. |
| 266 | return getType().isVolatileQualified(); |
| 267 | case UnaryOperator::Real: |
| 268 | case UnaryOperator::Imag: |
| 269 | // accessing a piece of a volatile complex is a side-effect. |
| 270 | return UO->getSubExpr()->getType().isVolatileQualified(); |
| 271 | |
| 272 | case UnaryOperator::Extension: |
| 273 | return UO->getSubExpr()->hasLocalSideEffect(); |
| 274 | } |
| 275 | } |
Chris Lattner | e7716e6 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 276 | case BinaryOperatorClass: { |
| 277 | const BinaryOperator *BinOp = cast<BinaryOperator>(this); |
| 278 | // Consider comma to have side effects if the LHS and RHS both do. |
| 279 | if (BinOp->getOpcode() == BinaryOperator::Comma) |
| 280 | return BinOp->getLHS()->hasLocalSideEffect() && |
| 281 | BinOp->getRHS()->hasLocalSideEffect(); |
| 282 | |
| 283 | return BinOp->isAssignmentOp(); |
| 284 | } |
Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 285 | case CompoundAssignOperatorClass: |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 286 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 287 | |
Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 288 | case ConditionalOperatorClass: { |
| 289 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
| 290 | return Exp->getCond()->hasLocalSideEffect() |
| 291 | || (Exp->getLHS() && Exp->getLHS()->hasLocalSideEffect()) |
| 292 | || (Exp->getRHS() && Exp->getRHS()->hasLocalSideEffect()); |
| 293 | } |
| 294 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 295 | case MemberExprClass: |
| 296 | case ArraySubscriptExprClass: |
| 297 | // If the base pointer or element is to a volatile pointer/field, accessing |
| 298 | // if is a side effect. |
| 299 | return getType().isVolatileQualified(); |
| 300 | |
| 301 | case CallExprClass: |
| 302 | // TODO: check attributes for pure/const. "void foo() { strlen("bar"); }" |
| 303 | // should warn. |
| 304 | return true; |
Chris Lattner | a9c0102 | 2007-09-26 22:06:30 +0000 | [diff] [blame] | 305 | case ObjCMessageExprClass: |
| 306 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 307 | |
| 308 | case CastExprClass: |
| 309 | // If this is a cast to void, check the operand. Otherwise, the result of |
| 310 | // the cast is unused. |
| 311 | if (getType()->isVoidType()) |
| 312 | return cast<CastExpr>(this)->getSubExpr()->hasLocalSideEffect(); |
| 313 | return false; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an |
| 318 | /// incomplete type other than void. Nonarray expressions that can be lvalues: |
| 319 | /// - name, where name must be a variable |
| 320 | /// - e[i] |
| 321 | /// - (e), where e must be an lvalue |
| 322 | /// - e.name, where e must be an lvalue |
| 323 | /// - e->name |
| 324 | /// - *e, the type of e cannot be a function type |
| 325 | /// - string-constant |
Chris Lattner | 7da36f6 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 326 | /// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension] |
Bill Wendling | 08ad47c | 2007-07-17 03:52:31 +0000 | [diff] [blame] | 327 | /// - reference type [C++ [expr]] |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 328 | /// |
Bill Wendling | ca51c97 | 2007-07-16 07:07:56 +0000 | [diff] [blame] | 329 | Expr::isLvalueResult Expr::isLvalue() const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 330 | // first, check the type (C99 6.3.2.1) |
Chris Lattner | cb4f9a6 | 2007-07-21 05:33:26 +0000 | [diff] [blame] | 331 | if (TR->isFunctionType()) // from isObjectType() |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 332 | return LV_NotObjectType; |
| 333 | |
Steve Naroff | 731ec57 | 2007-07-21 13:32:03 +0000 | [diff] [blame] | 334 | if (TR->isVoidType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 335 | return LV_IncompleteVoidType; |
Bill Wendling | 08ad47c | 2007-07-17 03:52:31 +0000 | [diff] [blame] | 336 | |
Chris Lattner | cb4f9a6 | 2007-07-21 05:33:26 +0000 | [diff] [blame] | 337 | if (TR->isReferenceType()) // C++ [expr] |
Bill Wendling | 08ad47c | 2007-07-17 03:52:31 +0000 | [diff] [blame] | 338 | return LV_Valid; |
| 339 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 340 | // the type looks fine, now check the expression |
| 341 | switch (getStmtClass()) { |
| 342 | case StringLiteralClass: // C99 6.5.1p4 |
Anders Carlsson | 7323a62 | 2007-11-30 22:47:59 +0000 | [diff] [blame] | 343 | return LV_Valid; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 344 | case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) |
| 345 | // For vectors, make sure base is an lvalue (i.e. not a function call). |
| 346 | if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType()) |
| 347 | return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(); |
| 348 | return LV_Valid; |
| 349 | case DeclRefExprClass: // C99 6.5.1p2 |
| 350 | if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl())) |
| 351 | return LV_Valid; |
| 352 | break; |
Anton Korobeynikov | fdd7566 | 2007-07-12 15:26:50 +0000 | [diff] [blame] | 353 | case MemberExprClass: { // C99 6.5.2.3p4 |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 354 | const MemberExpr *m = cast<MemberExpr>(this); |
| 355 | return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(); |
Anton Korobeynikov | fdd7566 | 2007-07-12 15:26:50 +0000 | [diff] [blame] | 356 | } |
Chris Lattner | 7da36f6 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 357 | case UnaryOperatorClass: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 358 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref) |
Chris Lattner | 7da36f6 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 359 | return LV_Valid; // C99 6.5.3p4 |
| 360 | |
| 361 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real || |
| 362 | cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag) |
| 363 | return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(); // GNU. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 364 | break; |
| 365 | case ParenExprClass: // C99 6.5.1p5 |
| 366 | return cast<ParenExpr>(this)->getSubExpr()->isLvalue(); |
Steve Naroff | e638639 | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 367 | case CompoundLiteralExprClass: // C99 6.5.2.5p5 |
| 368 | return LV_Valid; |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 369 | case OCUVectorElementExprClass: |
| 370 | if (cast<OCUVectorElementExpr>(this)->containsDuplicateElements()) |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 371 | return LV_DuplicateVectorComponents; |
| 372 | return LV_Valid; |
Steve Naroff | 027282d | 2007-11-12 14:34:27 +0000 | [diff] [blame] | 373 | case ObjCIvarRefExprClass: // ObjC instance variables are lvalues. |
| 374 | return LV_Valid; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 375 | default: |
| 376 | break; |
| 377 | } |
| 378 | return LV_InvalidExpression; |
| 379 | } |
| 380 | |
| 381 | /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, |
| 382 | /// does not have an incomplete type, does not have a const-qualified type, and |
| 383 | /// if it is a structure or union, does not have any member (including, |
| 384 | /// recursively, any member or element of all contained aggregates or unions) |
| 385 | /// with a const-qualified type. |
Bill Wendling | ca51c97 | 2007-07-16 07:07:56 +0000 | [diff] [blame] | 386 | Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 387 | isLvalueResult lvalResult = isLvalue(); |
| 388 | |
| 389 | switch (lvalResult) { |
| 390 | case LV_Valid: break; |
| 391 | case LV_NotObjectType: return MLV_NotObjectType; |
| 392 | case LV_IncompleteVoidType: return MLV_IncompleteVoidType; |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 393 | case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 394 | case LV_InvalidExpression: return MLV_InvalidExpression; |
| 395 | } |
| 396 | if (TR.isConstQualified()) |
| 397 | return MLV_ConstQualified; |
| 398 | if (TR->isArrayType()) |
| 399 | return MLV_ArrayType; |
| 400 | if (TR->isIncompleteType()) |
| 401 | return MLV_IncompleteType; |
| 402 | |
| 403 | if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) { |
| 404 | if (r->hasConstFields()) |
| 405 | return MLV_ConstQualified; |
| 406 | } |
| 407 | return MLV_Valid; |
| 408 | } |
| 409 | |
Chris Lattner | 4cc6271 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 410 | /// hasStaticStorage - Return true if this expression has static storage |
| 411 | /// duration. This means that the address of this expression is a link-time |
| 412 | /// constant. |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 413 | bool Expr::hasStaticStorage() const { |
| 414 | switch (getStmtClass()) { |
| 415 | default: |
| 416 | return false; |
Chris Lattner | 4cc6271 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 417 | case ParenExprClass: |
| 418 | return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage(); |
| 419 | case ImplicitCastExprClass: |
| 420 | return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage(); |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 421 | case DeclRefExprClass: { |
| 422 | const Decl *D = cast<DeclRefExpr>(this)->getDecl(); |
| 423 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 424 | return VD->hasStaticStorage(); |
| 425 | return false; |
| 426 | } |
Chris Lattner | fb70806 | 2007-11-28 04:30:09 +0000 | [diff] [blame] | 427 | case MemberExprClass: { |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 428 | const MemberExpr *M = cast<MemberExpr>(this); |
| 429 | return !M->isArrow() && M->getBase()->hasStaticStorage(); |
Chris Lattner | fb70806 | 2007-11-28 04:30:09 +0000 | [diff] [blame] | 430 | } |
Chris Lattner | 4cc6271 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 431 | case ArraySubscriptExprClass: |
| 432 | return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage(); |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 436 | bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 437 | switch (getStmtClass()) { |
| 438 | default: |
| 439 | if (Loc) *Loc = getLocStart(); |
| 440 | return false; |
| 441 | case ParenExprClass: |
| 442 | return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(Ctx, Loc); |
| 443 | case StringLiteralClass: |
Steve Naroff | 5d37e32 | 2007-11-09 15:00:03 +0000 | [diff] [blame] | 444 | case ObjCStringLiteralClass: |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 445 | case FloatingLiteralClass: |
| 446 | case IntegerLiteralClass: |
| 447 | case CharacterLiteralClass: |
| 448 | case ImaginaryLiteralClass: |
Anders Carlsson | 1a86b33 | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 449 | case TypesCompatibleExprClass: |
| 450 | case CXXBoolLiteralExprClass: |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 451 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 452 | case CallExprClass: { |
| 453 | const CallExpr *CE = cast<CallExpr>(this); |
| 454 | llvm::APSInt Result(32); |
Hartmut Kaiser | 86fd355 | 2007-09-16 21:35:35 +0000 | [diff] [blame] | 455 | Result.zextOrTrunc( |
| 456 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart()))); |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 457 | if (CE->isBuiltinClassifyType(Result)) |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 458 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 459 | if (Loc) *Loc = getLocStart(); |
| 460 | return false; |
| 461 | } |
Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 462 | case DeclRefExprClass: { |
| 463 | const Decl *D = cast<DeclRefExpr>(this)->getDecl(); |
| 464 | // Accept address of function. |
| 465 | if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D)) |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 466 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 467 | if (Loc) *Loc = getLocStart(); |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 468 | if (isa<VarDecl>(D)) |
| 469 | return TR->isArrayType(); |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 470 | return false; |
Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 471 | } |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 472 | case UnaryOperatorClass: { |
| 473 | const UnaryOperator *Exp = cast<UnaryOperator>(this); |
| 474 | |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 475 | // C99 6.6p9 |
Chris Lattner | 239c15e | 2007-12-11 23:11:17 +0000 | [diff] [blame] | 476 | if (Exp->getOpcode() == UnaryOperator::AddrOf) { |
| 477 | if (!Exp->getSubExpr()->hasStaticStorage()) { |
| 478 | if (Loc) *Loc = getLocStart(); |
| 479 | return false; |
| 480 | } |
| 481 | return true; |
| 482 | } |
Chris Lattner | 1d09ecc | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 483 | |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 484 | // Get the operand value. If this is sizeof/alignof, do not evalute the |
| 485 | // operand. This affects C99 6.6p3. |
| 486 | if (!Exp->isSizeOfAlignOfOp() && |
| 487 | !Exp->getSubExpr()->isConstantExpr(Ctx, Loc)) |
| 488 | return false; |
| 489 | |
| 490 | switch (Exp->getOpcode()) { |
| 491 | // Address, indirect, pre/post inc/dec, etc are not valid constant exprs. |
| 492 | // See C99 6.6p3. |
| 493 | default: |
| 494 | if (Loc) *Loc = Exp->getOperatorLoc(); |
| 495 | return false; |
| 496 | case UnaryOperator::Extension: |
| 497 | return true; // FIXME: this is wrong. |
| 498 | case UnaryOperator::SizeOf: |
| 499 | case UnaryOperator::AlignOf: |
| 500 | // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 501 | if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) { |
| 502 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 503 | return false; |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 504 | } |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 505 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 506 | case UnaryOperator::LNot: |
| 507 | case UnaryOperator::Plus: |
| 508 | case UnaryOperator::Minus: |
| 509 | case UnaryOperator::Not: |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 510 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 511 | } |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 512 | } |
| 513 | case SizeOfAlignOfTypeExprClass: { |
| 514 | const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); |
| 515 | // alignof always evaluates to a constant. |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 516 | if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) { |
| 517 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 518 | return false; |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 519 | } |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 520 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 521 | } |
| 522 | case BinaryOperatorClass: { |
| 523 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
| 524 | |
| 525 | // The LHS of a constant expr is always evaluated and needed. |
| 526 | if (!Exp->getLHS()->isConstantExpr(Ctx, Loc)) |
| 527 | return false; |
| 528 | |
| 529 | if (!Exp->getRHS()->isConstantExpr(Ctx, Loc)) |
| 530 | return false; |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 531 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 532 | } |
| 533 | case ImplicitCastExprClass: |
| 534 | case CastExprClass: { |
| 535 | const Expr *SubExpr; |
| 536 | SourceLocation CastLoc; |
| 537 | if (const CastExpr *C = dyn_cast<CastExpr>(this)) { |
| 538 | SubExpr = C->getSubExpr(); |
| 539 | CastLoc = C->getLParenLoc(); |
| 540 | } else { |
| 541 | SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr(); |
| 542 | CastLoc = getLocStart(); |
| 543 | } |
| 544 | if (!SubExpr->isConstantExpr(Ctx, Loc)) { |
| 545 | if (Loc) *Loc = SubExpr->getLocStart(); |
| 546 | return false; |
| 547 | } |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 548 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 549 | } |
| 550 | case ConditionalOperatorClass: { |
| 551 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 552 | if (!Exp->getCond()->isConstantExpr(Ctx, Loc) || |
Anders Carlsson | 3907323 | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 553 | // Handle the GNU extension for missing LHS. |
| 554 | !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) || |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 555 | !Exp->getRHS()->isConstantExpr(Ctx, Loc)) |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 556 | return false; |
Chris Lattner | 2777e49 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 557 | return true; |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
| 561 | return true; |
| 562 | } |
| 563 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 564 | /// isIntegerConstantExpr - this recursive routine will test if an expression is |
| 565 | /// an integer constant expression. Note: With the introduction of VLA's in |
| 566 | /// C99 the result of the sizeof operator is no longer always a constant |
| 567 | /// expression. The generalization of the wording to include any subexpression |
| 568 | /// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions |
| 569 | /// can appear as operands to other operators (e.g. &&, ||, ?:). For instance, |
| 570 | /// "0 || f()" can be treated as a constant expression. In C90 this expression, |
| 571 | /// occurring in a context requiring a constant, would have been a constraint |
| 572 | /// violation. FIXME: This routine currently implements C90 semantics. |
| 573 | /// To properly implement C99 semantics this routine will need to evaluate |
| 574 | /// expressions involving operators previously mentioned. |
| 575 | |
| 576 | /// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero, |
| 577 | /// comma, etc |
| 578 | /// |
| 579 | /// FIXME: This should ext-warn on overflow during evaluation! ISO C does not |
Chris Lattner | ccc213f | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 580 | /// permit this. This includes things like (int)1e1000 |
Chris Lattner | ce0afc0 | 2007-07-18 05:21:20 +0000 | [diff] [blame] | 581 | /// |
| 582 | /// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof |
| 583 | /// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer |
| 584 | /// cast+dereference. |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 585 | bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, |
| 586 | SourceLocation *Loc, bool isEvaluated) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 587 | switch (getStmtClass()) { |
| 588 | default: |
| 589 | if (Loc) *Loc = getLocStart(); |
| 590 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 591 | case ParenExprClass: |
| 592 | return cast<ParenExpr>(this)->getSubExpr()-> |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 593 | isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 594 | case IntegerLiteralClass: |
| 595 | Result = cast<IntegerLiteral>(this)->getValue(); |
| 596 | break; |
Chris Lattner | 2eadfb6 | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 597 | case CharacterLiteralClass: { |
| 598 | const CharacterLiteral *CL = cast<CharacterLiteral>(this); |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 599 | Result.zextOrTrunc( |
| 600 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CL->getLoc()))); |
Chris Lattner | 2eadfb6 | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 601 | Result = CL->getValue(); |
Chris Lattner | f0fbcb3 | 2007-07-16 21:04:56 +0000 | [diff] [blame] | 602 | Result.setIsUnsigned(!getType()->isSignedIntegerType()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 603 | break; |
Chris Lattner | 2eadfb6 | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 604 | } |
Steve Naroff | 7b658aa | 2007-08-02 04:09:23 +0000 | [diff] [blame] | 605 | case TypesCompatibleExprClass: { |
| 606 | const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this); |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 607 | Result.zextOrTrunc( |
| 608 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), TCE->getLocStart()))); |
Steve Naroff | ec0550f | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 609 | Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2()); |
Steve Naroff | 389cecc | 2007-08-02 00:13:27 +0000 | [diff] [blame] | 610 | break; |
Steve Naroff | 7b658aa | 2007-08-02 04:09:23 +0000 | [diff] [blame] | 611 | } |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 612 | case CallExprClass: { |
| 613 | const CallExpr *CE = cast<CallExpr>(this); |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 614 | Result.zextOrTrunc( |
| 615 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart()))); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 616 | if (CE->isBuiltinClassifyType(Result)) |
| 617 | break; |
| 618 | if (Loc) *Loc = getLocStart(); |
| 619 | return false; |
| 620 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 621 | case DeclRefExprClass: |
| 622 | if (const EnumConstantDecl *D = |
| 623 | dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) { |
| 624 | Result = D->getInitVal(); |
| 625 | break; |
| 626 | } |
| 627 | if (Loc) *Loc = getLocStart(); |
| 628 | return false; |
| 629 | case UnaryOperatorClass: { |
| 630 | const UnaryOperator *Exp = cast<UnaryOperator>(this); |
| 631 | |
| 632 | // Get the operand value. If this is sizeof/alignof, do not evalute the |
| 633 | // operand. This affects C99 6.6p3. |
Chris Lattner | 602dafd | 2007-08-23 21:42:50 +0000 | [diff] [blame] | 634 | if (!Exp->isSizeOfAlignOfOp() && |
| 635 | !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 636 | return false; |
| 637 | |
| 638 | switch (Exp->getOpcode()) { |
| 639 | // Address, indirect, pre/post inc/dec, etc are not valid constant exprs. |
| 640 | // See C99 6.6p3. |
| 641 | default: |
| 642 | if (Loc) *Loc = Exp->getOperatorLoc(); |
| 643 | return false; |
| 644 | case UnaryOperator::Extension: |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 645 | return true; // FIXME: this is wrong. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 646 | case UnaryOperator::SizeOf: |
| 647 | case UnaryOperator::AlignOf: |
| 648 | // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 649 | if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) { |
| 650 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 651 | return false; |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 652 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 653 | |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 654 | // Return the result in the right width. |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 655 | Result.zextOrTrunc( |
Chris Lattner | ccc213f | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 656 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), |
| 657 | Exp->getOperatorLoc()))); |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 658 | |
| 659 | // Get information about the size or align. |
Chris Lattner | da5a6b6 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 660 | if (Exp->getOpcode() == UnaryOperator::AlignOf) { |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 661 | Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(), |
| 662 | Exp->getOperatorLoc()); |
Chris Lattner | da5a6b6 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 663 | } else { |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 664 | unsigned CharSize = |
| 665 | Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc())); |
| 666 | |
Chris Lattner | da5a6b6 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 667 | Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(), |
| 668 | Exp->getOperatorLoc()) / CharSize; |
| 669 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 670 | break; |
| 671 | case UnaryOperator::LNot: { |
| 672 | bool Val = Result != 0; |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 673 | Result.zextOrTrunc( |
Chris Lattner | ccc213f | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 674 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), |
| 675 | Exp->getOperatorLoc()))); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 676 | Result = Val; |
| 677 | break; |
| 678 | } |
| 679 | case UnaryOperator::Plus: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 680 | break; |
| 681 | case UnaryOperator::Minus: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 682 | Result = -Result; |
| 683 | break; |
| 684 | case UnaryOperator::Not: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 685 | Result = ~Result; |
| 686 | break; |
| 687 | } |
| 688 | break; |
| 689 | } |
| 690 | case SizeOfAlignOfTypeExprClass: { |
| 691 | const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); |
| 692 | // alignof always evaluates to a constant. |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 693 | if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) { |
| 694 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 695 | return false; |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 696 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 697 | |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 698 | // Return the result in the right width. |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 699 | Result.zextOrTrunc( |
| 700 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()))); |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 701 | |
| 702 | // Get information about the size or align. |
Ted Kremenek | 060e470 | 2007-12-17 17:38:43 +0000 | [diff] [blame] | 703 | if (Exp->isSizeOf()) { |
| 704 | unsigned CharSize = |
| 705 | Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc())); |
| 706 | |
| 707 | Result = Ctx.getTypeSize(Exp->getArgumentType(), |
| 708 | Exp->getOperatorLoc()) / CharSize; |
| 709 | } |
Chris Lattner | 76e773a | 2007-07-18 18:38:36 +0000 | [diff] [blame] | 710 | else |
| 711 | Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc()); |
Ted Kremenek | 060e470 | 2007-12-17 17:38:43 +0000 | [diff] [blame] | 712 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 713 | break; |
| 714 | } |
| 715 | case BinaryOperatorClass: { |
| 716 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
| 717 | |
| 718 | // The LHS of a constant expr is always evaluated and needed. |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 719 | if (!Exp->getLHS()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 720 | return false; |
| 721 | |
| 722 | llvm::APSInt RHS(Result); |
| 723 | |
| 724 | // The short-circuiting &&/|| operators don't necessarily evaluate their |
| 725 | // RHS. Make sure to pass isEvaluated down correctly. |
| 726 | if (Exp->isLogicalOp()) { |
| 727 | bool RHSEval; |
| 728 | if (Exp->getOpcode() == BinaryOperator::LAnd) |
| 729 | RHSEval = Result != 0; |
| 730 | else { |
| 731 | assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical"); |
| 732 | RHSEval = Result == 0; |
| 733 | } |
| 734 | |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 735 | if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 736 | isEvaluated & RHSEval)) |
| 737 | return false; |
| 738 | } else { |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 739 | if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 740 | return false; |
| 741 | } |
| 742 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 743 | switch (Exp->getOpcode()) { |
| 744 | default: |
| 745 | if (Loc) *Loc = getLocStart(); |
| 746 | return false; |
| 747 | case BinaryOperator::Mul: |
| 748 | Result *= RHS; |
| 749 | break; |
| 750 | case BinaryOperator::Div: |
| 751 | if (RHS == 0) { |
| 752 | if (!isEvaluated) break; |
| 753 | if (Loc) *Loc = getLocStart(); |
| 754 | return false; |
| 755 | } |
| 756 | Result /= RHS; |
| 757 | break; |
| 758 | case BinaryOperator::Rem: |
| 759 | if (RHS == 0) { |
| 760 | if (!isEvaluated) break; |
| 761 | if (Loc) *Loc = getLocStart(); |
| 762 | return false; |
| 763 | } |
| 764 | Result %= RHS; |
| 765 | break; |
| 766 | case BinaryOperator::Add: Result += RHS; break; |
| 767 | case BinaryOperator::Sub: Result -= RHS; break; |
| 768 | case BinaryOperator::Shl: |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 769 | Result <<= |
| 770 | static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 771 | break; |
| 772 | case BinaryOperator::Shr: |
Chris Lattner | 701e5eb | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 773 | Result >>= |
| 774 | static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 775 | break; |
| 776 | case BinaryOperator::LT: Result = Result < RHS; break; |
| 777 | case BinaryOperator::GT: Result = Result > RHS; break; |
| 778 | case BinaryOperator::LE: Result = Result <= RHS; break; |
| 779 | case BinaryOperator::GE: Result = Result >= RHS; break; |
| 780 | case BinaryOperator::EQ: Result = Result == RHS; break; |
| 781 | case BinaryOperator::NE: Result = Result != RHS; break; |
| 782 | case BinaryOperator::And: Result &= RHS; break; |
| 783 | case BinaryOperator::Xor: Result ^= RHS; break; |
| 784 | case BinaryOperator::Or: Result |= RHS; break; |
| 785 | case BinaryOperator::LAnd: |
| 786 | Result = Result != 0 && RHS != 0; |
| 787 | break; |
| 788 | case BinaryOperator::LOr: |
| 789 | Result = Result != 0 || RHS != 0; |
| 790 | break; |
| 791 | |
| 792 | case BinaryOperator::Comma: |
| 793 | // C99 6.6p3: "shall not contain assignment, ..., or comma operators, |
| 794 | // *except* when they are contained within a subexpression that is not |
| 795 | // evaluated". Note that Assignment can never happen due to constraints |
| 796 | // on the LHS subexpr, so we don't need to check it here. |
| 797 | if (isEvaluated) { |
| 798 | if (Loc) *Loc = getLocStart(); |
| 799 | return false; |
| 800 | } |
| 801 | |
| 802 | // The result of the constant expr is the RHS. |
| 803 | Result = RHS; |
| 804 | return true; |
| 805 | } |
| 806 | |
| 807 | assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!"); |
| 808 | break; |
| 809 | } |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 810 | case ImplicitCastExprClass: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 811 | case CastExprClass: { |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 812 | const Expr *SubExpr; |
| 813 | SourceLocation CastLoc; |
| 814 | if (const CastExpr *C = dyn_cast<CastExpr>(this)) { |
| 815 | SubExpr = C->getSubExpr(); |
| 816 | CastLoc = C->getLParenLoc(); |
| 817 | } else { |
| 818 | SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr(); |
| 819 | CastLoc = getLocStart(); |
| 820 | } |
| 821 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 822 | // C99 6.6p6: shall only convert arithmetic types to integer types. |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 823 | if (!SubExpr->getType()->isArithmeticType() || |
| 824 | !getType()->isIntegerType()) { |
| 825 | if (Loc) *Loc = SubExpr->getLocStart(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 826 | return false; |
| 827 | } |
Chris Lattner | 987b15d | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 828 | |
| 829 | uint32_t DestWidth = |
| 830 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CastLoc)); |
| 831 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 832 | // Handle simple integer->integer casts. |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 833 | if (SubExpr->getType()->isIntegerType()) { |
| 834 | if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 835 | return false; |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 836 | |
| 837 | // Figure out if this is a truncate, extend or noop cast. |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 838 | // If the input is signed, do a sign extend, noop, or truncate. |
| 839 | if (SubExpr->getType()->isSignedIntegerType()) |
| 840 | Result.sextOrTrunc(DestWidth); |
| 841 | else // If the input is unsigned, do a zero extend, noop, or truncate. |
| 842 | Result.zextOrTrunc(DestWidth); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 843 | break; |
| 844 | } |
| 845 | |
| 846 | // Allow floating constants that are the immediate operands of casts or that |
| 847 | // are parenthesized. |
Chris Lattner | 26dc7b3 | 2007-07-15 23:54:50 +0000 | [diff] [blame] | 848 | const Expr *Operand = SubExpr; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 849 | while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand)) |
| 850 | Operand = PE->getSubExpr(); |
Chris Lattner | 987b15d | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 851 | |
| 852 | // If this isn't a floating literal, we can't handle it. |
| 853 | const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand); |
| 854 | if (!FL) { |
| 855 | if (Loc) *Loc = Operand->getLocStart(); |
| 856 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 857 | } |
Chris Lattner | 987b15d | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 858 | |
| 859 | // Determine whether we are converting to unsigned or signed. |
| 860 | bool DestSigned = getType()->isSignedIntegerType(); |
Chris Lattner | ccc213f | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 861 | |
| 862 | // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can |
| 863 | // be called multiple times per AST. |
Chris Lattner | 987b15d | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 864 | uint64_t Space[4]; |
Chris Lattner | ccc213f | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 865 | (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned, |
| 866 | llvm::APFloat::rmTowardZero); |
Chris Lattner | 987b15d | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 867 | Result = llvm::APInt(DestWidth, 4, Space); |
| 868 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 869 | } |
| 870 | case ConditionalOperatorClass: { |
| 871 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
| 872 | |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 873 | if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 874 | return false; |
| 875 | |
| 876 | const Expr *TrueExp = Exp->getLHS(); |
| 877 | const Expr *FalseExp = Exp->getRHS(); |
| 878 | if (Result == 0) std::swap(TrueExp, FalseExp); |
| 879 | |
| 880 | // Evaluate the false one first, discard the result. |
Anders Carlsson | 3907323 | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 881 | if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 882 | return false; |
| 883 | // Evalute the true one, capture the result. |
Anders Carlsson | 3907323 | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 884 | if (TrueExp && |
| 885 | !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 886 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 887 | break; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | // Cases that are valid constant exprs fall through to here. |
| 892 | Result.setIsUnsigned(getType()->isUnsignedIntegerType()); |
| 893 | return true; |
| 894 | } |
| 895 | |
| 896 | |
| 897 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an |
| 898 | /// integer constant expression with the value zero, or if this is one that is |
| 899 | /// cast to void*. |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 900 | bool Expr::isNullPointerConstant(ASTContext &Ctx) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 901 | // Strip off a cast to void*, if it exists. |
| 902 | if (const CastExpr *CE = dyn_cast<CastExpr>(this)) { |
| 903 | // Check that it is a cast to void*. |
| 904 | if (const PointerType *PT = dyn_cast<PointerType>(CE->getType())) { |
| 905 | QualType Pointee = PT->getPointeeType(); |
| 906 | if (Pointee.getQualifiers() == 0 && Pointee->isVoidType() && // to void* |
| 907 | CE->getSubExpr()->getType()->isIntegerType()) // from int. |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 908 | return CE->getSubExpr()->isNullPointerConstant(Ctx); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 909 | } |
Steve Naroff | 7269f2d | 2007-08-28 21:20:34 +0000 | [diff] [blame] | 910 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { |
Steve Naroff | 19a6ebd | 2007-08-29 00:00:02 +0000 | [diff] [blame] | 911 | // Ignore the ImplicitCastExpr type entirely. |
| 912 | return ICE->getSubExpr()->isNullPointerConstant(Ctx); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 913 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { |
| 914 | // Accept ((void*)0) as a null pointer constant, as many other |
| 915 | // implementations do. |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 916 | return PE->getSubExpr()->isNullPointerConstant(Ctx); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | // This expression must be an integer type. |
| 920 | if (!getType()->isIntegerType()) |
| 921 | return false; |
| 922 | |
| 923 | // If we have an integer constant expression, we need to *evaluate* it and |
| 924 | // test for the value 0. |
| 925 | llvm::APSInt Val(32); |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 926 | return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 927 | } |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 928 | |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 929 | unsigned OCUVectorElementExpr::getNumElements() const { |
Chris Lattner | 4d0ac88 | 2007-08-03 16:00:20 +0000 | [diff] [blame] | 930 | return strlen(Accessor.getName()); |
| 931 | } |
| 932 | |
| 933 | |
Chris Lattner | cb92a11 | 2007-08-02 21:47:28 +0000 | [diff] [blame] | 934 | /// getComponentType - Determine whether the components of this access are |
| 935 | /// "point" "color" or "texture" elements. |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 936 | OCUVectorElementExpr::ElementType |
| 937 | OCUVectorElementExpr::getElementType() const { |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 938 | // derive the component type, no need to waste space. |
| 939 | const char *compStr = Accessor.getName(); |
Chris Lattner | b4878f4 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 940 | |
Chris Lattner | 88dca04 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 941 | if (OCUVectorType::getPointAccessorIdx(*compStr) != -1) return Point; |
| 942 | if (OCUVectorType::getColorAccessorIdx(*compStr) != -1) return Color; |
Chris Lattner | b4878f4 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 943 | |
Chris Lattner | 88dca04 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 944 | assert(OCUVectorType::getTextureAccessorIdx(*compStr) != -1 && |
Chris Lattner | b4878f4 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 945 | "getComponentType(): Illegal accessor"); |
| 946 | return Texture; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 947 | } |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 948 | |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 949 | /// containsDuplicateElements - Return true if any element access is |
Chris Lattner | cb92a11 | 2007-08-02 21:47:28 +0000 | [diff] [blame] | 950 | /// repeated. |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 951 | bool OCUVectorElementExpr::containsDuplicateElements() const { |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 952 | const char *compStr = Accessor.getName(); |
| 953 | unsigned length = strlen(compStr); |
| 954 | |
| 955 | for (unsigned i = 0; i < length-1; i++) { |
| 956 | const char *s = compStr+i; |
| 957 | for (const char c = *s++; *s; s++) |
| 958 | if (c == *s) |
| 959 | return true; |
| 960 | } |
| 961 | return false; |
| 962 | } |
Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 963 | |
| 964 | /// getEncodedElementAccess - We encode fields with two bits per component. |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 965 | unsigned OCUVectorElementExpr::getEncodedElementAccess() const { |
Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 966 | const char *compStr = Accessor.getName(); |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 967 | unsigned length = getNumElements(); |
Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 968 | |
| 969 | unsigned Result = 0; |
| 970 | |
| 971 | while (length--) { |
| 972 | Result <<= 2; |
| 973 | int Idx = OCUVectorType::getAccessorIdx(compStr[length]); |
| 974 | assert(Idx != -1 && "Invalid accessor letter"); |
| 975 | Result |= Idx; |
| 976 | } |
| 977 | return Result; |
| 978 | } |
| 979 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 980 | // constructor for instance messages. |
Steve Naroff | bcfb06a | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 981 | ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo, |
Steve Naroff | db611d5 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 982 | QualType retType, ObjcMethodDecl *mproto, |
| 983 | SourceLocation LBrac, SourceLocation RBrac, |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 984 | Expr **ArgExprs, unsigned nargs) |
Steve Naroff | db611d5 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 985 | : Expr(ObjCMessageExprClass, retType), SelName(selInfo), |
| 986 | MethodProto(mproto), ClassName(0) { |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 987 | NumArgs = nargs; |
| 988 | SubExprs = new Expr*[NumArgs+1]; |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 989 | SubExprs[RECEIVER] = receiver; |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 990 | if (NumArgs) { |
| 991 | for (unsigned i = 0; i != NumArgs; ++i) |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 992 | SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); |
| 993 | } |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 994 | LBracloc = LBrac; |
| 995 | RBracloc = RBrac; |
| 996 | } |
| 997 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 998 | // constructor for class messages. |
| 999 | // FIXME: clsName should be typed to ObjCInterfaceType |
Steve Naroff | bcfb06a | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 1000 | ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, |
Steve Naroff | db611d5 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 1001 | QualType retType, ObjcMethodDecl *mproto, |
| 1002 | SourceLocation LBrac, SourceLocation RBrac, |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1003 | Expr **ArgExprs, unsigned nargs) |
Steve Naroff | db611d5 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 1004 | : Expr(ObjCMessageExprClass, retType), SelName(selInfo), |
| 1005 | MethodProto(mproto), ClassName(clsName) { |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1006 | NumArgs = nargs; |
| 1007 | SubExprs = new Expr*[NumArgs+1]; |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1008 | SubExprs[RECEIVER] = 0; |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1009 | if (NumArgs) { |
| 1010 | for (unsigned i = 0; i != NumArgs; ++i) |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1011 | SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); |
| 1012 | } |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1013 | LBracloc = LBrac; |
| 1014 | RBracloc = RBrac; |
| 1015 | } |
| 1016 | |
Chris Lattner | 27437ca | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 1017 | |
| 1018 | bool ChooseExpr::isConditionTrue(ASTContext &C) const { |
| 1019 | llvm::APSInt CondVal(32); |
| 1020 | bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C); |
| 1021 | assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst; |
| 1022 | return CondVal != 0; |
| 1023 | } |
| 1024 | |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1025 | //===----------------------------------------------------------------------===// |
| 1026 | // Child Iterators for iterating over subexpressions/substatements |
| 1027 | //===----------------------------------------------------------------------===// |
| 1028 | |
| 1029 | // DeclRefExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1030 | Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } |
| 1031 | Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1032 | |
Steve Naroff | 7779db4 | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 1033 | // ObjCIvarRefExpr |
| 1034 | Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return child_iterator(); } |
| 1035 | Stmt::child_iterator ObjCIvarRefExpr::child_end() { return child_iterator(); } |
| 1036 | |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1037 | // PreDefinedExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1038 | Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); } |
| 1039 | Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1040 | |
| 1041 | // IntegerLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1042 | Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } |
| 1043 | Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1044 | |
| 1045 | // CharacterLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1046 | Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); } |
| 1047 | Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1048 | |
| 1049 | // FloatingLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1050 | Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } |
| 1051 | Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1052 | |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1053 | // ImaginaryLiteral |
| 1054 | Stmt::child_iterator ImaginaryLiteral::child_begin() { |
| 1055 | return reinterpret_cast<Stmt**>(&Val); |
| 1056 | } |
| 1057 | Stmt::child_iterator ImaginaryLiteral::child_end() { |
| 1058 | return reinterpret_cast<Stmt**>(&Val)+1; |
| 1059 | } |
| 1060 | |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1061 | // StringLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1062 | Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } |
| 1063 | Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1064 | |
| 1065 | // ParenExpr |
| 1066 | Stmt::child_iterator ParenExpr::child_begin() { |
| 1067 | return reinterpret_cast<Stmt**>(&Val); |
| 1068 | } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1069 | Stmt::child_iterator ParenExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1070 | return reinterpret_cast<Stmt**>(&Val)+1; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | // UnaryOperator |
| 1074 | Stmt::child_iterator UnaryOperator::child_begin() { |
Ted Kremenek | f816f77 | 2007-12-15 00:39:18 +0000 | [diff] [blame] | 1075 | return reinterpret_cast<Stmt**>(&Val); |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1076 | } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1077 | Stmt::child_iterator UnaryOperator::child_end() { |
Ted Kremenek | f816f77 | 2007-12-15 00:39:18 +0000 | [diff] [blame] | 1078 | return reinterpret_cast<Stmt**>(&Val+1); |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | // SizeOfAlignOfTypeExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1082 | Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() { |
Ted Kremenek | 699e9fb | 2007-12-14 22:52:23 +0000 | [diff] [blame] | 1083 | // If the type is a VLA type (and not a typedef), the size expression of the |
| 1084 | // VLA needs to be treated as an executable expression. |
| 1085 | if (VariableArrayType* T = dyn_cast<VariableArrayType>(Ty.getTypePtr())) |
| 1086 | return child_iterator(T); |
| 1087 | else |
| 1088 | return child_iterator(); |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1089 | } |
| 1090 | Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() { |
Ted Kremenek | 699e9fb | 2007-12-14 22:52:23 +0000 | [diff] [blame] | 1091 | return child_iterator(); |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1092 | } |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1093 | |
| 1094 | // ArraySubscriptExpr |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1095 | Stmt::child_iterator ArraySubscriptExpr::child_begin() { |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1096 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1097 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1098 | Stmt::child_iterator ArraySubscriptExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1099 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | // CallExpr |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1103 | Stmt::child_iterator CallExpr::child_begin() { |
Ted Kremenek | 42a2977 | 2007-08-27 21:11:44 +0000 | [diff] [blame] | 1104 | return reinterpret_cast<Stmt**>(&SubExprs[0]); |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1105 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1106 | Stmt::child_iterator CallExpr::child_end() { |
Ted Kremenek | 42a2977 | 2007-08-27 21:11:44 +0000 | [diff] [blame] | 1107 | return reinterpret_cast<Stmt**>(&SubExprs[NumArgs+ARGS_START]); |
Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1108 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1109 | |
| 1110 | // MemberExpr |
| 1111 | Stmt::child_iterator MemberExpr::child_begin() { |
| 1112 | return reinterpret_cast<Stmt**>(&Base); |
| 1113 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1114 | Stmt::child_iterator MemberExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1115 | return reinterpret_cast<Stmt**>(&Base)+1; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | // OCUVectorElementExpr |
| 1119 | Stmt::child_iterator OCUVectorElementExpr::child_begin() { |
| 1120 | return reinterpret_cast<Stmt**>(&Base); |
| 1121 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1122 | Stmt::child_iterator OCUVectorElementExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1123 | return reinterpret_cast<Stmt**>(&Base)+1; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | // CompoundLiteralExpr |
| 1127 | Stmt::child_iterator CompoundLiteralExpr::child_begin() { |
| 1128 | return reinterpret_cast<Stmt**>(&Init); |
| 1129 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1130 | Stmt::child_iterator CompoundLiteralExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1131 | return reinterpret_cast<Stmt**>(&Init)+1; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | // ImplicitCastExpr |
| 1135 | Stmt::child_iterator ImplicitCastExpr::child_begin() { |
| 1136 | return reinterpret_cast<Stmt**>(&Op); |
| 1137 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1138 | Stmt::child_iterator ImplicitCastExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1139 | return reinterpret_cast<Stmt**>(&Op)+1; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | // CastExpr |
| 1143 | Stmt::child_iterator CastExpr::child_begin() { |
| 1144 | return reinterpret_cast<Stmt**>(&Op); |
| 1145 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1146 | Stmt::child_iterator CastExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1147 | return reinterpret_cast<Stmt**>(&Op)+1; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | // BinaryOperator |
| 1151 | Stmt::child_iterator BinaryOperator::child_begin() { |
| 1152 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1153 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1154 | Stmt::child_iterator BinaryOperator::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1155 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | // ConditionalOperator |
| 1159 | Stmt::child_iterator ConditionalOperator::child_begin() { |
| 1160 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1161 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1162 | Stmt::child_iterator ConditionalOperator::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1163 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | // AddrLabelExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1167 | Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } |
| 1168 | Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1169 | |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1170 | // StmtExpr |
| 1171 | Stmt::child_iterator StmtExpr::child_begin() { |
| 1172 | return reinterpret_cast<Stmt**>(&SubStmt); |
| 1173 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1174 | Stmt::child_iterator StmtExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1175 | return reinterpret_cast<Stmt**>(&SubStmt)+1; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | // TypesCompatibleExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1179 | Stmt::child_iterator TypesCompatibleExpr::child_begin() { |
| 1180 | return child_iterator(); |
| 1181 | } |
| 1182 | |
| 1183 | Stmt::child_iterator TypesCompatibleExpr::child_end() { |
| 1184 | return child_iterator(); |
| 1185 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1186 | |
| 1187 | // ChooseExpr |
| 1188 | Stmt::child_iterator ChooseExpr::child_begin() { |
| 1189 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1190 | } |
| 1191 | |
| 1192 | Stmt::child_iterator ChooseExpr::child_end() { |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1193 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1196 | // VAArgExpr |
| 1197 | Stmt::child_iterator VAArgExpr::child_begin() { |
| 1198 | return reinterpret_cast<Stmt**>(&Val); |
| 1199 | } |
| 1200 | |
| 1201 | Stmt::child_iterator VAArgExpr::child_end() { |
| 1202 | return reinterpret_cast<Stmt**>(&Val)+1; |
| 1203 | } |
| 1204 | |
Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 1205 | // InitListExpr |
| 1206 | Stmt::child_iterator InitListExpr::child_begin() { |
| 1207 | return reinterpret_cast<Stmt**>(&InitExprs[0]); |
| 1208 | } |
| 1209 | Stmt::child_iterator InitListExpr::child_end() { |
| 1210 | return reinterpret_cast<Stmt**>(&InitExprs[NumInits]); |
| 1211 | } |
| 1212 | |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1213 | // ObjCStringLiteral |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1214 | Stmt::child_iterator ObjCStringLiteral::child_begin() { |
| 1215 | return child_iterator(); |
| 1216 | } |
| 1217 | Stmt::child_iterator ObjCStringLiteral::child_end() { |
| 1218 | return child_iterator(); |
| 1219 | } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1220 | |
| 1221 | // ObjCEncodeExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1222 | Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } |
| 1223 | Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 1237c67 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1224 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1225 | // ObjCSelectorExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1226 | Stmt::child_iterator ObjCSelectorExpr::child_begin() { |
| 1227 | return child_iterator(); |
| 1228 | } |
| 1229 | Stmt::child_iterator ObjCSelectorExpr::child_end() { |
| 1230 | return child_iterator(); |
| 1231 | } |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1232 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1233 | // ObjCProtocolExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1234 | Stmt::child_iterator ObjCProtocolExpr::child_begin() { |
| 1235 | return child_iterator(); |
| 1236 | } |
| 1237 | Stmt::child_iterator ObjCProtocolExpr::child_end() { |
| 1238 | return child_iterator(); |
| 1239 | } |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1240 | |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1241 | // ObjCMessageExpr |
| 1242 | Stmt::child_iterator ObjCMessageExpr::child_begin() { |
| 1243 | return reinterpret_cast<Stmt**>(&SubExprs[0]); |
| 1244 | } |
| 1245 | Stmt::child_iterator ObjCMessageExpr::child_end() { |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1246 | return reinterpret_cast<Stmt**>(&SubExprs[getNumArgs()+ARGS_START]); |
Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |