| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
| Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This file implements the Expr class and subclasses. | 
|  | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
| Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 14 | #include "clang/AST/Expr.h" | 
| Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 15 | #include "clang/AST/ExprCXX.h" | 
| Chris Lattner | a4d55d8 | 2008-10-06 06:40:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/APValue.h" | 
| Chris Lattner | 2eadfb6 | 2007-07-15 23:32:58 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" | 
| Chris Lattner | a4d55d8 | 2008-10-06 06:40:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" | 
| Douglas Gregor | 98cd599 | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" | 
| Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" | 
| Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 21 | #include "clang/AST/RecordLayout.h" | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtVisitor.h" | 
| Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 23 | #include "clang/Lex/LiteralSupport.h" | 
|  | 24 | #include "clang/Lex/Lexer.h" | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 25 | #include "clang/Sema/SemaDiagnostic.h" | 
| Chris Lattner | 1b63e4f | 2009-06-14 01:54:56 +0000 | [diff] [blame] | 26 | #include "clang/Basic/Builtins.h" | 
| Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 27 | #include "clang/Basic/SourceManager.h" | 
| Chris Lattner | da5a6b6 | 2007-11-27 18:22:04 +0000 | [diff] [blame] | 28 | #include "clang/Basic/TargetInfo.h" | 
| Douglas Gregor | cf3293e | 2009-11-01 20:32:48 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 31 | #include <algorithm> | 
| Eli Friedman | 64f45a2 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 32 | #include <cstring> | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 33 | using namespace clang; | 
|  | 34 |  | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 35 | /// isKnownToHaveBooleanValue - Return true if this is an integer expression | 
|  | 36 | /// that is known to return 0 or 1.  This happens for _Bool/bool expressions | 
|  | 37 | /// but also int expressions which are produced by things like comparisons in | 
|  | 38 | /// C. | 
|  | 39 | bool Expr::isKnownToHaveBooleanValue() const { | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 40 | const Expr *E = IgnoreParens(); | 
|  | 41 |  | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 42 | // If this value has _Bool type, it is obvious 0/1. | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 43 | if (E->getType()->isBooleanType()) return true; | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 44 | // If this is a non-scalar-integer type, we don't care enough to try. | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 45 | if (!E->getType()->isIntegralOrEnumerationType()) return false; | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 46 |  | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 47 | if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 48 | switch (UO->getOpcode()) { | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 49 | case UO_Plus: | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 50 | return UO->getSubExpr()->isKnownToHaveBooleanValue(); | 
|  | 51 | default: | 
|  | 52 | return false; | 
|  | 53 | } | 
|  | 54 | } | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 55 |  | 
| John McCall | 6907fbe | 2010-06-12 01:56:02 +0000 | [diff] [blame] | 56 | // Only look through implicit casts.  If the user writes | 
|  | 57 | // '(int) (a && b)' treat it as an arbitrary int. | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 58 | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 59 | return CE->getSubExpr()->isKnownToHaveBooleanValue(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 60 |  | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 61 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 62 | switch (BO->getOpcode()) { | 
|  | 63 | default: return false; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 64 | case BO_LT:   // Relational operators. | 
|  | 65 | case BO_GT: | 
|  | 66 | case BO_LE: | 
|  | 67 | case BO_GE: | 
|  | 68 | case BO_EQ:   // Equality operators. | 
|  | 69 | case BO_NE: | 
|  | 70 | case BO_LAnd: // AND operator. | 
|  | 71 | case BO_LOr:  // Logical OR operator. | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 72 | return true; | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 73 |  | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 74 | case BO_And:  // Bitwise AND operator. | 
|  | 75 | case BO_Xor:  // Bitwise XOR operator. | 
|  | 76 | case BO_Or:   // Bitwise OR operator. | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 77 | // Handle things like (x==2)|(y==12). | 
|  | 78 | return BO->getLHS()->isKnownToHaveBooleanValue() && | 
|  | 79 | BO->getRHS()->isKnownToHaveBooleanValue(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 80 |  | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 81 | case BO_Comma: | 
|  | 82 | case BO_Assign: | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 83 | return BO->getRHS()->isKnownToHaveBooleanValue(); | 
|  | 84 | } | 
|  | 85 | } | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 86 |  | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 87 | if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 88 | return CO->getTrueExpr()->isKnownToHaveBooleanValue() && | 
|  | 89 | CO->getFalseExpr()->isKnownToHaveBooleanValue(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 90 |  | 
| Chris Lattner | 2b334bb | 2010-04-16 23:34:13 +0000 | [diff] [blame] | 91 | return false; | 
|  | 92 | } | 
|  | 93 |  | 
| John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 94 | // Amusing macro metaprogramming hack: check whether a class provides | 
|  | 95 | // a more specific implementation of getExprLoc(). | 
|  | 96 | namespace { | 
|  | 97 | /// This implementation is used when a class provides a custom | 
|  | 98 | /// implementation of getExprLoc. | 
|  | 99 | template <class E, class T> | 
|  | 100 | SourceLocation getExprLocImpl(const Expr *expr, | 
|  | 101 | SourceLocation (T::*v)() const) { | 
|  | 102 | return static_cast<const E*>(expr)->getExprLoc(); | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | /// This implementation is used when a class doesn't provide | 
|  | 106 | /// a custom implementation of getExprLoc.  Overload resolution | 
|  | 107 | /// should pick it over the implementation above because it's | 
|  | 108 | /// more specialized according to function template partial ordering. | 
|  | 109 | template <class E> | 
|  | 110 | SourceLocation getExprLocImpl(const Expr *expr, | 
|  | 111 | SourceLocation (Expr::*v)() const) { | 
|  | 112 | return static_cast<const E*>(expr)->getSourceRange().getBegin(); | 
|  | 113 | } | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | SourceLocation Expr::getExprLoc() const { | 
|  | 117 | switch (getStmtClass()) { | 
|  | 118 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); | 
|  | 119 | #define ABSTRACT_STMT(type) | 
|  | 120 | #define STMT(type, base) \ | 
|  | 121 | case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; | 
|  | 122 | #define EXPR(type, base) \ | 
|  | 123 | case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); | 
|  | 124 | #include "clang/AST/StmtNodes.inc" | 
|  | 125 | } | 
|  | 126 | llvm_unreachable("unknown statement kind"); | 
|  | 127 | return SourceLocation(); | 
|  | 128 | } | 
|  | 129 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 130 | //===----------------------------------------------------------------------===// | 
|  | 131 | // Primary Expressions. | 
|  | 132 | //===----------------------------------------------------------------------===// | 
|  | 133 |  | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 134 | /// \brief Compute the type-, value-, and instantiation-dependence of a | 
|  | 135 | /// declaration reference | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 136 | /// based on the declaration being referenced. | 
|  | 137 | static void computeDeclRefDependence(NamedDecl *D, QualType T, | 
|  | 138 | bool &TypeDependent, | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 139 | bool &ValueDependent, | 
|  | 140 | bool &InstantiationDependent) { | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 141 | TypeDependent = false; | 
|  | 142 | ValueDependent = false; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 143 | InstantiationDependent = false; | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 144 |  | 
|  | 145 | // (TD) C++ [temp.dep.expr]p3: | 
|  | 146 | //   An id-expression is type-dependent if it contains: | 
|  | 147 | // | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 148 | // and | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 149 | // | 
|  | 150 | // (VD) C++ [temp.dep.constexpr]p2: | 
|  | 151 | //  An identifier is value-dependent if it is: | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 152 |  | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 153 | //  (TD)  - an identifier that was declared with dependent type | 
|  | 154 | //  (VD)  - a name declared with a dependent type, | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 155 | if (T->isDependentType()) { | 
|  | 156 | TypeDependent = true; | 
|  | 157 | ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 158 | InstantiationDependent = true; | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 159 | return; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 160 | } else if (T->isInstantiationDependentType()) { | 
|  | 161 | InstantiationDependent = true; | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 162 | } | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 163 |  | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 164 | //  (TD)  - a conversion-function-id that specifies a dependent type | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 165 | if (D->getDeclName().getNameKind() | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 166 | == DeclarationName::CXXConversionFunctionName) { | 
|  | 167 | QualType T = D->getDeclName().getCXXNameType(); | 
|  | 168 | if (T->isDependentType()) { | 
|  | 169 | TypeDependent = true; | 
|  | 170 | ValueDependent = true; | 
|  | 171 | InstantiationDependent = true; | 
|  | 172 | return; | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | if (T->isInstantiationDependentType()) | 
|  | 176 | InstantiationDependent = true; | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 177 | } | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 178 |  | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 179 | //  (VD)  - the name of a non-type template parameter, | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 180 | if (isa<NonTypeTemplateParmDecl>(D)) { | 
|  | 181 | ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 182 | InstantiationDependent = true; | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 183 | return; | 
|  | 184 | } | 
|  | 185 |  | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 186 | //  (VD) - a constant with integral or enumeration type and is | 
|  | 187 | //         initialized with an expression that is value-dependent. | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 188 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) { | 
| Douglas Gregor | 2ade35e | 2010-06-16 00:17:44 +0000 | [diff] [blame] | 189 | if (Var->getType()->isIntegralOrEnumerationType() && | 
| Douglas Gregor | 501edb6 | 2010-01-15 16:21:02 +0000 | [diff] [blame] | 190 | Var->getType().getCVRQualifiers() == Qualifiers::Const) { | 
| Sebastian Redl | 31310a2 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 191 | if (const Expr *Init = Var->getAnyInitializer()) | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 192 | if (Init->isValueDependent()) { | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 193 | ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 194 | InstantiationDependent = true; | 
|  | 195 | } | 
| Douglas Gregor | bb6e73f | 2010-05-11 08:41:30 +0000 | [diff] [blame] | 196 | } | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 197 |  | 
| Douglas Gregor | bb6e73f | 2010-05-11 08:41:30 +0000 | [diff] [blame] | 198 | // (VD) - FIXME: Missing from the standard: | 
|  | 199 | //      -  a member function or a static data member of the current | 
|  | 200 | //         instantiation | 
|  | 201 | else if (Var->isStaticDataMember() && | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 202 | Var->getDeclContext()->isDependentContext()) { | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 203 | ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 204 | InstantiationDependent = true; | 
|  | 205 | } | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 206 |  | 
|  | 207 | return; | 
|  | 208 | } | 
|  | 209 |  | 
| Douglas Gregor | bb6e73f | 2010-05-11 08:41:30 +0000 | [diff] [blame] | 210 | // (VD) - FIXME: Missing from the standard: | 
|  | 211 | //      -  a member function or a static data member of the current | 
|  | 212 | //         instantiation | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 213 | if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { | 
|  | 214 | ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 215 | InstantiationDependent = true; | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 216 | return; | 
|  | 217 | } | 
|  | 218 | } | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 219 |  | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 220 | void DeclRefExpr::computeDependence() { | 
|  | 221 | bool TypeDependent = false; | 
|  | 222 | bool ValueDependent = false; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 223 | bool InstantiationDependent = false; | 
|  | 224 | computeDeclRefDependence(getDecl(), getType(), TypeDependent, ValueDependent, | 
|  | 225 | InstantiationDependent); | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 226 |  | 
|  | 227 | // (TD) C++ [temp.dep.expr]p3: | 
|  | 228 | //   An id-expression is type-dependent if it contains: | 
|  | 229 | // | 
|  | 230 | // and | 
|  | 231 | // | 
|  | 232 | // (VD) C++ [temp.dep.constexpr]p2: | 
|  | 233 | //  An identifier is value-dependent if it is: | 
|  | 234 | if (!TypeDependent && !ValueDependent && | 
|  | 235 | hasExplicitTemplateArgs() && | 
|  | 236 | TemplateSpecializationType::anyDependentTemplateArguments( | 
|  | 237 | getTemplateArgs(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 238 | getNumTemplateArgs(), | 
|  | 239 | InstantiationDependent)) { | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 240 | TypeDependent = true; | 
|  | 241 | ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 242 | InstantiationDependent = true; | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 243 | } | 
|  | 244 |  | 
|  | 245 | ExprBits.TypeDependent = TypeDependent; | 
|  | 246 | ExprBits.ValueDependent = ValueDependent; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 247 | ExprBits.InstantiationDependent = InstantiationDependent; | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 248 |  | 
| Douglas Gregor | 10738d3 | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 249 | // Is the declaration a parameter pack? | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 250 | if (getDecl()->isParameterPack()) | 
| Douglas Gregor | 1fe85ea | 2011-01-05 21:11:38 +0000 | [diff] [blame] | 251 | ExprBits.ContainsUnexpandedParameterPack = true; | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 252 | } | 
|  | 253 |  | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 254 | DeclRefExpr::DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 255 | ValueDecl *D, const DeclarationNameInfo &NameInfo, | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 256 | NamedDecl *FoundD, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 257 | const TemplateArgumentListInfo *TemplateArgs, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 258 | QualType T, ExprValueKind VK) | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 259 | : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), | 
| Chandler Carruth | cb66cff | 2011-05-01 21:29:53 +0000 | [diff] [blame] | 260 | D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { | 
|  | 261 | DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; | 
| Chandler Carruth | 7e740bd | 2011-05-01 21:55:21 +0000 | [diff] [blame] | 262 | if (QualifierLoc) | 
| Chandler Carruth | 6857c3e | 2011-05-01 22:14:37 +0000 | [diff] [blame] | 263 | getInternalQualifierLoc() = QualifierLoc; | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 264 | DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; | 
|  | 265 | if (FoundD) | 
|  | 266 | getInternalFoundDecl() = FoundD; | 
| Chandler Carruth | cb66cff | 2011-05-01 21:29:53 +0000 | [diff] [blame] | 267 | DeclRefExprBits.HasExplicitTemplateArgs = TemplateArgs ? 1 : 0; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 268 | if (TemplateArgs) { | 
|  | 269 | bool Dependent = false; | 
|  | 270 | bool InstantiationDependent = false; | 
|  | 271 | bool ContainsUnexpandedParameterPack = false; | 
|  | 272 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent, | 
|  | 273 | InstantiationDependent, | 
|  | 274 | ContainsUnexpandedParameterPack); | 
|  | 275 | if (InstantiationDependent) | 
|  | 276 | setInstantiationDependent(true); | 
|  | 277 | } | 
| Benjamin Kramer | b8da98a | 2011-10-10 12:54:05 +0000 | [diff] [blame] | 278 | DeclRefExprBits.HadMultipleCandidates = 0; | 
|  | 279 |  | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 280 | computeDependence(); | 
|  | 281 | } | 
|  | 282 |  | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 283 | DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 284 | NestedNameSpecifierLoc QualifierLoc, | 
| John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 285 | ValueDecl *D, | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 286 | SourceLocation NameLoc, | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 287 | QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 288 | ExprValueKind VK, | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 289 | NamedDecl *FoundD, | 
| Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 290 | const TemplateArgumentListInfo *TemplateArgs) { | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 291 | return Create(Context, QualifierLoc, D, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 292 | DeclarationNameInfo(D->getDeclName(), NameLoc), | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 293 | T, VK, FoundD, TemplateArgs); | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 294 | } | 
|  | 295 |  | 
|  | 296 | DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 297 | NestedNameSpecifierLoc QualifierLoc, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 298 | ValueDecl *D, | 
|  | 299 | const DeclarationNameInfo &NameInfo, | 
|  | 300 | QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 301 | ExprValueKind VK, | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 302 | NamedDecl *FoundD, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 303 | const TemplateArgumentListInfo *TemplateArgs) { | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 304 | // Filter out cases where the found Decl is the same as the value refenenced. | 
|  | 305 | if (D == FoundD) | 
|  | 306 | FoundD = 0; | 
|  | 307 |  | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 308 | std::size_t Size = sizeof(DeclRefExpr); | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 309 | if (QualifierLoc != 0) | 
| Chandler Carruth | 6857c3e | 2011-05-01 22:14:37 +0000 | [diff] [blame] | 310 | Size += sizeof(NestedNameSpecifierLoc); | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 311 | if (FoundD) | 
|  | 312 | Size += sizeof(NamedDecl *); | 
| John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 313 | if (TemplateArgs) | 
| Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 314 | Size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs); | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 315 |  | 
| Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 316 | void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 317 | return new (Mem) DeclRefExpr(QualifierLoc, D, NameInfo, FoundD, TemplateArgs, | 
|  | 318 | T, VK); | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 319 | } | 
|  | 320 |  | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 321 | DeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, | 
| Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 322 | bool HasQualifier, | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 323 | bool HasFoundDecl, | 
| Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 324 | bool HasExplicitTemplateArgs, | 
| Argyrios Kyrtzidis | 663e380 | 2010-07-08 13:09:47 +0000 | [diff] [blame] | 325 | unsigned NumTemplateArgs) { | 
|  | 326 | std::size_t Size = sizeof(DeclRefExpr); | 
|  | 327 | if (HasQualifier) | 
| Chandler Carruth | 6857c3e | 2011-05-01 22:14:37 +0000 | [diff] [blame] | 328 | Size += sizeof(NestedNameSpecifierLoc); | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 329 | if (HasFoundDecl) | 
|  | 330 | Size += sizeof(NamedDecl *); | 
| Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 331 | if (HasExplicitTemplateArgs) | 
| Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 332 | Size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs); | 
| Chandler Carruth | 3aa8140 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 333 |  | 
| Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 334 | void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); | 
| Argyrios Kyrtzidis | 663e380 | 2010-07-08 13:09:47 +0000 | [diff] [blame] | 335 | return new (Mem) DeclRefExpr(EmptyShell()); | 
|  | 336 | } | 
|  | 337 |  | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 338 | SourceRange DeclRefExpr::getSourceRange() const { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 339 | SourceRange R = getNameInfo().getSourceRange(); | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 340 | if (hasQualifier()) | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 341 | R.setBegin(getQualifierLoc().getBeginLoc()); | 
| John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 342 | if (hasExplicitTemplateArgs()) | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 343 | R.setEnd(getRAngleLoc()); | 
|  | 344 | return R; | 
|  | 345 | } | 
|  | 346 |  | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 347 | // FIXME: Maybe this should use DeclPrinter with a special "print predefined | 
|  | 348 | // expr" policy instead. | 
| Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 349 | std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { | 
|  | 350 | ASTContext &Context = CurrentDecl->getASTContext(); | 
|  | 351 |  | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 352 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { | 
| Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 353 | if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 354 | return FD->getNameAsString(); | 
|  | 355 |  | 
|  | 356 | llvm::SmallString<256> Name; | 
|  | 357 | llvm::raw_svector_ostream Out(Name); | 
|  | 358 |  | 
|  | 359 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { | 
| Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 360 | if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 361 | Out << "virtual "; | 
| Sam Weinig | 4eadcc5 | 2009-12-27 01:38:20 +0000 | [diff] [blame] | 362 | if (MD->isStatic()) | 
|  | 363 | Out << "static "; | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 364 | } | 
|  | 365 |  | 
|  | 366 | PrintingPolicy Policy(Context.getLangOptions()); | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 367 |  | 
|  | 368 | std::string Proto = FD->getQualifiedNameAsString(Policy); | 
|  | 369 |  | 
| John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 370 | const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 371 | const FunctionProtoType *FT = 0; | 
|  | 372 | if (FD->hasWrittenPrototype()) | 
|  | 373 | FT = dyn_cast<FunctionProtoType>(AFT); | 
|  | 374 |  | 
|  | 375 | Proto += "("; | 
|  | 376 | if (FT) { | 
|  | 377 | llvm::raw_string_ostream POut(Proto); | 
|  | 378 | for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { | 
|  | 379 | if (i) POut << ", "; | 
|  | 380 | std::string Param; | 
|  | 381 | FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); | 
|  | 382 | POut << Param; | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | if (FT->isVariadic()) { | 
|  | 386 | if (FD->getNumParams()) POut << ", "; | 
|  | 387 | POut << "..."; | 
|  | 388 | } | 
|  | 389 | } | 
|  | 390 | Proto += ")"; | 
|  | 391 |  | 
| Sam Weinig | 4eadcc5 | 2009-12-27 01:38:20 +0000 | [diff] [blame] | 392 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { | 
|  | 393 | Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); | 
|  | 394 | if (ThisQuals.hasConst()) | 
|  | 395 | Proto += " const"; | 
|  | 396 | if (ThisQuals.hasVolatile()) | 
|  | 397 | Proto += " volatile"; | 
|  | 398 | } | 
|  | 399 |  | 
| Sam Weinig | 3a1ce1e | 2009-12-06 23:55:13 +0000 | [diff] [blame] | 400 | if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) | 
|  | 401 | AFT->getResultType().getAsStringInternal(Proto, Policy); | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 402 |  | 
|  | 403 | Out << Proto; | 
|  | 404 |  | 
|  | 405 | Out.flush(); | 
|  | 406 | return Name.str().str(); | 
|  | 407 | } | 
|  | 408 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { | 
|  | 409 | llvm::SmallString<256> Name; | 
|  | 410 | llvm::raw_svector_ostream Out(Name); | 
|  | 411 | Out << (MD->isInstanceMethod() ? '-' : '+'); | 
|  | 412 | Out << '['; | 
| Ted Kremenek | b03d33e | 2010-03-18 21:23:08 +0000 | [diff] [blame] | 413 |  | 
|  | 414 | // For incorrect code, there might not be an ObjCInterfaceDecl.  Do | 
|  | 415 | // a null check to avoid a crash. | 
|  | 416 | if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) | 
| Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 417 | Out << *ID; | 
| Ted Kremenek | b03d33e | 2010-03-18 21:23:08 +0000 | [diff] [blame] | 418 |  | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 419 | if (const ObjCCategoryImplDecl *CID = | 
| Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 420 | dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) | 
|  | 421 | Out << '(' << CID << ')'; | 
|  | 422 |  | 
| Anders Carlsson | 3a082d8 | 2009-09-08 18:24:21 +0000 | [diff] [blame] | 423 | Out <<  ' '; | 
|  | 424 | Out << MD->getSelector().getAsString(); | 
|  | 425 | Out <<  ']'; | 
|  | 426 |  | 
|  | 427 | Out.flush(); | 
|  | 428 | return Name.str().str(); | 
|  | 429 | } | 
|  | 430 | if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { | 
|  | 431 | // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. | 
|  | 432 | return "top level"; | 
|  | 433 | } | 
|  | 434 | return ""; | 
|  | 435 | } | 
|  | 436 |  | 
| Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 437 | void APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { | 
|  | 438 | if (hasAllocation()) | 
|  | 439 | C.Deallocate(pVal); | 
|  | 440 |  | 
|  | 441 | BitWidth = Val.getBitWidth(); | 
|  | 442 | unsigned NumWords = Val.getNumWords(); | 
|  | 443 | const uint64_t* Words = Val.getRawData(); | 
|  | 444 | if (NumWords > 1) { | 
|  | 445 | pVal = new (C) uint64_t[NumWords]; | 
|  | 446 | std::copy(Words, Words + NumWords, pVal); | 
|  | 447 | } else if (NumWords == 1) | 
|  | 448 | VAL = Words[0]; | 
|  | 449 | else | 
|  | 450 | VAL = 0; | 
|  | 451 | } | 
|  | 452 |  | 
|  | 453 | IntegerLiteral * | 
|  | 454 | IntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, | 
|  | 455 | QualType type, SourceLocation l) { | 
|  | 456 | return new (C) IntegerLiteral(C, V, type, l); | 
|  | 457 | } | 
|  | 458 |  | 
|  | 459 | IntegerLiteral * | 
|  | 460 | IntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { | 
|  | 461 | return new (C) IntegerLiteral(Empty); | 
|  | 462 | } | 
|  | 463 |  | 
|  | 464 | FloatingLiteral * | 
|  | 465 | FloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, | 
|  | 466 | bool isexact, QualType Type, SourceLocation L) { | 
|  | 467 | return new (C) FloatingLiteral(C, V, isexact, Type, L); | 
|  | 468 | } | 
|  | 469 |  | 
|  | 470 | FloatingLiteral * | 
|  | 471 | FloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { | 
|  | 472 | return new (C) FloatingLiteral(Empty); | 
|  | 473 | } | 
|  | 474 |  | 
| Chris Lattner | da8249e | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 475 | /// getValueAsApproximateDouble - This returns the value as an inaccurate | 
|  | 476 | /// double.  Note that this may cause loss of precision, but is useful for | 
|  | 477 | /// debugging dumps, etc. | 
|  | 478 | double FloatingLiteral::getValueAsApproximateDouble() const { | 
|  | 479 | llvm::APFloat V = getValue(); | 
| Dale Johannesen | ee5a700 | 2008-10-09 23:02:32 +0000 | [diff] [blame] | 480 | bool ignored; | 
|  | 481 | V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, | 
|  | 482 | &ignored); | 
| Chris Lattner | da8249e | 2008-06-07 22:13:43 +0000 | [diff] [blame] | 483 | return V.convertToDouble(); | 
|  | 484 | } | 
|  | 485 |  | 
| Eli Friedman | 64f45a2 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 486 | int StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { | 
|  | 487 | int CharByteWidth; | 
|  | 488 | switch(k) { | 
|  | 489 | case Ascii: | 
|  | 490 | case UTF8: | 
|  | 491 | CharByteWidth = target.getCharWidth(); | 
|  | 492 | break; | 
|  | 493 | case Wide: | 
|  | 494 | CharByteWidth = target.getWCharWidth(); | 
|  | 495 | break; | 
|  | 496 | case UTF16: | 
|  | 497 | CharByteWidth = target.getChar16Width(); | 
|  | 498 | break; | 
|  | 499 | case UTF32: | 
|  | 500 | CharByteWidth = target.getChar32Width(); | 
|  | 501 | } | 
|  | 502 | assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); | 
|  | 503 | CharByteWidth /= 8; | 
|  | 504 | assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) | 
|  | 505 | && "character byte widths supported are 1, 2, and 4 only"); | 
|  | 506 | return CharByteWidth; | 
|  | 507 | } | 
|  | 508 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 509 | StringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, | 
| Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 510 | StringKind Kind, bool Pascal, QualType Ty, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | const SourceLocation *Loc, | 
| Anders Carlsson | a135fb4 | 2009-03-15 18:34:13 +0000 | [diff] [blame] | 512 | unsigned NumStrs) { | 
| Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 513 | // Allocate enough space for the StringLiteral plus an array of locations for | 
|  | 514 | // any concatenated string tokens. | 
|  | 515 | void *Mem = C.Allocate(sizeof(StringLiteral)+ | 
|  | 516 | sizeof(SourceLocation)*(NumStrs-1), | 
| Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 517 | llvm::alignOf<StringLiteral>()); | 
| Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 518 | StringLiteral *SL = new (Mem) StringLiteral(Ty); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 520 | // OPTIMIZE: could allocate this appended to the StringLiteral. | 
| Eli Friedman | 64f45a2 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 521 | SL->setString(C,Str,Kind,Pascal); | 
|  | 522 |  | 
| Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 523 | SL->TokLocs[0] = Loc[0]; | 
|  | 524 | SL->NumConcatenated = NumStrs; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 525 |  | 
| Chris Lattner | 726e168 | 2009-02-18 05:49:11 +0000 | [diff] [blame] | 526 | if (NumStrs != 1) | 
| Chris Lattner | 2085fd6 | 2009-02-18 06:40:38 +0000 | [diff] [blame] | 527 | memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); | 
|  | 528 | return SL; | 
| Chris Lattner | 726e168 | 2009-02-18 05:49:11 +0000 | [diff] [blame] | 529 | } | 
|  | 530 |  | 
| Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 531 | StringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { | 
|  | 532 | void *Mem = C.Allocate(sizeof(StringLiteral)+ | 
|  | 533 | sizeof(SourceLocation)*(NumStrs-1), | 
| Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 534 | llvm::alignOf<StringLiteral>()); | 
| Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 535 | StringLiteral *SL = new (Mem) StringLiteral(QualType()); | 
| Eli Friedman | 64f45a2 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 536 | SL->CharByteWidth = 0; | 
|  | 537 | SL->Length = 0; | 
| Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 538 | SL->NumConcatenated = NumStrs; | 
|  | 539 | return SL; | 
|  | 540 | } | 
|  | 541 |  | 
| Eli Friedman | 64f45a2 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 542 | void StringLiteral::setString(ASTContext &C, StringRef Str, | 
|  | 543 | StringKind Kind, bool IsPascal) { | 
|  | 544 | //FIXME: we assume that the string data comes from a target that uses the same | 
|  | 545 | // code unit size and endianess for the type of string. | 
|  | 546 | this->Kind = Kind; | 
|  | 547 | this->IsPascal = IsPascal; | 
|  | 548 |  | 
|  | 549 | CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind); | 
|  | 550 | assert((Str.size()%CharByteWidth == 0) | 
|  | 551 | && "size of data must be multiple of CharByteWidth"); | 
|  | 552 | Length = Str.size()/CharByteWidth; | 
|  | 553 |  | 
|  | 554 | switch(CharByteWidth) { | 
|  | 555 | case 1: { | 
|  | 556 | char *AStrData = new (C) char[Length]; | 
|  | 557 | std::memcpy(AStrData,Str.data(),Str.size()); | 
|  | 558 | StrData.asChar = AStrData; | 
|  | 559 | break; | 
|  | 560 | } | 
|  | 561 | case 2: { | 
|  | 562 | uint16_t *AStrData = new (C) uint16_t[Length]; | 
|  | 563 | std::memcpy(AStrData,Str.data(),Str.size()); | 
|  | 564 | StrData.asUInt16 = AStrData; | 
|  | 565 | break; | 
|  | 566 | } | 
|  | 567 | case 4: { | 
|  | 568 | uint32_t *AStrData = new (C) uint32_t[Length]; | 
|  | 569 | std::memcpy(AStrData,Str.data(),Str.size()); | 
|  | 570 | StrData.asUInt32 = AStrData; | 
|  | 571 | break; | 
|  | 572 | } | 
|  | 573 | default: | 
|  | 574 | assert(false && "unsupported CharByteWidth"); | 
|  | 575 | } | 
| Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 576 | } | 
|  | 577 |  | 
| Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 578 | /// getLocationOfByte - Return a source location that points to the specified | 
|  | 579 | /// byte of this string literal. | 
|  | 580 | /// | 
|  | 581 | /// Strings are amazingly complex.  They can be formed from multiple tokens and | 
|  | 582 | /// can have escape sequences in them in addition to the usual trigraph and | 
|  | 583 | /// escaped newline business.  This routine handles this complexity. | 
|  | 584 | /// | 
|  | 585 | SourceLocation StringLiteral:: | 
|  | 586 | getLocationOfByte(unsigned ByteNo, const SourceManager &SM, | 
|  | 587 | const LangOptions &Features, const TargetInfo &Target) const { | 
| Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 588 | assert(Kind == StringLiteral::Ascii && "This only works for ASCII strings"); | 
|  | 589 |  | 
| Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 590 | // Loop over all of the tokens in this string until we find the one that | 
|  | 591 | // contains the byte we're looking for. | 
|  | 592 | unsigned TokNo = 0; | 
|  | 593 | while (1) { | 
|  | 594 | assert(TokNo < getNumConcatenated() && "Invalid byte number!"); | 
|  | 595 | SourceLocation StrTokLoc = getStrTokenLoc(TokNo); | 
|  | 596 |  | 
|  | 597 | // Get the spelling of the string so that we can get the data that makes up | 
|  | 598 | // the string literal, not the identifier for the macro it is potentially | 
|  | 599 | // expanded through. | 
|  | 600 | SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); | 
|  | 601 |  | 
|  | 602 | // Re-lex the token to get its length and original spelling. | 
|  | 603 | std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); | 
|  | 604 | bool Invalid = false; | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 605 | StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); | 
| Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 606 | if (Invalid) | 
|  | 607 | return StrTokSpellingLoc; | 
|  | 608 |  | 
|  | 609 | const char *StrData = Buffer.data()+LocInfo.second; | 
|  | 610 |  | 
|  | 611 | // Create a langops struct and enable trigraphs.  This is sufficient for | 
|  | 612 | // relexing tokens. | 
|  | 613 | LangOptions LangOpts; | 
|  | 614 | LangOpts.Trigraphs = true; | 
|  | 615 |  | 
|  | 616 | // Create a lexer starting at the beginning of this token. | 
|  | 617 | Lexer TheLexer(StrTokSpellingLoc, Features, Buffer.begin(), StrData, | 
|  | 618 | Buffer.end()); | 
|  | 619 | Token TheTok; | 
|  | 620 | TheLexer.LexFromRawLexer(TheTok); | 
|  | 621 |  | 
|  | 622 | // Use the StringLiteralParser to compute the length of the string in bytes. | 
|  | 623 | StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); | 
|  | 624 | unsigned TokNumBytes = SLP.GetStringLength(); | 
|  | 625 |  | 
|  | 626 | // If the byte is in this token, return the location of the byte. | 
|  | 627 | if (ByteNo < TokNumBytes || | 
| Hans Wennborg | 935a70c | 2011-06-30 20:17:41 +0000 | [diff] [blame] | 628 | (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { | 
| Chris Lattner | 08f92e3 | 2010-11-17 07:37:15 +0000 | [diff] [blame] | 629 | unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); | 
|  | 630 |  | 
|  | 631 | // Now that we know the offset of the token in the spelling, use the | 
|  | 632 | // preprocessor to get the offset in the original source. | 
|  | 633 | return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | // Move to the next string token. | 
|  | 637 | ++TokNo; | 
|  | 638 | ByteNo -= TokNumBytes; | 
|  | 639 | } | 
|  | 640 | } | 
|  | 641 |  | 
|  | 642 |  | 
|  | 643 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 644 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it | 
|  | 645 | /// corresponds to, e.g. "sizeof" or "[pre]++". | 
|  | 646 | const char *UnaryOperator::getOpcodeStr(Opcode Op) { | 
|  | 647 | switch (Op) { | 
| David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 648 | default: llvm_unreachable("Unknown unary operator"); | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 649 | case UO_PostInc: return "++"; | 
|  | 650 | case UO_PostDec: return "--"; | 
|  | 651 | case UO_PreInc:  return "++"; | 
|  | 652 | case UO_PreDec:  return "--"; | 
|  | 653 | case UO_AddrOf:  return "&"; | 
|  | 654 | case UO_Deref:   return "*"; | 
|  | 655 | case UO_Plus:    return "+"; | 
|  | 656 | case UO_Minus:   return "-"; | 
|  | 657 | case UO_Not:     return "~"; | 
|  | 658 | case UO_LNot:    return "!"; | 
|  | 659 | case UO_Real:    return "__real"; | 
|  | 660 | case UO_Imag:    return "__imag"; | 
|  | 661 | case UO_Extension: return "__extension__"; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 662 | } | 
|  | 663 | } | 
|  | 664 |  | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 665 | UnaryOperatorKind | 
| Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 666 | UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { | 
|  | 667 | switch (OO) { | 
| David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 668 | default: llvm_unreachable("No unary operator for overloaded function"); | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 669 | case OO_PlusPlus:   return Postfix ? UO_PostInc : UO_PreInc; | 
|  | 670 | case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; | 
|  | 671 | case OO_Amp:        return UO_AddrOf; | 
|  | 672 | case OO_Star:       return UO_Deref; | 
|  | 673 | case OO_Plus:       return UO_Plus; | 
|  | 674 | case OO_Minus:      return UO_Minus; | 
|  | 675 | case OO_Tilde:      return UO_Not; | 
|  | 676 | case OO_Exclaim:    return UO_LNot; | 
| Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 677 | } | 
|  | 678 | } | 
|  | 679 |  | 
|  | 680 | OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { | 
|  | 681 | switch (Opc) { | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 682 | case UO_PostInc: case UO_PreInc: return OO_PlusPlus; | 
|  | 683 | case UO_PostDec: case UO_PreDec: return OO_MinusMinus; | 
|  | 684 | case UO_AddrOf: return OO_Amp; | 
|  | 685 | case UO_Deref: return OO_Star; | 
|  | 686 | case UO_Plus: return OO_Plus; | 
|  | 687 | case UO_Minus: return OO_Minus; | 
|  | 688 | case UO_Not: return OO_Tilde; | 
|  | 689 | case UO_LNot: return OO_Exclaim; | 
| Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 690 | default: return OO_None; | 
|  | 691 | } | 
|  | 692 | } | 
|  | 693 |  | 
|  | 694 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 695 | //===----------------------------------------------------------------------===// | 
|  | 696 | // Postfix Operators. | 
|  | 697 | //===----------------------------------------------------------------------===// | 
|  | 698 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 699 | CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, | 
|  | 700 | Expr **args, unsigned numargs, QualType t, ExprValueKind VK, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 701 | SourceLocation rparenloc) | 
|  | 702 | : Expr(SC, t, VK, OK_Ordinary, | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 703 | fn->isTypeDependent(), | 
|  | 704 | fn->isValueDependent(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 705 | fn->isInstantiationDependent(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 706 | fn->containsUnexpandedParameterPack()), | 
| Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 707 | NumArgs(numargs) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 709 | SubExprs = new (C) Stmt*[numargs+PREARGS_START+NumPreArgs]; | 
| Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 710 | SubExprs[FN] = fn; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 711 | for (unsigned i = 0; i != numargs; ++i) { | 
|  | 712 | if (args[i]->isTypeDependent()) | 
|  | 713 | ExprBits.TypeDependent = true; | 
|  | 714 | if (args[i]->isValueDependent()) | 
|  | 715 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 716 | if (args[i]->isInstantiationDependent()) | 
|  | 717 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 718 | if (args[i]->containsUnexpandedParameterPack()) | 
|  | 719 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 720 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 721 | SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 722 | } | 
| Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 723 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 724 | CallExprBits.NumPreArgs = NumPreArgs; | 
| Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 725 | RParenLoc = rparenloc; | 
|  | 726 | } | 
| Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 727 |  | 
| Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 728 | CallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 729 | QualType t, ExprValueKind VK, SourceLocation rparenloc) | 
|  | 730 | : Expr(CallExprClass, t, VK, OK_Ordinary, | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 731 | fn->isTypeDependent(), | 
|  | 732 | fn->isValueDependent(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 733 | fn->isInstantiationDependent(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 734 | fn->containsUnexpandedParameterPack()), | 
| Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 735 | NumArgs(numargs) { | 
| Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 736 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 737 | SubExprs = new (C) Stmt*[numargs+PREARGS_START]; | 
| Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 738 | SubExprs[FN] = fn; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 739 | for (unsigned i = 0; i != numargs; ++i) { | 
|  | 740 | if (args[i]->isTypeDependent()) | 
|  | 741 | ExprBits.TypeDependent = true; | 
|  | 742 | if (args[i]->isValueDependent()) | 
|  | 743 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 744 | if (args[i]->isInstantiationDependent()) | 
|  | 745 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 746 | if (args[i]->containsUnexpandedParameterPack()) | 
|  | 747 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 748 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 749 | SubExprs[i+PREARGS_START] = args[i]; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 750 | } | 
| Ted Kremenek | 668bf91 | 2009-02-09 20:51:47 +0000 | [diff] [blame] | 751 |  | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 752 | CallExprBits.NumPreArgs = 0; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 753 | RParenLoc = rparenloc; | 
|  | 754 | } | 
|  | 755 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | CallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) | 
|  | 757 | : Expr(SC, Empty), SubExprs(0), NumArgs(0) { | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 758 | // FIXME: Why do we allocate this? | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 759 | SubExprs = new (C) Stmt*[PREARGS_START]; | 
|  | 760 | CallExprBits.NumPreArgs = 0; | 
|  | 761 | } | 
|  | 762 |  | 
|  | 763 | CallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, | 
|  | 764 | EmptyShell Empty) | 
|  | 765 | : Expr(SC, Empty), SubExprs(0), NumArgs(0) { | 
|  | 766 | // FIXME: Why do we allocate this? | 
|  | 767 | SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; | 
|  | 768 | CallExprBits.NumPreArgs = NumPreArgs; | 
| Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 769 | } | 
|  | 770 |  | 
| Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 771 | Decl *CallExpr::getCalleeDecl() { | 
| John McCall | e8683d6 | 2011-09-13 23:08:34 +0000 | [diff] [blame] | 772 | Expr *CEE = getCallee()->IgnoreParenImpCasts(); | 
| Douglas Gregor | 1ddc9c4 | 2011-09-06 21:41:04 +0000 | [diff] [blame] | 773 |  | 
|  | 774 | while (SubstNonTypeTemplateParmExpr *NTTP | 
|  | 775 | = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { | 
|  | 776 | CEE = NTTP->getReplacement()->IgnoreParenCasts(); | 
|  | 777 | } | 
|  | 778 |  | 
| Sebastian Redl | 2001215 | 2010-09-10 20:55:30 +0000 | [diff] [blame] | 779 | // If we're calling a dereference, look at the pointer instead. | 
|  | 780 | if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { | 
|  | 781 | if (BO->isPtrMemOp()) | 
|  | 782 | CEE = BO->getRHS()->IgnoreParenCasts(); | 
|  | 783 | } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { | 
|  | 784 | if (UO->getOpcode() == UO_Deref) | 
|  | 785 | CEE = UO->getSubExpr()->IgnoreParenCasts(); | 
|  | 786 | } | 
| Chris Lattner | 6346f96 | 2009-07-17 15:46:27 +0000 | [diff] [blame] | 787 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) | 
| Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 788 | return DRE->getDecl(); | 
| Nuno Lopes | cb1c77f | 2009-12-24 00:28:18 +0000 | [diff] [blame] | 789 | if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) | 
|  | 790 | return ME->getMemberDecl(); | 
| Zhongxing Xu | a004254 | 2009-07-17 07:29:51 +0000 | [diff] [blame] | 791 |  | 
|  | 792 | return 0; | 
|  | 793 | } | 
|  | 794 |  | 
| Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 795 | FunctionDecl *CallExpr::getDirectCallee() { | 
| Chris Lattner | caabf9b | 2009-12-21 01:10:56 +0000 | [diff] [blame] | 796 | return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); | 
| Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 797 | } | 
|  | 798 |  | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 799 | /// setNumArgs - This changes the number of arguments present in this call. | 
|  | 800 | /// Any orphaned expressions are deleted by this, and any new operands are set | 
|  | 801 | /// to null. | 
| Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 802 | void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 803 | // No change, just return. | 
|  | 804 | if (NumArgs == getNumArgs()) return; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 805 |  | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 806 | // If shrinking # arguments, just delete the extras and forgot them. | 
|  | 807 | if (NumArgs < getNumArgs()) { | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 808 | this->NumArgs = NumArgs; | 
|  | 809 | return; | 
|  | 810 | } | 
|  | 811 |  | 
|  | 812 | // Otherwise, we are growing the # arguments.  New an bigger argument array. | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 813 | unsigned NumPreArgs = getNumPreArgs(); | 
|  | 814 | Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 815 | // Copy over args. | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 816 | for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 817 | NewSubExprs[i] = SubExprs[i]; | 
|  | 818 | // Null out new args. | 
| Peter Collingbourne | cc324ad | 2011-02-08 21:18:02 +0000 | [diff] [blame] | 819 | for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; | 
|  | 820 | i != NumArgs+PREARGS_START+NumPreArgs; ++i) | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 821 | NewSubExprs[i] = 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 |  | 
| Douglas Gregor | 88c9a46 | 2009-04-17 21:46:47 +0000 | [diff] [blame] | 823 | if (SubExprs) C.Deallocate(SubExprs); | 
| Chris Lattner | d18b329 | 2007-12-28 05:25:02 +0000 | [diff] [blame] | 824 | SubExprs = NewSubExprs; | 
|  | 825 | this->NumArgs = NumArgs; | 
|  | 826 | } | 
|  | 827 |  | 
| Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 828 | /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If | 
|  | 829 | /// not, return 0. | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 830 | unsigned CallExpr::isBuiltinCall(const ASTContext &Context) const { | 
| Steve Naroff | c4f8e8b | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 831 | // All simple function calls (e.g. func()) are implicitly cast to pointer to | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | // function. As a result, we try and obtain the DeclRefExpr from the | 
| Steve Naroff | c4f8e8b | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 833 | // ImplicitCastExpr. | 
|  | 834 | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); | 
|  | 835 | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). | 
| Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 836 | return 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 |  | 
| Steve Naroff | c4f8e8b | 2008-01-31 01:07:12 +0000 | [diff] [blame] | 838 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); | 
|  | 839 | if (!DRE) | 
| Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 840 | return 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 |  | 
| Anders Carlsson | bcba201 | 2008-01-31 02:13:57 +0000 | [diff] [blame] | 842 | const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); | 
|  | 843 | if (!FDecl) | 
| Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 844 | return 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 |  | 
| Douglas Gregor | 4fcd399 | 2008-11-21 15:30:19 +0000 | [diff] [blame] | 846 | if (!FDecl->getIdentifier()) | 
|  | 847 | return 0; | 
|  | 848 |  | 
| Douglas Gregor | 7814e6d | 2009-09-12 00:22:50 +0000 | [diff] [blame] | 849 | return FDecl->getBuiltinID(); | 
| Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 850 | } | 
| Anders Carlsson | bcba201 | 2008-01-31 02:13:57 +0000 | [diff] [blame] | 851 |  | 
| Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 852 | QualType CallExpr::getCallReturnType() const { | 
|  | 853 | QualType CalleeType = getCallee()->getType(); | 
| Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 854 | if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) | 
| Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 855 | CalleeType = FnTypePtr->getPointeeType(); | 
| Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 856 | else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) | 
| Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 857 | CalleeType = BPT->getPointeeType(); | 
| John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 858 | else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) | 
|  | 859 | // This should never be overloaded and so should never return null. | 
|  | 860 | CalleeType = Expr::findBoundMemberType(getCallee()); | 
| Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 861 |  | 
| John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 862 | const FunctionType *FnType = CalleeType->castAs<FunctionType>(); | 
| Anders Carlsson | 6dde78f | 2009-05-26 04:57:27 +0000 | [diff] [blame] | 863 | return FnType->getResultType(); | 
|  | 864 | } | 
| Chris Lattner | cb88896 | 2008-10-06 05:00:53 +0000 | [diff] [blame] | 865 |  | 
| John McCall | 2882eca | 2011-02-21 06:23:05 +0000 | [diff] [blame] | 866 | SourceRange CallExpr::getSourceRange() const { | 
|  | 867 | if (isa<CXXOperatorCallExpr>(this)) | 
|  | 868 | return cast<CXXOperatorCallExpr>(this)->getSourceRange(); | 
|  | 869 |  | 
|  | 870 | SourceLocation begin = getCallee()->getLocStart(); | 
|  | 871 | if (begin.isInvalid() && getNumArgs() > 0) | 
|  | 872 | begin = getArg(0)->getLocStart(); | 
|  | 873 | SourceLocation end = getRParenLoc(); | 
|  | 874 | if (end.isInvalid() && getNumArgs() > 0) | 
|  | 875 | end = getArg(getNumArgs() - 1)->getLocEnd(); | 
|  | 876 | return SourceRange(begin, end); | 
|  | 877 | } | 
|  | 878 |  | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 879 | OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 880 | SourceLocation OperatorLoc, | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 881 | TypeSourceInfo *tsi, | 
|  | 882 | OffsetOfNode* compsPtr, unsigned numComps, | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 883 | Expr** exprsPtr, unsigned numExprs, | 
|  | 884 | SourceLocation RParenLoc) { | 
|  | 885 | void *Mem = C.Allocate(sizeof(OffsetOfExpr) + | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 886 | sizeof(OffsetOfNode) * numComps + | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 887 | sizeof(Expr*) * numExprs); | 
|  | 888 |  | 
|  | 889 | return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, | 
|  | 890 | exprsPtr, numExprs, RParenLoc); | 
|  | 891 | } | 
|  | 892 |  | 
|  | 893 | OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, | 
|  | 894 | unsigned numComps, unsigned numExprs) { | 
|  | 895 | void *Mem = C.Allocate(sizeof(OffsetOfExpr) + | 
|  | 896 | sizeof(OffsetOfNode) * numComps + | 
|  | 897 | sizeof(Expr*) * numExprs); | 
|  | 898 | return new (Mem) OffsetOfExpr(numComps, numExprs); | 
|  | 899 | } | 
|  | 900 |  | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 901 | OffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 902 | SourceLocation OperatorLoc, TypeSourceInfo *tsi, | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 903 | OffsetOfNode* compsPtr, unsigned numComps, | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 904 | Expr** exprsPtr, unsigned numExprs, | 
|  | 905 | SourceLocation RParenLoc) | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 906 | : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, | 
|  | 907 | /*TypeDependent=*/false, | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 908 | /*ValueDependent=*/tsi->getType()->isDependentType(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 909 | tsi->getType()->isInstantiationDependentType(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 910 | tsi->getType()->containsUnexpandedParameterPack()), | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 911 | OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), | 
|  | 912 | NumComps(numComps), NumExprs(numExprs) | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 913 | { | 
|  | 914 | for(unsigned i = 0; i < numComps; ++i) { | 
|  | 915 | setComponent(i, compsPtr[i]); | 
|  | 916 | } | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 917 |  | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 918 | for(unsigned i = 0; i < numExprs; ++i) { | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 919 | if (exprsPtr[i]->isTypeDependent() || exprsPtr[i]->isValueDependent()) | 
|  | 920 | ExprBits.ValueDependent = true; | 
|  | 921 | if (exprsPtr[i]->containsUnexpandedParameterPack()) | 
|  | 922 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 923 |  | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 924 | setIndexExpr(i, exprsPtr[i]); | 
|  | 925 | } | 
|  | 926 | } | 
|  | 927 |  | 
|  | 928 | IdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { | 
|  | 929 | assert(getKind() == Field || getKind() == Identifier); | 
|  | 930 | if (getKind() == Field) | 
|  | 931 | return getField()->getIdentifier(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 932 |  | 
| Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 933 | return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); | 
|  | 934 | } | 
|  | 935 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 937 | NestedNameSpecifierLoc QualifierLoc, | 
| Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 938 | ValueDecl *memberdecl, | 
| John McCall | 161755a | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 939 | DeclAccessPair founddecl, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 940 | DeclarationNameInfo nameinfo, | 
| John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 941 | const TemplateArgumentListInfo *targs, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 942 | QualType ty, | 
|  | 943 | ExprValueKind vk, | 
|  | 944 | ExprObjectKind ok) { | 
| Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 945 | std::size_t Size = sizeof(MemberExpr); | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 946 |  | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 947 | bool hasQualOrFound = (QualifierLoc || | 
| John McCall | 161755a | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 948 | founddecl.getDecl() != memberdecl || | 
|  | 949 | founddecl.getAccess() != memberdecl->getAccess()); | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 950 | if (hasQualOrFound) | 
|  | 951 | Size += sizeof(MemberNameQualifier); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 952 |  | 
| John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 953 | if (targs) | 
| Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 954 | Size += ASTTemplateArgumentListInfo::sizeFor(*targs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 |  | 
| Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 956 | void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 957 | MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, | 
|  | 958 | ty, vk, ok); | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 959 |  | 
|  | 960 | if (hasQualOrFound) { | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 961 | // FIXME: Wrong. We should be looking at the member declaration we found. | 
|  | 962 | if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 963 | E->setValueDependent(true); | 
|  | 964 | E->setTypeDependent(true); | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 965 | E->setInstantiationDependent(true); | 
|  | 966 | } | 
|  | 967 | else if (QualifierLoc && | 
|  | 968 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) | 
|  | 969 | E->setInstantiationDependent(true); | 
|  | 970 |  | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 971 | E->HasQualifierOrFoundDecl = true; | 
|  | 972 |  | 
|  | 973 | MemberNameQualifier *NQ = E->getMemberQualifier(); | 
| Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 974 | NQ->QualifierLoc = QualifierLoc; | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 975 | NQ->FoundDecl = founddecl; | 
|  | 976 | } | 
|  | 977 |  | 
|  | 978 | if (targs) { | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 979 | bool Dependent = false; | 
|  | 980 | bool InstantiationDependent = false; | 
|  | 981 | bool ContainsUnexpandedParameterPack = false; | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 982 | E->HasExplicitTemplateArgumentList = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 983 | E->getExplicitTemplateArgs().initializeFrom(*targs, Dependent, | 
|  | 984 | InstantiationDependent, | 
|  | 985 | ContainsUnexpandedParameterPack); | 
|  | 986 | if (InstantiationDependent) | 
|  | 987 | E->setInstantiationDependent(true); | 
| John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 988 | } | 
|  | 989 |  | 
|  | 990 | return E; | 
| Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 991 | } | 
|  | 992 |  | 
| Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 993 | SourceRange MemberExpr::getSourceRange() const { | 
|  | 994 | SourceLocation StartLoc; | 
|  | 995 | if (isImplicitAccess()) { | 
|  | 996 | if (hasQualifier()) | 
|  | 997 | StartLoc = getQualifierLoc().getBeginLoc(); | 
|  | 998 | else | 
|  | 999 | StartLoc = MemberLoc; | 
|  | 1000 | } else { | 
|  | 1001 | // FIXME: We don't want this to happen. Rather, we should be able to | 
|  | 1002 | // detect all kinds of implicit accesses more cleanly. | 
|  | 1003 | StartLoc = getBase()->getLocStart(); | 
|  | 1004 | if (StartLoc.isInvalid()) | 
|  | 1005 | StartLoc = MemberLoc; | 
|  | 1006 | } | 
|  | 1007 |  | 
|  | 1008 | SourceLocation EndLoc = | 
|  | 1009 | HasExplicitTemplateArgumentList? getRAngleLoc() | 
|  | 1010 | : getMemberNameInfo().getEndLoc(); | 
|  | 1011 |  | 
|  | 1012 | return SourceRange(StartLoc, EndLoc); | 
|  | 1013 | } | 
|  | 1014 |  | 
| John McCall | 1d9b3b2 | 2011-09-09 05:25:32 +0000 | [diff] [blame] | 1015 | void CastExpr::CheckCastConsistency() const { | 
|  | 1016 | switch (getCastKind()) { | 
|  | 1017 | case CK_DerivedToBase: | 
|  | 1018 | case CK_UncheckedDerivedToBase: | 
|  | 1019 | case CK_DerivedToBaseMemberPointer: | 
|  | 1020 | case CK_BaseToDerived: | 
|  | 1021 | case CK_BaseToDerivedMemberPointer: | 
|  | 1022 | assert(!path_empty() && "Cast kind should have a base path!"); | 
|  | 1023 | break; | 
|  | 1024 |  | 
|  | 1025 | case CK_CPointerToObjCPointerCast: | 
|  | 1026 | assert(getType()->isObjCObjectPointerType()); | 
|  | 1027 | assert(getSubExpr()->getType()->isPointerType()); | 
|  | 1028 | goto CheckNoBasePath; | 
|  | 1029 |  | 
|  | 1030 | case CK_BlockPointerToObjCPointerCast: | 
|  | 1031 | assert(getType()->isObjCObjectPointerType()); | 
|  | 1032 | assert(getSubExpr()->getType()->isBlockPointerType()); | 
|  | 1033 | goto CheckNoBasePath; | 
|  | 1034 |  | 
|  | 1035 | case CK_BitCast: | 
|  | 1036 | // Arbitrary casts to C pointer types count as bitcasts. | 
|  | 1037 | // Otherwise, we should only have block and ObjC pointer casts | 
|  | 1038 | // here if they stay within the type kind. | 
|  | 1039 | if (!getType()->isPointerType()) { | 
|  | 1040 | assert(getType()->isObjCObjectPointerType() == | 
|  | 1041 | getSubExpr()->getType()->isObjCObjectPointerType()); | 
|  | 1042 | assert(getType()->isBlockPointerType() == | 
|  | 1043 | getSubExpr()->getType()->isBlockPointerType()); | 
|  | 1044 | } | 
|  | 1045 | goto CheckNoBasePath; | 
|  | 1046 |  | 
|  | 1047 | case CK_AnyPointerToBlockPointerCast: | 
|  | 1048 | assert(getType()->isBlockPointerType()); | 
|  | 1049 | assert(getSubExpr()->getType()->isAnyPointerType() && | 
|  | 1050 | !getSubExpr()->getType()->isBlockPointerType()); | 
|  | 1051 | goto CheckNoBasePath; | 
|  | 1052 |  | 
|  | 1053 | // These should not have an inheritance path. | 
|  | 1054 | case CK_Dynamic: | 
|  | 1055 | case CK_ToUnion: | 
|  | 1056 | case CK_ArrayToPointerDecay: | 
|  | 1057 | case CK_FunctionToPointerDecay: | 
|  | 1058 | case CK_NullToMemberPointer: | 
|  | 1059 | case CK_NullToPointer: | 
|  | 1060 | case CK_ConstructorConversion: | 
|  | 1061 | case CK_IntegralToPointer: | 
|  | 1062 | case CK_PointerToIntegral: | 
|  | 1063 | case CK_ToVoid: | 
|  | 1064 | case CK_VectorSplat: | 
|  | 1065 | case CK_IntegralCast: | 
|  | 1066 | case CK_IntegralToFloating: | 
|  | 1067 | case CK_FloatingToIntegral: | 
|  | 1068 | case CK_FloatingCast: | 
|  | 1069 | case CK_ObjCObjectLValueCast: | 
|  | 1070 | case CK_FloatingRealToComplex: | 
|  | 1071 | case CK_FloatingComplexToReal: | 
|  | 1072 | case CK_FloatingComplexCast: | 
|  | 1073 | case CK_FloatingComplexToIntegralComplex: | 
|  | 1074 | case CK_IntegralRealToComplex: | 
|  | 1075 | case CK_IntegralComplexToReal: | 
|  | 1076 | case CK_IntegralComplexCast: | 
|  | 1077 | case CK_IntegralComplexToFloatingComplex: | 
| John McCall | 33e56f3 | 2011-09-10 06:18:15 +0000 | [diff] [blame] | 1078 | case CK_ARCProduceObject: | 
|  | 1079 | case CK_ARCConsumeObject: | 
|  | 1080 | case CK_ARCReclaimReturnedObject: | 
|  | 1081 | case CK_ARCExtendBlockObject: | 
| John McCall | 1d9b3b2 | 2011-09-09 05:25:32 +0000 | [diff] [blame] | 1082 | assert(!getType()->isBooleanType() && "unheralded conversion to bool"); | 
|  | 1083 | goto CheckNoBasePath; | 
|  | 1084 |  | 
|  | 1085 | case CK_Dependent: | 
|  | 1086 | case CK_LValueToRValue: | 
|  | 1087 | case CK_GetObjCProperty: | 
|  | 1088 | case CK_NoOp: | 
|  | 1089 | case CK_PointerToBoolean: | 
|  | 1090 | case CK_IntegralToBoolean: | 
|  | 1091 | case CK_FloatingToBoolean: | 
|  | 1092 | case CK_MemberPointerToBoolean: | 
|  | 1093 | case CK_FloatingComplexToBoolean: | 
|  | 1094 | case CK_IntegralComplexToBoolean: | 
|  | 1095 | case CK_LValueBitCast:            // -> bool& | 
|  | 1096 | case CK_UserDefinedConversion:    // operator bool() | 
|  | 1097 | CheckNoBasePath: | 
|  | 1098 | assert(path_empty() && "Cast kind should not have a base path!"); | 
|  | 1099 | break; | 
|  | 1100 | } | 
|  | 1101 | } | 
|  | 1102 |  | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1103 | const char *CastExpr::getCastKindName() const { | 
|  | 1104 | switch (getCastKind()) { | 
| John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 1105 | case CK_Dependent: | 
|  | 1106 | return "Dependent"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1107 | case CK_BitCast: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1108 | return "BitCast"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1109 | case CK_LValueBitCast: | 
| Douglas Gregor | e39a389 | 2010-07-13 23:17:26 +0000 | [diff] [blame] | 1110 | return "LValueBitCast"; | 
| John McCall | 0ae287a | 2010-12-01 04:43:34 +0000 | [diff] [blame] | 1111 | case CK_LValueToRValue: | 
|  | 1112 | return "LValueToRValue"; | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 1113 | case CK_GetObjCProperty: | 
|  | 1114 | return "GetObjCProperty"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1115 | case CK_NoOp: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1116 | return "NoOp"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1117 | case CK_BaseToDerived: | 
| Anders Carlsson | 11de6de | 2009-11-12 16:43:42 +0000 | [diff] [blame] | 1118 | return "BaseToDerived"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1119 | case CK_DerivedToBase: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1120 | return "DerivedToBase"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1121 | case CK_UncheckedDerivedToBase: | 
| John McCall | 23cba80 | 2010-03-30 23:58:03 +0000 | [diff] [blame] | 1122 | return "UncheckedDerivedToBase"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1123 | case CK_Dynamic: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1124 | return "Dynamic"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1125 | case CK_ToUnion: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1126 | return "ToUnion"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1127 | case CK_ArrayToPointerDecay: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1128 | return "ArrayToPointerDecay"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1129 | case CK_FunctionToPointerDecay: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1130 | return "FunctionToPointerDecay"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1131 | case CK_NullToMemberPointer: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1132 | return "NullToMemberPointer"; | 
| John McCall | 404cd16 | 2010-11-13 01:35:44 +0000 | [diff] [blame] | 1133 | case CK_NullToPointer: | 
|  | 1134 | return "NullToPointer"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1135 | case CK_BaseToDerivedMemberPointer: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1136 | return "BaseToDerivedMemberPointer"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1137 | case CK_DerivedToBaseMemberPointer: | 
| Anders Carlsson | 1a31a18 | 2009-10-30 00:46:35 +0000 | [diff] [blame] | 1138 | return "DerivedToBaseMemberPointer"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1139 | case CK_UserDefinedConversion: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1140 | return "UserDefinedConversion"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1141 | case CK_ConstructorConversion: | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1142 | return "ConstructorConversion"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1143 | case CK_IntegralToPointer: | 
| Anders Carlsson | 7f9e646 | 2009-09-15 04:48:33 +0000 | [diff] [blame] | 1144 | return "IntegralToPointer"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1145 | case CK_PointerToIntegral: | 
| Anders Carlsson | 7f9e646 | 2009-09-15 04:48:33 +0000 | [diff] [blame] | 1146 | return "PointerToIntegral"; | 
| John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 1147 | case CK_PointerToBoolean: | 
|  | 1148 | return "PointerToBoolean"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1149 | case CK_ToVoid: | 
| Anders Carlsson | ebeaf20 | 2009-10-16 02:35:04 +0000 | [diff] [blame] | 1150 | return "ToVoid"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1151 | case CK_VectorSplat: | 
| Anders Carlsson | 16a8904 | 2009-10-16 05:23:41 +0000 | [diff] [blame] | 1152 | return "VectorSplat"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1153 | case CK_IntegralCast: | 
| Anders Carlsson | 82debc7 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 1154 | return "IntegralCast"; | 
| John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 1155 | case CK_IntegralToBoolean: | 
|  | 1156 | return "IntegralToBoolean"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1157 | case CK_IntegralToFloating: | 
| Anders Carlsson | 82debc7 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 1158 | return "IntegralToFloating"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1159 | case CK_FloatingToIntegral: | 
| Anders Carlsson | 82debc7 | 2009-10-18 18:12:03 +0000 | [diff] [blame] | 1160 | return "FloatingToIntegral"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1161 | case CK_FloatingCast: | 
| Benjamin Kramer | c6b2916 | 2009-10-18 19:02:15 +0000 | [diff] [blame] | 1162 | return "FloatingCast"; | 
| John McCall | daa8e4e | 2010-11-15 09:13:47 +0000 | [diff] [blame] | 1163 | case CK_FloatingToBoolean: | 
|  | 1164 | return "FloatingToBoolean"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1165 | case CK_MemberPointerToBoolean: | 
| Anders Carlsson | bc0e078 | 2009-11-23 20:04:44 +0000 | [diff] [blame] | 1166 | return "MemberPointerToBoolean"; | 
| John McCall | 1d9b3b2 | 2011-09-09 05:25:32 +0000 | [diff] [blame] | 1167 | case CK_CPointerToObjCPointerCast: | 
|  | 1168 | return "CPointerToObjCPointerCast"; | 
|  | 1169 | case CK_BlockPointerToObjCPointerCast: | 
|  | 1170 | return "BlockPointerToObjCPointerCast"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1171 | case CK_AnyPointerToBlockPointerCast: | 
| Fariborz Jahanian | 3b27f1a | 2009-12-11 22:40:48 +0000 | [diff] [blame] | 1172 | return "AnyPointerToBlockPointerCast"; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1173 | case CK_ObjCObjectLValueCast: | 
| Douglas Gregor | 569c316 | 2010-08-07 11:51:51 +0000 | [diff] [blame] | 1174 | return "ObjCObjectLValueCast"; | 
| John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 1175 | case CK_FloatingRealToComplex: | 
|  | 1176 | return "FloatingRealToComplex"; | 
| John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 1177 | case CK_FloatingComplexToReal: | 
|  | 1178 | return "FloatingComplexToReal"; | 
|  | 1179 | case CK_FloatingComplexToBoolean: | 
|  | 1180 | return "FloatingComplexToBoolean"; | 
| John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 1181 | case CK_FloatingComplexCast: | 
|  | 1182 | return "FloatingComplexCast"; | 
| John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 1183 | case CK_FloatingComplexToIntegralComplex: | 
|  | 1184 | return "FloatingComplexToIntegralComplex"; | 
| John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 1185 | case CK_IntegralRealToComplex: | 
|  | 1186 | return "IntegralRealToComplex"; | 
| John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 1187 | case CK_IntegralComplexToReal: | 
|  | 1188 | return "IntegralComplexToReal"; | 
|  | 1189 | case CK_IntegralComplexToBoolean: | 
|  | 1190 | return "IntegralComplexToBoolean"; | 
| John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 1191 | case CK_IntegralComplexCast: | 
|  | 1192 | return "IntegralComplexCast"; | 
| John McCall | f3ea8cf | 2010-11-14 08:17:51 +0000 | [diff] [blame] | 1193 | case CK_IntegralComplexToFloatingComplex: | 
|  | 1194 | return "IntegralComplexToFloatingComplex"; | 
| John McCall | 33e56f3 | 2011-09-10 06:18:15 +0000 | [diff] [blame] | 1195 | case CK_ARCConsumeObject: | 
|  | 1196 | return "ARCConsumeObject"; | 
|  | 1197 | case CK_ARCProduceObject: | 
|  | 1198 | return "ARCProduceObject"; | 
|  | 1199 | case CK_ARCReclaimReturnedObject: | 
|  | 1200 | return "ARCReclaimReturnedObject"; | 
|  | 1201 | case CK_ARCExtendBlockObject: | 
|  | 1202 | return "ARCCExtendBlockObject"; | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1203 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1204 |  | 
| John McCall | 2bb5d00 | 2010-11-13 09:02:35 +0000 | [diff] [blame] | 1205 | llvm_unreachable("Unhandled cast kind!"); | 
| Anders Carlsson | f8ec55a | 2009-09-03 00:59:21 +0000 | [diff] [blame] | 1206 | return 0; | 
|  | 1207 | } | 
|  | 1208 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1209 | Expr *CastExpr::getSubExprAsWritten() { | 
|  | 1210 | Expr *SubExpr = 0; | 
|  | 1211 | CastExpr *E = this; | 
|  | 1212 | do { | 
|  | 1213 | SubExpr = E->getSubExpr(); | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 1214 |  | 
|  | 1215 | // Skip through reference binding to temporary. | 
|  | 1216 | if (MaterializeTemporaryExpr *Materialize | 
|  | 1217 | = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) | 
|  | 1218 | SubExpr = Materialize->GetTemporaryExpr(); | 
|  | 1219 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1220 | // Skip any temporary bindings; they're implicit. | 
|  | 1221 | if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) | 
|  | 1222 | SubExpr = Binder->getSubExpr(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1223 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1224 | // Conversions by constructor and conversion functions have a | 
|  | 1225 | // subexpression describing the call; strip it off. | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1226 | if (E->getCastKind() == CK_ConstructorConversion) | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1227 | SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1228 | else if (E->getCastKind() == CK_UserDefinedConversion) | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1229 | SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1230 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1231 | // If the subexpression we're left with is an implicit cast, look | 
|  | 1232 | // through that, too. | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1233 | } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); | 
|  | 1234 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 1235 | return SubExpr; | 
|  | 1236 | } | 
|  | 1237 |  | 
| John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1238 | CXXBaseSpecifier **CastExpr::path_buffer() { | 
|  | 1239 | switch (getStmtClass()) { | 
|  | 1240 | #define ABSTRACT_STMT(x) | 
|  | 1241 | #define CASTEXPR(Type, Base) \ | 
|  | 1242 | case Stmt::Type##Class: \ | 
|  | 1243 | return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); | 
|  | 1244 | #define STMT(Type, Base) | 
|  | 1245 | #include "clang/AST/StmtNodes.inc" | 
|  | 1246 | default: | 
|  | 1247 | llvm_unreachable("non-cast expressions not possible here"); | 
|  | 1248 | return 0; | 
|  | 1249 | } | 
|  | 1250 | } | 
|  | 1251 |  | 
|  | 1252 | void CastExpr::setCastPath(const CXXCastPath &Path) { | 
|  | 1253 | assert(Path.size() == path_size()); | 
|  | 1254 | memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); | 
|  | 1255 | } | 
|  | 1256 |  | 
|  | 1257 | ImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, | 
|  | 1258 | CastKind Kind, Expr *Operand, | 
|  | 1259 | const CXXCastPath *BasePath, | 
| John McCall | 5baba9d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 1260 | ExprValueKind VK) { | 
| John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1261 | unsigned PathSize = (BasePath ? BasePath->size() : 0); | 
|  | 1262 | void *Buffer = | 
|  | 1263 | C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); | 
|  | 1264 | ImplicitCastExpr *E = | 
| John McCall | 5baba9d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 1265 | new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); | 
| John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1266 | if (PathSize) E->setCastPath(*BasePath); | 
|  | 1267 | return E; | 
|  | 1268 | } | 
|  | 1269 |  | 
|  | 1270 | ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, | 
|  | 1271 | unsigned PathSize) { | 
|  | 1272 | void *Buffer = | 
|  | 1273 | C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); | 
|  | 1274 | return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); | 
|  | 1275 | } | 
|  | 1276 |  | 
|  | 1277 |  | 
|  | 1278 | CStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1279 | ExprValueKind VK, CastKind K, Expr *Op, | 
| John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1280 | const CXXCastPath *BasePath, | 
|  | 1281 | TypeSourceInfo *WrittenTy, | 
|  | 1282 | SourceLocation L, SourceLocation R) { | 
|  | 1283 | unsigned PathSize = (BasePath ? BasePath->size() : 0); | 
|  | 1284 | void *Buffer = | 
|  | 1285 | C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); | 
|  | 1286 | CStyleCastExpr *E = | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1287 | new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); | 
| John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1288 | if (PathSize) E->setCastPath(*BasePath); | 
|  | 1289 | return E; | 
|  | 1290 | } | 
|  | 1291 |  | 
|  | 1292 | CStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { | 
|  | 1293 | void *Buffer = | 
|  | 1294 | C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); | 
|  | 1295 | return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); | 
|  | 1296 | } | 
|  | 1297 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1298 | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it | 
|  | 1299 | /// corresponds to, e.g. "<<=". | 
|  | 1300 | const char *BinaryOperator::getOpcodeStr(Opcode Op) { | 
|  | 1301 | switch (Op) { | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1302 | case BO_PtrMemD:   return ".*"; | 
|  | 1303 | case BO_PtrMemI:   return "->*"; | 
|  | 1304 | case BO_Mul:       return "*"; | 
|  | 1305 | case BO_Div:       return "/"; | 
|  | 1306 | case BO_Rem:       return "%"; | 
|  | 1307 | case BO_Add:       return "+"; | 
|  | 1308 | case BO_Sub:       return "-"; | 
|  | 1309 | case BO_Shl:       return "<<"; | 
|  | 1310 | case BO_Shr:       return ">>"; | 
|  | 1311 | case BO_LT:        return "<"; | 
|  | 1312 | case BO_GT:        return ">"; | 
|  | 1313 | case BO_LE:        return "<="; | 
|  | 1314 | case BO_GE:        return ">="; | 
|  | 1315 | case BO_EQ:        return "=="; | 
|  | 1316 | case BO_NE:        return "!="; | 
|  | 1317 | case BO_And:       return "&"; | 
|  | 1318 | case BO_Xor:       return "^"; | 
|  | 1319 | case BO_Or:        return "|"; | 
|  | 1320 | case BO_LAnd:      return "&&"; | 
|  | 1321 | case BO_LOr:       return "||"; | 
|  | 1322 | case BO_Assign:    return "="; | 
|  | 1323 | case BO_MulAssign: return "*="; | 
|  | 1324 | case BO_DivAssign: return "/="; | 
|  | 1325 | case BO_RemAssign: return "%="; | 
|  | 1326 | case BO_AddAssign: return "+="; | 
|  | 1327 | case BO_SubAssign: return "-="; | 
|  | 1328 | case BO_ShlAssign: return "<<="; | 
|  | 1329 | case BO_ShrAssign: return ">>="; | 
|  | 1330 | case BO_AndAssign: return "&="; | 
|  | 1331 | case BO_XorAssign: return "^="; | 
|  | 1332 | case BO_OrAssign:  return "|="; | 
|  | 1333 | case BO_Comma:     return ","; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1334 | } | 
| Douglas Gregor | baf5348 | 2009-03-12 22:51:37 +0000 | [diff] [blame] | 1335 |  | 
|  | 1336 | return ""; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1337 | } | 
|  | 1338 |  | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1339 | BinaryOperatorKind | 
| Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 1340 | BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { | 
|  | 1341 | switch (OO) { | 
| David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1342 | default: llvm_unreachable("Not an overloadable binary operator"); | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1343 | case OO_Plus: return BO_Add; | 
|  | 1344 | case OO_Minus: return BO_Sub; | 
|  | 1345 | case OO_Star: return BO_Mul; | 
|  | 1346 | case OO_Slash: return BO_Div; | 
|  | 1347 | case OO_Percent: return BO_Rem; | 
|  | 1348 | case OO_Caret: return BO_Xor; | 
|  | 1349 | case OO_Amp: return BO_And; | 
|  | 1350 | case OO_Pipe: return BO_Or; | 
|  | 1351 | case OO_Equal: return BO_Assign; | 
|  | 1352 | case OO_Less: return BO_LT; | 
|  | 1353 | case OO_Greater: return BO_GT; | 
|  | 1354 | case OO_PlusEqual: return BO_AddAssign; | 
|  | 1355 | case OO_MinusEqual: return BO_SubAssign; | 
|  | 1356 | case OO_StarEqual: return BO_MulAssign; | 
|  | 1357 | case OO_SlashEqual: return BO_DivAssign; | 
|  | 1358 | case OO_PercentEqual: return BO_RemAssign; | 
|  | 1359 | case OO_CaretEqual: return BO_XorAssign; | 
|  | 1360 | case OO_AmpEqual: return BO_AndAssign; | 
|  | 1361 | case OO_PipeEqual: return BO_OrAssign; | 
|  | 1362 | case OO_LessLess: return BO_Shl; | 
|  | 1363 | case OO_GreaterGreater: return BO_Shr; | 
|  | 1364 | case OO_LessLessEqual: return BO_ShlAssign; | 
|  | 1365 | case OO_GreaterGreaterEqual: return BO_ShrAssign; | 
|  | 1366 | case OO_EqualEqual: return BO_EQ; | 
|  | 1367 | case OO_ExclaimEqual: return BO_NE; | 
|  | 1368 | case OO_LessEqual: return BO_LE; | 
|  | 1369 | case OO_GreaterEqual: return BO_GE; | 
|  | 1370 | case OO_AmpAmp: return BO_LAnd; | 
|  | 1371 | case OO_PipePipe: return BO_LOr; | 
|  | 1372 | case OO_Comma: return BO_Comma; | 
|  | 1373 | case OO_ArrowStar: return BO_PtrMemI; | 
| Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 1374 | } | 
|  | 1375 | } | 
|  | 1376 |  | 
|  | 1377 | OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { | 
|  | 1378 | static const OverloadedOperatorKind OverOps[] = { | 
|  | 1379 | /* .* Cannot be overloaded */OO_None, OO_ArrowStar, | 
|  | 1380 | OO_Star, OO_Slash, OO_Percent, | 
|  | 1381 | OO_Plus, OO_Minus, | 
|  | 1382 | OO_LessLess, OO_GreaterGreater, | 
|  | 1383 | OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, | 
|  | 1384 | OO_EqualEqual, OO_ExclaimEqual, | 
|  | 1385 | OO_Amp, | 
|  | 1386 | OO_Caret, | 
|  | 1387 | OO_Pipe, | 
|  | 1388 | OO_AmpAmp, | 
|  | 1389 | OO_PipePipe, | 
|  | 1390 | OO_Equal, OO_StarEqual, | 
|  | 1391 | OO_SlashEqual, OO_PercentEqual, | 
|  | 1392 | OO_PlusEqual, OO_MinusEqual, | 
|  | 1393 | OO_LessLessEqual, OO_GreaterGreaterEqual, | 
|  | 1394 | OO_AmpEqual, OO_CaretEqual, | 
|  | 1395 | OO_PipeEqual, | 
|  | 1396 | OO_Comma | 
|  | 1397 | }; | 
|  | 1398 | return OverOps[Opc]; | 
|  | 1399 | } | 
|  | 1400 |  | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1401 | InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, | 
| Chris Lattner | 418f6c7 | 2008-10-26 23:43:26 +0000 | [diff] [blame] | 1402 | Expr **initExprs, unsigned numInits, | 
| Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1403 | SourceLocation rbraceloc) | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1404 | : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1405 | false, false), | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1406 | InitExprs(C, numInits), | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), | 
| Argyrios Kyrtzidis | 4423ac0 | 2011-04-21 00:27:41 +0000 | [diff] [blame] | 1408 | HadArrayRangeDesignator(false) | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1409 | { | 
| Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1410 | for (unsigned I = 0; I != numInits; ++I) { | 
|  | 1411 | if (initExprs[I]->isTypeDependent()) | 
| John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 1412 | ExprBits.TypeDependent = true; | 
| Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1413 | if (initExprs[I]->isValueDependent()) | 
| John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 1414 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1415 | if (initExprs[I]->isInstantiationDependent()) | 
|  | 1416 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1417 | if (initExprs[I]->containsUnexpandedParameterPack()) | 
|  | 1418 | ExprBits.ContainsUnexpandedParameterPack = true; | 
| Douglas Gregor | 73460a3 | 2009-11-19 23:25:22 +0000 | [diff] [blame] | 1419 | } | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1420 |  | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1421 | InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); | 
| Anders Carlsson | 66b5a8a | 2007-08-31 04:56:16 +0000 | [diff] [blame] | 1422 | } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1423 |  | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1424 | void InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { | 
| Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1425 | if (NumInits > InitExprs.size()) | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1426 | InitExprs.reserve(C, NumInits); | 
| Douglas Gregor | fa21920 | 2009-03-20 23:58:33 +0000 | [diff] [blame] | 1427 | } | 
|  | 1428 |  | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1429 | void InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1430 | InitExprs.resize(C, NumInits, 0); | 
| Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1431 | } | 
|  | 1432 |  | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1433 | Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { | 
| Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1434 | if (Init >= InitExprs.size()) { | 
| Ted Kremenek | 709210f | 2010-04-13 23:39:13 +0000 | [diff] [blame] | 1435 | InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); | 
| Ted Kremenek | ba7bc55 | 2010-02-19 01:50:18 +0000 | [diff] [blame] | 1436 | InitExprs.back() = expr; | 
|  | 1437 | return 0; | 
| Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1438 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 |  | 
| Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 1440 | Expr *Result = cast_or_null<Expr>(InitExprs[Init]); | 
|  | 1441 | InitExprs[Init] = expr; | 
|  | 1442 | return Result; | 
|  | 1443 | } | 
|  | 1444 |  | 
| Argyrios Kyrtzidis | 3e8dc2a | 2011-04-21 20:03:38 +0000 | [diff] [blame] | 1445 | void InitListExpr::setArrayFiller(Expr *filler) { | 
| Argyrios Kyrtzidis | 21f77cd | 2011-10-21 23:02:22 +0000 | [diff] [blame] | 1446 | assert(!hasArrayFiller() && "Filler already set!"); | 
| Argyrios Kyrtzidis | 3e8dc2a | 2011-04-21 20:03:38 +0000 | [diff] [blame] | 1447 | ArrayFillerOrUnionFieldInit = filler; | 
|  | 1448 | // Fill out any "holes" in the array due to designated initializers. | 
|  | 1449 | Expr **inits = getInits(); | 
|  | 1450 | for (unsigned i = 0, e = getNumInits(); i != e; ++i) | 
|  | 1451 | if (inits[i] == 0) | 
|  | 1452 | inits[i] = filler; | 
|  | 1453 | } | 
|  | 1454 |  | 
| Ted Kremenek | c4ba51f | 2010-11-09 02:11:40 +0000 | [diff] [blame] | 1455 | SourceRange InitListExpr::getSourceRange() const { | 
|  | 1456 | if (SyntacticForm) | 
|  | 1457 | return SyntacticForm->getSourceRange(); | 
|  | 1458 | SourceLocation Beg = LBraceLoc, End = RBraceLoc; | 
|  | 1459 | if (Beg.isInvalid()) { | 
|  | 1460 | // Find the first non-null initializer. | 
|  | 1461 | for (InitExprsTy::const_iterator I = InitExprs.begin(), | 
|  | 1462 | E = InitExprs.end(); | 
|  | 1463 | I != E; ++I) { | 
|  | 1464 | if (Stmt *S = *I) { | 
|  | 1465 | Beg = S->getLocStart(); | 
|  | 1466 | break; | 
|  | 1467 | } | 
|  | 1468 | } | 
|  | 1469 | } | 
|  | 1470 | if (End.isInvalid()) { | 
|  | 1471 | // Find the first non-null initializer from the end. | 
|  | 1472 | for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), | 
|  | 1473 | E = InitExprs.rend(); | 
|  | 1474 | I != E; ++I) { | 
|  | 1475 | if (Stmt *S = *I) { | 
|  | 1476 | End = S->getSourceRange().getEnd(); | 
|  | 1477 | break; | 
|  | 1478 | } | 
|  | 1479 | } | 
|  | 1480 | } | 
|  | 1481 | return SourceRange(Beg, End); | 
|  | 1482 | } | 
|  | 1483 |  | 
| Steve Naroff | bfdcae6 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 1484 | /// getFunctionType - Return the underlying function type for this block. | 
| Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1485 | /// | 
|  | 1486 | const FunctionType *BlockExpr::getFunctionType() const { | 
| Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 1487 | return getType()->getAs<BlockPointerType>()-> | 
| John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1488 | getPointeeType()->getAs<FunctionType>(); | 
| Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1489 | } | 
|  | 1490 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1491 | SourceLocation BlockExpr::getCaretLocation() const { | 
|  | 1492 | return TheBlock->getCaretLocation(); | 
| Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1493 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | const Stmt *BlockExpr::getBody() const { | 
| Douglas Gregor | 7297134 | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 1495 | return TheBlock->getBody(); | 
|  | 1496 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | Stmt *BlockExpr::getBody() { | 
|  | 1498 | return TheBlock->getBody(); | 
| Douglas Gregor | 7297134 | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 1499 | } | 
| Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 1500 |  | 
|  | 1501 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1502 | //===----------------------------------------------------------------------===// | 
|  | 1503 | // Generic Expression Routines | 
|  | 1504 | //===----------------------------------------------------------------------===// | 
|  | 1505 |  | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1506 | /// isUnusedResultAWarning - Return true if this immediate expression should | 
|  | 1507 | /// be warned about if the result is unused.  If so, fill in Loc and Ranges | 
|  | 1508 | /// with location to warn on and the source range[s] to report with the | 
|  | 1509 | /// warning. | 
|  | 1510 | bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1511 | SourceRange &R2, ASTContext &Ctx) const { | 
| Anders Carlsson | ffce2df | 2009-05-15 23:10:19 +0000 | [diff] [blame] | 1512 | // Don't warn if the expr is type dependent. The type could end up | 
|  | 1513 | // instantiating to void. | 
|  | 1514 | if (isTypeDependent()) | 
|  | 1515 | return false; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1516 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1517 | switch (getStmtClass()) { | 
|  | 1518 | default: | 
| John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1519 | if (getType()->isVoidType()) | 
|  | 1520 | return false; | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1521 | Loc = getExprLoc(); | 
|  | 1522 | R1 = getSourceRange(); | 
|  | 1523 | return true; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1524 | case ParenExprClass: | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1525 | return cast<ParenExpr>(this)->getSubExpr()-> | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1526 | isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1527 | case GenericSelectionExprClass: | 
|  | 1528 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> | 
|  | 1529 | isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1530 | case UnaryOperatorClass: { | 
|  | 1531 | const UnaryOperator *UO = cast<UnaryOperator>(this); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1532 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1533 | switch (UO->getOpcode()) { | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1534 | default: break; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1535 | case UO_PostInc: | 
|  | 1536 | case UO_PostDec: | 
|  | 1537 | case UO_PreInc: | 
|  | 1538 | case UO_PreDec:                 // ++/-- | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1539 | return false;  // Not a warning. | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1540 | case UO_Deref: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1541 | // Dereferencing a volatile pointer is a side-effect. | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1542 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1543 | return false; | 
|  | 1544 | break; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1545 | case UO_Real: | 
|  | 1546 | case UO_Imag: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1547 | // accessing a piece of a volatile complex is a side-effect. | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1548 | if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) | 
|  | 1549 | .isVolatileQualified()) | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1550 | return false; | 
|  | 1551 | break; | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1552 | case UO_Extension: | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1553 | return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1554 | } | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1555 | Loc = UO->getOperatorLoc(); | 
|  | 1556 | R1 = UO->getSubExpr()->getSourceRange(); | 
|  | 1557 | return true; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1558 | } | 
| Chris Lattner | e7716e6 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 1559 | case BinaryOperatorClass: { | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1560 | const BinaryOperator *BO = cast<BinaryOperator>(this); | 
| Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 1561 | switch (BO->getOpcode()) { | 
|  | 1562 | default: | 
|  | 1563 | break; | 
| Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 1564 | // Consider the RHS of comma for side effects. LHS was checked by | 
|  | 1565 | // Sema::CheckCommaOperands. | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1566 | case BO_Comma: | 
| Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 1567 | // ((foo = <blah>), 0) is an idiom for hiding the result (and | 
|  | 1568 | // lvalue-ness) of an assignment written in a macro. | 
|  | 1569 | if (IntegerLiteral *IE = | 
|  | 1570 | dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) | 
|  | 1571 | if (IE->getValue() == 0) | 
|  | 1572 | return false; | 
| Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 1573 | return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
|  | 1574 | // Consider '||', '&&' to have side effects if the LHS or RHS does. | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1575 | case BO_LAnd: | 
|  | 1576 | case BO_LOr: | 
| Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 1577 | if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || | 
|  | 1578 | !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) | 
|  | 1579 | return false; | 
|  | 1580 | break; | 
| John McCall | bf0ee35 | 2010-02-16 04:10:53 +0000 | [diff] [blame] | 1581 | } | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1582 | if (BO->isAssignmentOp()) | 
|  | 1583 | return false; | 
|  | 1584 | Loc = BO->getOperatorLoc(); | 
|  | 1585 | R1 = BO->getLHS()->getSourceRange(); | 
|  | 1586 | R2 = BO->getRHS()->getSourceRange(); | 
|  | 1587 | return true; | 
| Chris Lattner | e7716e6 | 2007-12-01 06:07:34 +0000 | [diff] [blame] | 1588 | } | 
| Chris Lattner | eb14fe8 | 2007-08-25 02:00:02 +0000 | [diff] [blame] | 1589 | case CompoundAssignOperatorClass: | 
| Douglas Gregor | c6dfe19 | 2010-05-08 22:41:50 +0000 | [diff] [blame] | 1590 | case VAArgExprClass: | 
| Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1591 | case AtomicExprClass: | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1592 | return false; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1593 |  | 
| Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 1594 | case ConditionalOperatorClass: { | 
| Ted Kremenek | fb7cb35 | 2011-03-01 20:34:48 +0000 | [diff] [blame] | 1595 | // If only one of the LHS or RHS is a warning, the operator might | 
|  | 1596 | // be being used for control flow. Only warn if both the LHS and | 
|  | 1597 | // RHS are warnings. | 
| Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 1598 | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); | 
| Ted Kremenek | fb7cb35 | 2011-03-01 20:34:48 +0000 | [diff] [blame] | 1599 | if (!Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) | 
|  | 1600 | return false; | 
|  | 1601 | if (!Exp->getLHS()) | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1602 | return true; | 
| Ted Kremenek | fb7cb35 | 2011-03-01 20:34:48 +0000 | [diff] [blame] | 1603 | return Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
| Fariborz Jahanian | ab38e4b | 2007-12-01 19:58:28 +0000 | [diff] [blame] | 1604 | } | 
|  | 1605 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1606 | case MemberExprClass: | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1607 | // If the base pointer or element is to a volatile pointer/field, accessing | 
|  | 1608 | // it is a side effect. | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1609 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1610 | return false; | 
|  | 1611 | Loc = cast<MemberExpr>(this)->getMemberLoc(); | 
|  | 1612 | R1 = SourceRange(Loc, Loc); | 
|  | 1613 | R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); | 
|  | 1614 | return true; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1616 | case ArraySubscriptExprClass: | 
|  | 1617 | // If the base pointer or element is to a volatile pointer/field, accessing | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1618 | // it is a side effect. | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1619 | if (Ctx.getCanonicalType(getType()).isVolatileQualified()) | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1620 | return false; | 
|  | 1621 | Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); | 
|  | 1622 | R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); | 
|  | 1623 | R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); | 
|  | 1624 | return true; | 
| Eli Friedman | 211f6ad | 2008-05-27 15:24:04 +0000 | [diff] [blame] | 1625 |  | 
| Chandler Carruth | 9b10683 | 2011-08-17 09:49:44 +0000 | [diff] [blame] | 1626 | case CXXOperatorCallExprClass: { | 
|  | 1627 | // We warn about operator== and operator!= even when user-defined operator | 
|  | 1628 | // overloads as there is no reasonable way to define these such that they | 
|  | 1629 | // have non-trivial, desirable side-effects. See the -Wunused-comparison | 
|  | 1630 | // warning: these operators are commonly typo'ed, and so warning on them | 
|  | 1631 | // provides additional value as well. If this list is updated, | 
|  | 1632 | // DiagnoseUnusedComparison should be as well. | 
|  | 1633 | const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); | 
|  | 1634 | if (Op->getOperator() == OO_EqualEqual || | 
| Matt Beaumont-Gay | 6e52183 | 2011-09-19 18:51:20 +0000 | [diff] [blame] | 1635 | Op->getOperator() == OO_ExclaimEqual) { | 
|  | 1636 | Loc = Op->getOperatorLoc(); | 
|  | 1637 | R1 = Op->getSourceRange(); | 
| Chandler Carruth | 9b10683 | 2011-08-17 09:49:44 +0000 | [diff] [blame] | 1638 | return true; | 
| Matt Beaumont-Gay | 6e52183 | 2011-09-19 18:51:20 +0000 | [diff] [blame] | 1639 | } | 
| Chandler Carruth | 9b10683 | 2011-08-17 09:49:44 +0000 | [diff] [blame] | 1640 |  | 
|  | 1641 | // Fallthrough for generic call handling. | 
|  | 1642 | } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1643 | case CallExprClass: | 
| Eli Friedman | 852871a | 2009-04-29 16:35:53 +0000 | [diff] [blame] | 1644 | case CXXMemberCallExprClass: { | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1645 | // If this is a direct call, get the callee. | 
|  | 1646 | const CallExpr *CE = cast<CallExpr>(this); | 
| Nuno Lopes | d20254f | 2009-12-20 23:11:08 +0000 | [diff] [blame] | 1647 | if (const Decl *FD = CE->getCalleeDecl()) { | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1648 | // If the callee has attribute pure, const, or warn_unused_result, warn | 
|  | 1649 | // about it. void foo() { strlen("bar"); } should warn. | 
| Chris Lattner | bc8d42c | 2009-10-13 04:53:48 +0000 | [diff] [blame] | 1650 | // | 
|  | 1651 | // Note: If new cases are added here, DiagnoseUnusedExprResult should be | 
|  | 1652 | // updated to match for QoI. | 
|  | 1653 | if (FD->getAttr<WarnUnusedResultAttr>() || | 
|  | 1654 | FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { | 
|  | 1655 | Loc = CE->getCallee()->getLocStart(); | 
|  | 1656 | R1 = CE->getCallee()->getSourceRange(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 |  | 
| Chris Lattner | bc8d42c | 2009-10-13 04:53:48 +0000 | [diff] [blame] | 1658 | if (unsigned NumArgs = CE->getNumArgs()) | 
|  | 1659 | R2 = SourceRange(CE->getArg(0)->getLocStart(), | 
|  | 1660 | CE->getArg(NumArgs-1)->getLocEnd()); | 
|  | 1661 | return true; | 
|  | 1662 | } | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1663 | } | 
|  | 1664 | return false; | 
|  | 1665 | } | 
| Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1666 |  | 
|  | 1667 | case CXXTemporaryObjectExprClass: | 
|  | 1668 | case CXXConstructExprClass: | 
|  | 1669 | return false; | 
|  | 1670 |  | 
| Fariborz Jahanian | f031774 | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1671 | case ObjCMessageExprClass: { | 
|  | 1672 | const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); | 
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1673 | if (Ctx.getLangOptions().ObjCAutoRefCount && | 
|  | 1674 | ME->isInstanceMessage() && | 
|  | 1675 | !ME->getType()->isVoidType() && | 
|  | 1676 | ME->getSelector().getIdentifierInfoForSlot(0) && | 
|  | 1677 | ME->getSelector().getIdentifierInfoForSlot(0) | 
|  | 1678 | ->getName().startswith("init")) { | 
|  | 1679 | Loc = getExprLoc(); | 
|  | 1680 | R1 = ME->getSourceRange(); | 
|  | 1681 | return true; | 
|  | 1682 | } | 
|  | 1683 |  | 
| Fariborz Jahanian | f031774 | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1684 | const ObjCMethodDecl *MD = ME->getMethodDecl(); | 
|  | 1685 | if (MD && MD->getAttr<WarnUnusedResultAttr>()) { | 
|  | 1686 | Loc = getExprLoc(); | 
|  | 1687 | return true; | 
|  | 1688 | } | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1689 | return false; | 
| Fariborz Jahanian | f031774 | 2010-03-30 18:22:15 +0000 | [diff] [blame] | 1690 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 |  | 
| John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1692 | case ObjCPropertyRefExprClass: | 
| Chris Lattner | 5e94a0d | 2009-08-16 16:51:50 +0000 | [diff] [blame] | 1693 | Loc = getExprLoc(); | 
|  | 1694 | R1 = getSourceRange(); | 
| Chris Lattner | a50089e | 2009-08-16 16:45:18 +0000 | [diff] [blame] | 1695 | return true; | 
| John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 1696 |  | 
| John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame^] | 1697 | case PseudoObjectExprClass: { | 
|  | 1698 | const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); | 
|  | 1699 |  | 
|  | 1700 | // Only complain about things that have the form of a getter. | 
|  | 1701 | if (isa<UnaryOperator>(PO->getSyntacticForm()) || | 
|  | 1702 | isa<BinaryOperator>(PO->getSyntacticForm())) | 
|  | 1703 | return false; | 
|  | 1704 |  | 
|  | 1705 | Loc = getExprLoc(); | 
|  | 1706 | R1 = getSourceRange(); | 
|  | 1707 | return true; | 
|  | 1708 | } | 
|  | 1709 |  | 
| Chris Lattner | 611b2ec | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1710 | case StmtExprClass: { | 
|  | 1711 | // Statement exprs don't logically have side effects themselves, but are | 
|  | 1712 | // sometimes used in macros in ways that give them a type that is unused. | 
|  | 1713 | // For example ({ blah; foo(); }) will end up with a type if foo has a type. | 
|  | 1714 | // however, if the result of the stmt expr is dead, we don't want to emit a | 
|  | 1715 | // warning. | 
|  | 1716 | const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); | 
| Argyrios Kyrtzidis | d2827af | 2010-09-19 21:21:10 +0000 | [diff] [blame] | 1717 | if (!CS->body_empty()) { | 
| Chris Lattner | 611b2ec | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1718 | if (const Expr *E = dyn_cast<Expr>(CS->body_back())) | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1719 | return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
| Argyrios Kyrtzidis | d2827af | 2010-09-19 21:21:10 +0000 | [diff] [blame] | 1720 | if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) | 
|  | 1721 | if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) | 
|  | 1722 | return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); | 
|  | 1723 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1724 |  | 
| John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1725 | if (getType()->isVoidType()) | 
|  | 1726 | return false; | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1727 | Loc = cast<StmtExpr>(this)->getLParenLoc(); | 
|  | 1728 | R1 = getSourceRange(); | 
|  | 1729 | return true; | 
| Chris Lattner | 611b2ec | 2008-07-26 19:51:01 +0000 | [diff] [blame] | 1730 | } | 
| Douglas Gregor | 6eec8e8 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 1731 | case CStyleCastExprClass: | 
| Chris Lattner | fb84664 | 2009-07-28 18:25:28 +0000 | [diff] [blame] | 1732 | // If this is an explicit cast to void, allow it.  People do this when they | 
|  | 1733 | // think they know what they're doing :). | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1734 | if (getType()->isVoidType()) | 
| Chris Lattner | fb84664 | 2009-07-28 18:25:28 +0000 | [diff] [blame] | 1735 | return false; | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1736 | Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); | 
|  | 1737 | R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); | 
|  | 1738 | return true; | 
| Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1739 | case CXXFunctionalCastExprClass: { | 
| John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1740 | if (getType()->isVoidType()) | 
|  | 1741 | return false; | 
| Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1742 | const CastExpr *CE = cast<CastExpr>(this); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1743 |  | 
| Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1744 | // If this is a cast to void or a constructor conversion, check the operand. | 
|  | 1745 | // Otherwise, the result of the cast is unused. | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1746 | if (CE->getCastKind() == CK_ToVoid || | 
|  | 1747 | CE->getCastKind() == CK_ConstructorConversion) | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1748 | return (cast<CastExpr>(this)->getSubExpr() | 
|  | 1749 | ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1750 | Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); | 
|  | 1751 | R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); | 
|  | 1752 | return true; | 
| Anders Carlsson | 58beed9 | 2009-11-17 17:11:23 +0000 | [diff] [blame] | 1753 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 |  | 
| Eli Friedman | 4be1f47 | 2008-05-19 21:24:43 +0000 | [diff] [blame] | 1755 | case ImplicitCastExprClass: | 
|  | 1756 | // Check the operand, since implicit casts are inserted by Sema | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1757 | return (cast<ImplicitCastExpr>(this) | 
|  | 1758 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); | 
| Eli Friedman | 4be1f47 | 2008-05-19 21:24:43 +0000 | [diff] [blame] | 1759 |  | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1760 | case CXXDefaultArgExprClass: | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1761 | return (cast<CXXDefaultArgExpr>(this) | 
|  | 1762 | ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1763 |  | 
|  | 1764 | case CXXNewExprClass: | 
|  | 1765 | // FIXME: In theory, there might be new expressions that don't have side | 
|  | 1766 | // effects (e.g. a placement new with an uninitialized POD). | 
|  | 1767 | case CXXDeleteExprClass: | 
| Chris Lattner | 026dc96 | 2009-02-14 07:37:35 +0000 | [diff] [blame] | 1768 | return false; | 
| Anders Carlsson | 2d46eb2 | 2009-08-16 04:11:06 +0000 | [diff] [blame] | 1769 | case CXXBindTemporaryExprClass: | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1770 | return (cast<CXXBindTemporaryExpr>(this) | 
|  | 1771 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); | 
| John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 1772 | case ExprWithCleanupsClass: | 
|  | 1773 | return (cast<ExprWithCleanups>(this) | 
| Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 1774 | ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1775 | } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1776 | } | 
|  | 1777 |  | 
| Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1778 | /// isOBJCGCCandidate - Check if an expression is objc gc'able. | 
| Fariborz Jahanian | 7f4f86a | 2009-09-08 23:38:54 +0000 | [diff] [blame] | 1779 | /// returns true, if it is; false otherwise. | 
| Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1780 | bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1781 | const Expr *E = IgnoreParens(); | 
|  | 1782 | switch (E->getStmtClass()) { | 
| Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1783 | default: | 
|  | 1784 | return false; | 
|  | 1785 | case ObjCIvarRefExprClass: | 
|  | 1786 | return true; | 
| Fariborz Jahanian | 207c521 | 2009-02-23 18:59:50 +0000 | [diff] [blame] | 1787 | case Expr::UnaryOperatorClass: | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1788 | return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); | 
| Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1789 | case ImplicitCastExprClass: | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1790 | return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 1791 | case MaterializeTemporaryExprClass: | 
|  | 1792 | return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() | 
|  | 1793 | ->isOBJCGCCandidate(Ctx); | 
| Fariborz Jahanian | 06b8912 | 2009-05-05 23:28:21 +0000 | [diff] [blame] | 1794 | case CStyleCastExprClass: | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1795 | return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); | 
| Fariborz Jahanian | e3f8349 | 2011-09-23 18:57:30 +0000 | [diff] [blame] | 1796 | case BlockDeclRefExprClass: | 
| Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1797 | case DeclRefExprClass: { | 
| Fariborz Jahanian | e3f8349 | 2011-09-23 18:57:30 +0000 | [diff] [blame] | 1798 |  | 
|  | 1799 | const Decl *D; | 
|  | 1800 | if (const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E)) | 
|  | 1801 | D = BDRE->getDecl(); | 
|  | 1802 | else | 
|  | 1803 | D = cast<DeclRefExpr>(E)->getDecl(); | 
|  | 1804 |  | 
| Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1805 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { | 
|  | 1806 | if (VD->hasGlobalStorage()) | 
|  | 1807 | return true; | 
|  | 1808 | QualType T = VD->getType(); | 
| Fariborz Jahanian | 59a53fa | 2009-09-16 18:09:18 +0000 | [diff] [blame] | 1809 | // dereferencing to a  pointer is always a gc'able candidate, | 
|  | 1810 | // unless it is __weak. | 
| Daniel Dunbar | 7e88a60 | 2009-09-17 06:31:17 +0000 | [diff] [blame] | 1811 | return T->isPointerType() && | 
| John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1812 | (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); | 
| Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1813 | } | 
| Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1814 | return false; | 
|  | 1815 | } | 
| Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1816 | case MemberExprClass: { | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1817 | const MemberExpr *M = cast<MemberExpr>(E); | 
| Fariborz Jahanian | 102e390 | 2009-06-01 21:29:32 +0000 | [diff] [blame] | 1818 | return M->getBase()->isOBJCGCCandidate(Ctx); | 
| Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1819 | } | 
|  | 1820 | case ArraySubscriptExprClass: | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1821 | return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); | 
| Fariborz Jahanian | 44baa8a | 2009-02-22 18:40:18 +0000 | [diff] [blame] | 1822 | } | 
|  | 1823 | } | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1824 |  | 
| Argyrios Kyrtzidis | 11ab790 | 2010-11-01 18:49:26 +0000 | [diff] [blame] | 1825 | bool Expr::isBoundMemberFunction(ASTContext &Ctx) const { | 
|  | 1826 | if (isTypeDependent()) | 
|  | 1827 | return false; | 
| John McCall | 7eb0a9e | 2010-11-24 05:12:34 +0000 | [diff] [blame] | 1828 | return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; | 
| Argyrios Kyrtzidis | 11ab790 | 2010-11-01 18:49:26 +0000 | [diff] [blame] | 1829 | } | 
|  | 1830 |  | 
| John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1831 | QualType Expr::findBoundMemberType(const Expr *expr) { | 
| John McCall | e0a22d0 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1832 | assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); | 
| John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1833 |  | 
|  | 1834 | // Bound member expressions are always one of these possibilities: | 
|  | 1835 | //   x->m      x.m      x->*y      x.*y | 
|  | 1836 | // (possibly parenthesized) | 
|  | 1837 |  | 
|  | 1838 | expr = expr->IgnoreParens(); | 
|  | 1839 | if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { | 
|  | 1840 | assert(isa<CXXMethodDecl>(mem->getMemberDecl())); | 
|  | 1841 | return mem->getMemberDecl()->getType(); | 
|  | 1842 | } | 
|  | 1843 |  | 
|  | 1844 | if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { | 
|  | 1845 | QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() | 
|  | 1846 | ->getPointeeType(); | 
|  | 1847 | assert(type->isFunctionType()); | 
|  | 1848 | return type; | 
|  | 1849 | } | 
|  | 1850 |  | 
|  | 1851 | assert(isa<UnresolvedMemberExpr>(expr)); | 
|  | 1852 | return QualType(); | 
|  | 1853 | } | 
|  | 1854 |  | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1855 | static Expr::CanThrowResult MergeCanThrow(Expr::CanThrowResult CT1, | 
|  | 1856 | Expr::CanThrowResult CT2) { | 
|  | 1857 | // CanThrowResult constants are ordered so that the maximum is the correct | 
|  | 1858 | // merge result. | 
|  | 1859 | return CT1 > CT2 ? CT1 : CT2; | 
|  | 1860 | } | 
|  | 1861 |  | 
|  | 1862 | static Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) { | 
|  | 1863 | Expr *E = const_cast<Expr*>(CE); | 
|  | 1864 | Expr::CanThrowResult R = Expr::CT_Cannot; | 
| John McCall | 7502c1d | 2011-02-13 04:07:26 +0000 | [diff] [blame] | 1865 | for (Expr::child_range I = E->children(); I && R != Expr::CT_Can; ++I) { | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1866 | R = MergeCanThrow(R, cast<Expr>(*I)->CanThrow(C)); | 
|  | 1867 | } | 
|  | 1868 | return R; | 
|  | 1869 | } | 
|  | 1870 |  | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1871 | static Expr::CanThrowResult CanCalleeThrow(ASTContext &Ctx, const Expr *E, | 
|  | 1872 | const Decl *D, | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1873 | bool NullThrows = true) { | 
|  | 1874 | if (!D) | 
|  | 1875 | return NullThrows ? Expr::CT_Can : Expr::CT_Cannot; | 
|  | 1876 |  | 
|  | 1877 | // See if we can get a function type from the decl somehow. | 
|  | 1878 | const ValueDecl *VD = dyn_cast<ValueDecl>(D); | 
|  | 1879 | if (!VD) // If we have no clue what we're calling, assume the worst. | 
|  | 1880 | return Expr::CT_Can; | 
|  | 1881 |  | 
| Sebastian Redl | 5221d8f | 2010-09-10 22:34:40 +0000 | [diff] [blame] | 1882 | // As an extension, we assume that __attribute__((nothrow)) functions don't | 
|  | 1883 | // throw. | 
|  | 1884 | if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>()) | 
|  | 1885 | return Expr::CT_Cannot; | 
|  | 1886 |  | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1887 | QualType T = VD->getType(); | 
|  | 1888 | const FunctionProtoType *FT; | 
|  | 1889 | if ((FT = T->getAs<FunctionProtoType>())) { | 
|  | 1890 | } else if (const PointerType *PT = T->getAs<PointerType>()) | 
|  | 1891 | FT = PT->getPointeeType()->getAs<FunctionProtoType>(); | 
|  | 1892 | else if (const ReferenceType *RT = T->getAs<ReferenceType>()) | 
|  | 1893 | FT = RT->getPointeeType()->getAs<FunctionProtoType>(); | 
|  | 1894 | else if (const MemberPointerType *MT = T->getAs<MemberPointerType>()) | 
|  | 1895 | FT = MT->getPointeeType()->getAs<FunctionProtoType>(); | 
|  | 1896 | else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) | 
|  | 1897 | FT = BT->getPointeeType()->getAs<FunctionProtoType>(); | 
|  | 1898 |  | 
|  | 1899 | if (!FT) | 
|  | 1900 | return Expr::CT_Can; | 
|  | 1901 |  | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1902 | if (FT->getExceptionSpecType() == EST_Delayed) { | 
|  | 1903 | assert(isa<CXXConstructorDecl>(D) && | 
|  | 1904 | "only constructor exception specs can be unknown"); | 
|  | 1905 | Ctx.getDiagnostics().Report(E->getLocStart(), | 
|  | 1906 | diag::err_exception_spec_unknown) | 
|  | 1907 | << E->getSourceRange(); | 
|  | 1908 | return Expr::CT_Can; | 
|  | 1909 | } | 
|  | 1910 |  | 
| Sebastian Redl | 8026f6d | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 1911 | return FT->isNothrow(Ctx) ? Expr::CT_Cannot : Expr::CT_Can; | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1912 | } | 
|  | 1913 |  | 
|  | 1914 | static Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) { | 
|  | 1915 | if (DC->isTypeDependent()) | 
|  | 1916 | return Expr::CT_Dependent; | 
|  | 1917 |  | 
| Sebastian Redl | 295995c | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 1918 | if (!DC->getTypeAsWritten()->isReferenceType()) | 
|  | 1919 | return Expr::CT_Cannot; | 
|  | 1920 |  | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 1921 | if (DC->getSubExpr()->isTypeDependent()) | 
|  | 1922 | return Expr::CT_Dependent; | 
|  | 1923 |  | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1924 | return DC->getCastKind() == clang::CK_Dynamic? Expr::CT_Can : Expr::CT_Cannot; | 
|  | 1925 | } | 
|  | 1926 |  | 
|  | 1927 | static Expr::CanThrowResult CanTypeidThrow(ASTContext &C, | 
|  | 1928 | const CXXTypeidExpr *DC) { | 
|  | 1929 | if (DC->isTypeOperand()) | 
|  | 1930 | return Expr::CT_Cannot; | 
|  | 1931 |  | 
|  | 1932 | Expr *Op = DC->getExprOperand(); | 
|  | 1933 | if (Op->isTypeDependent()) | 
|  | 1934 | return Expr::CT_Dependent; | 
|  | 1935 |  | 
|  | 1936 | const RecordType *RT = Op->getType()->getAs<RecordType>(); | 
|  | 1937 | if (!RT) | 
|  | 1938 | return Expr::CT_Cannot; | 
|  | 1939 |  | 
|  | 1940 | if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic()) | 
|  | 1941 | return Expr::CT_Cannot; | 
|  | 1942 |  | 
|  | 1943 | if (Op->Classify(C).isPRValue()) | 
|  | 1944 | return Expr::CT_Cannot; | 
|  | 1945 |  | 
|  | 1946 | return Expr::CT_Can; | 
|  | 1947 | } | 
|  | 1948 |  | 
|  | 1949 | Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { | 
|  | 1950 | // C++ [expr.unary.noexcept]p3: | 
|  | 1951 | //   [Can throw] if in a potentially-evaluated context the expression would | 
|  | 1952 | //   contain: | 
|  | 1953 | switch (getStmtClass()) { | 
|  | 1954 | case CXXThrowExprClass: | 
|  | 1955 | //   - a potentially evaluated throw-expression | 
|  | 1956 | return CT_Can; | 
|  | 1957 |  | 
|  | 1958 | case CXXDynamicCastExprClass: { | 
|  | 1959 | //   - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), | 
|  | 1960 | //     where T is a reference type, that requires a run-time check | 
|  | 1961 | CanThrowResult CT = CanDynamicCastThrow(cast<CXXDynamicCastExpr>(this)); | 
|  | 1962 | if (CT == CT_Can) | 
|  | 1963 | return CT; | 
|  | 1964 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 1965 | } | 
|  | 1966 |  | 
|  | 1967 | case CXXTypeidExprClass: | 
|  | 1968 | //   - a potentially evaluated typeid expression applied to a glvalue | 
|  | 1969 | //     expression whose type is a polymorphic class type | 
|  | 1970 | return CanTypeidThrow(C, cast<CXXTypeidExpr>(this)); | 
|  | 1971 |  | 
|  | 1972 | //   - a potentially evaluated call to a function, member function, function | 
|  | 1973 | //     pointer, or member function pointer that does not have a non-throwing | 
|  | 1974 | //     exception-specification | 
|  | 1975 | case CallExprClass: | 
|  | 1976 | case CXXOperatorCallExprClass: | 
|  | 1977 | case CXXMemberCallExprClass: { | 
| Eli Friedman | ebc93e176 | 2011-05-12 02:11:32 +0000 | [diff] [blame] | 1978 | const CallExpr *CE = cast<CallExpr>(this); | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 1979 | CanThrowResult CT; | 
|  | 1980 | if (isTypeDependent()) | 
|  | 1981 | CT = CT_Dependent; | 
| Eli Friedman | ebc93e176 | 2011-05-12 02:11:32 +0000 | [diff] [blame] | 1982 | else if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens())) | 
|  | 1983 | CT = CT_Cannot; | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 1984 | else | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1985 | CT = CanCalleeThrow(C, this, CE->getCalleeDecl()); | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1986 | if (CT == CT_Can) | 
|  | 1987 | return CT; | 
|  | 1988 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 1989 | } | 
|  | 1990 |  | 
| Sebastian Redl | 295995c | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 1991 | case CXXConstructExprClass: | 
|  | 1992 | case CXXTemporaryObjectExprClass: { | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1993 | CanThrowResult CT = CanCalleeThrow(C, this, | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 1994 | cast<CXXConstructExpr>(this)->getConstructor()); | 
|  | 1995 | if (CT == CT_Can) | 
|  | 1996 | return CT; | 
|  | 1997 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 1998 | } | 
|  | 1999 |  | 
|  | 2000 | case CXXNewExprClass: { | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 2001 | CanThrowResult CT; | 
|  | 2002 | if (isTypeDependent()) | 
|  | 2003 | CT = CT_Dependent; | 
|  | 2004 | else | 
|  | 2005 | CT = MergeCanThrow( | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2006 | CanCalleeThrow(C, this, cast<CXXNewExpr>(this)->getOperatorNew()), | 
|  | 2007 | CanCalleeThrow(C, this, cast<CXXNewExpr>(this)->getConstructor(), | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 2008 | /*NullThrows*/false)); | 
|  | 2009 | if (CT == CT_Can) | 
|  | 2010 | return CT; | 
|  | 2011 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 2012 | } | 
|  | 2013 |  | 
|  | 2014 | case CXXDeleteExprClass: { | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 2015 | CanThrowResult CT; | 
|  | 2016 | QualType DTy = cast<CXXDeleteExpr>(this)->getDestroyedType(); | 
|  | 2017 | if (DTy.isNull() || DTy->isDependentType()) { | 
|  | 2018 | CT = CT_Dependent; | 
|  | 2019 | } else { | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2020 | CT = CanCalleeThrow(C, this, | 
|  | 2021 | cast<CXXDeleteExpr>(this)->getOperatorDelete()); | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 2022 | if (const RecordType *RT = DTy->getAs<RecordType>()) { | 
|  | 2023 | const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2024 | CT = MergeCanThrow(CT, CanCalleeThrow(C, this, RD->getDestructor())); | 
| Sebastian Redl | 0b34cf7 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 2025 | } | 
| Eli Friedman | be57cf4 | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 2026 | if (CT == CT_Can) | 
|  | 2027 | return CT; | 
| Sebastian Redl | 0b34cf7 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 2028 | } | 
|  | 2029 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 2030 | } | 
|  | 2031 |  | 
|  | 2032 | case CXXBindTemporaryExprClass: { | 
|  | 2033 | // The bound temporary has to be destroyed again, which might throw. | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2034 | CanThrowResult CT = CanCalleeThrow(C, this, | 
| Sebastian Redl | 0b34cf7 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 2035 | cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor()); | 
|  | 2036 | if (CT == CT_Can) | 
|  | 2037 | return CT; | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 2038 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 2039 | } | 
|  | 2040 |  | 
|  | 2041 | // ObjC message sends are like function calls, but never have exception | 
|  | 2042 | // specs. | 
|  | 2043 | case ObjCMessageExprClass: | 
|  | 2044 | case ObjCPropertyRefExprClass: | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 2045 | return CT_Can; | 
|  | 2046 |  | 
|  | 2047 | // Many other things have subexpressions, so we have to test those. | 
|  | 2048 | // Some are simple: | 
|  | 2049 | case ParenExprClass: | 
|  | 2050 | case MemberExprClass: | 
|  | 2051 | case CXXReinterpretCastExprClass: | 
|  | 2052 | case CXXConstCastExprClass: | 
|  | 2053 | case ConditionalOperatorClass: | 
|  | 2054 | case CompoundLiteralExprClass: | 
|  | 2055 | case ExtVectorElementExprClass: | 
|  | 2056 | case InitListExprClass: | 
|  | 2057 | case DesignatedInitExprClass: | 
|  | 2058 | case ParenListExprClass: | 
|  | 2059 | case VAArgExprClass: | 
|  | 2060 | case CXXDefaultArgExprClass: | 
| John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 2061 | case ExprWithCleanupsClass: | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 2062 | case ObjCIvarRefExprClass: | 
|  | 2063 | case ObjCIsaExprClass: | 
|  | 2064 | case ShuffleVectorExprClass: | 
|  | 2065 | return CanSubExprsThrow(C, this); | 
|  | 2066 |  | 
|  | 2067 | // Some might be dependent for other reasons. | 
|  | 2068 | case UnaryOperatorClass: | 
|  | 2069 | case ArraySubscriptExprClass: | 
|  | 2070 | case ImplicitCastExprClass: | 
|  | 2071 | case CStyleCastExprClass: | 
|  | 2072 | case CXXStaticCastExprClass: | 
|  | 2073 | case CXXFunctionalCastExprClass: | 
|  | 2074 | case BinaryOperatorClass: | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2075 | case CompoundAssignOperatorClass: | 
|  | 2076 | case MaterializeTemporaryExprClass: { | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 2077 | CanThrowResult CT = isTypeDependent() ? CT_Dependent : CT_Cannot; | 
|  | 2078 | return MergeCanThrow(CT, CanSubExprsThrow(C, this)); | 
|  | 2079 | } | 
|  | 2080 |  | 
|  | 2081 | // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms. | 
|  | 2082 | case StmtExprClass: | 
|  | 2083 | return CT_Can; | 
|  | 2084 |  | 
|  | 2085 | case ChooseExprClass: | 
|  | 2086 | if (isTypeDependent() || isValueDependent()) | 
|  | 2087 | return CT_Dependent; | 
|  | 2088 | return cast<ChooseExpr>(this)->getChosenSubExpr(C)->CanThrow(C); | 
|  | 2089 |  | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2090 | case GenericSelectionExprClass: | 
|  | 2091 | if (cast<GenericSelectionExpr>(this)->isResultDependent()) | 
|  | 2092 | return CT_Dependent; | 
|  | 2093 | return cast<GenericSelectionExpr>(this)->getResultExpr()->CanThrow(C); | 
|  | 2094 |  | 
| Sebastian Redl | 369e51f | 2010-09-10 20:55:33 +0000 | [diff] [blame] | 2095 | // Some expressions are always dependent. | 
|  | 2096 | case DependentScopeDeclRefExprClass: | 
|  | 2097 | case CXXUnresolvedConstructExprClass: | 
|  | 2098 | case CXXDependentScopeMemberExprClass: | 
|  | 2099 | return CT_Dependent; | 
|  | 2100 |  | 
|  | 2101 | default: | 
|  | 2102 | // All other expressions don't have subexpressions, or else they are | 
|  | 2103 | // unevaluated. | 
|  | 2104 | return CT_Cannot; | 
|  | 2105 | } | 
|  | 2106 | } | 
|  | 2107 |  | 
| Ted Kremenek | 4e99a5f | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 2108 | Expr* Expr::IgnoreParens() { | 
|  | 2109 | Expr* E = this; | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2110 | while (true) { | 
|  | 2111 | if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { | 
|  | 2112 | E = P->getSubExpr(); | 
|  | 2113 | continue; | 
|  | 2114 | } | 
|  | 2115 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { | 
|  | 2116 | if (P->getOpcode() == UO_Extension) { | 
|  | 2117 | E = P->getSubExpr(); | 
|  | 2118 | continue; | 
|  | 2119 | } | 
|  | 2120 | } | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2121 | if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { | 
|  | 2122 | if (!P->isResultDependent()) { | 
|  | 2123 | E = P->getResultExpr(); | 
|  | 2124 | continue; | 
|  | 2125 | } | 
|  | 2126 | } | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2127 | return E; | 
|  | 2128 | } | 
| Ted Kremenek | 4e99a5f | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 2129 | } | 
|  | 2130 |  | 
| Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 2131 | /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr | 
|  | 2132 | /// or CastExprs or ImplicitCastExprs, returning their operand. | 
|  | 2133 | Expr *Expr::IgnoreParenCasts() { | 
|  | 2134 | Expr *E = this; | 
|  | 2135 | while (true) { | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2136 | if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { | 
| Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 2137 | E = P->getSubExpr(); | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2138 | continue; | 
|  | 2139 | } | 
|  | 2140 | if (CastExpr *P = dyn_cast<CastExpr>(E)) { | 
| Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 2141 | E = P->getSubExpr(); | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2142 | continue; | 
|  | 2143 | } | 
|  | 2144 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { | 
|  | 2145 | if (P->getOpcode() == UO_Extension) { | 
|  | 2146 | E = P->getSubExpr(); | 
|  | 2147 | continue; | 
|  | 2148 | } | 
|  | 2149 | } | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2150 | if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { | 
|  | 2151 | if (!P->isResultDependent()) { | 
|  | 2152 | E = P->getResultExpr(); | 
|  | 2153 | continue; | 
|  | 2154 | } | 
|  | 2155 | } | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2156 | if (MaterializeTemporaryExpr *Materialize | 
|  | 2157 | = dyn_cast<MaterializeTemporaryExpr>(E)) { | 
|  | 2158 | E = Materialize->GetTemporaryExpr(); | 
|  | 2159 | continue; | 
|  | 2160 | } | 
| Douglas Gregor | c0244c5 | 2011-09-08 17:56:33 +0000 | [diff] [blame] | 2161 | if (SubstNonTypeTemplateParmExpr *NTTP | 
|  | 2162 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { | 
|  | 2163 | E = NTTP->getReplacement(); | 
|  | 2164 | continue; | 
|  | 2165 | } | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2166 | return E; | 
| Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 2167 | } | 
|  | 2168 | } | 
|  | 2169 |  | 
| John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 2170 | /// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue | 
|  | 2171 | /// casts.  This is intended purely as a temporary workaround for code | 
|  | 2172 | /// that hasn't yet been rewritten to do the right thing about those | 
|  | 2173 | /// casts, and may disappear along with the last internal use. | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2174 | Expr *Expr::IgnoreParenLValueCasts() { | 
|  | 2175 | Expr *E = this; | 
| John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 2176 | while (true) { | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2177 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { | 
|  | 2178 | E = P->getSubExpr(); | 
|  | 2179 | continue; | 
| John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 2180 | } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2181 | if (P->getCastKind() == CK_LValueToRValue) { | 
|  | 2182 | E = P->getSubExpr(); | 
|  | 2183 | continue; | 
|  | 2184 | } | 
| John McCall | 9c5d70c | 2010-12-04 08:24:19 +0000 | [diff] [blame] | 2185 | } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { | 
|  | 2186 | if (P->getOpcode() == UO_Extension) { | 
|  | 2187 | E = P->getSubExpr(); | 
|  | 2188 | continue; | 
|  | 2189 | } | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2190 | } else if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { | 
|  | 2191 | if (!P->isResultDependent()) { | 
|  | 2192 | E = P->getResultExpr(); | 
|  | 2193 | continue; | 
|  | 2194 | } | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2195 | } else if (MaterializeTemporaryExpr *Materialize | 
|  | 2196 | = dyn_cast<MaterializeTemporaryExpr>(E)) { | 
|  | 2197 | E = Materialize->GetTemporaryExpr(); | 
|  | 2198 | continue; | 
| Douglas Gregor | c0244c5 | 2011-09-08 17:56:33 +0000 | [diff] [blame] | 2199 | } else if (SubstNonTypeTemplateParmExpr *NTTP | 
|  | 2200 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { | 
|  | 2201 | E = NTTP->getReplacement(); | 
|  | 2202 | continue; | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2203 | } | 
|  | 2204 | break; | 
|  | 2205 | } | 
|  | 2206 | return E; | 
|  | 2207 | } | 
|  | 2208 |  | 
| John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 2209 | Expr *Expr::IgnoreParenImpCasts() { | 
|  | 2210 | Expr *E = this; | 
|  | 2211 | while (true) { | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2212 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { | 
| John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 2213 | E = P->getSubExpr(); | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2214 | continue; | 
|  | 2215 | } | 
|  | 2216 | if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { | 
| John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 2217 | E = P->getSubExpr(); | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2218 | continue; | 
|  | 2219 | } | 
|  | 2220 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { | 
|  | 2221 | if (P->getOpcode() == UO_Extension) { | 
|  | 2222 | E = P->getSubExpr(); | 
|  | 2223 | continue; | 
|  | 2224 | } | 
|  | 2225 | } | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2226 | if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { | 
|  | 2227 | if (!P->isResultDependent()) { | 
|  | 2228 | E = P->getResultExpr(); | 
|  | 2229 | continue; | 
|  | 2230 | } | 
|  | 2231 | } | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2232 | if (MaterializeTemporaryExpr *Materialize | 
|  | 2233 | = dyn_cast<MaterializeTemporaryExpr>(E)) { | 
|  | 2234 | E = Materialize->GetTemporaryExpr(); | 
|  | 2235 | continue; | 
|  | 2236 | } | 
| Douglas Gregor | c0244c5 | 2011-09-08 17:56:33 +0000 | [diff] [blame] | 2237 | if (SubstNonTypeTemplateParmExpr *NTTP | 
|  | 2238 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { | 
|  | 2239 | E = NTTP->getReplacement(); | 
|  | 2240 | continue; | 
|  | 2241 | } | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2242 | return E; | 
| John McCall | 2fc46bf | 2010-05-05 22:59:52 +0000 | [diff] [blame] | 2243 | } | 
|  | 2244 | } | 
|  | 2245 |  | 
| Hans Wennborg | 2f072b4 | 2011-06-09 17:06:51 +0000 | [diff] [blame] | 2246 | Expr *Expr::IgnoreConversionOperator() { | 
|  | 2247 | if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) { | 
| Chandler Carruth | 14d251c | 2011-06-21 17:22:09 +0000 | [diff] [blame] | 2248 | if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) | 
| Hans Wennborg | 2f072b4 | 2011-06-09 17:06:51 +0000 | [diff] [blame] | 2249 | return MCE->getImplicitObjectArgument(); | 
|  | 2250 | } | 
|  | 2251 | return this; | 
|  | 2252 | } | 
|  | 2253 |  | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2254 | /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the | 
|  | 2255 | /// value (including ptr->int casts of the same size).  Strip off any | 
|  | 2256 | /// ParenExpr or CastExprs, returning their operand. | 
|  | 2257 | Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { | 
|  | 2258 | Expr *E = this; | 
|  | 2259 | while (true) { | 
|  | 2260 | if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { | 
|  | 2261 | E = P->getSubExpr(); | 
|  | 2262 | continue; | 
|  | 2263 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 |  | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2265 | if (CastExpr *P = dyn_cast<CastExpr>(E)) { | 
|  | 2266 | // We ignore integer <-> casts that are of the same width, ptr<->ptr and | 
| Douglas Gregor | 2ade35e | 2010-06-16 00:17:44 +0000 | [diff] [blame] | 2267 | // ptr<->int casts of the same width.  We also ignore all identity casts. | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2268 | Expr *SE = P->getSubExpr(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2269 |  | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2270 | if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { | 
|  | 2271 | E = SE; | 
|  | 2272 | continue; | 
|  | 2273 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2274 |  | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2275 | if ((E->getType()->isPointerType() || | 
| Douglas Gregor | 9d3347a | 2010-06-16 00:35:25 +0000 | [diff] [blame] | 2276 | E->getType()->isIntegralType(Ctx)) && | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2277 | (SE->getType()->isPointerType() || | 
| Douglas Gregor | 9d3347a | 2010-06-16 00:35:25 +0000 | [diff] [blame] | 2278 | SE->getType()->isIntegralType(Ctx)) && | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2279 | Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { | 
|  | 2280 | E = SE; | 
|  | 2281 | continue; | 
|  | 2282 | } | 
|  | 2283 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 |  | 
| Abramo Bagnara | b9eb35c | 2010-10-15 07:51:18 +0000 | [diff] [blame] | 2285 | if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { | 
|  | 2286 | if (P->getOpcode() == UO_Extension) { | 
|  | 2287 | E = P->getSubExpr(); | 
|  | 2288 | continue; | 
|  | 2289 | } | 
|  | 2290 | } | 
|  | 2291 |  | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2292 | if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { | 
|  | 2293 | if (!P->isResultDependent()) { | 
|  | 2294 | E = P->getResultExpr(); | 
|  | 2295 | continue; | 
|  | 2296 | } | 
|  | 2297 | } | 
|  | 2298 |  | 
| Douglas Gregor | c0244c5 | 2011-09-08 17:56:33 +0000 | [diff] [blame] | 2299 | if (SubstNonTypeTemplateParmExpr *NTTP | 
|  | 2300 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { | 
|  | 2301 | E = NTTP->getReplacement(); | 
|  | 2302 | continue; | 
|  | 2303 | } | 
|  | 2304 |  | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2305 | return E; | 
|  | 2306 | } | 
|  | 2307 | } | 
|  | 2308 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 2309 | bool Expr::isDefaultArgument() const { | 
|  | 2310 | const Expr *E = this; | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2311 | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) | 
|  | 2312 | E = M->GetTemporaryExpr(); | 
|  | 2313 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 2314 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) | 
|  | 2315 | E = ICE->getSubExprAsWritten(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2316 |  | 
| Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 2317 | return isa<CXXDefaultArgExpr>(E); | 
|  | 2318 | } | 
| Chris Lattner | ecdd841 | 2009-03-13 17:28:01 +0000 | [diff] [blame] | 2319 |  | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2320 | /// \brief Skip over any no-op casts and any temporary-binding | 
|  | 2321 | /// expressions. | 
| Anders Carlsson | f8b3015 | 2010-11-28 16:40:49 +0000 | [diff] [blame] | 2322 | static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2323 | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) | 
|  | 2324 | E = M->GetTemporaryExpr(); | 
|  | 2325 |  | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2326 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2327 | if (ICE->getCastKind() == CK_NoOp) | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2328 | E = ICE->getSubExpr(); | 
|  | 2329 | else | 
|  | 2330 | break; | 
|  | 2331 | } | 
|  | 2332 |  | 
|  | 2333 | while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) | 
|  | 2334 | E = BE->getSubExpr(); | 
|  | 2335 |  | 
|  | 2336 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2337 | if (ICE->getCastKind() == CK_NoOp) | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2338 | E = ICE->getSubExpr(); | 
|  | 2339 | else | 
|  | 2340 | break; | 
|  | 2341 | } | 
| Anders Carlsson | f8b3015 | 2010-11-28 16:40:49 +0000 | [diff] [blame] | 2342 |  | 
|  | 2343 | return E->IgnoreParens(); | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2344 | } | 
|  | 2345 |  | 
| John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 2346 | /// isTemporaryObject - Determines if this expression produces a | 
|  | 2347 | /// temporary of the given class type. | 
|  | 2348 | bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { | 
|  | 2349 | if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) | 
|  | 2350 | return false; | 
|  | 2351 |  | 
| Anders Carlsson | f8b3015 | 2010-11-28 16:40:49 +0000 | [diff] [blame] | 2352 | const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2353 |  | 
| John McCall | 58277b5 | 2010-09-15 20:59:13 +0000 | [diff] [blame] | 2354 | // Temporaries are by definition pr-values of class type. | 
| Fariborz Jahanian | db148be | 2010-09-27 17:30:38 +0000 | [diff] [blame] | 2355 | if (!E->Classify(C).isPRValue()) { | 
|  | 2356 | // In this context, property reference is a message call and is pr-value. | 
| John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2357 | if (!isa<ObjCPropertyRefExpr>(E)) | 
| Fariborz Jahanian | db148be | 2010-09-27 17:30:38 +0000 | [diff] [blame] | 2358 | return false; | 
|  | 2359 | } | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2360 |  | 
| John McCall | 19e60ad | 2010-09-16 06:57:56 +0000 | [diff] [blame] | 2361 | // Black-list a few cases which yield pr-values of class type that don't | 
|  | 2362 | // refer to temporaries of that type: | 
|  | 2363 |  | 
|  | 2364 | // - implicit derived-to-base conversions | 
| John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 2365 | if (isa<ImplicitCastExpr>(E)) { | 
|  | 2366 | switch (cast<ImplicitCastExpr>(E)->getCastKind()) { | 
|  | 2367 | case CK_DerivedToBase: | 
|  | 2368 | case CK_UncheckedDerivedToBase: | 
|  | 2369 | return false; | 
|  | 2370 | default: | 
|  | 2371 | break; | 
|  | 2372 | } | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2373 | } | 
|  | 2374 |  | 
| John McCall | 19e60ad | 2010-09-16 06:57:56 +0000 | [diff] [blame] | 2375 | // - member expressions (all) | 
|  | 2376 | if (isa<MemberExpr>(E)) | 
|  | 2377 | return false; | 
|  | 2378 |  | 
| John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 2379 | // - opaque values (all) | 
|  | 2380 | if (isa<OpaqueValueExpr>(E)) | 
|  | 2381 | return false; | 
|  | 2382 |  | 
| John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 2383 | return true; | 
| Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 2384 | } | 
|  | 2385 |  | 
| Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 2386 | bool Expr::isImplicitCXXThis() const { | 
|  | 2387 | const Expr *E = this; | 
|  | 2388 |  | 
|  | 2389 | // Strip away parentheses and casts we don't care about. | 
|  | 2390 | while (true) { | 
|  | 2391 | if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { | 
|  | 2392 | E = Paren->getSubExpr(); | 
|  | 2393 | continue; | 
|  | 2394 | } | 
|  | 2395 |  | 
|  | 2396 | if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | 
|  | 2397 | if (ICE->getCastKind() == CK_NoOp || | 
|  | 2398 | ICE->getCastKind() == CK_LValueToRValue || | 
|  | 2399 | ICE->getCastKind() == CK_DerivedToBase || | 
|  | 2400 | ICE->getCastKind() == CK_UncheckedDerivedToBase) { | 
|  | 2401 | E = ICE->getSubExpr(); | 
|  | 2402 | continue; | 
|  | 2403 | } | 
|  | 2404 | } | 
|  | 2405 |  | 
|  | 2406 | if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { | 
|  | 2407 | if (UnOp->getOpcode() == UO_Extension) { | 
|  | 2408 | E = UnOp->getSubExpr(); | 
|  | 2409 | continue; | 
|  | 2410 | } | 
|  | 2411 | } | 
|  | 2412 |  | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2413 | if (const MaterializeTemporaryExpr *M | 
|  | 2414 | = dyn_cast<MaterializeTemporaryExpr>(E)) { | 
|  | 2415 | E = M->GetTemporaryExpr(); | 
|  | 2416 | continue; | 
|  | 2417 | } | 
|  | 2418 |  | 
| Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 2419 | break; | 
|  | 2420 | } | 
|  | 2421 |  | 
|  | 2422 | if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) | 
|  | 2423 | return This->isImplicit(); | 
|  | 2424 |  | 
|  | 2425 | return false; | 
|  | 2426 | } | 
|  | 2427 |  | 
| Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 2428 | /// hasAnyTypeDependentArguments - Determines if any of the expressions | 
|  | 2429 | /// in Exprs is type-dependent. | 
|  | 2430 | bool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { | 
|  | 2431 | for (unsigned I = 0; I < NumExprs; ++I) | 
|  | 2432 | if (Exprs[I]->isTypeDependent()) | 
|  | 2433 | return true; | 
|  | 2434 |  | 
|  | 2435 | return false; | 
|  | 2436 | } | 
|  | 2437 |  | 
|  | 2438 | /// hasAnyValueDependentArguments - Determines if any of the expressions | 
|  | 2439 | /// in Exprs is value-dependent. | 
|  | 2440 | bool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { | 
|  | 2441 | for (unsigned I = 0; I < NumExprs; ++I) | 
|  | 2442 | if (Exprs[I]->isValueDependent()) | 
|  | 2443 | return true; | 
|  | 2444 |  | 
|  | 2445 | return false; | 
|  | 2446 | } | 
|  | 2447 |  | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2448 | bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2449 | // This function is attempting whether an expression is an initializer | 
|  | 2450 | // which can be evaluated at compile-time.  isEvaluatable handles most | 
|  | 2451 | // of the cases, but it can't deal with some initializer-specific | 
|  | 2452 | // expressions, and it can't deal with aggregates; we deal with those here, | 
|  | 2453 | // and fall back to isEvaluatable for the other cases. | 
|  | 2454 |  | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2455 | // If we ever capture reference-binding directly in the AST, we can | 
|  | 2456 | // kill the second parameter. | 
|  | 2457 |  | 
|  | 2458 | if (IsForRef) { | 
|  | 2459 | EvalResult Result; | 
|  | 2460 | return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; | 
|  | 2461 | } | 
| Eli Friedman | 1f4a6db | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 2462 |  | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2463 | switch (getStmtClass()) { | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2464 | default: break; | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2465 | case StringLiteralClass: | 
| Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2466 | case ObjCStringLiteralClass: | 
| Chris Lattner | eaf2bb8 | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 2467 | case ObjCEncodeExprClass: | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2468 | return true; | 
| John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 2469 | case CXXTemporaryObjectExprClass: | 
|  | 2470 | case CXXConstructExprClass: { | 
|  | 2471 | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2472 |  | 
|  | 2473 | // Only if it's | 
|  | 2474 | // 1) an application of the trivial default constructor or | 
| John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 2475 | if (!CE->getConstructor()->isTrivial()) return false; | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2476 | if (!CE->getNumArgs()) return true; | 
|  | 2477 |  | 
|  | 2478 | // 2) an elidable trivial copy construction of an operand which is | 
|  | 2479 | //    itself a constant initializer.  Note that we consider the | 
|  | 2480 | //    operand on its own, *not* as a reference binding. | 
|  | 2481 | return CE->isElidable() && | 
|  | 2482 | CE->getArg(0)->isConstantInitializer(Ctx, false); | 
| John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 2483 | } | 
| Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 2484 | case CompoundLiteralExprClass: { | 
| Eli Friedman | 1f4a6db | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 2485 | // This handles gcc's extension that allows global initializers like | 
|  | 2486 | // "struct x {int x;} x = (struct x) {};". | 
|  | 2487 | // FIXME: This accepts other cases it shouldn't! | 
| Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 2488 | const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2489 | return Exp->isConstantInitializer(Ctx, false); | 
| Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 2490 | } | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2491 | case InitListExprClass: { | 
| Eli Friedman | 1f4a6db | 2009-02-20 02:36:22 +0000 | [diff] [blame] | 2492 | // FIXME: This doesn't deal with fields with reference types correctly. | 
|  | 2493 | // FIXME: This incorrectly allows pointers cast to integers to be assigned | 
|  | 2494 | // to bitfields. | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2495 | const InitListExpr *Exp = cast<InitListExpr>(this); | 
|  | 2496 | unsigned numInits = Exp->getNumInits(); | 
|  | 2497 | for (unsigned i = 0; i < numInits; i++) { | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2498 | if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2499 | return false; | 
|  | 2500 | } | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2501 | return true; | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2502 | } | 
| Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 2503 | case ImplicitValueInitExprClass: | 
|  | 2504 | return true; | 
| Chris Lattner | 3ae9f48 | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 2505 | case ParenExprClass: | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2506 | return cast<ParenExpr>(this)->getSubExpr() | 
|  | 2507 | ->isConstantInitializer(Ctx, IsForRef); | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2508 | case GenericSelectionExprClass: | 
|  | 2509 | if (cast<GenericSelectionExpr>(this)->isResultDependent()) | 
|  | 2510 | return false; | 
|  | 2511 | return cast<GenericSelectionExpr>(this)->getResultExpr() | 
|  | 2512 | ->isConstantInitializer(Ctx, IsForRef); | 
| Abramo Bagnara | 5cadfab | 2010-09-27 07:13:32 +0000 | [diff] [blame] | 2513 | case ChooseExprClass: | 
|  | 2514 | return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) | 
|  | 2515 | ->isConstantInitializer(Ctx, IsForRef); | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2516 | case UnaryOperatorClass: { | 
|  | 2517 | const UnaryOperator* Exp = cast<UnaryOperator>(this); | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2518 | if (Exp->getOpcode() == UO_Extension) | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2519 | return Exp->getSubExpr()->isConstantInitializer(Ctx, false); | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2520 | break; | 
|  | 2521 | } | 
| Chris Lattner | 3ae9f48 | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 2522 | case BinaryOperatorClass: { | 
|  | 2523 | // Special case &&foo - &&bar.  It would be nice to generalize this somehow | 
|  | 2524 | // but this handles the common case. | 
|  | 2525 | const BinaryOperator *Exp = cast<BinaryOperator>(this); | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2526 | if (Exp->getOpcode() == BO_Sub && | 
| Chris Lattner | 3ae9f48 | 2009-10-13 07:14:16 +0000 | [diff] [blame] | 2527 | isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && | 
|  | 2528 | isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) | 
|  | 2529 | return true; | 
|  | 2530 | break; | 
|  | 2531 | } | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2532 | case CXXFunctionalCastExprClass: | 
| John McCall | b4b9b15 | 2010-08-01 21:51:45 +0000 | [diff] [blame] | 2533 | case CXXStaticCastExprClass: | 
| Chris Lattner | 81045d8 | 2009-04-21 05:19:11 +0000 | [diff] [blame] | 2534 | case ImplicitCastExprClass: | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2535 | case CStyleCastExprClass: | 
|  | 2536 | // Handle casts with a destination that's a struct or union; this | 
|  | 2537 | // deals with both the gcc no-op struct cast extension and the | 
|  | 2538 | // cast-to-union extension. | 
|  | 2539 | if (getType()->isRecordType()) | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2540 | return cast<CastExpr>(this)->getSubExpr() | 
|  | 2541 | ->isConstantInitializer(Ctx, false); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2542 |  | 
| Chris Lattner | 430656e | 2009-10-13 22:12:09 +0000 | [diff] [blame] | 2543 | // Integer->integer casts can be handled here, which is important for | 
|  | 2544 | // things like (int)(&&x-&&y).  Scary but true. | 
|  | 2545 | if (getType()->isIntegerType() && | 
|  | 2546 | cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) | 
| John McCall | 4204f07 | 2010-08-02 21:13:48 +0000 | [diff] [blame] | 2547 | return cast<CastExpr>(this)->getSubExpr() | 
|  | 2548 | ->isConstantInitializer(Ctx, false); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2549 |  | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2550 | break; | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2551 |  | 
|  | 2552 | case MaterializeTemporaryExprClass: | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2553 | return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2554 | ->isConstantInitializer(Ctx, false); | 
| Anders Carlsson | e8a32b8 | 2008-11-24 05:23:59 +0000 | [diff] [blame] | 2555 | } | 
| Eli Friedman | c39dc9a | 2009-01-25 03:12:18 +0000 | [diff] [blame] | 2556 | return isEvaluatable(Ctx); | 
| Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 2557 | } | 
|  | 2558 |  | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2559 | /// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null | 
|  | 2560 | /// pointer constant or not, as well as the specific kind of constant detected. | 
|  | 2561 | /// Null pointer constants can be integer constant expressions with the | 
|  | 2562 | /// value zero, casts of zero to void*, nullptr (C++0X), or __null | 
|  | 2563 | /// (a GNU extension). | 
|  | 2564 | Expr::NullPointerConstantKind | 
|  | 2565 | Expr::isNullPointerConstant(ASTContext &Ctx, | 
|  | 2566 | NullPointerConstantValueDependence NPC) const { | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2567 | if (isValueDependent()) { | 
|  | 2568 | switch (NPC) { | 
|  | 2569 | case NPC_NeverValueDependent: | 
| David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2570 | llvm_unreachable("Unexpected value dependent expression!"); | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2571 | case NPC_ValueDependentIsNull: | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2572 | if (isTypeDependent() || getType()->isIntegralType(Ctx)) | 
|  | 2573 | return NPCK_ZeroInteger; | 
|  | 2574 | else | 
|  | 2575 | return NPCK_NotNull; | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2576 |  | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2577 | case NPC_ValueDependentIsNotNull: | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2578 | return NPCK_NotNull; | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2579 | } | 
|  | 2580 | } | 
| Daniel Dunbar | f515b22 | 2009-09-18 08:46:16 +0000 | [diff] [blame] | 2581 |  | 
| Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2582 | // Strip off a cast to void*, if it exists. Except in C++. | 
| Argyrios Kyrtzidis | 0835a3c | 2008-08-18 23:01:59 +0000 | [diff] [blame] | 2583 | if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { | 
| Sebastian Redl | 6215dee | 2008-11-04 11:45:54 +0000 | [diff] [blame] | 2584 | if (!Ctx.getLangOptions().CPlusPlus) { | 
| Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2585 | // Check that it is a cast to void*. | 
| Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2586 | if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { | 
| Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2587 | QualType Pointee = PT->getPointeeType(); | 
| John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2588 | if (!Pointee.hasQualifiers() && | 
| Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2589 | Pointee->isVoidType() &&                              // to void* | 
|  | 2590 | CE->getSubExpr()->getType()->isIntegerType())         // from int. | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2591 | return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); | 
| Sebastian Redl | 0777972 | 2008-10-31 14:43:28 +0000 | [diff] [blame] | 2592 | } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2593 | } | 
| Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2594 | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { | 
|  | 2595 | // Ignore the ImplicitCastExpr type entirely. | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2596 | return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); | 
| Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2597 | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { | 
|  | 2598 | // Accept ((void*)0) as a null pointer constant, as many other | 
|  | 2599 | // implementations do. | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2600 | return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2601 | } else if (const GenericSelectionExpr *GE = | 
|  | 2602 | dyn_cast<GenericSelectionExpr>(this)) { | 
|  | 2603 | return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | } else if (const CXXDefaultArgExpr *DefaultArg | 
| Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 2605 | = dyn_cast<CXXDefaultArgExpr>(this)) { | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 2606 | // See through default argument expressions | 
| Douglas Gregor | ce94049 | 2009-09-25 04:25:58 +0000 | [diff] [blame] | 2607 | return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); | 
| Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 2608 | } else if (isa<GNUNullExpr>(this)) { | 
|  | 2609 | // The GNU __null extension is always a null pointer constant. | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2610 | return NPCK_GNUNull; | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2611 | } else if (const MaterializeTemporaryExpr *M | 
|  | 2612 | = dyn_cast<MaterializeTemporaryExpr>(this)) { | 
|  | 2613 | return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); | 
| John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame^] | 2614 | } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { | 
|  | 2615 | if (const Expr *Source = OVE->getSourceExpr()) | 
|  | 2616 | return Source->isNullPointerConstant(Ctx, NPC); | 
| Steve Naroff | aaffbf7 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 2617 | } | 
| Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 2618 |  | 
| Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 2619 | // C++0x nullptr_t is always a null pointer constant. | 
|  | 2620 | if (getType()->isNullPtrType()) | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2621 | return NPCK_CXX0X_nullptr; | 
| Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 2622 |  | 
| Fariborz Jahanian | ff3a078 | 2010-09-27 22:42:37 +0000 | [diff] [blame] | 2623 | if (const RecordType *UT = getType()->getAsUnionType()) | 
|  | 2624 | if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) | 
|  | 2625 | if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ | 
|  | 2626 | const Expr *InitExpr = CLE->getInitializer(); | 
|  | 2627 | if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) | 
|  | 2628 | return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); | 
|  | 2629 | } | 
| Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 2630 | // This expression must be an integer type. | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2631 | if (!getType()->isIntegerType() || | 
| Fariborz Jahanian | 56fc0d1 | 2009-10-06 00:09:31 +0000 | [diff] [blame] | 2632 | (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2633 | return NPCK_NotNull; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2635 | // If we have an integer constant expression, we need to *evaluate* it and | 
|  | 2636 | // test for the value 0. | 
| Eli Friedman | 09de176 | 2009-04-25 22:37:12 +0000 | [diff] [blame] | 2637 | llvm::APSInt Result; | 
| Chandler Carruth | 82214a8 | 2011-02-18 23:54:50 +0000 | [diff] [blame] | 2638 | bool IsNull = isIntegerConstantExpr(Result, Ctx) && Result == 0; | 
|  | 2639 |  | 
|  | 2640 | return (IsNull ? NPCK_ZeroInteger : NPCK_NotNull); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2641 | } | 
| Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 2642 |  | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2643 | /// \brief If this expression is an l-value for an Objective C | 
|  | 2644 | /// property, find the underlying property reference expression. | 
|  | 2645 | const ObjCPropertyRefExpr *Expr::getObjCProperty() const { | 
|  | 2646 | const Expr *E = this; | 
|  | 2647 | while (true) { | 
|  | 2648 | assert((E->getValueKind() == VK_LValue && | 
|  | 2649 | E->getObjectKind() == OK_ObjCProperty) && | 
|  | 2650 | "expression is not a property reference"); | 
|  | 2651 | E = E->IgnoreParenCasts(); | 
|  | 2652 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { | 
|  | 2653 | if (BO->getOpcode() == BO_Comma) { | 
|  | 2654 | E = BO->getRHS(); | 
|  | 2655 | continue; | 
|  | 2656 | } | 
|  | 2657 | } | 
|  | 2658 |  | 
|  | 2659 | break; | 
|  | 2660 | } | 
|  | 2661 |  | 
|  | 2662 | return cast<ObjCPropertyRefExpr>(E); | 
|  | 2663 | } | 
|  | 2664 |  | 
| Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2665 | FieldDecl *Expr::getBitField() { | 
| Douglas Gregor | 6f4a69a | 2009-07-06 15:38:40 +0000 | [diff] [blame] | 2666 | Expr *E = this->IgnoreParens(); | 
| Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2667 |  | 
| Douglas Gregor | de4b1d8 | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 2668 | while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | 
| John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 2669 | if (ICE->getCastKind() == CK_LValueToRValue || | 
|  | 2670 | (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) | 
| Douglas Gregor | de4b1d8 | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 2671 | E = ICE->getSubExpr()->IgnoreParens(); | 
|  | 2672 | else | 
|  | 2673 | break; | 
|  | 2674 | } | 
|  | 2675 |  | 
| Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2676 | if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) | 
| Douglas Gregor | 86f1940 | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 2677 | if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) | 
| Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2678 | if (Field->isBitField()) | 
|  | 2679 | return Field; | 
|  | 2680 |  | 
| Argyrios Kyrtzidis | 0f279e7 | 2010-10-30 19:52:22 +0000 | [diff] [blame] | 2681 | if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) | 
|  | 2682 | if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) | 
|  | 2683 | if (Field->isBitField()) | 
|  | 2684 | return Field; | 
|  | 2685 |  | 
| Eli Friedman | 42068e9 | 2011-07-13 02:05:57 +0000 | [diff] [blame] | 2686 | if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { | 
| Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2687 | if (BinOp->isAssignmentOp() && BinOp->getLHS()) | 
|  | 2688 | return BinOp->getLHS()->getBitField(); | 
|  | 2689 |  | 
| Eli Friedman | 42068e9 | 2011-07-13 02:05:57 +0000 | [diff] [blame] | 2690 | if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) | 
|  | 2691 | return BinOp->getRHS()->getBitField(); | 
|  | 2692 | } | 
|  | 2693 |  | 
| Douglas Gregor | 33bbbc5 | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 2694 | return 0; | 
| Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2695 | } | 
|  | 2696 |  | 
| Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2697 | bool Expr::refersToVectorElement() const { | 
|  | 2698 | const Expr *E = this->IgnoreParens(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2699 |  | 
| Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2700 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { | 
| John McCall | 5baba9d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 2701 | if (ICE->getValueKind() != VK_RValue && | 
| John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2702 | ICE->getCastKind() == CK_NoOp) | 
| Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2703 | E = ICE->getSubExpr()->IgnoreParens(); | 
|  | 2704 | else | 
|  | 2705 | break; | 
|  | 2706 | } | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2707 |  | 
| Anders Carlsson | 0938026 | 2010-01-31 17:18:49 +0000 | [diff] [blame] | 2708 | if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) | 
|  | 2709 | return ASE->getBase()->getType()->isVectorType(); | 
|  | 2710 |  | 
|  | 2711 | if (isa<ExtVectorElementExpr>(E)) | 
|  | 2712 | return true; | 
|  | 2713 |  | 
|  | 2714 | return false; | 
|  | 2715 | } | 
|  | 2716 |  | 
| Chris Lattner | 2140e90 | 2009-02-16 22:14:05 +0000 | [diff] [blame] | 2717 | /// isArrow - Return true if the base expression is a pointer to vector, | 
|  | 2718 | /// return false if the base expression is a vector. | 
|  | 2719 | bool ExtVectorElementExpr::isArrow() const { | 
|  | 2720 | return getBase()->getType()->isPointerType(); | 
|  | 2721 | } | 
|  | 2722 |  | 
| Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2723 | unsigned ExtVectorElementExpr::getNumElements() const { | 
| John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2724 | if (const VectorType *VT = getType()->getAs<VectorType>()) | 
| Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2725 | return VT->getNumElements(); | 
|  | 2726 | return 1; | 
| Chris Lattner | 4d0ac88 | 2007-08-03 16:00:20 +0000 | [diff] [blame] | 2727 | } | 
|  | 2728 |  | 
| Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2729 | /// containsDuplicateElements - Return true if any element access is repeated. | 
| Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2730 | bool ExtVectorElementExpr::containsDuplicateElements() const { | 
| Daniel Dunbar | a2b34eb | 2009-10-18 02:09:09 +0000 | [diff] [blame] | 2731 | // FIXME: Refactor this code to an accessor on the AST node which returns the | 
|  | 2732 | // "type" of component access, and share with code below and in Sema. | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2733 | StringRef Comp = Accessor->getName(); | 
| Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 2734 |  | 
|  | 2735 | // Halving swizzles do not contain duplicate elements. | 
| Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2736 | if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") | 
| Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 2737 | return false; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2738 |  | 
| Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 2739 | // Advance past s-char prefix on hex swizzles. | 
| Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2740 | if (Comp[0] == 's' || Comp[0] == 'S') | 
|  | 2741 | Comp = Comp.substr(1); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 |  | 
| Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2743 | for (unsigned i = 0, e = Comp.size(); i != e; ++i) | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2744 | if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) | 
| Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 2745 | return true; | 
| Daniel Dunbar | 1502742 | 2009-10-17 23:53:04 +0000 | [diff] [blame] | 2746 |  | 
| Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 2747 | return false; | 
|  | 2748 | } | 
| Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 2749 |  | 
| Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2750 | /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. | 
| Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 2751 | void ExtVectorElementExpr::getEncodedElementAccess( | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2752 | SmallVectorImpl<unsigned> &Elts) const { | 
|  | 2753 | StringRef Comp = Accessor->getName(); | 
| Daniel Dunbar | 4b55b24 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 2754 | if (Comp[0] == 's' || Comp[0] == 'S') | 
|  | 2755 | Comp = Comp.substr(1); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2756 |  | 
| Daniel Dunbar | 4b55b24 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 2757 | bool isHi =   Comp == "hi"; | 
|  | 2758 | bool isLo =   Comp == "lo"; | 
|  | 2759 | bool isEven = Comp == "even"; | 
|  | 2760 | bool isOdd  = Comp == "odd"; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 |  | 
| Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2762 | for (unsigned i = 0, e = getNumElements(); i != e; ++i) { | 
|  | 2763 | uint64_t Index; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2764 |  | 
| Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2765 | if (isHi) | 
|  | 2766 | Index = e + i; | 
|  | 2767 | else if (isLo) | 
|  | 2768 | Index = i; | 
|  | 2769 | else if (isEven) | 
|  | 2770 | Index = 2 * i; | 
|  | 2771 | else if (isOdd) | 
|  | 2772 | Index = 2 * i + 1; | 
|  | 2773 | else | 
| Daniel Dunbar | 4b55b24 | 2009-10-18 02:09:31 +0000 | [diff] [blame] | 2774 | Index = ExtVectorType::getAccessorIdx(Comp[i]); | 
| Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 2775 |  | 
| Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 2776 | Elts.push_back(Index); | 
| Chris Lattner | b8f849d | 2007-08-02 23:36:59 +0000 | [diff] [blame] | 2777 | } | 
| Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 2778 | } | 
|  | 2779 |  | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2780 | ObjCMessageExpr::ObjCMessageExpr(QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2781 | ExprValueKind VK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2782 | SourceLocation LBracLoc, | 
|  | 2783 | SourceLocation SuperLoc, | 
|  | 2784 | bool IsInstanceSuper, | 
|  | 2785 | QualType SuperType, | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2786 | Selector Sel, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2787 | ArrayRef<SourceLocation> SelLocs, | 
|  | 2788 | SelectorLocationsKind SelLocsK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2789 | ObjCMethodDecl *Method, | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2790 | ArrayRef<Expr *> Args, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2791 | SourceLocation RBracLoc) | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2792 | : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 2793 | /*TypeDependent=*/false, /*ValueDependent=*/false, | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 2794 | /*InstantiationDependent=*/false, | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 2795 | /*ContainsUnexpandedParameterPack=*/false), | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2796 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method | 
|  | 2797 | : Sel.getAsOpaquePtr())), | 
| Argyrios Kyrtzidis | b994e6c | 2011-10-03 06:36:55 +0000 | [diff] [blame] | 2798 | Kind(IsInstanceSuper? SuperInstance : SuperClass), | 
|  | 2799 | HasMethod(Method != 0), IsDelegateInitCall(false), SuperLoc(SuperLoc), | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2800 | LBracLoc(LBracLoc), RBracLoc(RBracLoc) | 
| Douglas Gregor | c2350e5 | 2010-03-08 16:40:19 +0000 | [diff] [blame] | 2801 | { | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2802 | initArgsAndSelLocs(Args, SelLocs, SelLocsK); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2803 | setReceiverPointer(SuperType.getAsOpaquePtr()); | 
| Ted Kremenek | 4df728e | 2008-06-24 15:50:53 +0000 | [diff] [blame] | 2804 | } | 
|  | 2805 |  | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2806 | ObjCMessageExpr::ObjCMessageExpr(QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2807 | ExprValueKind VK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2808 | SourceLocation LBracLoc, | 
|  | 2809 | TypeSourceInfo *Receiver, | 
| Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2810 | Selector Sel, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2811 | ArrayRef<SourceLocation> SelLocs, | 
|  | 2812 | SelectorLocationsKind SelLocsK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2813 | ObjCMethodDecl *Method, | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2814 | ArrayRef<Expr *> Args, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2815 | SourceLocation RBracLoc) | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2816 | : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 2817 | T->isDependentType(), T->isInstantiationDependentType(), | 
|  | 2818 | T->containsUnexpandedParameterPack()), | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2819 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method | 
|  | 2820 | : Sel.getAsOpaquePtr())), | 
| Argyrios Kyrtzidis | b994e6c | 2011-10-03 06:36:55 +0000 | [diff] [blame] | 2821 | Kind(Class), | 
|  | 2822 | HasMethod(Method != 0), IsDelegateInitCall(false), | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2823 | LBracLoc(LBracLoc), RBracLoc(RBracLoc) | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2824 | { | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2825 | initArgsAndSelLocs(Args, SelLocs, SelLocsK); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2826 | setReceiverPointer(Receiver); | 
| Ted Kremenek | 4df728e | 2008-06-24 15:50:53 +0000 | [diff] [blame] | 2827 | } | 
|  | 2828 |  | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2829 | ObjCMessageExpr::ObjCMessageExpr(QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2830 | ExprValueKind VK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2831 | SourceLocation LBracLoc, | 
|  | 2832 | Expr *Receiver, | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2833 | Selector Sel, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2834 | ArrayRef<SourceLocation> SelLocs, | 
|  | 2835 | SelectorLocationsKind SelLocsK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2836 | ObjCMethodDecl *Method, | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2837 | ArrayRef<Expr *> Args, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2838 | SourceLocation RBracLoc) | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2839 | : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 2840 | Receiver->isTypeDependent(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 2841 | Receiver->isInstantiationDependent(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 2842 | Receiver->containsUnexpandedParameterPack()), | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2843 | SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method | 
|  | 2844 | : Sel.getAsOpaquePtr())), | 
| Argyrios Kyrtzidis | b994e6c | 2011-10-03 06:36:55 +0000 | [diff] [blame] | 2845 | Kind(Instance), | 
|  | 2846 | HasMethod(Method != 0), IsDelegateInitCall(false), | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2847 | LBracLoc(LBracLoc), RBracLoc(RBracLoc) | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2848 | { | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2849 | initArgsAndSelLocs(Args, SelLocs, SelLocsK); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2850 | setReceiverPointer(Receiver); | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2851 | } | 
|  | 2852 |  | 
|  | 2853 | void ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args, | 
|  | 2854 | ArrayRef<SourceLocation> SelLocs, | 
|  | 2855 | SelectorLocationsKind SelLocsK) { | 
|  | 2856 | setNumArgs(Args.size()); | 
| Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2857 | Expr **MyArgs = getArgs(); | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2858 | for (unsigned I = 0; I != Args.size(); ++I) { | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 2859 | if (Args[I]->isTypeDependent()) | 
|  | 2860 | ExprBits.TypeDependent = true; | 
|  | 2861 | if (Args[I]->isValueDependent()) | 
|  | 2862 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 2863 | if (Args[I]->isInstantiationDependent()) | 
|  | 2864 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 2865 | if (Args[I]->containsUnexpandedParameterPack()) | 
|  | 2866 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 2867 |  | 
|  | 2868 | MyArgs[I] = Args[I]; | 
|  | 2869 | } | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2870 |  | 
|  | 2871 | SelLocsKind = SelLocsK; | 
|  | 2872 | if (SelLocsK == SelLoc_NonStandard) | 
|  | 2873 | std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); | 
| Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 2874 | } | 
|  | 2875 |  | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2876 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2877 | ExprValueKind VK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2878 | SourceLocation LBracLoc, | 
|  | 2879 | SourceLocation SuperLoc, | 
|  | 2880 | bool IsInstanceSuper, | 
|  | 2881 | QualType SuperType, | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2882 | Selector Sel, | 
| Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2883 | ArrayRef<SourceLocation> SelLocs, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2884 | ObjCMethodDecl *Method, | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2885 | ArrayRef<Expr *> Args, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2886 | SourceLocation RBracLoc) { | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2887 | SelectorLocationsKind SelLocsK; | 
|  | 2888 | ObjCMessageExpr *Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2889 | return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2890 | SuperType, Sel, SelLocs, SelLocsK, | 
|  | 2891 | Method, Args, RBracLoc); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2892 | } | 
|  | 2893 |  | 
|  | 2894 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2895 | ExprValueKind VK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2896 | SourceLocation LBracLoc, | 
|  | 2897 | TypeSourceInfo *Receiver, | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2898 | Selector Sel, | 
| Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2899 | ArrayRef<SourceLocation> SelLocs, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2900 | ObjCMethodDecl *Method, | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2901 | ArrayRef<Expr *> Args, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2902 | SourceLocation RBracLoc) { | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2903 | SelectorLocationsKind SelLocsK; | 
|  | 2904 | ObjCMessageExpr *Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); | 
| Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2905 | return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2906 | SelLocs, SelLocsK, Method, Args, RBracLoc); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2907 | } | 
|  | 2908 |  | 
|  | 2909 | ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2910 | ExprValueKind VK, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2911 | SourceLocation LBracLoc, | 
|  | 2912 | Expr *Receiver, | 
| Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2913 | Selector Sel, | 
| Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2914 | ArrayRef<SourceLocation> SelLocs, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2915 | ObjCMethodDecl *Method, | 
| Argyrios Kyrtzidis | 8d9ed79 | 2011-10-03 06:36:45 +0000 | [diff] [blame] | 2916 | ArrayRef<Expr *> Args, | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2917 | SourceLocation RBracLoc) { | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2918 | SelectorLocationsKind SelLocsK; | 
|  | 2919 | ObjCMessageExpr *Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); | 
| Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2920 | return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2921 | SelLocs, SelLocsK, Method, Args, RBracLoc); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2922 | } | 
|  | 2923 |  | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2924 | ObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2925 | unsigned NumArgs, | 
|  | 2926 | unsigned NumStoredSelLocs) { | 
|  | 2927 | ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2928 | return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); | 
|  | 2929 | } | 
| Argyrios Kyrtzidis | e005d19 | 2010-12-10 20:08:30 +0000 | [diff] [blame] | 2930 |  | 
| Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2931 | ObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, | 
|  | 2932 | ArrayRef<Expr *> Args, | 
|  | 2933 | SourceLocation RBraceLoc, | 
|  | 2934 | ArrayRef<SourceLocation> SelLocs, | 
|  | 2935 | Selector Sel, | 
|  | 2936 | SelectorLocationsKind &SelLocsK) { | 
|  | 2937 | SelLocsK = hasStandardSelectorLocs(Sel, SelLocs, Args, RBraceLoc); | 
|  | 2938 | unsigned NumStoredSelLocs = (SelLocsK == SelLoc_NonStandard) ? SelLocs.size() | 
|  | 2939 | : 0; | 
|  | 2940 | return alloc(C, Args.size(), NumStoredSelLocs); | 
|  | 2941 | } | 
|  | 2942 |  | 
|  | 2943 | ObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, | 
|  | 2944 | unsigned NumArgs, | 
|  | 2945 | unsigned NumStoredSelLocs) { | 
|  | 2946 | unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + | 
|  | 2947 | NumArgs * sizeof(Expr *) + NumStoredSelLocs * sizeof(SourceLocation); | 
|  | 2948 | return (ObjCMessageExpr *)C.Allocate(Size, | 
|  | 2949 | llvm::AlignOf<ObjCMessageExpr>::Alignment); | 
|  | 2950 | } | 
|  | 2951 |  | 
|  | 2952 | void ObjCMessageExpr::getSelectorLocs( | 
|  | 2953 | SmallVectorImpl<SourceLocation> &SelLocs) const { | 
|  | 2954 | for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) | 
|  | 2955 | SelLocs.push_back(getSelectorLoc(i)); | 
|  | 2956 | } | 
|  | 2957 |  | 
| Argyrios Kyrtzidis | e005d19 | 2010-12-10 20:08:30 +0000 | [diff] [blame] | 2958 | SourceRange ObjCMessageExpr::getReceiverRange() const { | 
|  | 2959 | switch (getReceiverKind()) { | 
|  | 2960 | case Instance: | 
|  | 2961 | return getInstanceReceiver()->getSourceRange(); | 
|  | 2962 |  | 
|  | 2963 | case Class: | 
|  | 2964 | return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); | 
|  | 2965 |  | 
|  | 2966 | case SuperInstance: | 
|  | 2967 | case SuperClass: | 
|  | 2968 | return getSuperLoc(); | 
|  | 2969 | } | 
|  | 2970 |  | 
|  | 2971 | return SourceLocation(); | 
|  | 2972 | } | 
|  | 2973 |  | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2974 | Selector ObjCMessageExpr::getSelector() const { | 
|  | 2975 | if (HasMethod) | 
|  | 2976 | return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) | 
|  | 2977 | ->getSelector(); | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2978 | return Selector(SelectorOrMethod); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2979 | } | 
|  | 2980 |  | 
|  | 2981 | ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { | 
|  | 2982 | switch (getReceiverKind()) { | 
|  | 2983 | case Instance: | 
|  | 2984 | if (const ObjCObjectPointerType *Ptr | 
|  | 2985 | = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) | 
|  | 2986 | return Ptr->getInterfaceDecl(); | 
|  | 2987 | break; | 
|  | 2988 |  | 
|  | 2989 | case Class: | 
| John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2990 | if (const ObjCObjectType *Ty | 
|  | 2991 | = getClassReceiver()->getAs<ObjCObjectType>()) | 
|  | 2992 | return Ty->getInterface(); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 2993 | break; | 
|  | 2994 |  | 
|  | 2995 | case SuperInstance: | 
|  | 2996 | if (const ObjCObjectPointerType *Ptr | 
|  | 2997 | = getSuperType()->getAs<ObjCObjectPointerType>()) | 
|  | 2998 | return Ptr->getInterfaceDecl(); | 
|  | 2999 | break; | 
|  | 3000 |  | 
|  | 3001 | case SuperClass: | 
| Argyrios Kyrtzidis | ee8a6ca | 2011-01-25 00:03:48 +0000 | [diff] [blame] | 3002 | if (const ObjCObjectType *Iface | 
|  | 3003 | = getSuperType()->getAs<ObjCObjectType>()) | 
|  | 3004 | return Iface->getInterface(); | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 3005 | break; | 
|  | 3006 | } | 
|  | 3007 |  | 
|  | 3008 | return 0; | 
| Ted Kremenek | eb3b324 | 2010-02-11 22:41:21 +0000 | [diff] [blame] | 3009 | } | 
| Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 3010 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3011 | StringRef ObjCBridgedCastExpr::getBridgeKindName() const { | 
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3012 | switch (getBridgeKind()) { | 
|  | 3013 | case OBC_Bridge: | 
|  | 3014 | return "__bridge"; | 
|  | 3015 | case OBC_BridgeTransfer: | 
|  | 3016 | return "__bridge_transfer"; | 
|  | 3017 | case OBC_BridgeRetained: | 
|  | 3018 | return "__bridge_retained"; | 
|  | 3019 | } | 
|  | 3020 |  | 
|  | 3021 | return "__bridge"; | 
|  | 3022 | } | 
|  | 3023 |  | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 3024 | bool ChooseExpr::isConditionTrue(const ASTContext &C) const { | 
| Richard Smith | a6b8b2c | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 3025 | return getCond()->EvaluateKnownConstInt(C) != 0; | 
| Chris Lattner | 27437ca | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 3026 | } | 
|  | 3027 |  | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3028 | ShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, | 
|  | 3029 | QualType Type, SourceLocation BLoc, | 
|  | 3030 | SourceLocation RP) | 
|  | 3031 | : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, | 
|  | 3032 | Type->isDependentType(), Type->isDependentType(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3033 | Type->isInstantiationDependentType(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3034 | Type->containsUnexpandedParameterPack()), | 
|  | 3035 | BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) | 
|  | 3036 | { | 
|  | 3037 | SubExprs = new (C) Stmt*[nexpr]; | 
|  | 3038 | for (unsigned i = 0; i < nexpr; i++) { | 
|  | 3039 | if (args[i]->isTypeDependent()) | 
|  | 3040 | ExprBits.TypeDependent = true; | 
|  | 3041 | if (args[i]->isValueDependent()) | 
|  | 3042 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3043 | if (args[i]->isInstantiationDependent()) | 
|  | 3044 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3045 | if (args[i]->containsUnexpandedParameterPack()) | 
|  | 3046 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 3047 |  | 
|  | 3048 | SubExprs[i] = args[i]; | 
|  | 3049 | } | 
|  | 3050 | } | 
|  | 3051 |  | 
| Nate Begeman | 888376a | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 3052 | void ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, | 
|  | 3053 | unsigned NumExprs) { | 
|  | 3054 | if (SubExprs) C.Deallocate(SubExprs); | 
|  | 3055 |  | 
|  | 3056 | SubExprs = new (C) Stmt* [NumExprs]; | 
| Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 3057 | this->NumExprs = NumExprs; | 
|  | 3058 | memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3059 | } | 
| Nate Begeman | 888376a | 2009-08-12 02:28:50 +0000 | [diff] [blame] | 3060 |  | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 3061 | GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, | 
|  | 3062 | SourceLocation GenericLoc, Expr *ControllingExpr, | 
|  | 3063 | TypeSourceInfo **AssocTypes, Expr **AssocExprs, | 
|  | 3064 | unsigned NumAssocs, SourceLocation DefaultLoc, | 
|  | 3065 | SourceLocation RParenLoc, | 
|  | 3066 | bool ContainsUnexpandedParameterPack, | 
|  | 3067 | unsigned ResultIndex) | 
|  | 3068 | : Expr(GenericSelectionExprClass, | 
|  | 3069 | AssocExprs[ResultIndex]->getType(), | 
|  | 3070 | AssocExprs[ResultIndex]->getValueKind(), | 
|  | 3071 | AssocExprs[ResultIndex]->getObjectKind(), | 
|  | 3072 | AssocExprs[ResultIndex]->isTypeDependent(), | 
|  | 3073 | AssocExprs[ResultIndex]->isValueDependent(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3074 | AssocExprs[ResultIndex]->isInstantiationDependent(), | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 3075 | ContainsUnexpandedParameterPack), | 
|  | 3076 | AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), | 
|  | 3077 | SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), | 
|  | 3078 | ResultIndex(ResultIndex), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), | 
|  | 3079 | RParenLoc(RParenLoc) { | 
|  | 3080 | SubExprs[CONTROLLING] = ControllingExpr; | 
|  | 3081 | std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); | 
|  | 3082 | std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); | 
|  | 3083 | } | 
|  | 3084 |  | 
|  | 3085 | GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, | 
|  | 3086 | SourceLocation GenericLoc, Expr *ControllingExpr, | 
|  | 3087 | TypeSourceInfo **AssocTypes, Expr **AssocExprs, | 
|  | 3088 | unsigned NumAssocs, SourceLocation DefaultLoc, | 
|  | 3089 | SourceLocation RParenLoc, | 
|  | 3090 | bool ContainsUnexpandedParameterPack) | 
|  | 3091 | : Expr(GenericSelectionExprClass, | 
|  | 3092 | Context.DependentTy, | 
|  | 3093 | VK_RValue, | 
|  | 3094 | OK_Ordinary, | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3095 | /*isTypeDependent=*/true, | 
|  | 3096 | /*isValueDependent=*/true, | 
|  | 3097 | /*isInstantiationDependent=*/true, | 
| Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 3098 | ContainsUnexpandedParameterPack), | 
|  | 3099 | AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), | 
|  | 3100 | SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), | 
|  | 3101 | ResultIndex(-1U), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), | 
|  | 3102 | RParenLoc(RParenLoc) { | 
|  | 3103 | SubExprs[CONTROLLING] = ControllingExpr; | 
|  | 3104 | std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); | 
|  | 3105 | std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); | 
|  | 3106 | } | 
|  | 3107 |  | 
| Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 3108 | //===----------------------------------------------------------------------===// | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3109 | //  DesignatedInitExpr | 
|  | 3110 | //===----------------------------------------------------------------------===// | 
|  | 3111 |  | 
| Chandler Carruth | b113824 | 2011-06-16 06:47:06 +0000 | [diff] [blame] | 3112 | IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3113 | assert(Kind == FieldDesignator && "Only valid on a field designator"); | 
|  | 3114 | if (Field.NameOrField & 0x01) | 
|  | 3115 | return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); | 
|  | 3116 | else | 
|  | 3117 | return getField()->getIdentifier(); | 
|  | 3118 | } | 
|  | 3119 |  | 
| Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3120 | DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3121 | unsigned NumDesignators, | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3122 | const Designator *Designators, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3123 | SourceLocation EqualOrColonLoc, | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3124 | bool GNUSyntax, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | Expr **IndexExprs, | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3126 | unsigned NumIndexExprs, | 
|  | 3127 | Expr *Init) | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | : Expr(DesignatedInitExprClass, Ty, | 
| John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 3129 | Init->getValueKind(), Init->getObjectKind(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3130 | Init->isTypeDependent(), Init->isValueDependent(), | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3131 | Init->isInstantiationDependent(), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3132 | Init->containsUnexpandedParameterPack()), | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), | 
|  | 3134 | NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3135 | this->Designators = new (C) Designator[NumDesignators]; | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3136 |  | 
|  | 3137 | // Record the initializer itself. | 
| John McCall | 7502c1d | 2011-02-13 04:07:26 +0000 | [diff] [blame] | 3138 | child_range Child = children(); | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3139 | *Child++ = Init; | 
|  | 3140 |  | 
|  | 3141 | // Copy the designators and their subexpressions, computing | 
|  | 3142 | // value-dependence along the way. | 
|  | 3143 | unsigned IndexIdx = 0; | 
|  | 3144 | for (unsigned I = 0; I != NumDesignators; ++I) { | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3145 | this->Designators[I] = Designators[I]; | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3146 |  | 
|  | 3147 | if (this->Designators[I].isArrayDesignator()) { | 
|  | 3148 | // Compute type- and value-dependence. | 
|  | 3149 | Expr *Index = IndexExprs[IndexIdx]; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3150 | if (Index->isTypeDependent() || Index->isValueDependent()) | 
|  | 3151 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3152 | if (Index->isInstantiationDependent()) | 
|  | 3153 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3154 | // Propagate unexpanded parameter packs. | 
|  | 3155 | if (Index->containsUnexpandedParameterPack()) | 
|  | 3156 | ExprBits.ContainsUnexpandedParameterPack = true; | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3157 |  | 
|  | 3158 | // Copy the index expressions into permanent storage. | 
|  | 3159 | *Child++ = IndexExprs[IndexIdx++]; | 
|  | 3160 | } else if (this->Designators[I].isArrayRangeDesignator()) { | 
|  | 3161 | // Compute type- and value-dependence. | 
|  | 3162 | Expr *Start = IndexExprs[IndexIdx]; | 
|  | 3163 | Expr *End = IndexExprs[IndexIdx + 1]; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3164 | if (Start->isTypeDependent() || Start->isValueDependent() || | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3165 | End->isTypeDependent() || End->isValueDependent()) { | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3166 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3167 | ExprBits.InstantiationDependent = true; | 
|  | 3168 | } else if (Start->isInstantiationDependent() || | 
|  | 3169 | End->isInstantiationDependent()) { | 
|  | 3170 | ExprBits.InstantiationDependent = true; | 
|  | 3171 | } | 
|  | 3172 |  | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3173 | // Propagate unexpanded parameter packs. | 
|  | 3174 | if (Start->containsUnexpandedParameterPack() || | 
|  | 3175 | End->containsUnexpandedParameterPack()) | 
|  | 3176 | ExprBits.ContainsUnexpandedParameterPack = true; | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3177 |  | 
|  | 3178 | // Copy the start/end expressions into permanent storage. | 
|  | 3179 | *Child++ = IndexExprs[IndexIdx++]; | 
|  | 3180 | *Child++ = IndexExprs[IndexIdx++]; | 
|  | 3181 | } | 
|  | 3182 | } | 
|  | 3183 |  | 
|  | 3184 | assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3185 | } | 
|  | 3186 |  | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3187 | DesignatedInitExpr * | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | DesignatedInitExpr::Create(ASTContext &C, Designator *Designators, | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3189 | unsigned NumDesignators, | 
|  | 3190 | Expr **IndexExprs, unsigned NumIndexExprs, | 
|  | 3191 | SourceLocation ColonOrEqualLoc, | 
|  | 3192 | bool UsesColonSyntax, Expr *Init) { | 
| Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 3193 | void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + | 
| Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 3194 | sizeof(Stmt *) * (NumIndexExprs + 1), 8); | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3195 | return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, | 
| Douglas Gregor | 9ea6276 | 2009-05-21 23:17:49 +0000 | [diff] [blame] | 3196 | ColonOrEqualLoc, UsesColonSyntax, | 
|  | 3197 | IndexExprs, NumIndexExprs, Init); | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3198 | } | 
|  | 3199 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3200 | DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, | 
| Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3201 | unsigned NumIndexExprs) { | 
|  | 3202 | void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + | 
|  | 3203 | sizeof(Stmt *) * (NumIndexExprs + 1), 8); | 
|  | 3204 | return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); | 
|  | 3205 | } | 
|  | 3206 |  | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3207 | void DesignatedInitExpr::setDesignators(ASTContext &C, | 
|  | 3208 | const Designator *Desigs, | 
| Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3209 | unsigned NumDesigs) { | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3210 | Designators = new (C) Designator[NumDesigs]; | 
| Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3211 | NumDesignators = NumDesigs; | 
|  | 3212 | for (unsigned I = 0; I != NumDesigs; ++I) | 
|  | 3213 | Designators[I] = Desigs[I]; | 
|  | 3214 | } | 
|  | 3215 |  | 
| Abramo Bagnara | 24f4674 | 2011-03-16 15:08:46 +0000 | [diff] [blame] | 3216 | SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { | 
|  | 3217 | DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); | 
|  | 3218 | if (size() == 1) | 
|  | 3219 | return DIE->getDesignator(0)->getSourceRange(); | 
|  | 3220 | return SourceRange(DIE->getDesignator(0)->getStartLocation(), | 
|  | 3221 | DIE->getDesignator(size()-1)->getEndLocation()); | 
|  | 3222 | } | 
|  | 3223 |  | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3224 | SourceRange DesignatedInitExpr::getSourceRange() const { | 
|  | 3225 | SourceLocation StartLoc; | 
| Chris Lattner | d603eaa | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 3226 | Designator &First = | 
|  | 3227 | *const_cast<DesignatedInitExpr*>(this)->designators_begin(); | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3228 | if (First.isFieldDesignator()) { | 
| Douglas Gregor | eeae8f0 | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 3229 | if (GNUSyntax) | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3230 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); | 
|  | 3231 | else | 
|  | 3232 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); | 
|  | 3233 | } else | 
| Chris Lattner | d603eaa | 2009-02-16 22:33:34 +0000 | [diff] [blame] | 3234 | StartLoc = | 
|  | 3235 | SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3236 | return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); | 
|  | 3237 | } | 
|  | 3238 |  | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3239 | Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) { | 
|  | 3240 | assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); | 
|  | 3241 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); | 
|  | 3242 | Ptr += sizeof(DesignatedInitExpr); | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3243 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); | 
|  | 3244 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); | 
|  | 3245 | } | 
|  | 3246 |  | 
|  | 3247 | Expr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3248 | assert(D.Kind == Designator::ArrayRangeDesignator && | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3249 | "Requires array range designator"); | 
|  | 3250 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); | 
|  | 3251 | Ptr += sizeof(DesignatedInitExpr); | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3252 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); | 
|  | 3253 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); | 
|  | 3254 | } | 
|  | 3255 |  | 
|  | 3256 | Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | assert(D.Kind == Designator::ArrayRangeDesignator && | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3258 | "Requires array range designator"); | 
|  | 3259 | char* Ptr = static_cast<char*>(static_cast<void *>(this)); | 
|  | 3260 | Ptr += sizeof(DesignatedInitExpr); | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3261 | Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); | 
|  | 3262 | return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); | 
|  | 3263 | } | 
|  | 3264 |  | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3265 | /// \brief Replaces the designator at index @p Idx with the series | 
|  | 3266 | /// of designators in [First, Last). | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3267 | void DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | const Designator *First, | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3269 | const Designator *Last) { | 
|  | 3270 | unsigned NumNewDesignators = Last - First; | 
|  | 3271 | if (NumNewDesignators == 0) { | 
|  | 3272 | std::copy_backward(Designators + Idx + 1, | 
|  | 3273 | Designators + NumDesignators, | 
|  | 3274 | Designators + Idx); | 
|  | 3275 | --NumNewDesignators; | 
|  | 3276 | return; | 
|  | 3277 | } else if (NumNewDesignators == 1) { | 
|  | 3278 | Designators[Idx] = *First; | 
|  | 3279 | return; | 
|  | 3280 | } | 
|  | 3281 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | Designator *NewDesignators | 
| Douglas Gregor | 319d57f | 2010-01-06 23:17:19 +0000 | [diff] [blame] | 3283 | = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3284 | std::copy(Designators, Designators + Idx, NewDesignators); | 
|  | 3285 | std::copy(First, Last, NewDesignators + Idx); | 
|  | 3286 | std::copy(Designators + Idx + 1, Designators + NumDesignators, | 
|  | 3287 | NewDesignators + Idx + NumNewDesignators); | 
| Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 3288 | Designators = NewDesignators; | 
|  | 3289 | NumDesignators = NumDesignators - 1 + NumNewDesignators; | 
|  | 3290 | } | 
|  | 3291 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3292 | ParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, | 
| Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 3293 | Expr **exprs, unsigned nexprs, | 
| Manuel Klimek | 0d9106f | 2011-06-22 20:02:16 +0000 | [diff] [blame] | 3294 | SourceLocation rparenloc, QualType T) | 
|  | 3295 | : Expr(ParenListExprClass, T, VK_RValue, OK_Ordinary, | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3296 | false, false, false, false), | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3297 | NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { | 
| Manuel Klimek | 0d9106f | 2011-06-22 20:02:16 +0000 | [diff] [blame] | 3298 | assert(!T.isNull() && "ParenListExpr must have a valid type"); | 
| Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 3299 | Exprs = new (C) Stmt*[nexprs]; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3300 | for (unsigned i = 0; i != nexprs; ++i) { | 
|  | 3301 | if (exprs[i]->isTypeDependent()) | 
|  | 3302 | ExprBits.TypeDependent = true; | 
|  | 3303 | if (exprs[i]->isValueDependent()) | 
|  | 3304 | ExprBits.ValueDependent = true; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3305 | if (exprs[i]->isInstantiationDependent()) | 
|  | 3306 | ExprBits.InstantiationDependent = true; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3307 | if (exprs[i]->containsUnexpandedParameterPack()) | 
|  | 3308 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 3309 |  | 
| Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 3310 | Exprs[i] = exprs[i]; | 
| Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 3311 | } | 
| Nate Begeman | 2ef13e5 | 2009-08-10 23:49:36 +0000 | [diff] [blame] | 3312 | } | 
|  | 3313 |  | 
| John McCall | e996ffd | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 3314 | const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { | 
|  | 3315 | if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) | 
|  | 3316 | e = ewc->getSubExpr(); | 
| Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 3317 | if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) | 
|  | 3318 | e = m->GetTemporaryExpr(); | 
| John McCall | e996ffd | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 3319 | e = cast<CXXConstructExpr>(e)->getArg(0); | 
|  | 3320 | while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) | 
|  | 3321 | e = ice->getSubExpr(); | 
|  | 3322 | return cast<OpaqueValueExpr>(e); | 
|  | 3323 | } | 
|  | 3324 |  | 
| John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame^] | 3325 | PseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &Context, EmptyShell sh, | 
|  | 3326 | unsigned numSemanticExprs) { | 
|  | 3327 | void *buffer = Context.Allocate(sizeof(PseudoObjectExpr) + | 
|  | 3328 | (1 + numSemanticExprs) * sizeof(Expr*), | 
|  | 3329 | llvm::alignOf<PseudoObjectExpr>()); | 
|  | 3330 | return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); | 
|  | 3331 | } | 
|  | 3332 |  | 
|  | 3333 | PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) | 
|  | 3334 | : Expr(PseudoObjectExprClass, shell) { | 
|  | 3335 | PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; | 
|  | 3336 | } | 
|  | 3337 |  | 
|  | 3338 | PseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &C, Expr *syntax, | 
|  | 3339 | ArrayRef<Expr*> semantics, | 
|  | 3340 | unsigned resultIndex) { | 
|  | 3341 | assert(syntax && "no syntactic expression!"); | 
|  | 3342 | assert(semantics.size() && "no semantic expressions!"); | 
|  | 3343 |  | 
|  | 3344 | QualType type; | 
|  | 3345 | ExprValueKind VK; | 
|  | 3346 | if (resultIndex == NoResult) { | 
|  | 3347 | type = C.VoidTy; | 
|  | 3348 | VK = VK_RValue; | 
|  | 3349 | } else { | 
|  | 3350 | assert(resultIndex < semantics.size()); | 
|  | 3351 | type = semantics[resultIndex]->getType(); | 
|  | 3352 | VK = semantics[resultIndex]->getValueKind(); | 
|  | 3353 | assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary); | 
|  | 3354 | } | 
|  | 3355 |  | 
|  | 3356 | void *buffer = C.Allocate(sizeof(PseudoObjectExpr) + | 
|  | 3357 | (1 + semantics.size()) * sizeof(Expr*), | 
|  | 3358 | llvm::alignOf<PseudoObjectExpr>()); | 
|  | 3359 | return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, | 
|  | 3360 | resultIndex); | 
|  | 3361 | } | 
|  | 3362 |  | 
|  | 3363 | PseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, | 
|  | 3364 | Expr *syntax, ArrayRef<Expr*> semantics, | 
|  | 3365 | unsigned resultIndex) | 
|  | 3366 | : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, | 
|  | 3367 | /*filled in at end of ctor*/ false, false, false, false) { | 
|  | 3368 | PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; | 
|  | 3369 | PseudoObjectExprBits.ResultIndex = resultIndex + 1; | 
|  | 3370 |  | 
|  | 3371 | for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { | 
|  | 3372 | Expr *E = (i == 0 ? syntax : semantics[i-1]); | 
|  | 3373 | getSubExprsBuffer()[i] = E; | 
|  | 3374 |  | 
|  | 3375 | if (E->isTypeDependent()) | 
|  | 3376 | ExprBits.TypeDependent = true; | 
|  | 3377 | if (E->isValueDependent()) | 
|  | 3378 | ExprBits.ValueDependent = true; | 
|  | 3379 | if (E->isInstantiationDependent()) | 
|  | 3380 | ExprBits.InstantiationDependent = true; | 
|  | 3381 | if (E->containsUnexpandedParameterPack()) | 
|  | 3382 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 3383 |  | 
|  | 3384 | if (isa<OpaqueValueExpr>(E)) | 
|  | 3385 | assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != 0 && | 
|  | 3386 | "opaque-value semantic expressions for pseudo-object " | 
|  | 3387 | "operations must have sources"); | 
|  | 3388 | } | 
|  | 3389 | } | 
|  | 3390 |  | 
| Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 3391 | //===----------------------------------------------------------------------===// | 
| Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 3392 | //  ExprIterator. | 
|  | 3393 | //===----------------------------------------------------------------------===// | 
|  | 3394 |  | 
|  | 3395 | Expr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } | 
|  | 3396 | Expr* ExprIterator::operator*() const { return cast<Expr>(*I); } | 
|  | 3397 | Expr* ExprIterator::operator->() const { return cast<Expr>(*I); } | 
|  | 3398 | const Expr* ConstExprIterator::operator[](size_t idx) const { | 
|  | 3399 | return cast<Expr>(I[idx]); | 
|  | 3400 | } | 
|  | 3401 | const Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } | 
|  | 3402 | const Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } | 
|  | 3403 |  | 
|  | 3404 | //===----------------------------------------------------------------------===// | 
| Ted Kremenek | 77ed8e4 | 2007-08-24 18:13:47 +0000 | [diff] [blame] | 3405 | //  Child Iterators for iterating over subexpressions/substatements | 
|  | 3406 | //===----------------------------------------------------------------------===// | 
|  | 3407 |  | 
| Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 3408 | // UnaryExprOrTypeTraitExpr | 
|  | 3409 | Stmt::child_range UnaryExprOrTypeTraitExpr::children() { | 
| Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 3410 | // If this is of a type and the type is a VLA type (and not a typedef), the | 
|  | 3411 | // size expression of the VLA needs to be treated as an executable expression. | 
|  | 3412 | // Why isn't this weirdness documented better in StmtIterator? | 
|  | 3413 | if (isArgumentType()) { | 
| John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3414 | if (const VariableArrayType* T = dyn_cast<VariableArrayType>( | 
| Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 3415 | getArgumentType().getTypePtr())) | 
| John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3416 | return child_range(child_iterator(T), child_iterator()); | 
|  | 3417 | return child_range(); | 
| Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 3418 | } | 
| John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3419 | return child_range(&Argument.Ex, &Argument.Ex + 1); | 
| Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 3420 | } | 
| Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 3421 |  | 
| Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 3422 | // ObjCMessageExpr | 
| John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3423 | Stmt::child_range ObjCMessageExpr::children() { | 
|  | 3424 | Stmt **begin; | 
| Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 3425 | if (getReceiverKind() == Instance) | 
| John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3426 | begin = reinterpret_cast<Stmt **>(this + 1); | 
|  | 3427 | else | 
|  | 3428 | begin = reinterpret_cast<Stmt **>(getArgs()); | 
|  | 3429 | return child_range(begin, | 
|  | 3430 | reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); | 
| Steve Naroff | 563477d | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 3431 | } | 
|  | 3432 |  | 
| Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 3433 | // Blocks | 
| John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3434 | BlockDeclRefExpr::BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, | 
| Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 3435 | SourceLocation l, bool ByRef, | 
| John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3436 | bool constAdded) | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3437 | : Expr(BlockDeclRefExprClass, t, VK, OK_Ordinary, false, false, false, | 
| Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 3438 | d->isParameterPack()), | 
| John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3439 | D(d), Loc(l), IsByRef(ByRef), ConstQualAdded(constAdded) | 
| Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 3440 | { | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 3441 | bool TypeDependent = false; | 
|  | 3442 | bool ValueDependent = false; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3443 | bool InstantiationDependent = false; | 
|  | 3444 | computeDeclRefDependence(D, getType(), TypeDependent, ValueDependent, | 
|  | 3445 | InstantiationDependent); | 
| Douglas Gregor | d967e31 | 2011-01-19 21:52:31 +0000 | [diff] [blame] | 3446 | ExprBits.TypeDependent = TypeDependent; | 
|  | 3447 | ExprBits.ValueDependent = ValueDependent; | 
| Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 3448 | ExprBits.InstantiationDependent = InstantiationDependent; | 
| Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 3449 | } | 
| Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3450 |  | 
|  | 3451 |  | 
|  | 3452 | AtomicExpr::AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, | 
|  | 3453 | QualType t, AtomicOp op, SourceLocation RP) | 
|  | 3454 | : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, | 
|  | 3455 | false, false, false, false), | 
|  | 3456 | NumSubExprs(nexpr), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) | 
|  | 3457 | { | 
|  | 3458 | for (unsigned i = 0; i < nexpr; i++) { | 
|  | 3459 | if (args[i]->isTypeDependent()) | 
|  | 3460 | ExprBits.TypeDependent = true; | 
|  | 3461 | if (args[i]->isValueDependent()) | 
|  | 3462 | ExprBits.ValueDependent = true; | 
|  | 3463 | if (args[i]->isInstantiationDependent()) | 
|  | 3464 | ExprBits.InstantiationDependent = true; | 
|  | 3465 | if (args[i]->containsUnexpandedParameterPack()) | 
|  | 3466 | ExprBits.ContainsUnexpandedParameterPack = true; | 
|  | 3467 |  | 
|  | 3468 | SubExprs[i] = args[i]; | 
|  | 3469 | } | 
|  | 3470 | } |