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 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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" |
| 17 | #include "clang/Lex/IdentifierTable.h" |
| 18 | using namespace clang; |
| 19 | |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | // Primary Expressions. |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
| 24 | StringLiteral::StringLiteral(const char *strData, unsigned byteLength, |
| 25 | bool Wide, QualType t, SourceLocation firstLoc, |
| 26 | SourceLocation lastLoc) : |
| 27 | Expr(StringLiteralClass, t) { |
| 28 | // OPTIMIZE: could allocate this appended to the StringLiteral. |
| 29 | char *AStrData = new char[byteLength]; |
| 30 | memcpy(AStrData, strData, byteLength); |
| 31 | StrData = AStrData; |
| 32 | ByteLength = byteLength; |
| 33 | IsWide = Wide; |
| 34 | firstTokLoc = firstLoc; |
| 35 | lastTokLoc = lastLoc; |
| 36 | } |
| 37 | |
| 38 | StringLiteral::~StringLiteral() { |
| 39 | delete[] StrData; |
| 40 | } |
| 41 | |
| 42 | bool UnaryOperator::isPostfix(Opcode Op) { |
| 43 | switch (Op) { |
| 44 | case PostInc: |
| 45 | case PostDec: |
| 46 | return true; |
| 47 | default: |
| 48 | return false; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 53 | /// corresponds to, e.g. "sizeof" or "[pre]++". |
| 54 | const char *UnaryOperator::getOpcodeStr(Opcode Op) { |
| 55 | switch (Op) { |
| 56 | default: assert(0 && "Unknown unary operator"); |
| 57 | case PostInc: return "++"; |
| 58 | case PostDec: return "--"; |
| 59 | case PreInc: return "++"; |
| 60 | case PreDec: return "--"; |
| 61 | case AddrOf: return "&"; |
| 62 | case Deref: return "*"; |
| 63 | case Plus: return "+"; |
| 64 | case Minus: return "-"; |
| 65 | case Not: return "~"; |
| 66 | case LNot: return "!"; |
| 67 | case Real: return "__real"; |
| 68 | case Imag: return "__imag"; |
| 69 | case SizeOf: return "sizeof"; |
| 70 | case AlignOf: return "alignof"; |
| 71 | case Extension: return "__extension__"; |
Chris Lattner | 0d9bcea | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 72 | case OffsetOf: return "__builtin_offsetof"; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | // Postfix Operators. |
| 78 | //===----------------------------------------------------------------------===// |
| 79 | |
| 80 | CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, |
| 81 | SourceLocation rparenloc) |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 82 | : Expr(CallExprClass, t), NumArgs(numargs) { |
| 83 | SubExprs = new Expr*[numargs+1]; |
| 84 | SubExprs[FN] = fn; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 85 | for (unsigned i = 0; i != numargs; ++i) |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 86 | SubExprs[i+ARGS_START] = args[i]; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 87 | RParenLoc = rparenloc; |
| 88 | } |
| 89 | |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 90 | bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const { |
| 91 | // The following enum mimics gcc's internal "typeclass.h" file. |
| 92 | enum gcc_type_class { |
| 93 | no_type_class = -1, |
| 94 | void_type_class, integer_type_class, char_type_class, |
| 95 | enumeral_type_class, boolean_type_class, |
| 96 | pointer_type_class, reference_type_class, offset_type_class, |
| 97 | real_type_class, complex_type_class, |
| 98 | function_type_class, method_type_class, |
| 99 | record_type_class, union_type_class, |
| 100 | array_type_class, string_type_class, |
| 101 | lang_type_class |
| 102 | }; |
| 103 | Result.setIsSigned(true); |
| 104 | |
| 105 | // All simple function calls (e.g. func()) are implicitly cast to pointer to |
| 106 | // function. As a result, we try and obtain the DeclRefExpr from the |
| 107 | // ImplicitCastExpr. |
| 108 | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); |
| 109 | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). |
| 110 | return false; |
| 111 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); |
| 112 | if (!DRE) |
| 113 | return false; |
| 114 | |
| 115 | // We have a DeclRefExpr. |
| 116 | if (strcmp(DRE->getDecl()->getName(), "__builtin_classify_type") == 0) { |
| 117 | // If no argument was supplied, default to "no_type_class". This isn't |
| 118 | // ideal, however it's what gcc does. |
| 119 | Result = static_cast<uint64_t>(no_type_class); |
| 120 | if (NumArgs >= 1) { |
| 121 | QualType argType = getArg(0)->getType(); |
| 122 | |
| 123 | if (argType->isVoidType()) |
| 124 | Result = void_type_class; |
| 125 | else if (argType->isEnumeralType()) |
| 126 | Result = enumeral_type_class; |
| 127 | else if (argType->isBooleanType()) |
| 128 | Result = boolean_type_class; |
| 129 | else if (argType->isCharType()) |
| 130 | Result = string_type_class; // gcc doesn't appear to use char_type_class |
| 131 | else if (argType->isIntegerType()) |
| 132 | Result = integer_type_class; |
| 133 | else if (argType->isPointerType()) |
| 134 | Result = pointer_type_class; |
| 135 | else if (argType->isReferenceType()) |
| 136 | Result = reference_type_class; |
| 137 | else if (argType->isRealType()) |
| 138 | Result = real_type_class; |
| 139 | else if (argType->isComplexType()) |
| 140 | Result = complex_type_class; |
| 141 | else if (argType->isFunctionType()) |
| 142 | Result = function_type_class; |
| 143 | else if (argType->isStructureType()) |
| 144 | Result = record_type_class; |
| 145 | else if (argType->isUnionType()) |
| 146 | Result = union_type_class; |
| 147 | else if (argType->isArrayType()) |
| 148 | Result = array_type_class; |
| 149 | else if (argType->isUnionType()) |
| 150 | Result = union_type_class; |
| 151 | else // FIXME: offset_type_class, method_type_class, & lang_type_class? |
| 152 | assert(1 && "CallExpr::isBuiltinClassifyType(): unimplemented type"); |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | return false; |
| 157 | } |
| 158 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 159 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
| 160 | /// corresponds to, e.g. "<<=". |
| 161 | const char *BinaryOperator::getOpcodeStr(Opcode Op) { |
| 162 | switch (Op) { |
| 163 | default: assert(0 && "Unknown binary operator"); |
| 164 | case Mul: return "*"; |
| 165 | case Div: return "/"; |
| 166 | case Rem: return "%"; |
| 167 | case Add: return "+"; |
| 168 | case Sub: return "-"; |
| 169 | case Shl: return "<<"; |
| 170 | case Shr: return ">>"; |
| 171 | case LT: return "<"; |
| 172 | case GT: return ">"; |
| 173 | case LE: return "<="; |
| 174 | case GE: return ">="; |
| 175 | case EQ: return "=="; |
| 176 | case NE: return "!="; |
| 177 | case And: return "&"; |
| 178 | case Xor: return "^"; |
| 179 | case Or: return "|"; |
| 180 | case LAnd: return "&&"; |
| 181 | case LOr: return "||"; |
| 182 | case Assign: return "="; |
| 183 | case MulAssign: return "*="; |
| 184 | case DivAssign: return "/="; |
| 185 | case RemAssign: return "%="; |
| 186 | case AddAssign: return "+="; |
| 187 | case SubAssign: return "-="; |
| 188 | case ShlAssign: return "<<="; |
| 189 | case ShrAssign: return ">>="; |
| 190 | case AndAssign: return "&="; |
| 191 | case XorAssign: return "^="; |
| 192 | case OrAssign: return "|="; |
| 193 | case Comma: return ","; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | //===----------------------------------------------------------------------===// |
| 199 | // Generic Expression Routines |
| 200 | //===----------------------------------------------------------------------===// |
| 201 | |
| 202 | /// hasLocalSideEffect - Return true if this immediate expression has side |
| 203 | /// effects, not counting any sub-expressions. |
| 204 | bool Expr::hasLocalSideEffect() const { |
| 205 | switch (getStmtClass()) { |
| 206 | default: |
| 207 | return false; |
| 208 | case ParenExprClass: |
| 209 | return cast<ParenExpr>(this)->getSubExpr()->hasLocalSideEffect(); |
| 210 | case UnaryOperatorClass: { |
| 211 | const UnaryOperator *UO = cast<UnaryOperator>(this); |
| 212 | |
| 213 | switch (UO->getOpcode()) { |
| 214 | default: return false; |
| 215 | case UnaryOperator::PostInc: |
| 216 | case UnaryOperator::PostDec: |
| 217 | case UnaryOperator::PreInc: |
| 218 | case UnaryOperator::PreDec: |
| 219 | return true; // ++/-- |
| 220 | |
| 221 | case UnaryOperator::Deref: |
| 222 | // Dereferencing a volatile pointer is a side-effect. |
| 223 | return getType().isVolatileQualified(); |
| 224 | case UnaryOperator::Real: |
| 225 | case UnaryOperator::Imag: |
| 226 | // accessing a piece of a volatile complex is a side-effect. |
| 227 | return UO->getSubExpr()->getType().isVolatileQualified(); |
| 228 | |
| 229 | case UnaryOperator::Extension: |
| 230 | return UO->getSubExpr()->hasLocalSideEffect(); |
| 231 | } |
| 232 | } |
| 233 | case BinaryOperatorClass: |
| 234 | return cast<BinaryOperator>(this)->isAssignmentOp(); |
Chris Lattner | 06078d2 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 235 | case CompoundAssignOperatorClass: |
Chris Lattner | 9c0da3b | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 236 | return true; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 237 | |
| 238 | case MemberExprClass: |
| 239 | case ArraySubscriptExprClass: |
| 240 | // If the base pointer or element is to a volatile pointer/field, accessing |
| 241 | // if is a side effect. |
| 242 | return getType().isVolatileQualified(); |
| 243 | |
| 244 | case CallExprClass: |
| 245 | // TODO: check attributes for pure/const. "void foo() { strlen("bar"); }" |
| 246 | // should warn. |
| 247 | return true; |
| 248 | |
| 249 | case CastExprClass: |
| 250 | // If this is a cast to void, check the operand. Otherwise, the result of |
| 251 | // the cast is unused. |
| 252 | if (getType()->isVoidType()) |
| 253 | return cast<CastExpr>(this)->getSubExpr()->hasLocalSideEffect(); |
| 254 | return false; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an |
| 259 | /// incomplete type other than void. Nonarray expressions that can be lvalues: |
| 260 | /// - name, where name must be a variable |
| 261 | /// - e[i] |
| 262 | /// - (e), where e must be an lvalue |
| 263 | /// - e.name, where e must be an lvalue |
| 264 | /// - e->name |
| 265 | /// - *e, the type of e cannot be a function type |
| 266 | /// - string-constant |
| 267 | /// - reference type [C++ [expr]] |
| 268 | /// |
| 269 | Expr::isLvalueResult Expr::isLvalue() const { |
| 270 | // first, check the type (C99 6.3.2.1) |
| 271 | if (TR->isFunctionType()) // from isObjectType() |
| 272 | return LV_NotObjectType; |
| 273 | |
| 274 | if (TR->isVoidType()) |
| 275 | return LV_IncompleteVoidType; |
| 276 | |
| 277 | if (TR->isReferenceType()) // C++ [expr] |
| 278 | return LV_Valid; |
| 279 | |
| 280 | // the type looks fine, now check the expression |
| 281 | switch (getStmtClass()) { |
| 282 | case StringLiteralClass: // C99 6.5.1p4 |
| 283 | case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) |
| 284 | // For vectors, make sure base is an lvalue (i.e. not a function call). |
| 285 | if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType()) |
| 286 | return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(); |
| 287 | return LV_Valid; |
| 288 | case DeclRefExprClass: // C99 6.5.1p2 |
| 289 | if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl())) |
| 290 | return LV_Valid; |
| 291 | break; |
| 292 | case MemberExprClass: { // C99 6.5.2.3p4 |
| 293 | const MemberExpr *m = cast<MemberExpr>(this); |
| 294 | return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(); |
| 295 | } |
| 296 | case UnaryOperatorClass: // C99 6.5.3p4 |
| 297 | if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref) |
| 298 | return LV_Valid; |
| 299 | break; |
| 300 | case ParenExprClass: // C99 6.5.1p5 |
| 301 | return cast<ParenExpr>(this)->getSubExpr()->isLvalue(); |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 302 | case OCUVectorElementExprClass: |
| 303 | if (cast<OCUVectorElementExpr>(this)->containsDuplicateElements()) |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 304 | return LV_DuplicateVectorComponents; |
| 305 | return LV_Valid; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 306 | default: |
| 307 | break; |
| 308 | } |
| 309 | return LV_InvalidExpression; |
| 310 | } |
| 311 | |
| 312 | /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, |
| 313 | /// does not have an incomplete type, does not have a const-qualified type, and |
| 314 | /// if it is a structure or union, does not have any member (including, |
| 315 | /// recursively, any member or element of all contained aggregates or unions) |
| 316 | /// with a const-qualified type. |
| 317 | Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { |
| 318 | isLvalueResult lvalResult = isLvalue(); |
| 319 | |
| 320 | switch (lvalResult) { |
| 321 | case LV_Valid: break; |
| 322 | case LV_NotObjectType: return MLV_NotObjectType; |
| 323 | case LV_IncompleteVoidType: return MLV_IncompleteVoidType; |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 324 | case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 325 | case LV_InvalidExpression: return MLV_InvalidExpression; |
| 326 | } |
| 327 | if (TR.isConstQualified()) |
| 328 | return MLV_ConstQualified; |
| 329 | if (TR->isArrayType()) |
| 330 | return MLV_ArrayType; |
| 331 | if (TR->isIncompleteType()) |
| 332 | return MLV_IncompleteType; |
| 333 | |
| 334 | if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) { |
| 335 | if (r->hasConstFields()) |
| 336 | return MLV_ConstQualified; |
| 337 | } |
| 338 | return MLV_Valid; |
| 339 | } |
| 340 | |
| 341 | /// isIntegerConstantExpr - this recursive routine will test if an expression is |
| 342 | /// an integer constant expression. Note: With the introduction of VLA's in |
| 343 | /// C99 the result of the sizeof operator is no longer always a constant |
| 344 | /// expression. The generalization of the wording to include any subexpression |
| 345 | /// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions |
| 346 | /// can appear as operands to other operators (e.g. &&, ||, ?:). For instance, |
| 347 | /// "0 || f()" can be treated as a constant expression. In C90 this expression, |
| 348 | /// occurring in a context requiring a constant, would have been a constraint |
| 349 | /// violation. FIXME: This routine currently implements C90 semantics. |
| 350 | /// To properly implement C99 semantics this routine will need to evaluate |
| 351 | /// expressions involving operators previously mentioned. |
| 352 | |
| 353 | /// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero, |
| 354 | /// comma, etc |
| 355 | /// |
| 356 | /// FIXME: This should ext-warn on overflow during evaluation! ISO C does not |
| 357 | /// permit this. |
| 358 | /// |
| 359 | /// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof |
| 360 | /// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer |
| 361 | /// cast+dereference. |
| 362 | bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, |
| 363 | SourceLocation *Loc, bool isEvaluated) const { |
| 364 | switch (getStmtClass()) { |
| 365 | default: |
| 366 | if (Loc) *Loc = getLocStart(); |
| 367 | return false; |
| 368 | case ParenExprClass: |
| 369 | return cast<ParenExpr>(this)->getSubExpr()-> |
| 370 | isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated); |
| 371 | case IntegerLiteralClass: |
| 372 | Result = cast<IntegerLiteral>(this)->getValue(); |
| 373 | break; |
| 374 | case CharacterLiteralClass: { |
| 375 | const CharacterLiteral *CL = cast<CharacterLiteral>(this); |
| 376 | Result.zextOrTrunc(Ctx.getTypeSize(getType(), CL->getLoc())); |
| 377 | Result = CL->getValue(); |
| 378 | Result.setIsUnsigned(!getType()->isSignedIntegerType()); |
| 379 | break; |
| 380 | } |
Steve Naroff | c6f0fd3 | 2007-08-02 04:09:23 +0000 | [diff] [blame] | 381 | case TypesCompatibleExprClass: { |
| 382 | const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this); |
| 383 | Result.zextOrTrunc(Ctx.getTypeSize(getType(), TCE->getLocStart())); |
| 384 | Result = TCE->typesAreCompatible(); |
Steve Naroff | 1200b5a | 2007-08-02 00:13:27 +0000 | [diff] [blame] | 385 | break; |
Steve Naroff | c6f0fd3 | 2007-08-02 04:09:23 +0000 | [diff] [blame] | 386 | } |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 387 | case CallExprClass: { |
| 388 | const CallExpr *CE = cast<CallExpr>(this); |
| 389 | Result.zextOrTrunc(Ctx.getTypeSize(getType(), CE->getLocStart())); |
| 390 | if (CE->isBuiltinClassifyType(Result)) |
| 391 | break; |
| 392 | if (Loc) *Loc = getLocStart(); |
| 393 | return false; |
| 394 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 395 | case DeclRefExprClass: |
| 396 | if (const EnumConstantDecl *D = |
| 397 | dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) { |
| 398 | Result = D->getInitVal(); |
| 399 | break; |
| 400 | } |
| 401 | if (Loc) *Loc = getLocStart(); |
| 402 | return false; |
| 403 | case UnaryOperatorClass: { |
| 404 | const UnaryOperator *Exp = cast<UnaryOperator>(this); |
| 405 | |
| 406 | // Get the operand value. If this is sizeof/alignof, do not evalute the |
| 407 | // operand. This affects C99 6.6p3. |
Chris Lattner | 5a9b624 | 2007-08-23 21:42:50 +0000 | [diff] [blame] | 408 | if (!Exp->isSizeOfAlignOfOp() && |
| 409 | !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 410 | return false; |
| 411 | |
| 412 | switch (Exp->getOpcode()) { |
| 413 | // Address, indirect, pre/post inc/dec, etc are not valid constant exprs. |
| 414 | // See C99 6.6p3. |
| 415 | default: |
| 416 | if (Loc) *Loc = Exp->getOperatorLoc(); |
| 417 | return false; |
| 418 | case UnaryOperator::Extension: |
| 419 | return true; // FIXME: this is wrong. |
| 420 | case UnaryOperator::SizeOf: |
| 421 | case UnaryOperator::AlignOf: |
| 422 | // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. |
| 423 | if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc)) |
| 424 | return false; |
| 425 | |
| 426 | // Return the result in the right width. |
| 427 | Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())); |
| 428 | |
| 429 | // Get information about the size or align. |
| 430 | if (Exp->getOpcode() == UnaryOperator::SizeOf) |
| 431 | Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(), |
| 432 | Exp->getOperatorLoc()); |
| 433 | else |
| 434 | Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(), |
| 435 | Exp->getOperatorLoc()); |
| 436 | break; |
| 437 | case UnaryOperator::LNot: { |
| 438 | bool Val = Result != 0; |
| 439 | Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())); |
| 440 | Result = Val; |
| 441 | break; |
| 442 | } |
| 443 | case UnaryOperator::Plus: |
| 444 | break; |
| 445 | case UnaryOperator::Minus: |
| 446 | Result = -Result; |
| 447 | break; |
| 448 | case UnaryOperator::Not: |
| 449 | Result = ~Result; |
| 450 | break; |
| 451 | } |
| 452 | break; |
| 453 | } |
| 454 | case SizeOfAlignOfTypeExprClass: { |
| 455 | const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); |
| 456 | // alignof always evaluates to a constant. |
| 457 | if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc)) |
| 458 | return false; |
| 459 | |
| 460 | // Return the result in the right width. |
| 461 | Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())); |
| 462 | |
| 463 | // Get information about the size or align. |
| 464 | if (Exp->isSizeOf()) |
| 465 | Result = Ctx.getTypeSize(Exp->getArgumentType(), Exp->getOperatorLoc()); |
| 466 | else |
| 467 | Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc()); |
| 468 | break; |
| 469 | } |
| 470 | case BinaryOperatorClass: { |
| 471 | const BinaryOperator *Exp = cast<BinaryOperator>(this); |
| 472 | |
| 473 | // The LHS of a constant expr is always evaluated and needed. |
| 474 | if (!Exp->getLHS()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 475 | return false; |
| 476 | |
| 477 | llvm::APSInt RHS(Result); |
| 478 | |
| 479 | // The short-circuiting &&/|| operators don't necessarily evaluate their |
| 480 | // RHS. Make sure to pass isEvaluated down correctly. |
| 481 | if (Exp->isLogicalOp()) { |
| 482 | bool RHSEval; |
| 483 | if (Exp->getOpcode() == BinaryOperator::LAnd) |
| 484 | RHSEval = Result != 0; |
| 485 | else { |
| 486 | assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical"); |
| 487 | RHSEval = Result == 0; |
| 488 | } |
| 489 | |
| 490 | if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, |
| 491 | isEvaluated & RHSEval)) |
| 492 | return false; |
| 493 | } else { |
| 494 | if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated)) |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | switch (Exp->getOpcode()) { |
| 499 | default: |
| 500 | if (Loc) *Loc = getLocStart(); |
| 501 | return false; |
| 502 | case BinaryOperator::Mul: |
| 503 | Result *= RHS; |
| 504 | break; |
| 505 | case BinaryOperator::Div: |
| 506 | if (RHS == 0) { |
| 507 | if (!isEvaluated) break; |
| 508 | if (Loc) *Loc = getLocStart(); |
| 509 | return false; |
| 510 | } |
| 511 | Result /= RHS; |
| 512 | break; |
| 513 | case BinaryOperator::Rem: |
| 514 | if (RHS == 0) { |
| 515 | if (!isEvaluated) break; |
| 516 | if (Loc) *Loc = getLocStart(); |
| 517 | return false; |
| 518 | } |
| 519 | Result %= RHS; |
| 520 | break; |
| 521 | case BinaryOperator::Add: Result += RHS; break; |
| 522 | case BinaryOperator::Sub: Result -= RHS; break; |
| 523 | case BinaryOperator::Shl: |
| 524 | Result <<= RHS.getLimitedValue(Result.getBitWidth()-1); |
| 525 | break; |
| 526 | case BinaryOperator::Shr: |
| 527 | Result >>= RHS.getLimitedValue(Result.getBitWidth()-1); |
| 528 | break; |
| 529 | case BinaryOperator::LT: Result = Result < RHS; break; |
| 530 | case BinaryOperator::GT: Result = Result > RHS; break; |
| 531 | case BinaryOperator::LE: Result = Result <= RHS; break; |
| 532 | case BinaryOperator::GE: Result = Result >= RHS; break; |
| 533 | case BinaryOperator::EQ: Result = Result == RHS; break; |
| 534 | case BinaryOperator::NE: Result = Result != RHS; break; |
| 535 | case BinaryOperator::And: Result &= RHS; break; |
| 536 | case BinaryOperator::Xor: Result ^= RHS; break; |
| 537 | case BinaryOperator::Or: Result |= RHS; break; |
| 538 | case BinaryOperator::LAnd: |
| 539 | Result = Result != 0 && RHS != 0; |
| 540 | break; |
| 541 | case BinaryOperator::LOr: |
| 542 | Result = Result != 0 || RHS != 0; |
| 543 | break; |
| 544 | |
| 545 | case BinaryOperator::Comma: |
| 546 | // C99 6.6p3: "shall not contain assignment, ..., or comma operators, |
| 547 | // *except* when they are contained within a subexpression that is not |
| 548 | // evaluated". Note that Assignment can never happen due to constraints |
| 549 | // on the LHS subexpr, so we don't need to check it here. |
| 550 | if (isEvaluated) { |
| 551 | if (Loc) *Loc = getLocStart(); |
| 552 | return false; |
| 553 | } |
| 554 | |
| 555 | // The result of the constant expr is the RHS. |
| 556 | Result = RHS; |
| 557 | return true; |
| 558 | } |
| 559 | |
| 560 | assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!"); |
| 561 | break; |
| 562 | } |
| 563 | case ImplicitCastExprClass: |
| 564 | case CastExprClass: { |
| 565 | const Expr *SubExpr; |
| 566 | SourceLocation CastLoc; |
| 567 | if (const CastExpr *C = dyn_cast<CastExpr>(this)) { |
| 568 | SubExpr = C->getSubExpr(); |
| 569 | CastLoc = C->getLParenLoc(); |
| 570 | } else { |
| 571 | SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr(); |
| 572 | CastLoc = getLocStart(); |
| 573 | } |
| 574 | |
| 575 | // C99 6.6p6: shall only convert arithmetic types to integer types. |
| 576 | if (!SubExpr->getType()->isArithmeticType() || |
| 577 | !getType()->isIntegerType()) { |
| 578 | if (Loc) *Loc = SubExpr->getLocStart(); |
| 579 | return false; |
| 580 | } |
| 581 | |
| 582 | // Handle simple integer->integer casts. |
| 583 | if (SubExpr->getType()->isIntegerType()) { |
| 584 | if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 585 | return false; |
| 586 | |
| 587 | // Figure out if this is a truncate, extend or noop cast. |
| 588 | unsigned DestWidth = Ctx.getTypeSize(getType(), CastLoc); |
| 589 | |
| 590 | // If the input is signed, do a sign extend, noop, or truncate. |
| 591 | if (SubExpr->getType()->isSignedIntegerType()) |
| 592 | Result.sextOrTrunc(DestWidth); |
| 593 | else // If the input is unsigned, do a zero extend, noop, or truncate. |
| 594 | Result.zextOrTrunc(DestWidth); |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | // Allow floating constants that are the immediate operands of casts or that |
| 599 | // are parenthesized. |
| 600 | const Expr *Operand = SubExpr; |
| 601 | while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand)) |
| 602 | Operand = PE->getSubExpr(); |
| 603 | |
| 604 | if (const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand)) { |
| 605 | // FIXME: Evaluate this correctly! |
| 606 | Result = (int)FL->getValue(); |
| 607 | break; |
| 608 | } |
| 609 | if (Loc) *Loc = Operand->getLocStart(); |
| 610 | return false; |
| 611 | } |
| 612 | case ConditionalOperatorClass: { |
| 613 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
| 614 | |
| 615 | if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 616 | return false; |
| 617 | |
| 618 | const Expr *TrueExp = Exp->getLHS(); |
| 619 | const Expr *FalseExp = Exp->getRHS(); |
| 620 | if (Result == 0) std::swap(TrueExp, FalseExp); |
| 621 | |
| 622 | // Evaluate the false one first, discard the result. |
| 623 | if (!FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false)) |
| 624 | return false; |
| 625 | // Evalute the true one, capture the result. |
| 626 | if (!TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated)) |
| 627 | return false; |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | // Cases that are valid constant exprs fall through to here. |
| 633 | Result.setIsUnsigned(getType()->isUnsignedIntegerType()); |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an |
| 639 | /// integer constant expression with the value zero, or if this is one that is |
| 640 | /// cast to void*. |
| 641 | bool Expr::isNullPointerConstant(ASTContext &Ctx) const { |
| 642 | // Strip off a cast to void*, if it exists. |
| 643 | if (const CastExpr *CE = dyn_cast<CastExpr>(this)) { |
| 644 | // Check that it is a cast to void*. |
| 645 | if (const PointerType *PT = dyn_cast<PointerType>(CE->getType())) { |
| 646 | QualType Pointee = PT->getPointeeType(); |
| 647 | if (Pointee.getQualifiers() == 0 && Pointee->isVoidType() && // to void* |
| 648 | CE->getSubExpr()->getType()->isIntegerType()) // from int. |
| 649 | return CE->getSubExpr()->isNullPointerConstant(Ctx); |
| 650 | } |
Steve Naroff | 1d6b247 | 2007-08-28 21:20:34 +0000 | [diff] [blame] | 651 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { |
Steve Naroff | 3d05287 | 2007-08-29 00:00:02 +0000 | [diff] [blame] | 652 | // Ignore the ImplicitCastExpr type entirely. |
| 653 | return ICE->getSubExpr()->isNullPointerConstant(Ctx); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 654 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { |
| 655 | // Accept ((void*)0) as a null pointer constant, as many other |
| 656 | // implementations do. |
| 657 | return PE->getSubExpr()->isNullPointerConstant(Ctx); |
| 658 | } |
| 659 | |
| 660 | // This expression must be an integer type. |
| 661 | if (!getType()->isIntegerType()) |
| 662 | return false; |
| 663 | |
| 664 | // If we have an integer constant expression, we need to *evaluate* it and |
| 665 | // test for the value 0. |
| 666 | llvm::APSInt Val(32); |
| 667 | return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0; |
| 668 | } |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 669 | |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 670 | unsigned OCUVectorElementExpr::getNumElements() const { |
Chris Lattner | 5054785 | 2007-08-03 16:00:20 +0000 | [diff] [blame] | 671 | return strlen(Accessor.getName()); |
| 672 | } |
| 673 | |
| 674 | |
Chris Lattner | f4bf551 | 2007-08-02 21:47:28 +0000 | [diff] [blame] | 675 | /// getComponentType - Determine whether the components of this access are |
| 676 | /// "point" "color" or "texture" elements. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 677 | OCUVectorElementExpr::ElementType |
| 678 | OCUVectorElementExpr::getElementType() const { |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 679 | // derive the component type, no need to waste space. |
| 680 | const char *compStr = Accessor.getName(); |
Chris Lattner | abf25b3 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 681 | |
Chris Lattner | 9096b79 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 682 | if (OCUVectorType::getPointAccessorIdx(*compStr) != -1) return Point; |
| 683 | if (OCUVectorType::getColorAccessorIdx(*compStr) != -1) return Color; |
Chris Lattner | abf25b3 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 684 | |
Chris Lattner | 9096b79 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 685 | assert(OCUVectorType::getTextureAccessorIdx(*compStr) != -1 && |
Chris Lattner | abf25b3 | 2007-08-02 22:20:00 +0000 | [diff] [blame] | 686 | "getComponentType(): Illegal accessor"); |
| 687 | return Texture; |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 688 | } |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 689 | |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 690 | /// containsDuplicateElements - Return true if any element access is |
Chris Lattner | f4bf551 | 2007-08-02 21:47:28 +0000 | [diff] [blame] | 691 | /// repeated. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 692 | bool OCUVectorElementExpr::containsDuplicateElements() const { |
Steve Naroff | ba67f69 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 693 | const char *compStr = Accessor.getName(); |
| 694 | unsigned length = strlen(compStr); |
| 695 | |
| 696 | for (unsigned i = 0; i < length-1; i++) { |
| 697 | const char *s = compStr+i; |
| 698 | for (const char c = *s++; *s; s++) |
| 699 | if (c == *s) |
| 700 | return true; |
| 701 | } |
| 702 | return false; |
| 703 | } |
Chris Lattner | 42158e7 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 704 | |
| 705 | /// getEncodedElementAccess - We encode fields with two bits per component. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 706 | unsigned OCUVectorElementExpr::getEncodedElementAccess() const { |
Chris Lattner | 42158e7 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 707 | const char *compStr = Accessor.getName(); |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 708 | unsigned length = getNumElements(); |
Chris Lattner | 42158e7 | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 709 | |
| 710 | unsigned Result = 0; |
| 711 | |
| 712 | while (length--) { |
| 713 | Result <<= 2; |
| 714 | int Idx = OCUVectorType::getAccessorIdx(compStr[length]); |
| 715 | assert(Idx != -1 && "Invalid accessor letter"); |
| 716 | Result |= Idx; |
| 717 | } |
| 718 | return Result; |
| 719 | } |
| 720 | |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 721 | //===----------------------------------------------------------------------===// |
| 722 | // Child Iterators for iterating over subexpressions/substatements |
| 723 | //===----------------------------------------------------------------------===// |
| 724 | |
| 725 | // DeclRefExpr |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 726 | Stmt::child_iterator DeclRefExpr::child_begin() { return NULL; } |
| 727 | Stmt::child_iterator DeclRefExpr::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 728 | |
| 729 | // PreDefinedExpr |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 730 | Stmt::child_iterator PreDefinedExpr::child_begin() { return NULL; } |
| 731 | Stmt::child_iterator PreDefinedExpr::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 732 | |
| 733 | // IntegerLiteral |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 734 | Stmt::child_iterator IntegerLiteral::child_begin() { return NULL; } |
| 735 | Stmt::child_iterator IntegerLiteral::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 736 | |
| 737 | // CharacterLiteral |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 738 | Stmt::child_iterator CharacterLiteral::child_begin() { return NULL; } |
| 739 | Stmt::child_iterator CharacterLiteral::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 740 | |
| 741 | // FloatingLiteral |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 742 | Stmt::child_iterator FloatingLiteral::child_begin() { return NULL; } |
| 743 | Stmt::child_iterator FloatingLiteral::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 744 | |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 745 | // ImaginaryLiteral |
| 746 | Stmt::child_iterator ImaginaryLiteral::child_begin() { |
| 747 | return reinterpret_cast<Stmt**>(&Val); |
| 748 | } |
| 749 | Stmt::child_iterator ImaginaryLiteral::child_end() { |
| 750 | return reinterpret_cast<Stmt**>(&Val)+1; |
| 751 | } |
| 752 | |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 753 | // StringLiteral |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 754 | Stmt::child_iterator StringLiteral::child_begin() { return NULL; } |
| 755 | Stmt::child_iterator StringLiteral::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 756 | |
| 757 | // ParenExpr |
| 758 | Stmt::child_iterator ParenExpr::child_begin() { |
| 759 | return reinterpret_cast<Stmt**>(&Val); |
| 760 | } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 761 | Stmt::child_iterator ParenExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 762 | return reinterpret_cast<Stmt**>(&Val)+1; |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // UnaryOperator |
| 766 | Stmt::child_iterator UnaryOperator::child_begin() { |
| 767 | return reinterpret_cast<Stmt**>(&Val); |
| 768 | } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 769 | Stmt::child_iterator UnaryOperator::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 770 | return reinterpret_cast<Stmt**>(&Val)+1; |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | // SizeOfAlignOfTypeExpr |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 774 | Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() { return NULL; } |
| 775 | Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() { return NULL; } |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 776 | |
| 777 | // ArraySubscriptExpr |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 778 | Stmt::child_iterator ArraySubscriptExpr::child_begin() { |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 779 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 780 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 781 | Stmt::child_iterator ArraySubscriptExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 782 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // CallExpr |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 786 | Stmt::child_iterator CallExpr::child_begin() { |
Ted Kremenek | 15ede50 | 2007-08-27 21:11:44 +0000 | [diff] [blame] | 787 | return reinterpret_cast<Stmt**>(&SubExprs[0]); |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 788 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 789 | Stmt::child_iterator CallExpr::child_end() { |
Ted Kremenek | 15ede50 | 2007-08-27 21:11:44 +0000 | [diff] [blame] | 790 | return reinterpret_cast<Stmt**>(&SubExprs[NumArgs+ARGS_START]); |
Ted Kremenek | e4acb9c | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 791 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 792 | |
| 793 | // MemberExpr |
| 794 | Stmt::child_iterator MemberExpr::child_begin() { |
| 795 | return reinterpret_cast<Stmt**>(&Base); |
| 796 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 797 | Stmt::child_iterator MemberExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 798 | return reinterpret_cast<Stmt**>(&Base)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | // OCUVectorElementExpr |
| 802 | Stmt::child_iterator OCUVectorElementExpr::child_begin() { |
| 803 | return reinterpret_cast<Stmt**>(&Base); |
| 804 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 805 | Stmt::child_iterator OCUVectorElementExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 806 | return reinterpret_cast<Stmt**>(&Base)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | // CompoundLiteralExpr |
| 810 | Stmt::child_iterator CompoundLiteralExpr::child_begin() { |
| 811 | return reinterpret_cast<Stmt**>(&Init); |
| 812 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 813 | Stmt::child_iterator CompoundLiteralExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 814 | return reinterpret_cast<Stmt**>(&Init)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // ImplicitCastExpr |
| 818 | Stmt::child_iterator ImplicitCastExpr::child_begin() { |
| 819 | return reinterpret_cast<Stmt**>(&Op); |
| 820 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 821 | Stmt::child_iterator ImplicitCastExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 822 | return reinterpret_cast<Stmt**>(&Op)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | // CastExpr |
| 826 | Stmt::child_iterator CastExpr::child_begin() { |
| 827 | return reinterpret_cast<Stmt**>(&Op); |
| 828 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 829 | Stmt::child_iterator CastExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 830 | return reinterpret_cast<Stmt**>(&Op)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | // BinaryOperator |
| 834 | Stmt::child_iterator BinaryOperator::child_begin() { |
| 835 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 836 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 837 | Stmt::child_iterator BinaryOperator::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 838 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | // ConditionalOperator |
| 842 | Stmt::child_iterator ConditionalOperator::child_begin() { |
| 843 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 844 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 845 | Stmt::child_iterator ConditionalOperator::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 846 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | // AddrLabelExpr |
| 850 | Stmt::child_iterator AddrLabelExpr::child_begin() { return NULL; } |
| 851 | Stmt::child_iterator AddrLabelExpr::child_end() { return NULL; } |
| 852 | |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 853 | // StmtExpr |
| 854 | Stmt::child_iterator StmtExpr::child_begin() { |
| 855 | return reinterpret_cast<Stmt**>(&SubStmt); |
| 856 | } |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 857 | Stmt::child_iterator StmtExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 858 | return reinterpret_cast<Stmt**>(&SubStmt)+1; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | // TypesCompatibleExpr |
| 862 | Stmt::child_iterator TypesCompatibleExpr::child_begin() { return NULL; } |
| 863 | Stmt::child_iterator TypesCompatibleExpr::child_end() { return NULL; } |
| 864 | |
| 865 | // ChooseExpr |
| 866 | Stmt::child_iterator ChooseExpr::child_begin() { |
| 867 | return reinterpret_cast<Stmt**>(&SubExprs); |
| 868 | } |
| 869 | |
| 870 | Stmt::child_iterator ChooseExpr::child_end() { |
Chris Lattner | 1de66eb | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 871 | return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR; |
Ted Kremenek | 9fdc8a9 | 2007-08-24 20:06:47 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | // ObjCStringLiteral |
| 875 | Stmt::child_iterator ObjCStringLiteral::child_begin() { return NULL; } |
| 876 | Stmt::child_iterator ObjCStringLiteral::child_end() { return NULL; } |
| 877 | |
| 878 | // ObjCEncodeExpr |
| 879 | Stmt::child_iterator ObjCEncodeExpr::child_begin() { return NULL; } |
| 880 | Stmt::child_iterator ObjCEncodeExpr::child_end() { return NULL; } |
| 881 | |