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