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