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 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 360 | if (TR->isReferenceType()) // C++ [expr] |
| 361 | return LV_Valid; |
| 362 | |
| 363 | // the type looks fine, now check the expression |
| 364 | switch (getStmtClass()) { |
| 365 | case StringLiteralClass: // C99 6.5.1p4 |
Anders Carlsson | 9e933a2 | 2007-11-30 22:47:59 +0000 | [diff] [blame] | 366 | return LV_Valid; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 367 | case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) |
| 368 | // For vectors, make sure base is an lvalue (i.e. not a function call). |
| 369 | if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType()) |
| 370 | return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(); |
| 371 | return LV_Valid; |
| 372 | case DeclRefExprClass: // C99 6.5.1p2 |
| 373 | if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl())) |
| 374 | return LV_Valid; |
| 375 | break; |
| 376 | case MemberExprClass: { // C99 6.5.2.3p4 |
| 377 | const MemberExpr *m = cast<MemberExpr>(this); |
| 378 | return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(); |
| 379 | } |
Chris Lattner | 5bf7202 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 380 | case UnaryOperatorClass: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 381 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref) |
Chris Lattner | 5bf7202 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 382 | return LV_Valid; // C99 6.5.3p4 |
| 383 | |
| 384 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real || |
| 385 | cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag) |
| 386 | return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(); // GNU. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 387 | break; |
| 388 | case ParenExprClass: // C99 6.5.1p5 |
| 389 | return cast<ParenExpr>(this)->getSubExpr()->isLvalue(); |
Steve Naroff | c7c6653 | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 390 | case CompoundLiteralExprClass: // C99 6.5.2.5p5 |
| 391 | return LV_Valid; |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 392 | case OCUVectorElementExprClass: |
| 393 | if (cast<OCUVectorElementExpr>(this)->containsDuplicateElements()) |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 394 | return LV_DuplicateVectorComponents; |
| 395 | return LV_Valid; |
Steve Naroff | 46f18f2 | 2007-11-12 14:34:27 +0000 | [diff] [blame] | 396 | case ObjCIvarRefExprClass: // ObjC instance variables are lvalues. |
| 397 | return LV_Valid; |
Chris Lattner | 7e63751 | 2008-01-12 08:14:25 +0000 | [diff] [blame] | 398 | case PreDefinedExprClass: |
| 399 | return LV_Valid; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 400 | default: |
| 401 | break; |
| 402 | } |
| 403 | return LV_InvalidExpression; |
| 404 | } |
| 405 | |
| 406 | /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, |
| 407 | /// does not have an incomplete type, does not have a const-qualified type, and |
| 408 | /// if it is a structure or union, does not have any member (including, |
| 409 | /// recursively, any member or element of all contained aggregates or unions) |
| 410 | /// with a const-qualified type. |
| 411 | Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { |
| 412 | isLvalueResult lvalResult = isLvalue(); |
| 413 | |
| 414 | switch (lvalResult) { |
| 415 | case LV_Valid: break; |
| 416 | case LV_NotObjectType: return MLV_NotObjectType; |
| 417 | case LV_IncompleteVoidType: return MLV_IncompleteVoidType; |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 418 | case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 419 | case LV_InvalidExpression: return MLV_InvalidExpression; |
| 420 | } |
| 421 | if (TR.isConstQualified()) |
| 422 | return MLV_ConstQualified; |
| 423 | if (TR->isArrayType()) |
| 424 | return MLV_ArrayType; |
| 425 | if (TR->isIncompleteType()) |
| 426 | return MLV_IncompleteType; |
| 427 | |
| 428 | if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) { |
| 429 | if (r->hasConstFields()) |
| 430 | return MLV_ConstQualified; |
| 431 | } |
| 432 | return MLV_Valid; |
| 433 | } |
| 434 | |
Chris Lattner | 743ec37 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 435 | /// hasStaticStorage - Return true if this expression has static storage |
| 436 | /// duration. This means that the address of this expression is a link-time |
| 437 | /// constant. |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 438 | bool Expr::hasStaticStorage() const { |
| 439 | switch (getStmtClass()) { |
| 440 | default: |
| 441 | return false; |
Chris Lattner | 743ec37 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 442 | case ParenExprClass: |
| 443 | return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage(); |
| 444 | case ImplicitCastExprClass: |
| 445 | return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage(); |
Steve Naroff | be37fc0 | 2008-01-14 18:19:28 +0000 | [diff] [blame] | 446 | case CompoundLiteralExprClass: |
| 447 | return cast<CompoundLiteralExpr>(this)->isFileScope(); |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 448 | case DeclRefExprClass: { |
| 449 | const Decl *D = cast<DeclRefExpr>(this)->getDecl(); |
| 450 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 451 | return VD->hasStaticStorage(); |
| 452 | return false; |
| 453 | } |
Chris Lattner | db586bf | 2007-11-28 04:30:09 +0000 | [diff] [blame] | 454 | case MemberExprClass: { |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 455 | const MemberExpr *M = cast<MemberExpr>(this); |
| 456 | return !M->isArrow() && M->getBase()->hasStaticStorage(); |
Chris Lattner | db586bf | 2007-11-28 04:30:09 +0000 | [diff] [blame] | 457 | } |
Chris Lattner | 743ec37 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 458 | case ArraySubscriptExprClass: |
| 459 | return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage(); |
Chris Lattner | 7e63751 | 2008-01-12 08:14:25 +0000 | [diff] [blame] | 460 | case PreDefinedExprClass: |
| 461 | return true; |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Ted Kremenek | 87e30c5 | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 465 | Expr* Expr::IgnoreParens() { |
| 466 | Expr* E = this; |
| 467 | while (ParenExpr* P = dyn_cast<ParenExpr>(E)) |
| 468 | E = P->getSubExpr(); |
| 469 | |
| 470 | return E; |
| 471 | } |
| 472 | |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 473 | bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 474 | switch (getStmtClass()) { |
| 475 | default: |
| 476 | if (Loc) *Loc = getLocStart(); |
| 477 | return false; |
| 478 | case ParenExprClass: |
| 479 | return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(Ctx, Loc); |
| 480 | case StringLiteralClass: |
Steve Naroff | 4fdea13 | 2007-11-09 15:00:03 +0000 | [diff] [blame] | 481 | case ObjCStringLiteralClass: |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 482 | case FloatingLiteralClass: |
| 483 | case IntegerLiteralClass: |
| 484 | case CharacterLiteralClass: |
| 485 | case ImaginaryLiteralClass: |
Anders Carlsson | 855d78d | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 486 | case TypesCompatibleExprClass: |
| 487 | case CXXBoolLiteralExprClass: |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 488 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 489 | case CallExprClass: { |
| 490 | const CallExpr *CE = cast<CallExpr>(this); |
| 491 | llvm::APSInt Result(32); |
Hartmut Kaiser | 38af701 | 2007-09-16 21:35:35 +0000 | [diff] [blame] | 492 | Result.zextOrTrunc( |
| 493 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart()))); |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 494 | if (CE->isBuiltinClassifyType(Result)) |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 495 | return true; |
Steve Naroff | 44aec4c | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 496 | if (CE->isBuiltinConstantExpr()) |
| 497 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 498 | if (Loc) *Loc = getLocStart(); |
| 499 | return false; |
| 500 | } |
Chris Lattner | 42e86b6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 501 | case DeclRefExprClass: { |
| 502 | const Decl *D = cast<DeclRefExpr>(this)->getDecl(); |
| 503 | // Accept address of function. |
| 504 | if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D)) |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 505 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 506 | if (Loc) *Loc = getLocStart(); |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 507 | if (isa<VarDecl>(D)) |
| 508 | return TR->isArrayType(); |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 509 | return false; |
Chris Lattner | 42e86b6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 510 | } |
Steve Naroff | f91f972 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 511 | case CompoundLiteralExprClass: |
| 512 | if (Loc) *Loc = getLocStart(); |
| 513 | // 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] | 514 | // Allow "(vector type){2,4}" since the elements are all constant. |
| 515 | return TR->isArrayType() || TR->isVectorType(); |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 516 | case UnaryOperatorClass: { |
| 517 | const UnaryOperator *Exp = cast<UnaryOperator>(this); |
| 518 | |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 519 | // C99 6.6p9 |
Chris Lattner | 35b662f | 2007-12-11 23:11:17 +0000 | [diff] [blame] | 520 | if (Exp->getOpcode() == UnaryOperator::AddrOf) { |
| 521 | if (!Exp->getSubExpr()->hasStaticStorage()) { |
| 522 | if (Loc) *Loc = getLocStart(); |
| 523 | return false; |
| 524 | } |
| 525 | return true; |
| 526 | } |
Chris Lattner | ba3ddb2 | 2007-11-13 18:05:45 +0000 | [diff] [blame] | 527 | |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 528 | // Get the operand value. If this is sizeof/alignof, do not evalute the |
| 529 | // operand. This affects C99 6.6p3. |
Steve Naroff | f0b2354 | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 530 | if (!Exp->isSizeOfAlignOfOp() && |
| 531 | Exp->getOpcode() != UnaryOperator::OffsetOf && |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 532 | !Exp->getSubExpr()->isConstantExpr(Ctx, Loc)) |
| 533 | return false; |
| 534 | |
| 535 | switch (Exp->getOpcode()) { |
| 536 | // Address, indirect, pre/post inc/dec, etc are not valid constant exprs. |
| 537 | // See C99 6.6p3. |
| 538 | default: |
| 539 | if (Loc) *Loc = Exp->getOperatorLoc(); |
| 540 | return false; |
| 541 | case UnaryOperator::Extension: |
| 542 | return true; // FIXME: this is wrong. |
| 543 | case UnaryOperator::SizeOf: |
| 544 | case UnaryOperator::AlignOf: |
Steve Naroff | f0b2354 | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 545 | case UnaryOperator::OffsetOf: |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 546 | // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 547 | if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) { |
| 548 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 549 | return false; |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 550 | } |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 551 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 552 | case UnaryOperator::LNot: |
| 553 | case UnaryOperator::Plus: |
| 554 | case UnaryOperator::Minus: |
| 555 | case UnaryOperator::Not: |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 556 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 557 | } |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 558 | } |
| 559 | case SizeOfAlignOfTypeExprClass: { |
| 560 | const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); |
| 561 | // alignof always evaluates to a constant. |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 562 | if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) { |
| 563 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 564 | return false; |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 565 | } |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 566 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 567 | } |
| 568 | case BinaryOperatorClass: { |
| 569 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
| 570 | |
| 571 | // The LHS of a constant expr is always evaluated and needed. |
| 572 | if (!Exp->getLHS()->isConstantExpr(Ctx, Loc)) |
| 573 | return false; |
| 574 | |
| 575 | if (!Exp->getRHS()->isConstantExpr(Ctx, Loc)) |
| 576 | return false; |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 577 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 578 | } |
| 579 | case ImplicitCastExprClass: |
| 580 | case CastExprClass: { |
| 581 | const Expr *SubExpr; |
| 582 | SourceLocation CastLoc; |
| 583 | if (const CastExpr *C = dyn_cast<CastExpr>(this)) { |
| 584 | SubExpr = C->getSubExpr(); |
| 585 | CastLoc = C->getLParenLoc(); |
| 586 | } else { |
| 587 | SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr(); |
| 588 | CastLoc = getLocStart(); |
| 589 | } |
| 590 | if (!SubExpr->isConstantExpr(Ctx, Loc)) { |
| 591 | if (Loc) *Loc = SubExpr->getLocStart(); |
| 592 | return false; |
| 593 | } |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 594 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 595 | } |
| 596 | case ConditionalOperatorClass: { |
| 597 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 598 | if (!Exp->getCond()->isConstantExpr(Ctx, Loc) || |
Anders Carlsson | 37365fc | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 599 | // Handle the GNU extension for missing LHS. |
| 600 | !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) || |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 601 | !Exp->getRHS()->isConstantExpr(Ctx, Loc)) |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 602 | return false; |
Chris Lattner | 06db613 | 2007-10-18 00:20:32 +0000 | [diff] [blame] | 603 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 604 | } |
Steve Naroff | f0b2354 | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 605 | case InitListExprClass: { |
| 606 | const InitListExpr *Exp = cast<InitListExpr>(this); |
| 607 | unsigned numInits = Exp->getNumInits(); |
| 608 | for (unsigned i = 0; i < numInits; i++) { |
| 609 | if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) { |
| 610 | if (Loc) *Loc = Exp->getInit(i)->getLocStart(); |
| 611 | return false; |
| 612 | } |
| 613 | } |
| 614 | return true; |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 615 | } |
Steve Naroff | f0b2354 | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 616 | } |
Steve Naroff | 7c9d72d | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 619 | /// isIntegerConstantExpr - this recursive routine will test if an expression is |
| 620 | /// an integer constant expression. Note: With the introduction of VLA's in |
| 621 | /// C99 the result of the sizeof operator is no longer always a constant |
| 622 | /// expression. The generalization of the wording to include any subexpression |
| 623 | /// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions |
| 624 | /// can appear as operands to other operators (e.g. &&, ||, ?:). For instance, |
| 625 | /// "0 || f()" can be treated as a constant expression. In C90 this expression, |
| 626 | /// occurring in a context requiring a constant, would have been a constraint |
| 627 | /// violation. FIXME: This routine currently implements C90 semantics. |
| 628 | /// To properly implement C99 semantics this routine will need to evaluate |
| 629 | /// expressions involving operators previously mentioned. |
| 630 | |
| 631 | /// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero, |
| 632 | /// comma, etc |
| 633 | /// |
| 634 | /// 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] | 635 | /// permit this. This includes things like (int)1e1000 |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 636 | /// |
| 637 | /// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof |
| 638 | /// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer |
| 639 | /// cast+dereference. |
| 640 | bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, |
| 641 | SourceLocation *Loc, bool isEvaluated) const { |
| 642 | switch (getStmtClass()) { |
| 643 | default: |
| 644 | if (Loc) *Loc = getLocStart(); |
| 645 | return false; |
| 646 | case ParenExprClass: |
| 647 | return cast<ParenExpr>(this)->getSubExpr()-> |
| 648 | isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated); |
| 649 | case IntegerLiteralClass: |
| 650 | Result = cast<IntegerLiteral>(this)->getValue(); |
| 651 | break; |
| 652 | case CharacterLiteralClass: { |
| 653 | const CharacterLiteral *CL = cast<CharacterLiteral>(this); |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 654 | Result.zextOrTrunc( |
| 655 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CL->getLoc()))); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 656 | Result = CL->getValue(); |
| 657 | Result.setIsUnsigned(!getType()->isSignedIntegerType()); |
| 658 | break; |
| 659 | } |
Steve Naroff | c6f0fd3 | 2007-08-02 04:09:23 +0000 | [diff] [blame] | 660 | case TypesCompatibleExprClass: { |
| 661 | const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this); |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 662 | Result.zextOrTrunc( |
| 663 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), TCE->getLocStart()))); |
Steve Naroff | 85f0dc5 | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 664 | Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2()); |
Steve Naroff | 1200b5a | 2007-08-02 00:13:27 +0000 | [diff] [blame] | 665 | break; |
Steve Naroff | c6f0fd3 | 2007-08-02 04:09:23 +0000 | [diff] [blame] | 666 | } |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 667 | case CallExprClass: { |
| 668 | const CallExpr *CE = cast<CallExpr>(this); |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 669 | Result.zextOrTrunc( |
| 670 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart()))); |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 671 | if (CE->isBuiltinClassifyType(Result)) |
| 672 | break; |
| 673 | if (Loc) *Loc = getLocStart(); |
| 674 | return false; |
| 675 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 676 | case DeclRefExprClass: |
| 677 | if (const EnumConstantDecl *D = |
| 678 | dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) { |
| 679 | Result = D->getInitVal(); |
| 680 | break; |
| 681 | } |
| 682 | if (Loc) *Loc = getLocStart(); |
| 683 | return false; |
| 684 | case UnaryOperatorClass: { |
| 685 | const UnaryOperator *Exp = cast<UnaryOperator>(this); |
| 686 | |
| 687 | // Get the operand value. If this is sizeof/alignof, do not evalute the |
| 688 | // operand. This affects C99 6.6p3. |
Anders Carlsson | 52774ad | 2008-01-29 15:56:48 +0000 | [diff] [blame] | 689 | if (!Exp->isSizeOfAlignOfOp() && !Exp->isOffsetOfOp() && |
Chris Lattner | 5a9b624 | 2007-08-23 21:42:50 +0000 | [diff] [blame] | 690 | !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 691 | return false; |
| 692 | |
| 693 | switch (Exp->getOpcode()) { |
| 694 | // Address, indirect, pre/post inc/dec, etc are not valid constant exprs. |
| 695 | // See C99 6.6p3. |
| 696 | default: |
| 697 | if (Loc) *Loc = Exp->getOperatorLoc(); |
| 698 | return false; |
| 699 | case UnaryOperator::Extension: |
| 700 | return true; // FIXME: this is wrong. |
| 701 | case UnaryOperator::SizeOf: |
| 702 | case UnaryOperator::AlignOf: |
| 703 | // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 704 | if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) { |
| 705 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 706 | return false; |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 707 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 708 | |
| 709 | // Return the result in the right width. |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 710 | Result.zextOrTrunc( |
Chris Lattner | 9d020b3 | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 711 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), |
| 712 | Exp->getOperatorLoc()))); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 713 | |
| 714 | // Get information about the size or align. |
Chris Lattner | d4dc267 | 2008-01-02 21:54:09 +0000 | [diff] [blame] | 715 | if (Exp->getSubExpr()->getType()->isFunctionType()) { |
| 716 | // GCC extension: sizeof(function) = 1. |
| 717 | Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1; |
| 718 | } else if (Exp->getOpcode() == UnaryOperator::AlignOf) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 719 | Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(), |
| 720 | Exp->getOperatorLoc()); |
Chris Lattner | d9ffbc9 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 721 | } else { |
Ted Kremenek | d7f64cd | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 722 | unsigned CharSize = |
| 723 | Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc())); |
| 724 | |
Chris Lattner | d9ffbc9 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 725 | Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(), |
| 726 | Exp->getOperatorLoc()) / CharSize; |
| 727 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 728 | break; |
| 729 | case UnaryOperator::LNot: { |
Chris Lattner | f00fdc0 | 2008-01-25 19:16:19 +0000 | [diff] [blame] | 730 | bool Val = Result == 0; |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 731 | Result.zextOrTrunc( |
Chris Lattner | 9d020b3 | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 732 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), |
| 733 | Exp->getOperatorLoc()))); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 734 | Result = Val; |
| 735 | break; |
| 736 | } |
| 737 | case UnaryOperator::Plus: |
| 738 | break; |
| 739 | case UnaryOperator::Minus: |
| 740 | Result = -Result; |
| 741 | break; |
| 742 | case UnaryOperator::Not: |
| 743 | Result = ~Result; |
| 744 | break; |
Anders Carlsson | 52774ad | 2008-01-29 15:56:48 +0000 | [diff] [blame] | 745 | case UnaryOperator::OffsetOf: |
| 746 | Result = Exp->evaluateOffsetOf(Ctx); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 747 | } |
| 748 | break; |
| 749 | } |
| 750 | case SizeOfAlignOfTypeExprClass: { |
| 751 | const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); |
| 752 | // alignof always evaluates to a constant. |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 753 | if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) { |
| 754 | if (Loc) *Loc = Exp->getOperatorLoc(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 755 | return false; |
Chris Lattner | b3ff082 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 756 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 757 | |
| 758 | // Return the result in the right width. |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 759 | Result.zextOrTrunc( |
| 760 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()))); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 761 | |
| 762 | // Get information about the size or align. |
Chris Lattner | d4dc267 | 2008-01-02 21:54:09 +0000 | [diff] [blame] | 763 | if (Exp->getArgumentType()->isFunctionType()) { |
| 764 | // GCC extension: sizeof(function) = 1. |
| 765 | Result = Exp->isSizeOf() ? 1 : 4; |
| 766 | } else if (Exp->isSizeOf()) { |
Ted Kremenek | a9d0fd9 | 2007-12-17 17:38:43 +0000 | [diff] [blame] | 767 | unsigned CharSize = |
| 768 | Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc())); |
| 769 | |
| 770 | Result = Ctx.getTypeSize(Exp->getArgumentType(), |
| 771 | Exp->getOperatorLoc()) / CharSize; |
| 772 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 773 | else |
| 774 | Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc()); |
Ted Kremenek | a9d0fd9 | 2007-12-17 17:38:43 +0000 | [diff] [blame] | 775 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 776 | break; |
| 777 | } |
| 778 | case BinaryOperatorClass: { |
| 779 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
| 780 | |
| 781 | // The LHS of a constant expr is always evaluated and needed. |
| 782 | if (!Exp->getLHS()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 783 | return false; |
| 784 | |
| 785 | llvm::APSInt RHS(Result); |
| 786 | |
| 787 | // The short-circuiting &&/|| operators don't necessarily evaluate their |
| 788 | // RHS. Make sure to pass isEvaluated down correctly. |
| 789 | if (Exp->isLogicalOp()) { |
| 790 | bool RHSEval; |
| 791 | if (Exp->getOpcode() == BinaryOperator::LAnd) |
| 792 | RHSEval = Result != 0; |
| 793 | else { |
| 794 | assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical"); |
| 795 | RHSEval = Result == 0; |
| 796 | } |
| 797 | |
| 798 | if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, |
| 799 | isEvaluated & RHSEval)) |
| 800 | return false; |
| 801 | } else { |
| 802 | if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated)) |
| 803 | return false; |
| 804 | } |
| 805 | |
| 806 | switch (Exp->getOpcode()) { |
| 807 | default: |
| 808 | if (Loc) *Loc = getLocStart(); |
| 809 | return false; |
| 810 | case BinaryOperator::Mul: |
| 811 | Result *= RHS; |
| 812 | break; |
| 813 | case BinaryOperator::Div: |
| 814 | if (RHS == 0) { |
| 815 | if (!isEvaluated) break; |
| 816 | if (Loc) *Loc = getLocStart(); |
| 817 | return false; |
| 818 | } |
| 819 | Result /= RHS; |
| 820 | break; |
| 821 | case BinaryOperator::Rem: |
| 822 | if (RHS == 0) { |
| 823 | if (!isEvaluated) break; |
| 824 | if (Loc) *Loc = getLocStart(); |
| 825 | return false; |
| 826 | } |
| 827 | Result %= RHS; |
| 828 | break; |
| 829 | case BinaryOperator::Add: Result += RHS; break; |
| 830 | case BinaryOperator::Sub: Result -= RHS; break; |
| 831 | case BinaryOperator::Shl: |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 832 | Result <<= |
| 833 | static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 834 | break; |
| 835 | case BinaryOperator::Shr: |
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::LT: Result = Result < RHS; break; |
| 840 | case BinaryOperator::GT: Result = Result > RHS; break; |
| 841 | case BinaryOperator::LE: Result = Result <= RHS; break; |
| 842 | case BinaryOperator::GE: Result = Result >= RHS; break; |
| 843 | case BinaryOperator::EQ: Result = Result == RHS; break; |
| 844 | case BinaryOperator::NE: Result = Result != RHS; break; |
| 845 | case BinaryOperator::And: Result &= RHS; break; |
| 846 | case BinaryOperator::Xor: Result ^= RHS; break; |
| 847 | case BinaryOperator::Or: Result |= RHS; break; |
| 848 | case BinaryOperator::LAnd: |
| 849 | Result = Result != 0 && RHS != 0; |
| 850 | break; |
| 851 | case BinaryOperator::LOr: |
| 852 | Result = Result != 0 || RHS != 0; |
| 853 | break; |
| 854 | |
| 855 | case BinaryOperator::Comma: |
| 856 | // C99 6.6p3: "shall not contain assignment, ..., or comma operators, |
| 857 | // *except* when they are contained within a subexpression that is not |
| 858 | // evaluated". Note that Assignment can never happen due to constraints |
| 859 | // on the LHS subexpr, so we don't need to check it here. |
| 860 | if (isEvaluated) { |
| 861 | if (Loc) *Loc = getLocStart(); |
| 862 | return false; |
| 863 | } |
| 864 | |
| 865 | // The result of the constant expr is the RHS. |
| 866 | Result = RHS; |
| 867 | return true; |
| 868 | } |
| 869 | |
| 870 | assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!"); |
| 871 | break; |
| 872 | } |
| 873 | case ImplicitCastExprClass: |
| 874 | case CastExprClass: { |
| 875 | const Expr *SubExpr; |
| 876 | SourceLocation CastLoc; |
| 877 | if (const CastExpr *C = dyn_cast<CastExpr>(this)) { |
| 878 | SubExpr = C->getSubExpr(); |
| 879 | CastLoc = C->getLParenLoc(); |
| 880 | } else { |
| 881 | SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr(); |
| 882 | CastLoc = getLocStart(); |
| 883 | } |
| 884 | |
| 885 | // C99 6.6p6: shall only convert arithmetic types to integer types. |
| 886 | if (!SubExpr->getType()->isArithmeticType() || |
| 887 | !getType()->isIntegerType()) { |
| 888 | if (Loc) *Loc = SubExpr->getLocStart(); |
| 889 | return false; |
| 890 | } |
Chris Lattner | 76a0c1b | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 891 | |
| 892 | uint32_t DestWidth = |
| 893 | static_cast<uint32_t>(Ctx.getTypeSize(getType(), CastLoc)); |
| 894 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 895 | // Handle simple integer->integer casts. |
| 896 | if (SubExpr->getType()->isIntegerType()) { |
| 897 | if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 898 | return false; |
| 899 | |
| 900 | // Figure out if this is a truncate, extend or noop cast. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 901 | // If the input is signed, do a sign extend, noop, or truncate. |
Chris Lattner | 000c410 | 2008-01-09 18:59:34 +0000 | [diff] [blame] | 902 | if (getType()->isBooleanType()) { |
| 903 | // Conversion to bool compares against zero. |
| 904 | Result = Result != 0; |
| 905 | Result.zextOrTrunc(DestWidth); |
| 906 | } else if (SubExpr->getType()->isSignedIntegerType()) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 907 | Result.sextOrTrunc(DestWidth); |
| 908 | else // If the input is unsigned, do a zero extend, noop, or truncate. |
| 909 | Result.zextOrTrunc(DestWidth); |
| 910 | break; |
| 911 | } |
| 912 | |
| 913 | // Allow floating constants that are the immediate operands of casts or that |
| 914 | // are parenthesized. |
| 915 | const Expr *Operand = SubExpr; |
| 916 | while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand)) |
| 917 | Operand = PE->getSubExpr(); |
Chris Lattner | 76a0c1b | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 918 | |
| 919 | // If this isn't a floating literal, we can't handle it. |
| 920 | const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand); |
| 921 | if (!FL) { |
| 922 | if (Loc) *Loc = Operand->getLocStart(); |
| 923 | return false; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 924 | } |
Chris Lattner | 000c410 | 2008-01-09 18:59:34 +0000 | [diff] [blame] | 925 | |
| 926 | // If the destination is boolean, compare against zero. |
| 927 | if (getType()->isBooleanType()) { |
| 928 | Result = !FL->getValue().isZero(); |
| 929 | Result.zextOrTrunc(DestWidth); |
| 930 | break; |
| 931 | } |
Chris Lattner | 76a0c1b | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 932 | |
| 933 | // Determine whether we are converting to unsigned or signed. |
| 934 | bool DestSigned = getType()->isSignedIntegerType(); |
Chris Lattner | 9d020b3 | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 935 | |
| 936 | // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can |
| 937 | // be called multiple times per AST. |
Chris Lattner | 76a0c1b | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 938 | uint64_t Space[4]; |
Chris Lattner | 9d020b3 | 2007-09-26 00:47:26 +0000 | [diff] [blame] | 939 | (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned, |
| 940 | llvm::APFloat::rmTowardZero); |
Chris Lattner | 76a0c1b | 2007-09-22 19:04:13 +0000 | [diff] [blame] | 941 | Result = llvm::APInt(DestWidth, 4, Space); |
| 942 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 943 | } |
| 944 | case ConditionalOperatorClass: { |
| 945 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
| 946 | |
| 947 | if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 948 | return false; |
| 949 | |
| 950 | const Expr *TrueExp = Exp->getLHS(); |
| 951 | const Expr *FalseExp = Exp->getRHS(); |
| 952 | if (Result == 0) std::swap(TrueExp, FalseExp); |
| 953 | |
| 954 | // Evaluate the false one first, discard the result. |
Anders Carlsson | 37365fc | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 955 | if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 956 | return false; |
| 957 | // Evalute the true one, capture the result. |
Anders Carlsson | 37365fc | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 958 | if (TrueExp && |
| 959 | !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 960 | return false; |
| 961 | break; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | // Cases that are valid constant exprs fall through to here. |
| 966 | Result.setIsUnsigned(getType()->isUnsignedIntegerType()); |
| 967 | return true; |
| 968 | } |
| 969 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 970 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an |
| 971 | /// integer constant expression with the value zero, or if this is one that is |
| 972 | /// cast to void*. |
| 973 | bool Expr::isNullPointerConstant(ASTContext &Ctx) const { |
Steve Naroff | a2e5322 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 974 | // Strip off a cast to void*, if it exists. |
| 975 | if (const CastExpr *CE = dyn_cast<CastExpr>(this)) { |
| 976 | // Check that it is a cast to void*. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 977 | if (const PointerType *PT = dyn_cast<PointerType>(CE->getType())) { |
| 978 | QualType Pointee = PT->getPointeeType(); |
Steve Naroff | a2e5322 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 979 | if (Pointee.getQualifiers() == 0 && Pointee->isVoidType() && // to void* |
| 980 | CE->getSubExpr()->getType()->isIntegerType()) // from int. |
| 981 | return CE->getSubExpr()->isNullPointerConstant(Ctx); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 982 | } |
Steve Naroff | a2e5322 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 983 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { |
| 984 | // Ignore the ImplicitCastExpr type entirely. |
| 985 | return ICE->getSubExpr()->isNullPointerConstant(Ctx); |
| 986 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { |
| 987 | // Accept ((void*)0) as a null pointer constant, as many other |
| 988 | // implementations do. |
| 989 | return PE->getSubExpr()->isNullPointerConstant(Ctx); |
Steve Naroff | f33a985 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 990 | } |
Steve Naroff | a2e5322 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 991 | |
| 992 | // This expression must be an integer type. |
| 993 | if (!getType()->isIntegerType()) |
| 994 | return false; |
| 995 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 996 | // If we have an integer constant expression, we need to *evaluate* it and |
| 997 | // test for the value 0. |
| 998 | llvm::APSInt Val(32); |
Steve Naroff | a2e5322 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 999 | return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1000 | } |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1001 | |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1002 | unsigned OCUVectorElementExpr::getNumElements() const { |
Chris Lattner | 5054785 | 2007-08-03 16:00:20 +0000 | [diff] [blame] | 1003 | return strlen(Accessor.getName()); |
| 1004 | } |
| 1005 | |
| 1006 | |
Chris Lattner | f4bf551 | 2007-08-02 21:47:28 +0000 | [diff] [blame] | 1007 | /// getComponentType - Determine whether the components of this access are |
| 1008 | /// "point" "color" or "texture" elements. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1009 | OCUVectorElementExpr::ElementType |
| 1010 | OCUVectorElementExpr::getElementType() const { |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1011 | // derive the component type, no need to waste space. |
| 1012 | const char *compStr = Accessor.getName(); |
Chris Lattner | abf25b3 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 1013 | |
Chris Lattner | 9096b79 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 1014 | if (OCUVectorType::getPointAccessorIdx(*compStr) != -1) return Point; |
| 1015 | if (OCUVectorType::getColorAccessorIdx(*compStr) != -1) return Color; |
Chris Lattner | abf25b3 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 1016 | |
Chris Lattner | 9096b79 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 1017 | assert(OCUVectorType::getTextureAccessorIdx(*compStr) != -1 && |
Chris Lattner | abf25b3 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 1018 | "getComponentType(): Illegal accessor"); |
| 1019 | return Texture; |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1020 | } |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1021 | |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1022 | /// containsDuplicateElements - Return true if any element access is |
Chris Lattner | f4bf551 | 2007-08-02 21:47:28 +0000 | [diff] [blame] | 1023 | /// repeated. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1024 | bool OCUVectorElementExpr::containsDuplicateElements() const { |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1025 | const char *compStr = Accessor.getName(); |
| 1026 | unsigned length = strlen(compStr); |
| 1027 | |
| 1028 | for (unsigned i = 0; i < length-1; i++) { |
| 1029 | const char *s = compStr+i; |
| 1030 | for (const char c = *s++; *s; s++) |
| 1031 | if (c == *s) |
| 1032 | return true; |
| 1033 | } |
| 1034 | return false; |
| 1035 | } |
Chris Lattner | 42158e7 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 1036 | |
| 1037 | /// getEncodedElementAccess - We encode fields with two bits per component. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1038 | unsigned OCUVectorElementExpr::getEncodedElementAccess() const { |
Chris Lattner | 42158e7 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 1039 | const char *compStr = Accessor.getName(); |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1040 | unsigned length = getNumElements(); |
Chris Lattner | 42158e7 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 1041 | |
| 1042 | unsigned Result = 0; |
| 1043 | |
| 1044 | while (length--) { |
| 1045 | Result <<= 2; |
| 1046 | int Idx = OCUVectorType::getAccessorIdx(compStr[length]); |
| 1047 | assert(Idx != -1 && "Invalid accessor letter"); |
| 1048 | Result |= Idx; |
| 1049 | } |
| 1050 | return Result; |
| 1051 | } |
| 1052 | |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1053 | // constructor for instance messages. |
Steve Naroff | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 1054 | ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1055 | QualType retType, ObjCMethodDecl *mproto, |
Steve Naroff | 1e1c391 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 1056 | SourceLocation LBrac, SourceLocation RBrac, |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1057 | Expr **ArgExprs, unsigned nargs) |
Steve Naroff | 1e1c391 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 1058 | : Expr(ObjCMessageExprClass, retType), SelName(selInfo), |
| 1059 | MethodProto(mproto), ClassName(0) { |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1060 | NumArgs = nargs; |
| 1061 | SubExprs = new Expr*[NumArgs+1]; |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1062 | SubExprs[RECEIVER] = receiver; |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1063 | if (NumArgs) { |
| 1064 | for (unsigned i = 0; i != NumArgs; ++i) |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1065 | SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); |
| 1066 | } |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1067 | LBracloc = LBrac; |
| 1068 | RBracloc = RBrac; |
| 1069 | } |
| 1070 | |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1071 | // constructor for class messages. |
| 1072 | // FIXME: clsName should be typed to ObjCInterfaceType |
Steve Naroff | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 1073 | ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1074 | QualType retType, ObjCMethodDecl *mproto, |
Steve Naroff | 1e1c391 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 1075 | SourceLocation LBrac, SourceLocation RBrac, |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1076 | Expr **ArgExprs, unsigned nargs) |
Steve Naroff | 1e1c391 | 2007-11-03 16:37:59 +0000 | [diff] [blame] | 1077 | : Expr(ObjCMessageExprClass, retType), SelName(selInfo), |
| 1078 | MethodProto(mproto), ClassName(clsName) { |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1079 | NumArgs = nargs; |
| 1080 | SubExprs = new Expr*[NumArgs+1]; |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1081 | SubExprs[RECEIVER] = 0; |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1082 | if (NumArgs) { |
| 1083 | for (unsigned i = 0; i != NumArgs; ++i) |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1084 | SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); |
| 1085 | } |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1086 | LBracloc = LBrac; |
| 1087 | RBracloc = RBrac; |
| 1088 | } |
| 1089 | |
Chris Lattner | f624cd2 | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 1090 | |
| 1091 | bool ChooseExpr::isConditionTrue(ASTContext &C) const { |
| 1092 | llvm::APSInt CondVal(32); |
| 1093 | bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C); |
| 1094 | assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst; |
| 1095 | return CondVal != 0; |
| 1096 | } |
| 1097 | |
Anders Carlsson | 52774ad | 2008-01-29 15:56:48 +0000 | [diff] [blame] | 1098 | static int64_t evaluateOffsetOf(ASTContext& C, const Expr *E) |
| 1099 | { |
| 1100 | if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { |
| 1101 | QualType Ty = ME->getBase()->getType(); |
| 1102 | |
| 1103 | RecordDecl *RD = Ty->getAsRecordType()->getDecl(); |
| 1104 | const ASTRecordLayout &RL = C.getASTRecordLayout(RD, SourceLocation()); |
| 1105 | FieldDecl *FD = ME->getMemberDecl(); |
| 1106 | |
| 1107 | // FIXME: This is linear time. |
| 1108 | unsigned i = 0, e = 0; |
| 1109 | for (i = 0, e = RD->getNumMembers(); i != e; i++) { |
| 1110 | if (RD->getMember(i) == FD) |
| 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | return RL.getFieldOffset(i) + evaluateOffsetOf(C, ME->getBase()); |
| 1115 | } else if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 1116 | const Expr *Base = ASE->getBase(); |
| 1117 | llvm::APSInt Idx(32); |
| 1118 | bool ICE = ASE->getIdx()->isIntegerConstantExpr(Idx, C); |
| 1119 | assert(ICE && "Array index is not a constant integer!"); |
| 1120 | |
| 1121 | int64_t size = C.getTypeSize(ASE->getType(), SourceLocation()); |
| 1122 | size *= Idx.getSExtValue(); |
| 1123 | |
| 1124 | return size + evaluateOffsetOf(C, Base); |
| 1125 | } else if (isa<CompoundLiteralExpr>(E)) |
| 1126 | return 0; |
| 1127 | |
| 1128 | assert(0 && "Unknown offsetof subexpression!"); |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | int64_t UnaryOperator::evaluateOffsetOf(ASTContext& C) const |
| 1133 | { |
| 1134 | assert(Opc == OffsetOf && "Unary operator not offsetof!"); |
| 1135 | |
| 1136 | unsigned CharSize = |
| 1137 | C.Target.getCharWidth(C.getFullLoc(getOperatorLoc())); |
| 1138 | |
| 1139 | return ::evaluateOffsetOf(C, Val) / CharSize; |
| 1140 | } |
| 1141 | |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1142 | //===----------------------------------------------------------------------===// |
| 1143 | // Child Iterators for iterating over subexpressions/substatements |
| 1144 | //===----------------------------------------------------------------------===// |
| 1145 | |
| 1146 | // DeclRefExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1147 | Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } |
| 1148 | Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1149 | |
Steve Naroff | 5eb2a4a | 2007-11-12 14:29:37 +0000 | [diff] [blame] | 1150 | // ObjCIvarRefExpr |
| 1151 | Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return child_iterator(); } |
| 1152 | Stmt::child_iterator ObjCIvarRefExpr::child_end() { return child_iterator(); } |
| 1153 | |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1154 | // PreDefinedExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1155 | Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); } |
| 1156 | Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1157 | |
| 1158 | // IntegerLiteral |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1159 | Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } |
| 1160 | Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1161 | |
| 1162 | // CharacterLiteral |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1163 | Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); } |
| 1164 | Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1165 | |
| 1166 | // FloatingLiteral |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1167 | Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } |
| 1168 | Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1169 | |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1170 | // ImaginaryLiteral |
| 1171 | Stmt::child_iterator ImaginaryLiteral::child_begin() { |
| 1172 | return reinterpret_cast<Stmt**>(&Val); |
| 1173 | } |
| 1174 | Stmt::child_iterator ImaginaryLiteral::child_end() { |
| 1175 | return reinterpret_cast<Stmt**>(&Val)+1; |
| 1176 | } |
| 1177 | |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1178 | // StringLiteral |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1179 | Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } |
| 1180 | Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1181 | |
| 1182 | // ParenExpr |
| 1183 | Stmt::child_iterator ParenExpr::child_begin() { |
| 1184 | return reinterpret_cast<Stmt**>(&Val); |
| 1185 | } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1186 | Stmt::child_iterator ParenExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1187 | return reinterpret_cast<Stmt**>(&Val)+1; |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | // UnaryOperator |
| 1191 | Stmt::child_iterator UnaryOperator::child_begin() { |
Ted Kremenek | 6d7ea52 | 2007-12-15 00:39:18 +0000 | [diff] [blame] | 1192 | return reinterpret_cast<Stmt**>(&Val); |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1193 | } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1194 | Stmt::child_iterator UnaryOperator::child_end() { |
Ted Kremenek | 6d7ea52 | 2007-12-15 00:39:18 +0000 | [diff] [blame] | 1195 | return reinterpret_cast<Stmt**>(&Val+1); |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | // SizeOfAlignOfTypeExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1199 | Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() { |
Ted Kremenek | b7cf095 | 2007-12-14 22:52:23 +0000 | [diff] [blame] | 1200 | // If the type is a VLA type (and not a typedef), the size expression of the |
| 1201 | // VLA needs to be treated as an executable expression. |
| 1202 | if (VariableArrayType* T = dyn_cast<VariableArrayType>(Ty.getTypePtr())) |
| 1203 | return child_iterator(T); |
| 1204 | else |
| 1205 | return child_iterator(); |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1206 | } |
| 1207 | Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() { |
Ted Kremenek | b7cf095 | 2007-12-14 22:52:23 +0000 | [diff] [blame] | 1208 | return child_iterator(); |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1209 | } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1210 | |
| 1211 | // ArraySubscriptExpr |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1212 | Stmt::child_iterator ArraySubscriptExpr::child_begin() { |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1213 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1214 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1215 | Stmt::child_iterator ArraySubscriptExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1216 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | // CallExpr |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1220 | Stmt::child_iterator CallExpr::child_begin() { |
Ted Kremenek | 15ede50 | 2007-08-27 21:11:44 +0000 | [diff] [blame] | 1221 | return reinterpret_cast<Stmt**>(&SubExprs[0]); |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1222 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1223 | Stmt::child_iterator CallExpr::child_end() { |
Ted Kremenek | 15ede50 | 2007-08-27 21:11:44 +0000 | [diff] [blame] | 1224 | return reinterpret_cast<Stmt**>(&SubExprs[NumArgs+ARGS_START]); |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 1225 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1226 | |
| 1227 | // MemberExpr |
| 1228 | Stmt::child_iterator MemberExpr::child_begin() { |
| 1229 | return reinterpret_cast<Stmt**>(&Base); |
| 1230 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1231 | Stmt::child_iterator MemberExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1232 | return reinterpret_cast<Stmt**>(&Base)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | // OCUVectorElementExpr |
| 1236 | Stmt::child_iterator OCUVectorElementExpr::child_begin() { |
| 1237 | return reinterpret_cast<Stmt**>(&Base); |
| 1238 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1239 | Stmt::child_iterator OCUVectorElementExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1240 | return reinterpret_cast<Stmt**>(&Base)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | // CompoundLiteralExpr |
| 1244 | Stmt::child_iterator CompoundLiteralExpr::child_begin() { |
| 1245 | return reinterpret_cast<Stmt**>(&Init); |
| 1246 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1247 | Stmt::child_iterator CompoundLiteralExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1248 | return reinterpret_cast<Stmt**>(&Init)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | // ImplicitCastExpr |
| 1252 | Stmt::child_iterator ImplicitCastExpr::child_begin() { |
| 1253 | return reinterpret_cast<Stmt**>(&Op); |
| 1254 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1255 | Stmt::child_iterator ImplicitCastExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1256 | return reinterpret_cast<Stmt**>(&Op)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | // CastExpr |
| 1260 | Stmt::child_iterator CastExpr::child_begin() { |
| 1261 | return reinterpret_cast<Stmt**>(&Op); |
| 1262 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1263 | Stmt::child_iterator CastExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1264 | return reinterpret_cast<Stmt**>(&Op)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | // BinaryOperator |
| 1268 | Stmt::child_iterator BinaryOperator::child_begin() { |
| 1269 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1270 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1271 | Stmt::child_iterator BinaryOperator::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1272 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | // ConditionalOperator |
| 1276 | Stmt::child_iterator ConditionalOperator::child_begin() { |
| 1277 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1278 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1279 | Stmt::child_iterator ConditionalOperator::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1280 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | // AddrLabelExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1284 | Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } |
| 1285 | Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1286 | |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1287 | // StmtExpr |
| 1288 | Stmt::child_iterator StmtExpr::child_begin() { |
| 1289 | return reinterpret_cast<Stmt**>(&SubStmt); |
| 1290 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1291 | Stmt::child_iterator StmtExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1292 | return reinterpret_cast<Stmt**>(&SubStmt)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | // TypesCompatibleExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1296 | Stmt::child_iterator TypesCompatibleExpr::child_begin() { |
| 1297 | return child_iterator(); |
| 1298 | } |
| 1299 | |
| 1300 | Stmt::child_iterator TypesCompatibleExpr::child_end() { |
| 1301 | return child_iterator(); |
| 1302 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1303 | |
| 1304 | // ChooseExpr |
| 1305 | Stmt::child_iterator ChooseExpr::child_begin() { |
| 1306 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 1307 | } |
| 1308 | |
| 1309 | Stmt::child_iterator ChooseExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 1310 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
Nate Begeman | 9f3bfb7 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 1313 | // OverloadExpr |
| 1314 | Stmt::child_iterator OverloadExpr::child_begin() { |
| 1315 | return reinterpret_cast<Stmt**>(&SubExprs[0]); |
| 1316 | } |
| 1317 | Stmt::child_iterator OverloadExpr::child_end() { |
Nate Begeman | bd881ef | 2008-01-30 20:50:20 +0000 | [diff] [blame] | 1318 | return reinterpret_cast<Stmt**>(&SubExprs[NumExprs]); |
Nate Begeman | 9f3bfb7 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Anders Carlsson | 3676033 | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1321 | // VAArgExpr |
| 1322 | Stmt::child_iterator VAArgExpr::child_begin() { |
| 1323 | return reinterpret_cast<Stmt**>(&Val); |
| 1324 | } |
| 1325 | |
| 1326 | Stmt::child_iterator VAArgExpr::child_end() { |
| 1327 | return reinterpret_cast<Stmt**>(&Val)+1; |
| 1328 | } |
| 1329 | |
Anders Carlsson | 762b7c7 | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 1330 | // InitListExpr |
| 1331 | Stmt::child_iterator InitListExpr::child_begin() { |
| 1332 | return reinterpret_cast<Stmt**>(&InitExprs[0]); |
| 1333 | } |
| 1334 | Stmt::child_iterator InitListExpr::child_end() { |
| 1335 | return reinterpret_cast<Stmt**>(&InitExprs[NumInits]); |
| 1336 | } |
| 1337 | |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1338 | // ObjCStringLiteral |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1339 | Stmt::child_iterator ObjCStringLiteral::child_begin() { |
| 1340 | return child_iterator(); |
| 1341 | } |
| 1342 | Stmt::child_iterator ObjCStringLiteral::child_end() { |
| 1343 | return child_iterator(); |
| 1344 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1345 | |
| 1346 | // ObjCEncodeExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1347 | Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } |
| 1348 | Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 1349 | |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1350 | // ObjCSelectorExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1351 | Stmt::child_iterator ObjCSelectorExpr::child_begin() { |
| 1352 | return child_iterator(); |
| 1353 | } |
| 1354 | Stmt::child_iterator ObjCSelectorExpr::child_end() { |
| 1355 | return child_iterator(); |
| 1356 | } |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1357 | |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1358 | // ObjCProtocolExpr |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 1359 | Stmt::child_iterator ObjCProtocolExpr::child_begin() { |
| 1360 | return child_iterator(); |
| 1361 | } |
| 1362 | Stmt::child_iterator ObjCProtocolExpr::child_end() { |
| 1363 | return child_iterator(); |
| 1364 | } |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1365 | |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1366 | // ObjCMessageExpr |
| 1367 | Stmt::child_iterator ObjCMessageExpr::child_begin() { |
| 1368 | return reinterpret_cast<Stmt**>(&SubExprs[0]); |
| 1369 | } |
| 1370 | Stmt::child_iterator ObjCMessageExpr::child_end() { |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1371 | return reinterpret_cast<Stmt**>(&SubExprs[getNumArgs()+ARGS_START]); |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |