Expr.cpp revision 4059da87fa2fe9f415c9656dc63e75d5d4a489ef
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.cpp - Expression AST Node Implementation --------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expr class and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Expr.h" 150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor#include "clang/AST/ExprCXX.h" 16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h" 172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h" 18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h" 1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h" 20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 2125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor#include "clang/AST/EvaluatedExprVisitor.h" 2219cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h" 2408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Lex/LiteralSupport.h" 2508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Lex/Lexer.h" 267a614d8380297fcd2bc23986241905d97222948cRichard Smith#include "clang/Sema/SemaDiagnostic.h" 271b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 2808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Basic/SourceManager.h" 29da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 30cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 32ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 3364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman#include <cstring> 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 392b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 402b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 41f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 42f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 432b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 44f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (E->getType()->isBooleanType()) return true; 45c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 46f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!E->getType()->isIntegralOrEnumerationType()) return false; 47c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 48f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { 492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 542b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 552b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 56c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 576907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 586907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 59f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) 602b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 61c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 632b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 642b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 732b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 74c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 792b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 802b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 81c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 842b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 852b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 862b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 87c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 88f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) 892b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 91c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 932b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 942b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 9563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// Amusing macro metaprogramming hack: check whether a class provides 9663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// a more specific implementation of getExprLoc(). 9790e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// 9890e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// See also Stmt.cpp:{getLocStart(),getLocEnd()}. 9963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallnamespace { 10063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class provides a custom 10163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// implementation of getExprLoc. 10263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E, class T> 10363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 10463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (T::*v)() const) { 10563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getExprLoc(); 10663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 10863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class doesn't provide 10963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// a custom implementation of getExprLoc. Overload resolution 11063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// should pick it over the implementation above because it's 11163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// more specialized according to function template partial ordering. 11263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E> 11363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 11463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (Expr::*v)() const) { 11590e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar return static_cast<const E*>(expr)->getLocStart(); 11663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 11863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 11963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallSourceLocation Expr::getExprLoc() const { 12063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall switch (getStmtClass()) { 12163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 12263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(type) 12363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define STMT(type, base) \ 12463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; 12563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define EXPR(type, base) \ 12663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); 12763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#include "clang/AST/StmtNodes.inc" 12863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 12963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall llvm_unreachable("unknown statement kind"); 13063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 13163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// \brief Compute the type-, value-, and instantiation-dependence of a 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// declaration reference 138d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// based on the declaration being referenced. 1393d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarstatic void computeDeclRefDependence(ASTContext &Ctx, NamedDecl *D, QualType T, 140d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &TypeDependent, 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &ValueDependent, 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 143d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = false; 144d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = false; 145561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = false; 1460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1470da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 1480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 1490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 150c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 1510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 1520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 1530da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 154d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1550da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 1560da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 157d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (T->isDependentType()) { 158d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 159d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 160561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 161d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 162561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (T->isInstantiationDependentType()) { 163561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 165d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 167d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (D->getDeclName().getNameKind() 168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor == DeclarationName::CXXConversionFunctionName) { 169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualType T = D->getDeclName().getCXXNameType(); 170561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isDependentType()) { 171561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeDependent = true; 172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ValueDependent = true; 173561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return; 175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 176561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 177561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isInstantiationDependentType()) 178561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1790da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 180561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 182d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<NonTypeTemplateParmDecl>(D)) { 183d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 184561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 185d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 186d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 187d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1880da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 1890da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 190db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - a constant with literal type and is initialized with an 191db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11]. 192db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - FIXME: Missing from the standard: 193db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // - an entity with reference type and is initialized with an 194db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11] 195d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 1964e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if ((Ctx.getLangOpts().CPlusPlus0x ? 197db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isLiteralType() : 198db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isIntegralOrEnumerationType()) && 199db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith (Var->getType().getCVRQualifiers() == Qualifiers::Const || 200db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isReferenceType())) { 20131310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 202561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Init->isValueDependent()) { 203d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 204561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 205561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 206db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 207db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith 208bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 209bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 210bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 211db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith if (Var->isStaticDataMember() && 212db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getDeclContext()->isDependentContext()) { 213d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 214561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 215561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 216d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 217d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 218d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 219d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 220bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 221bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 222bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 223d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { 224d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 225561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 226db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 227d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor} 228d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2293d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarvoid DeclRefExpr::computeDependence(ASTContext &Ctx) { 230d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 231d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 232561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 2333d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent, 2343d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar ValueDependent, InstantiationDependent); 235d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 236d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 237d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An id-expression is type-dependent if it contains: 238d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 239d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // and 240d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 241d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 242d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An identifier is value-dependent if it is: 243d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (!TypeDependent && !ValueDependent && 244d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor hasExplicitTemplateArgs() && 245d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 246d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getTemplateArgs(), 247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor getNumTemplateArgs(), 248561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) { 249d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 250d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 251561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 252d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 253d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 254d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 255d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 256561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = InstantiationDependent; 257d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 25810738d36b150aa65206890c1c845cdba076e4200Douglas Gregor // Is the declaration a parameter pack? 259d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (getDecl()->isParameterPack()) 2601fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 2620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 2633d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel DunbarDeclRefExpr::DeclRefExpr(ASTContext &Ctx, 2643d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NestedNameSpecifierLoc QualifierLoc, 265e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 266f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ValueDecl *D, bool RefersToEnclosingLocal, 267f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const DeclarationNameInfo &NameInfo, 2683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 2692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 271561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 272cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 273cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; 2747e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth if (QualifierLoc) 2756857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth getInternalQualifierLoc() = QualifierLoc; 2763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; 2773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 2783aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth getInternalFoundDecl() = FoundD; 279e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo 280e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0; 281f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExprBits.RefersToEnclosingLocal = RefersToEnclosingLocal; 282561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TemplateArgs) { 283561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 284561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 285561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 286e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, 287e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 288e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 289e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 290561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 291561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(true); 292e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 293e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 294561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 295b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer DeclRefExprBits.HadMultipleCandidates = 0; 296b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer 2973d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDependence(Ctx); 2982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 2992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 300a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 30140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 302e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 303dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 304f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 305a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 3060da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3083aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3090da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 310e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return Create(Context, QualifierLoc, TemplateKWLoc, D, 311f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 3122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 3133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth T, VK, FoundD, TemplateArgs); 3142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3162577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 31740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 318e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 3192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 320f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 3212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 3222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 323f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3243aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 3263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth // Filter out cases where the found Decl is the same as the value refenenced. 3273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (D == FoundD) 3283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth FoundD = 0; 3293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 330a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 33140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc != 0) 3326857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 3333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 3343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 335d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 336e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); 337e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 338e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 3393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 3403248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 3413d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, 342f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 3433d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NameInfo, FoundD, TemplateArgs, T, VK); 344a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 345a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3463aa8140bde5b9bedf13e46ec0a668daa54814196Chandler CarruthDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, 347def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 3483aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 349e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 350663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 351663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 352663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 3536857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 3543aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (HasFoundDecl) 3553aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 356e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (HasTemplateKWAndArgsInfo) 357e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 3583aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 3593248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 360663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 361663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 362663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 363a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 3642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange R = getNameInfo().getSourceRange(); 365a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 36640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor R.setBegin(getQualifierLoc().getBeginLoc()); 367096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 368a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 369a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 370a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 371396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocStart() const { 372396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasQualifier()) 373396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 374396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocStart(); 375396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 376396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocEnd() const { 377396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 378396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getRAngleLoc(); 379396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocEnd(); 380396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 381a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 3833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 384848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 385848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 386848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 3873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 388848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 3893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 3903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 391f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 3923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 3933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 395848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 3963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 3974eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 3984eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 3993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4014e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie PrintingPolicy Policy(Context.getLangOpts()); 4023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 403abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream POut(Proto); 4043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 405abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionDecl *Decl = FD; 406abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) 407abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Decl = Pattern; 408abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); 4093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 4103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 4113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 4123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 413abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << "("; 4143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 415abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) { 4163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 4177ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis POut << Decl->getParamDecl(i)->getType().stream(Policy); 4183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 4213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 4223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 4233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 425abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << ")"; 4263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4274eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 4284eadcc569223135e13353c9381b448986e3f7053Sam Weinig Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); 4294eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasConst()) 430abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " const"; 4314eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasVolatile()) 432abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " volatile"; 433abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor RefQualifierKind Ref = MD->getRefQualifier(); 434abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Ref == RQ_LValue) 435abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &"; 436abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor else if (Ref == RQ_RValue) 437abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &&"; 438abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 439abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 440abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; 441abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor SpecsTy Specs; 442abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const DeclContext *Ctx = FD->getDeclContext(); 443abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor while (Ctx && isa<NamedDecl>(Ctx)) { 444abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const ClassTemplateSpecializationDecl *Spec 445abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); 446abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Spec && !Spec->isExplicitSpecialization()) 447abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Specs.push_back(Spec); 448abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Ctx = Ctx->getParent(); 449abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 450abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 451abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor std::string TemplateParams; 452abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream TOut(TemplateParams); 453abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend(); 454abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor I != E; ++I) { 455abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList *Params 456abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = (*I)->getSpecializedTemplate()->getTemplateParameters(); 457abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList &Args = (*I)->getTemplateArgs(); 458abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args.size()); 459abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) { 460abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 461abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 462abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 463abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args.get(i).print(Policy, TOut); 464abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 465abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 4664eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 4674eadcc569223135e13353c9381b448986e3f7053Sam Weinig 468abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor FunctionTemplateSpecializationInfo *FSI 469abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FD->getTemplateSpecializationInfo(); 470abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (FSI && !FSI->isExplicitSpecialization()) { 471abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList* Params 472abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FSI->getTemplate()->getTemplateParameters(); 473abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList* Args = FSI->TemplateArguments; 474abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args->size()); 475abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Params->size(); i != e; ++i) { 476abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 477abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 478abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 479abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args->get(i).print(Policy, TOut); 480abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 481abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 482abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 483abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 484abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut.flush(); 485abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (!TemplateParams.empty()) { 486abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor // remove the trailing comma and space 487abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TemplateParams.resize(TemplateParams.size() - 2); 488abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " [" << TemplateParams << "]"; 489abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 490abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 491abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut.flush(); 492abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 4933a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 4943a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 4953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 4973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 4993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 502f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 5033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 5043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 5053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 506b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 507b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 508b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 509b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 510b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer Out << *ID; 511b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 5123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 513900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 514f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramer Out << '(' << *CID << ')'; 515900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 5163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 5173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 5183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 5193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 5213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 5243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 5253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 5263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 5283a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 5293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 5319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 5329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 5339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 5359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 5369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 5379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 5389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 5399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 5409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 5419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 5429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 5439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 5449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 5479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 5489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 5499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 5509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 5539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 5549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 5559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 5589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 5599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 5609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 5619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 5649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 56531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return new (C) FloatingLiteral(C, Empty); 5669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 568da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 569da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 570da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 571da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 572da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 573ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 574ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 575ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 576da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 577da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 578da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 5790fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewyckyint StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { 580fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman int CharByteWidth = 0; 5810fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky switch(k) { 58264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Ascii: 58364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF8: 5840fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getCharWidth(); 58564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 58664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Wide: 5870fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getWCharWidth(); 58864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 58964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF16: 5900fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar16Width(); 59164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 59264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF32: 5930fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar32Width(); 594fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman break; 59564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 59664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); 59764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman CharByteWidth /= 8; 5980fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) 59964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "character byte widths supported are 1, 2, and 4 only"); 60064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return CharByteWidth; 60164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman} 60264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 6035f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, 6045cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind Kind, bool Pascal, QualType Ty, 6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 606a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 6072085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 6082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 6092085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 6102085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 6113248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 6122085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 6131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 61564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->setString(C,Str,Kind,Pascal); 61664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 6172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 6182085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 620726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 6212085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 6222085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 623726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 624726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 625673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 626673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 627673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 6283248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 629673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 63064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->CharByteWidth = 0; 63164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->Length = 0; 632673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 633673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 634673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 635673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 63664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedmanvoid StringLiteral::setString(ASTContext &C, StringRef Str, 63764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal) { 63864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman //FIXME: we assume that the string data comes from a target that uses the same 63964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman // code unit size and endianess for the type of string. 64064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->Kind = Kind; 64164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->IsPascal = IsPascal; 64264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 6430fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind); 64464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((Str.size()%CharByteWidth == 0) 64564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "size of data must be multiple of CharByteWidth"); 64664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman Length = Str.size()/CharByteWidth; 64764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 64864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman switch(CharByteWidth) { 64964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 1: { 65064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman char *AStrData = new (C) char[Length]; 65164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman std::memcpy(AStrData,Str.data(),Str.size()); 65264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asChar = AStrData; 65364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 65464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 65564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 2: { 65664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint16_t *AStrData = new (C) uint16_t[Length]; 65764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman std::memcpy(AStrData,Str.data(),Str.size()); 65864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt16 = AStrData; 65964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 66064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 66164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 4: { 66264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t *AStrData = new (C) uint32_t[Length]; 66364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman std::memcpy(AStrData,Str.data(),Str.size()); 66464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt32 = AStrData; 66564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 66664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 66764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman default: 66864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(false && "unsupported CharByteWidth"); 66964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 670673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 671673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 67208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 67308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 67408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 67508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 67608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 67708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 67808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 67908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 68008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 68108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 6825cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor assert(Kind == StringLiteral::Ascii && "This only works for ASCII strings"); 6835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 68408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 68508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 68608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 68708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 68808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 68908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 69008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 69108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 69208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 69308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 69408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 69508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 69608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 69708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 69808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 6995f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 70008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 70108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 70208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 70308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 70408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 70508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a langops struct and enable trigraphs. This is sufficient for 70608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // relexing tokens. 70708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOptions LangOpts; 70808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOpts.Trigraphs = true; 70908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 71008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 711df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, 712df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Buffer.begin(), StrData, Buffer.end()); 71308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 71408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 71508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 71608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 71708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 71808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 71908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 72008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 72108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 722935a70c1e76d78985f20d422940280161b941299Hans Wennborg (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { 72308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 72408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 72508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 72608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 72708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 72808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 72908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 73008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 73108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 73208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 73308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 73408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 73508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 73608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 73708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 7422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 7432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 7442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 7452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 7462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 7472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 7482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 7492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 7502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 7512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 7522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 7532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 7542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 756561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("Unknown unary operator"); 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 760bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 761bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 762b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("No unary operator for overloaded function"); 7632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 7642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 7652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 7662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 7672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 7682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 7692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 7702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 771bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 772bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 773bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 774bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 775bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 7762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 7772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 7782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 7792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 7802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 7812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 7822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 7832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 784bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 785bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 786bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 787bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 788bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 793cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 794cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 795f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 796f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 797bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 798bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 799561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 800bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 801898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 803cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[numargs+PREARGS_START+NumPreArgs]; 804b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 805bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != numargs; ++i) { 806bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 807bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 808bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 809bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 810561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 811561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 812bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 813bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 814bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 815cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; 816bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 817668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 818cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 819b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 820b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 821e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 822668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 823f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 824f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 825bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 826bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 827561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 828bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 829898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 830668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 831cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[numargs+PREARGS_START]; 83277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 833bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != numargs; ++i) { 834bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 835bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 836bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 837bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 838561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 839561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 840bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 841bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 842bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 843cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START] = args[i]; 844bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 845668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 846cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 852bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // FIXME: Why do we allocate this? 853cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START]; 854cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 855cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne} 856cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 857cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, 858cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne EmptyShell Empty) 859cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 860cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // FIXME: Why do we allocate this? 861cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; 862cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 8631f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 8641f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 865d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 866e8683d6d389def2fce229325435ba3c2b3f75492John McCall Expr *CEE = getCallee()->IgnoreParenImpCasts(); 8671ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 8681ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor while (SubstNonTypeTemplateParmExpr *NTTP 8691ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { 8701ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor CEE = NTTP->getReplacement()->IgnoreParenCasts(); 8711ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor } 8721ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 873200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 874200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 875200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 876200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 877200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 878200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 879200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 880200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 8816346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 882d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 883cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 884cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 885a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 886a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 887a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 888a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 889d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 890caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 891d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 892d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 893d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 894d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 895d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 8968189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 897d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 898d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 900d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 901d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 902d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 903d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 904d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 905d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 906d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 907cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs = getNumPreArgs(); 908cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; 909d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 910cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) 911d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 912d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 913cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; 914cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne i != NumArgs+PREARGS_START+NumPreArgs; ++i) 915d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91788c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 918d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 919d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 920d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 921d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 922cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 923cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 924180f47959a066795cc0f409433023af448bb0328Richard Smithunsigned CallExpr::isBuiltinCall() const { 925c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 927c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 928c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 929c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 930cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 932c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 933c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 934cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 9351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 936bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 937bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 938cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 9391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9404fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 9414fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 9424fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 9437814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 944cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 945bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 9466dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 9476dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 9486217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 9496dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 9506217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 9516dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 952864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) 953864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // This should never be overloaded and so should never return null. 954864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall CalleeType = Expr::findBoundMemberType(getCallee()); 9555291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 956864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall const FunctionType *FnType = CalleeType->castAs<FunctionType>(); 9576dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 9586dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 959cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 9602882eca5a184c78f793188083f6ce539740a5cf2John McCallSourceRange CallExpr::getSourceRange() const { 9612882eca5a184c78f793188083f6ce539740a5cf2John McCall if (isa<CXXOperatorCallExpr>(this)) 9622882eca5a184c78f793188083f6ce539740a5cf2John McCall return cast<CXXOperatorCallExpr>(this)->getSourceRange(); 9632882eca5a184c78f793188083f6ce539740a5cf2John McCall 9642882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceLocation begin = getCallee()->getLocStart(); 9652882eca5a184c78f793188083f6ce539740a5cf2John McCall if (begin.isInvalid() && getNumArgs() > 0) 9662882eca5a184c78f793188083f6ce539740a5cf2John McCall begin = getArg(0)->getLocStart(); 9672882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceLocation end = getRParenLoc(); 9682882eca5a184c78f793188083f6ce539740a5cf2John McCall if (end.isInvalid() && getNumArgs() > 0) 9692882eca5a184c78f793188083f6ce539740a5cf2John McCall end = getArg(getNumArgs() - 1)->getLocEnd(); 9702882eca5a184c78f793188083f6ce539740a5cf2John McCall return SourceRange(begin, end); 9712882eca5a184c78f793188083f6ce539740a5cf2John McCall} 9728fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocStart() const { 9738fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 9748fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return cast<CXXOperatorCallExpr>(this)->getSourceRange().getBegin(); 9758fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 9768fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation begin = getCallee()->getLocStart(); 9778fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (begin.isInvalid() && getNumArgs() > 0) 9788fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar begin = getArg(0)->getLocStart(); 9798fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return begin; 9808fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 9818fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocEnd() const { 9828fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 9838fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return cast<CXXOperatorCallExpr>(this)->getSourceRange().getEnd(); 9848fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 9858fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation end = getRParenLoc(); 9868fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (end.isInvalid() && getNumArgs() > 0) 9878fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar end = getArg(getNumArgs() - 1)->getLocEnd(); 9888fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return end; 9898fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 9902882eca5a184c78f793188083f6ce539740a5cf2John McCall 991c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 9928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 993c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 994c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 9958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 9968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 9978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 998c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt sizeof(OffsetOfNode) * numComps + 9998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 10008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 10018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, 10028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor exprsPtr, numExprs, RParenLoc); 10038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 10048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 10058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 10068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 10078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 10088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 10098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 10108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 10118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 10128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1013c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 10148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1015c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 10168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 10178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 1018f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 1019f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 1020bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType(), 1021561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tsi->getType()->isInstantiationDependentType(), 1022bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tsi->getType()->containsUnexpandedParameterPack()), 1023c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 1024c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NumComps(numComps), NumExprs(numExprs) 10258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 10268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numComps; ++i) { 10278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setComponent(i, compsPtr[i]); 10288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1029c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numExprs; ++i) { 1031bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprsPtr[i]->isTypeDependent() || exprsPtr[i]->isValueDependent()) 1032bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 1033bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprsPtr[i]->containsUnexpandedParameterPack()) 1034bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1035bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 10368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setIndexExpr(i, exprsPtr[i]); 10378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 10388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 10398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 10408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 10418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 10428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 10438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 1044c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 10468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 10478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 104940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1050e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1051f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 1052161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 10532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 1054d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1055f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 1056f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 1057f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 105883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 10596bb8017bb9e828d118e15e59d71c66bba323c364John McCall 106040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor bool hasQualOrFound = (QualifierLoc || 1061161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 1062161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 10636bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 10646bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1066d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 1067e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(targs->size()); 1068e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 1069e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10713248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 1072f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 1073f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 10746bb8017bb9e828d118e15e59d71c66bba323c364John McCall 10756bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 107640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor // FIXME: Wrong. We should be looking at the member declaration we found. 107740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { 10786bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 10796bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 1080561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1081561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1082561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (QualifierLoc && 1083561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) 1084561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1085561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 10866bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 10876bb8017bb9e828d118e15e59d71c66bba323c364John McCall 10886bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 108940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NQ->QualifierLoc = QualifierLoc; 10906bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 10916bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 10926bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1093e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->HasTemplateKWAndArgsInfo = (targs || TemplateKWLoc.isValid()); 1094e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 10956bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 1096561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 1097561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 1098561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 1099e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *targs, 1100e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 1101e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 1102e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 1103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 1104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1105e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 1106e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 11076bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 11086bb8017bb9e828d118e15e59d71c66bba323c364John McCall 11096bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 111083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 111183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 111275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas GregorSourceRange MemberExpr::getSourceRange() const { 1113396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return SourceRange(getLocStart(), getLocEnd()); 1114396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 1115396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocStart() const { 111675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (isImplicitAccess()) { 111775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (hasQualifier()) 1118396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 1119396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 112075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 1121e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1122396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // FIXME: We don't want this to happen. Rather, we should be able to 1123396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // detect all kinds of implicit accesses more cleanly. 1124396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar SourceLocation BaseStartLoc = getBase()->getLocStart(); 1125396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (BaseStartLoc.isValid()) 1126396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return BaseStartLoc; 1127396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 1128396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 1129396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocEnd() const { 1130396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 1131396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getRAngleLoc(); 1132396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getMemberNameInfo().getEndLoc(); 113375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 113475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 11351d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCallvoid CastExpr::CheckCastConsistency() const { 11361d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall switch (getCastKind()) { 11371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBase: 11381d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UncheckedDerivedToBase: 11391d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBaseMemberPointer: 11401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerived: 11411d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerivedMemberPointer: 11421d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 11431d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 11441d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 11451d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 11461d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 11471d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isPointerType()); 11481d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 11491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 11501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 11511d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 11521d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isBlockPointerType()); 11531d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 11541d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 11554d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 11564d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getType()->isMemberPointerType()); 11574d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getSubExpr()->getType()->isMemberPointerType()); 11584d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall goto CheckNoBasePath; 11594d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 11601d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BitCast: 11611d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Arbitrary casts to C pointer types count as bitcasts. 11621d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Otherwise, we should only have block and ObjC pointer casts 11631d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // here if they stay within the type kind. 11641d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (!getType()->isPointerType()) { 11651d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType() == 11661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isObjCObjectPointerType()); 11671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType() == 11681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isBlockPointerType()); 11691d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 11701d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 11711d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 11721d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_AnyPointerToBlockPointerCast: 11731d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType()); 11741d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isAnyPointerType() && 11751d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall !getSubExpr()->getType()->isBlockPointerType()); 11761d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 11771d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1178ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1179ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getType()->isBlockPointerType()); 1180ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getSubExpr()->getType()->isBlockPointerType()); 1181ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor goto CheckNoBasePath; 1182ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor 11831d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // These should not have an inheritance path. 11841d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dynamic: 11851d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToUnion: 11861d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ArrayToPointerDecay: 11871d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FunctionToPointerDecay: 11881d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToMemberPointer: 11891d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToPointer: 11901d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ConstructorConversion: 11911d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToPointer: 11921d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToIntegral: 11931d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToVoid: 11941d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_VectorSplat: 11951d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralCast: 11961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToFloating: 11971d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToIntegral: 11981d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingCast: 11991d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ObjCObjectLValueCast: 12001d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingRealToComplex: 12011d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToReal: 12021d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexCast: 12031d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToIntegralComplex: 12041d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralRealToComplex: 12051d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToReal: 12061d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexCast: 12071d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToFloatingComplex: 120833e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 120933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 121033e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 121133e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 12121d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 12131d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 12141d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 12151d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dependent: 12161d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueToRValue: 12171d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NoOp: 12187a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 12197a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 12201d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToBoolean: 12211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToBoolean: 12221d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToBoolean: 12231d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_MemberPointerToBoolean: 12241d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToBoolean: 12251d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToBoolean: 12261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueBitCast: // -> bool& 12271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UserDefinedConversion: // operator bool() 12281d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CheckNoBasePath: 12291d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 12301d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 12311d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 12321d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall} 12331d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1234f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 1235f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 1236daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 1237daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 12382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 1239f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 12402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 1241e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 12420ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 12430ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall return "LValueToRValue"; 12442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 1245f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 12462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 124711de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 12482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 1249f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 12502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 125123cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 12522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 1253f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 12542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 1255f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 12562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 1257f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 12582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 1259f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 12602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 1261f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 1262404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 1263404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 12642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 1265f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 12662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 12671a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 12684d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 12694d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall return "ReinterpretMemberPointer"; 12702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 1271f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 12722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 1273f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 12742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 12757f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 12762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 12777f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 1278daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 1279daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 12802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 1281ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 12822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 128316a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 12842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 128582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 1286daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 1287daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 12882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 128982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 12902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 129182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 12922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 1293c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 1294daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 1295daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 12962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 1297bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 12981d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 12991d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "CPointerToObjCPointerCast"; 13001d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 13011d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "BlockPointerToObjCPointerCast"; 13022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 13033b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 13042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 1305569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 13062bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 13072bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 1308f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 1309f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 1310f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 1311f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 13122bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 13132bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 1314f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 1315f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 13162bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 13172bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 1318f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 1319f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 1320f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 1321f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 13222bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 13232bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 1324f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 1325f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 132633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 132733e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCConsumeObject"; 132833e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 132933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCProduceObject"; 133033e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 133133e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCReclaimReturnedObject"; 133233e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 133333e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCCExtendBlockObject"; 13347a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 13357a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "AtomicToNonAtomic"; 13367a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 13377a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "NonAtomicToAtomic"; 1338ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1339ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor return "CopyAndAutoreleaseBlockObject"; 1340f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13422bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 1343f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 1344f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 13456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 13466eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 13476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 13486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 13496eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 135003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 135103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Skip through reference binding to temporary. 135203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 135303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) 135403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SubExpr = Materialize->GetTemporaryExpr(); 135503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 13566eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 13576eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 13586eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 1359c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13606eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 13616eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 13622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 13636eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 13642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 13656eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 1366c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13676eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 13686eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 1369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 1370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13716eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 13726eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 13736eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 1374f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 1375f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 1376f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 1377f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 1378f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 1379f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 1380f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 1381f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 1382f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 1383f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 1384f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 1385f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1386f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1387f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 1388f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 1389f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 1390f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1391f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1392f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 1393f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 1394f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 13955baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 1396f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1397f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1398f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1399f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 14005baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 1401f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1402f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1403f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1404f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1405f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 1406f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 1407f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1408f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1409f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 1410f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1411f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1412f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1413f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 1414f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 1415f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 1416f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 1417f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 1418f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1419f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1420f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1421f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 1422f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 1423f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1424f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1425f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1426f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1427f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 1428f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1429f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1430f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 1431f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1432f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 14372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 14382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 14392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 14402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 14412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 14422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 14432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 14442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 14452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 14462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 14472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 14482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 14492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 14502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 14512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 14522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 14532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 14542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 14552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 14562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 14572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 14582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 14592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 14602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 14612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 14622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 14632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 14642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 14652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 14662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 14672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 14682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1470baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 14713026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid OpCode!"); 14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1475063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1476063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1477b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not an overloadable binary operator"); 14782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 14792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 14802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 14812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 14822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 14832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 14842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 14852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 14862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 14872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 14882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 14892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 14902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 14912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 14922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 14932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 14942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 14952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 14962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 14972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 14982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 14992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 15002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 15012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 15022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 15032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 15042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 15052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 15062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 15072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 15082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1509063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1510063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1511063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1512063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1513063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1514063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1515063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1516063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1517063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1518063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1519063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1520063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1521063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1522063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1523063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1524063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1525063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1526063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1527063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1528063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1529063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1530063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1531063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1532063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1533063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1534063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1535063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1536709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 1537418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 15384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 1539bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, 1540561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1541709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs(C, numInits), 154232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0) 154332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl{ 154432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl sawArrayRangeDesignator(false); 154532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl setInitializesStdInitializerList(false); 1546ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek for (unsigned I = 0; I != numInits; ++I) { 1547ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 15488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1549ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 15508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1551561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (initExprs[I]->isInstantiationDependent()) 1552561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1553bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (initExprs[I]->containsUnexpandedParameterPack()) 1554bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 155573460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1556c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1557709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); 155866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1560709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1561ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1562709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1563fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1564fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1565709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1566709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 15674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 15684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1569709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1570ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1571709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1572ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1573ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 15744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 15774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 15784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 15794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 15804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 15813e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidisvoid InitListExpr::setArrayFiller(Expr *filler) { 158221f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis assert(!hasArrayFiller() && "Filler already set!"); 15833e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis ArrayFillerOrUnionFieldInit = filler; 15843e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis // Fill out any "holes" in the array due to designated initializers. 15853e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis Expr **inits = getInits(); 15863e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis for (unsigned i = 0, e = getNumInits(); i != e; ++i) 15873e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis if (inits[i] == 0) 15883e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis inits[i] = filler; 15893e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis} 15903e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis 1591fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smithbool InitListExpr::isStringLiteralInit() const { 1592fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith if (getNumInits() != 1) 1593fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1594fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(getType()); 1595fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith if (!CAT || !CAT->getElementType()->isIntegerType()) 1596fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1597fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith const Expr *Init = getInit(0)->IgnoreParenImpCasts(); 1598fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); 1599fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith} 1600fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith 1601c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted KremenekSourceRange InitListExpr::getSourceRange() const { 1602c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (SyntacticForm) 1603c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SyntacticForm->getSourceRange(); 1604c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek SourceLocation Beg = LBraceLoc, End = RBraceLoc; 1605c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1606c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1607c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1608c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1609c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1610c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1611c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1612c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1613c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1614c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1615c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1616c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1617c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1618c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 1619c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.rend(); 1620c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1621c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1622c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek End = S->getSourceRange().getEnd(); 1623c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1624c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1625c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1626c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1627c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SourceRange(Beg, End); 1628c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1629c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1630bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 16314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 1632a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCallconst FunctionProtoType *BlockExpr::getFunctionType() const { 1633a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall // The block pointer is never sugared, but the function type might be. 1634a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall return cast<BlockPointerType>(getType()) 1635a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall ->getPointeeType()->castAs<FunctionProtoType>(); 16364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 16374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 16381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 164056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 16427297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 16437297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 16441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 16467297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 164756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 164856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1653026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1654026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1655026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1656026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1657a6115068cde719142eb394db88612c185cabd05bEli Friedmanbool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, 1658a6115068cde719142eb394db88612c185cabd05bEli Friedman SourceRange &R1, SourceRange &R2, 1659a6115068cde719142eb394db88612c185cabd05bEli Friedman ASTContext &Ctx) const { 1660ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1661ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1662ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1663ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 16670faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 16680faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1669a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1670026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1671026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1672026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 16735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1674026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1675a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1676f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 1677f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr()-> 1678a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 16795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 16805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1683a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Plus: 1684a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Minus: 1685a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_AddrOf: 1686a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Not: 1687a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_LNot: 1688a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Deref: 1689a6115068cde719142eb394db88612c185cabd05bEli Friedman break; 16902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 16912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 16922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 16932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1694026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 16952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 16962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1698df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1699df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1700026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1701026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 17022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1703a6115068cde719142eb394db88612c185cabd05bEli Friedman return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1705a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1706026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1707026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1708026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1710e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1711026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1712c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1713c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1714c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 171525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 171625973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 17172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1718c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1719c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1720c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1721c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1722c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1723c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 1724a6115068cde719142eb394db88612c185cabd05bEli Friedman return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 172525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 17262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 17272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 1728a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || 1729a6115068cde719142eb394db88612c185cabd05bEli Friedman !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 173025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 173125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1732bf0ee354163f87623a4b60412544243911332343John McCall } 1733026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1734026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1735a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1736026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1737026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1738026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1739026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1740e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1741eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1742c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1743276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman case AtomicExprClass: 1744026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 17455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1746ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1747fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // If only one of the LHS or RHS is a warning, the operator might 1748fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // be being used for control flow. Only warn if both the LHS and 1749fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // RHS are warnings. 1750ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 1751a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 1752fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek return false; 1753fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek if (!Exp->getLHS()) 1754026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1755a6115068cde719142eb394db88612c185cabd05bEli Friedman return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1756ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1757ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1759a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1760026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1761026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1762026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1763026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 17641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 1766a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1767026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 1768026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 1769026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 1770026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1771211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 17729b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth case CXXOperatorCallExprClass: { 17739b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // We warn about operator== and operator!= even when user-defined operator 17749b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // overloads as there is no reasonable way to define these such that they 17759b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // have non-trivial, desirable side-effects. See the -Wunused-comparison 17769b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // warning: these operators are commonly typo'ed, and so warning on them 17779b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // provides additional value as well. If this list is updated, 17789b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // DiagnoseUnusedComparison should be as well. 17799b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); 17809b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth if (Op->getOperator() == OO_EqualEqual || 17816e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Op->getOperator() == OO_ExclaimEqual) { 1782a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 17836e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Loc = Op->getOperatorLoc(); 17846e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay R1 = Op->getSourceRange(); 17859b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth return true; 17866e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay } 17879b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth 17889b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // Fallthrough for generic call handling. 17899b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth } 17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 17919fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case CXXMemberCallExprClass: 17929fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case UserDefinedLiteralClass: { 1793026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 1794026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 1795d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 1796026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 1797026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 1798bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 1799bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 1800bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 1801bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 1802bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 1803a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1804bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 1805bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 1806bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 1807bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 1808bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 1809bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 1810bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 1811bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1812026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 1813026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1814026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 181558beed91d468863b8c85bce43425422703838d27Anders Carlsson 181658beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 181758beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 181858beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 181958beed91d468863b8c85bce43425422703838d27Anders Carlsson 1820f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 1821f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 18224e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().ObjCAutoRefCount && 1823f85e193739c953358c865005855253af4f68a497John McCall ME->isInstanceMessage() && 1824f85e193739c953358c865005855253af4f68a497John McCall !ME->getType()->isVoidType() && 1825f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) && 1826f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) 1827f85e193739c953358c865005855253af4f68a497John McCall ->getName().startswith("init")) { 1828a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1829f85e193739c953358c865005855253af4f68a497John McCall Loc = getExprLoc(); 1830f85e193739c953358c865005855253af4f68a497John McCall R1 = ME->getSourceRange(); 1831f85e193739c953358c865005855253af4f68a497John McCall return true; 1832f85e193739c953358c865005855253af4f68a497John McCall } 1833f85e193739c953358c865005855253af4f68a497John McCall 1834f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 1835f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 1836a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1837f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 1838f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 1839f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 1840026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1841f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 18421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall case ObjCPropertyRefExprClass: 1844a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 18455e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 18465e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 1847a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 184812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 18494b9c2d235fb9449e249d74f48ecfec601650de93John McCall case PseudoObjectExprClass: { 18504b9c2d235fb9449e249d74f48ecfec601650de93John McCall const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 18514b9c2d235fb9449e249d74f48ecfec601650de93John McCall 18524b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Only complain about things that have the form of a getter. 18534b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<UnaryOperator>(PO->getSyntacticForm()) || 18544b9c2d235fb9449e249d74f48ecfec601650de93John McCall isa<BinaryOperator>(PO->getSyntacticForm())) 18554b9c2d235fb9449e249d74f48ecfec601650de93John McCall return false; 18564b9c2d235fb9449e249d74f48ecfec601650de93John McCall 1857a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 18584b9c2d235fb9449e249d74f48ecfec601650de93John McCall Loc = getExprLoc(); 18594b9c2d235fb9449e249d74f48ecfec601650de93John McCall R1 = getSourceRange(); 18604b9c2d235fb9449e249d74f48ecfec601650de93John McCall return true; 18614b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 18624b9c2d235fb9449e249d74f48ecfec601650de93John McCall 1863611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 1864611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 1865611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 1866611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 1867611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 1868611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 1869611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 1870d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 1871611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 1872a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1873d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 1874d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 1875a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1876d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18780faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 18790faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1880a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1881026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 1882026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1883026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1884611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 1885a6115068cde719142eb394db88612c185cabd05bEli Friedman case CStyleCastExprClass: { 18864059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman // Ignore an explicit cast to void unless the operand is a non-trivial 1887a6115068cde719142eb394db88612c185cabd05bEli Friedman // volatile lvalue. 18884059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CastExpr *CE = cast<CastExpr>(this); 1889a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ToVoid) { 1890a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getSubExpr()->isGLValue() && 18914059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman CE->getSubExpr()->getType().isVolatileQualified()) { 18924059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const DeclRefExpr *DRE = 18934059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); 18944059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (!(DRE && isa<VarDecl>(DRE->getDecl()) && 18954059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) { 18964059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, 18974059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1, R2, Ctx); 18984059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 18994059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 19000faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1901a6115068cde719142eb394db88612c185cabd05bEli Friedman } 19024059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 1903a6115068cde719142eb394db88612c185cabd05bEli Friedman // If this is a cast to a constructor conversion, check the operand. 190458beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 1905a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ConstructorConversion) 1906a6115068cde719142eb394db88612c185cabd05bEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 19074059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 1908a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 19094059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (const CXXFunctionalCastExpr *CXXCE = 19104059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<CXXFunctionalCastExpr>(this)) { 19114059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CXXCE->getTypeBeginLoc(); 19124059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CXXCE->getSubExpr()->getSourceRange(); 19134059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } else { 19144059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); 19154059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CStyleCE->getLParenLoc(); 19164059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CStyleCE->getSubExpr()->getSourceRange(); 19174059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 1918026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 191958beed91d468863b8c85bce43425422703838d27Anders Carlsson } 1920a6115068cde719142eb394db88612c185cabd05bEli Friedman case ImplicitCastExprClass: { 1921a6115068cde719142eb394db88612c185cabd05bEli Friedman const CastExpr *ICE = cast<ImplicitCastExpr>(this); 1922a6115068cde719142eb394db88612c185cabd05bEli Friedman 1923a6115068cde719142eb394db88612c185cabd05bEli Friedman // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. 1924a6115068cde719142eb394db88612c185cabd05bEli Friedman if (ICE->getCastKind() == CK_LValueToRValue && 1925a6115068cde719142eb394db88612c185cabd05bEli Friedman ICE->getSubExpr()->getType().isVolatileQualified()) 1926a6115068cde719142eb394db88612c185cabd05bEli Friedman return false; 19274be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 1928a6115068cde719142eb394db88612c185cabd05bEli Friedman return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1929a6115068cde719142eb394db88612c185cabd05bEli Friedman } 193004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 1931df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 1932a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 19334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 19344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 19354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 19364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 19374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 1938026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 19392d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 1940df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 1941a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 19424765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 19434765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return (cast<ExprWithCleanups>(this) 1944a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 19454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 19465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 194844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 19497f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 1950102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 1951f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 1952f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne switch (E->getStmtClass()) { 195344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 195444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 195544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 195644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1957207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1958f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 195944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1960f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 196103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 196203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() 196303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isOBJCGCCandidate(Ctx); 196406b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1965f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 1966a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 1967f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const Decl *D = cast<DeclRefExpr>(E)->getDecl(); 1968e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian 1969102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1970102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1971102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1972102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 197359a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 197459a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 19757e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 19760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 1977102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 197844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 197944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 198083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 1981f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const MemberExpr *M = cast<MemberExpr>(E); 1982102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 198344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 198444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1985f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); 198644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 198744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 1988369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 198911ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 199011ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 199111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 19927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 199311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 199411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 1995864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallQualType Expr::findBoundMemberType(const Expr *expr) { 1996e0a22d06888c13989b3f72db319f1d498bf69153John McCall assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); 1997864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1998864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Bound member expressions are always one of these possibilities: 1999864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // x->m x.m x->*y x.*y 2000864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // (possibly parenthesized) 2001864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2002864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall expr = expr->IgnoreParens(); 2003864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { 2004864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<CXXMethodDecl>(mem->getMemberDecl())); 2005864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return mem->getMemberDecl()->getType(); 2006864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2007864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2008864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { 2009864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() 2010864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ->getPointeeType(); 2011864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(type->isFunctionType()); 2012864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return type; 2013864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2014864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2015864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<UnresolvedMemberExpr>(expr)); 2016864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return QualType(); 2017864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 2018864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 20194e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 20204e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 2021b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 2022b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 2023b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2024b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2025b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2026b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2027b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2028b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2029b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2030b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2031b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2032f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2033f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2034f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2036f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2037f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2038b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 2039b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 20404e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 20414e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 204256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 204356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 204456f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 204556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 204656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 2047b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 204856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2049b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2050b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2051b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 205256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2053b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2054b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2055b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2056b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2057b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2058b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2059b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2060b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2061f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2062f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2063f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2064f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2065f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2066f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 206703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 206803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 206903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 207003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 207103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2072c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2073c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2074c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2075c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2076c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2077b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 207856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 207956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 208056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 20819c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue 20829c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts. This is intended purely as a temporary workaround for code 20839c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// that hasn't yet been rewritten to do the right thing about those 20849c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts, and may disappear along with the last internal use. 2085f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallExpr *Expr::IgnoreParenLValueCasts() { 2086f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *E = this; 20879c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall while (true) { 2088f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2089f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2090f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 20919c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2092f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (P->getCastKind() == CK_LValueToRValue) { 2093f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2094f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2095f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 20969c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 20979c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall if (P->getOpcode() == UO_Extension) { 20989c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall E = P->getSubExpr(); 20999c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall continue; 21009c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } 2101f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2102f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2103f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2104f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2105f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 210603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (MaterializeTemporaryExpr *Materialize 210703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 210803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 210903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 2110c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } else if (SubstNonTypeTemplateParmExpr *NTTP 2111c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2112c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2113c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2114f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2115f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2116f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2117f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return E; 2118f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2119f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 21202fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 21212fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 21222fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 2123b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 21242fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2125b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2126b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2127b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 21282fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2129b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2130b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2131b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2132b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2133b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2134b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2135b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2136b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2137f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2138f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2139f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2140f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2141f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2142f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 214303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 214403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 214503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 214603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 214703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2148c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2149c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2150c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2151c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2152c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2153b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 21542fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 21552fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 21562fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 21572f072b442879b8bba8c5dea11d7c61bedb1924aeHans WennborgExpr *Expr::IgnoreConversionOperator() { 21582f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) { 215914d251cd62942bf7d56bb87a267ba2ca2f7fae3eChandler Carruth if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) 21602f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return MCE->getImplicitObjectArgument(); 21612f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 21622f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return this; 21632f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg} 21642f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 2165ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 2166ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 2167ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 2168ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 2169ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 2170ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 2171ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2172ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 2173ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2174ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2176ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2177ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 21782ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 2179ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 21801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2181ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 2182ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2183ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2184ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 21851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2186b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 21879d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 2188b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 21899d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 2190ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 2191ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2192ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2193ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2194ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 21951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2196b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2197b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2198b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2199b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2200b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2201b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2202b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 2203f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2204f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2205f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2206f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2207f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2208f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2209f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 2210c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2211c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2212c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2213c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2214c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2215c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor 2216ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 2217ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2218ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 2219ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 22206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 22216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 222203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 222303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 222403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 22256eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 22266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 2227c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 22286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 22296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 2230ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 22312f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 22322f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 2233f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 223403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 223503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 223603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 22372f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 22382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 22392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 22402f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 22412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 22422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 22432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 22442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 22452f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 22462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 22472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 22482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 22492f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 22502f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 22512f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 22522f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 2253f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 2254f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 22552f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 22562f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2257558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 2258558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 2259558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 2260558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 2261558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 22622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2263f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 22642f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 226558277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 2266db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 2267db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 226812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!isa<ObjCPropertyRefExpr>(E)) 2269db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 2270db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 22712f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 227219e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 227319e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 227419e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 227519e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 2276558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 2277558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 2278558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 2279558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 2280558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 2281558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 2282558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 2283558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 22842f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 22852f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 228619e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 228719e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 228819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 228919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 229056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // - opaque values (all) 229156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (isa<OpaqueValueExpr>(E)) 229256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return false; 229356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 2294558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 22952f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 22962f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 229775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregorbool Expr::isImplicitCXXThis() const { 229875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor const Expr *E = this; 229975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 230075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // Strip away parentheses and casts we don't care about. 230175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor while (true) { 230275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { 230375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = Paren->getSubExpr(); 230475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 230575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 230675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 230775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 230875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (ICE->getCastKind() == CK_NoOp || 230975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_LValueToRValue || 231075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_DerivedToBase || 231175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_UncheckedDerivedToBase) { 231275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = ICE->getSubExpr(); 231375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 231475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 231575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 231675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 231775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { 231875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (UnOp->getOpcode() == UO_Extension) { 231975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = UnOp->getSubExpr(); 232075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 232175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 232275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 232375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 232403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M 232503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 232603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 232703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 232803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 232903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 233075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor break; 233175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 233275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 233375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) 233475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return This->isImplicit(); 233575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 233675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return false; 233775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 233875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 2339898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 2340898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 234113a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charlesbool Expr::hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs) { 234213a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles for (unsigned I = 0; I < Exprs.size(); ++I) 2343898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 2344898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2345898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2346898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2347898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2348898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 23494204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 2350c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 2351c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 2352c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 2353c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 2354c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 2355c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 23564204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 23574204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 23584204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 23594204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 23604204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 23614204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 23624204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 23631f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 2364e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 2365c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 23664ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case IntegerLiteralClass: 23674ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case FloatingLiteralClass: 2368e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 236914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 2370eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 2371e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 2372b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 2373b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 2374b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 23754204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 23764204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 2377180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->getConstructor()->isTrivial()) { 2378180f47959a066795cc0f409433023af448bb0328Richard Smith // 1) an application of the trivial default constructor or 2379180f47959a066795cc0f409433023af448bb0328Richard Smith if (!CE->getNumArgs()) return true; 2380180f47959a066795cc0f409433023af448bb0328Richard Smith 2381180f47959a066795cc0f409433023af448bb0328Richard Smith // 2) an elidable trivial copy construction of an operand which is 2382180f47959a066795cc0f409433023af448bb0328Richard Smith // itself a constant initializer. Note that we consider the 2383180f47959a066795cc0f409433023af448bb0328Richard Smith // operand on its own, *not* as a reference binding. 2384180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->isElidable() && 2385180f47959a066795cc0f409433023af448bb0328Richard Smith CE->getArg(0)->isConstantInitializer(Ctx, false)) 2386180f47959a066795cc0f409433023af448bb0328Richard Smith return true; 2387180f47959a066795cc0f409433023af448bb0328Richard Smith } 2388180f47959a066795cc0f409433023af448bb0328Richard Smith 2389180f47959a066795cc0f409433023af448bb0328Richard Smith // 3) a foldable constexpr constructor. 2390180f47959a066795cc0f409433023af448bb0328Richard Smith break; 2391b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 239259b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 23931f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 23941f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 23951f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 239659b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 23974204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 239859b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 2399e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 24001f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 24011f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 24021f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 2403e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 2404e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 2405e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 24064204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 2407e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 2408e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2409c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 2410e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 24113498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 24123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 24133ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 24144204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 24154204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 2416f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 2417f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (cast<GenericSelectionExpr>(this)->isResultDependent()) 2418f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return false; 2419f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr() 2420f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ->isConstantInitializer(Ctx, IsForRef); 24215cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 24225cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 24235cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 2424c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 2425c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 24262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 24274204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 2428c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2429c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 24304204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 2431b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 243281045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 2433d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith case CStyleCastExprClass: { 2434d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith const CastExpr *CE = cast<CastExpr>(this); 2435d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 24367a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // If we're promoting an integer to an _Atomic type then this is constant 24377a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // if the integer is constant. We also need to check the converse in case 24387a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // someone does something like: 24397a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 24407a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // int a = (_Atomic(int))42; 24417a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 24427a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // I doubt anyone would write code like this directly, but it's quite 24437a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // possible as the result of macro expansions. 24447a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall if (CE->getCastKind() == CK_NonAtomicToAtomic || 24457a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall CE->getCastKind() == CK_AtomicToNonAtomic) 24467a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return CE->getSubExpr()->isConstantInitializer(Ctx, false); 24477a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall 2448d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith // Handle bitcasts of vector constants. 2449d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith if (getType()->isVectorType() && CE->getCastKind() == CK_BitCast) 2450d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2451d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 24526bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // Handle misc casts we want to ignore. 24536bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // FIXME: Is it really safe to ignore all these? 24546bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman if (CE->getCastKind() == CK_NoOp || 24556bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_LValueToRValue || 24566bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ToUnion || 24576bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ConstructorConversion) 2458d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2459d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 2460c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2461d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith } 246203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 24635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() 246403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isConstantInitializer(Ctx, false); 2465e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2466c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 246738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 246838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 246925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregornamespace { 247025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// \brief Look for a call to a non-trivial function within an expression. 247125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor class NonTrivialCallFinder : public EvaluatedExprVisitor<NonTrivialCallFinder> 247225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor { 247325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor typedef EvaluatedExprVisitor<NonTrivialCallFinder> Inherited; 247425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 247525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool NonTrivial; 247625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 247725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor public: 247825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor explicit NonTrivialCallFinder(ASTContext &Context) 2479b11e52540166a2958439cfe562c25931e4460759Douglas Gregor : Inherited(Context), NonTrivial(false) { } 248025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 248125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool hasNonTrivialCall() const { return NonTrivial; } 248225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 248325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCallExpr(CallExpr *E) { 248425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (CXXMethodDecl *Method 248525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor = dyn_cast_or_null<CXXMethodDecl>(E->getCalleeDecl())) { 248625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (Method->isTrivial()) { 248725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 248825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 248925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 249025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 249125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 249225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 249325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 249425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 249525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 249625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXConstructExpr(CXXConstructExpr *E) { 249725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getConstructor()->isTrivial()) { 249825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 249925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 250025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 250125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 250225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 250325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 250425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 250525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 250625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 250725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getTemporary()->getDestructor()->isTrivial()) { 250825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 250925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 251025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 251125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 251225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 251325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 251425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor }; 251525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 251625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 251725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregorbool Expr::hasNonTrivialCall(ASTContext &Ctx) { 251825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivialCallFinder Finder(Ctx); 251925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Finder.Visit(this); 252025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return Finder.hasNonTrivialCall(); 252125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 252225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 252382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null 252482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// pointer constant or not, as well as the specific kind of constant detected. 252582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// Null pointer constants can be integer constant expressions with the 252682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// value zero, casts of zero to void*, nullptr (C++0X), or __null 252782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// (a GNU extension). 252882214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::NullPointerConstantKind 252982214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::isNullPointerConstant(ASTContext &Ctx, 253082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const { 2531ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 2532ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 2533ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 2534b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected value dependent expression!"); 2535ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 253682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth if (isTypeDependent() || getType()->isIntegralType(Ctx)) 253782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_ZeroInteger; 253882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth else 253982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2541ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 254282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2543ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2544ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2545f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 25460777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 25470835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 25484e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) { 25490777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 25506217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 25510777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 25520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 25530777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 25540777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 2555ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 25560777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 25575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2558aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 2559aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 2560ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2561aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 2562aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 2563aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 2564ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2565f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (const GenericSelectionExpr *GE = 2566f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne dyn_cast<GenericSelectionExpr>(this)) { 2567f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); 25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 25698123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 257004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 2571ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 25722d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 25732d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 257482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_GNUNull; 257503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (const MaterializeTemporaryExpr *M 257603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(this)) { 257703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); 25784b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { 25794b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (const Expr *Source = OVE->getSourceExpr()) 25804b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Source->isNullPointerConstant(Ctx, NPC); 2581aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 25822d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 25836e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 25846e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 258582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_CXX0X_nullptr; 25866e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2587ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 2588ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 2589ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 2590ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 2591ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 2592ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 2593ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 2594aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 2595c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 25964e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType())) 259782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 25981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 260070488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // test for the value 0. Don't use the C++11 constant expression semantics 260170488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // for this, for now; once the dust settles on core issue 903, we might only 260270488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // allow a literal 0 here in C++11 mode. 26034e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().CPlusPlus0x) { 260470488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isCXX98IntegralConstantExpr(Ctx)) 260570488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 260670488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } else { 260770488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isIntegerConstantExpr(Ctx)) 260870488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 260970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } 261082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 261170488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return (EvaluateKnownConstInt(Ctx) == 0) ? NPCK_ZeroInteger : NPCK_NotNull; 26125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 261331a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 2614f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// \brief If this expression is an l-value for an Objective C 2615f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// property, find the underlying property reference expression. 2616f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallconst ObjCPropertyRefExpr *Expr::getObjCProperty() const { 2617f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *E = this; 2618f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall while (true) { 2619f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall assert((E->getValueKind() == VK_LValue && 2620f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E->getObjectKind() == OK_ObjCProperty) && 2621f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall "expression is not a property reference"); 2622f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = E->IgnoreParenCasts(); 2623f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 2624f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (BO->getOpcode() == BO_Comma) { 2625f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = BO->getRHS(); 2626f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2627f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2628f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2629f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 2630f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2631f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2632f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 2633f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return cast<ObjCPropertyRefExpr>(E); 2634f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2635f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 263633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 26376f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 263833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 2639de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 2640f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ICE->getCastKind() == CK_LValueToRValue || 2641f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) 2642de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 2643de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 2644de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 2645de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 2646de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 264727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 264886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 264933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 265033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 265133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 26520f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 26530f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 26540f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 26550f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 26560f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 265742068e9d420889014ee26894e421fead336b239dEli Friedman if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { 265833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 265933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 266033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 266142068e9d420889014ee26894e421fead336b239dEli Friedman if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) 266242068e9d420889014ee26894e421fead336b239dEli Friedman return BinOp->getRHS()->getBitField(); 266342068e9d420889014ee26894e421fead336b239dEli Friedman } 266442068e9d420889014ee26894e421fead336b239dEli Friedman 266533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 266627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 266727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 2668093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 2669093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 2670c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2671093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 26725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 26732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 2674093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 2675093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 2676093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 2677093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 2678c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2679093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 2680093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 2681093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2682093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 2683093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 2684093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2685093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 2686093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 2687093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 26882140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 26892140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 26902140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 26912140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 26922140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 26932140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2694213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 2695183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 26968a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 26978a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 26984d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 26994d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 27008a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 2701213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 2702a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 2703a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 27045f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 2705190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 2706190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 2707150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 2708190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2710190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 2711150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 2712150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 27131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2714150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 27155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) 2716fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 2717150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 2718fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 2719fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 2720b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 27218a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 27223b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 27235f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<unsigned> &Elts) const { 27245f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 27254b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 27264b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27284b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 27294b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 27304b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 27314b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 27321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 27348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 27351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27368a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 27378a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 27388a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 27398a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 27408a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 27418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 27428a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 27438a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 27448a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 27454b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 2746b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 27473b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 2748b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 27498a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 27508a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 275104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2752f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 275304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 275404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 275504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 275604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2757c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2758207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2759207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 276004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 27618d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2762746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 2763746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 2764f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 2765bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 2766561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 2767bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 276804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 276904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2770b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(IsInstanceSuper? SuperInstance : SuperClass), 2771746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 2772746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SuperLoc(SuperLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 2773c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 2774207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 277504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 277604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 277704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 277804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2779f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 278004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 278104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2782f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 2783207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2784207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 278504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 27868d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2787746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 2788746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 2789f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 2790561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isInstantiationDependentType(), 2791561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->containsUnexpandedParameterPack()), 279204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 279304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2794b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Class), 2795746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 2796207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 279704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 2798207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 279904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 280004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 280104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 280204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2803f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 280404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 280504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2806c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2807207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2808207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 280904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 28108d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2811746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 2812746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 2813f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 2814bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->isTypeDependent(), 2815561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Receiver->isInstantiationDependent(), 2816bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->containsUnexpandedParameterPack()), 281704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 281804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2819b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Instance), 2820746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 2821207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 282204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 2823207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 282404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 2825207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2826207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2827207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args, 2828207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2829207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK) { 2830207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis setNumArgs(Args.size()); 2831aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 28328d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis for (unsigned I = 0; I != Args.size(); ++I) { 2833bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 2834bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2835bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 2836bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2837561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[I]->isInstantiationDependent()) 2838561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 2839bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 2840bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2841bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2842bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 2843bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 2844207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 284519562c97669532084a71895197f4444305dd432aBenjamin Kramer SelLocsKind = SelLocsK; 28460c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (!isImplicit()) { 28470c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (SelLocsK == SelLoc_NonStandard) 28480c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 28490c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis } 285004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 285104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 285204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2853f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 285404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 285504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 285604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 285704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2858c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2859951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 286004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 28618d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2862746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 2863746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 2864746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 2865746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 2866746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 2867746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 2868746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 2869746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 2870746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 2871746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 2872f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 2873207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SuperType, Sel, SelLocs, SelLocsK, 2874746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Method, Args, RBracLoc, isImplicit); 287504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 287604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 287704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2878f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 287904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 288004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2881c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2882951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 288304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 28848d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2885746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 2886746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 2887746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 2888746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 2889746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 2890746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 2891746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 2892746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 2893746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 2894746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 2895951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 2896746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 2897746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 289804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 289904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 290004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2901f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 290204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 290304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2904f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 2905951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 290604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 29078d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2908746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 2909746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 2910746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 2911746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 2912746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 2913746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 2914746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 2915746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 2916746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 2917746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 2918951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 2919746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 2920746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 292104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 292204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 2923c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 2924207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 2925207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 2926207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs); 292704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 292804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 2929e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2930207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 2931207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2932207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 2933207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2934207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 2935207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK) { 2936207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocsK = hasStandardSelectorLocs(Sel, SelLocs, Args, RBraceLoc); 2937207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs = (SelLocsK == SelLoc_NonStandard) ? SelLocs.size() 2938207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis : 0; 2939207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return alloc(C, Args.size(), NumStoredSelLocs); 2940207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2941207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2942207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 2943207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 2944207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 2945207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 2946207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis NumArgs * sizeof(Expr *) + NumStoredSelLocs * sizeof(SourceLocation); 2947207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (ObjCMessageExpr *)C.Allocate(Size, 2948207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::AlignOf<ObjCMessageExpr>::Alignment); 2949207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2950207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2951207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::getSelectorLocs( 2952207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVectorImpl<SourceLocation> &SelLocs) const { 2953207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 2954207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs.push_back(getSelectorLoc(i)); 2955207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2956207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2957e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios KyrtzidisSourceRange ObjCMessageExpr::getReceiverRange() const { 2958e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis switch (getReceiverKind()) { 2959e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Instance: 2960e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getInstanceReceiver()->getSourceRange(); 2961e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2962e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Class: 2963e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); 2964e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2965e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperInstance: 2966e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperClass: 2967e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getSuperLoc(); 2968e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis } 2969e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 29703026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid ReceiverKind!"); 2971e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis} 2972e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 297304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 297404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 297504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 297604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 2977c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 297804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 297904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 298004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 298104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 298204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 298304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 298404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) 298504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 298604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 29874df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 298804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 2989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *Ty 2990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall = getClassReceiver()->getAs<ObjCObjectType>()) 2991c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Ty->getInterface(); 299204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 29934df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 299404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 299504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 299604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 299704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 299804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 2999c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 300004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 3001ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis if (const ObjCObjectType *Iface 3002ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis = getSuperType()->getAs<ObjCObjectType>()) 3003ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis return Iface->getInterface(); 300404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 300504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 30060389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 300704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 3008eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 30090389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 30105f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef ObjCBridgedCastExpr::getBridgeKindName() const { 3011f85e193739c953358c865005855253af4f68a497John McCall switch (getBridgeKind()) { 3012f85e193739c953358c865005855253af4f68a497John McCall case OBC_Bridge: 3013f85e193739c953358c865005855253af4f68a497John McCall return "__bridge"; 3014f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeTransfer: 3015f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_transfer"; 3016f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeRetained: 3017f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_retained"; 3018f85e193739c953358c865005855253af4f68a497John McCall } 30193026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie 30203026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid BridgeKind!"); 3021f85e193739c953358c865005855253af4f68a497John McCall} 3022f85e193739c953358c865005855253af4f68a497John McCall 30234ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ChooseExpr::isConditionTrue(const ASTContext &C) const { 3024a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getCond()->EvaluateKnownConstInt(C) != 0; 302527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 302627437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 3027bebbe0d9b7568ce43a464286bee49429489ef483Douglas GregorShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 3028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor QualType Type, SourceLocation BLoc, 3029bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP) 3030bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 3031bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 3032561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 3033bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->containsUnexpandedParameterPack()), 3034bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) 3035bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor{ 3036bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs = new (C) Stmt*[nexpr]; 3037bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i < nexpr; i++) { 3038bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 3039bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3040bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 3041bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3042561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 3043561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3044bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 3045bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3046bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3047bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs[i] = args[i]; 3048bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3049bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 3050bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3051888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 3052888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 3053888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 3054888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3055888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 305694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 305794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 30581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 3059888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3060f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3061f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3062f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3063f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3064f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3065f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3066f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex) 3067f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3068f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getType(), 3069f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getValueKind(), 3070f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getObjectKind(), 3071f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isTypeDependent(), 3072f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isValueDependent(), 3073561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor AssocExprs[ResultIndex]->isInstantiationDependent(), 3074f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 3075f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), 3076f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), 3077f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ResultIndex(ResultIndex), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), 3078f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne RParenLoc(RParenLoc) { 3079f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 3080f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); 3081f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); 3082f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3083f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3084f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3085f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3086f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3087f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3088f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3089f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack) 3090f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3091f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Context.DependentTy, 3092f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne VK_RValue, 3093f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne OK_Ordinary, 3094561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isTypeDependent=*/true, 3095561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isValueDependent=*/true, 3096561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isInstantiationDependent=*/true, 3097f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 3098f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), 3099f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), 3100f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ResultIndex(-1U), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), 3101f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne RParenLoc(RParenLoc) { 3102f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 3103f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); 3104f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); 3105f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3106f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 310777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 310805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3111b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler CarruthIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { 311205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 311405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 311705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 311805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3119c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 3120319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 3121ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 31221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 3123ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 31241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **IndexExprs, 31259ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 31269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 31271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 3128f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 3129bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->isTypeDependent(), Init->isValueDependent(), 3130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Init->isInstantiationDependent(), 3131bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->containsUnexpandedParameterPack()), 31321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 31331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 3134319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 31359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 31377502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall child_range Child = children(); 31389ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 31399ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 31419ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 31429ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 31439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 3144ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 31459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31469ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 31479ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 31489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 3149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->isTypeDependent() || Index->isValueDependent()) 3150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Index->isInstantiationDependent()) 3152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->containsUnexpandedParameterPack()) 3155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 31569ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31579ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 31589ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 31599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 31609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 31619ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 31629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 3163bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->isTypeDependent() || Start->isValueDependent() || 3164561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isTypeDependent() || End->isValueDependent()) { 3165bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3167561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (Start->isInstantiationDependent() || 3168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isInstantiationDependent()) { 3169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3170561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 3171561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->containsUnexpandedParameterPack() || 3174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->containsUnexpandedParameterPack()) 3175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 31769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 31789ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 31799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 31809ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 31819ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 31829ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31839ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 3184ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3185ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 31871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 3192c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3193c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3194319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 31959ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 31969ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 319705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 319805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 31991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 3200d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 3201d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3202d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3203d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 3204d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3205d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3206319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 3207319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 3208d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 3209319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 3210d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 3211d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 3212d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 3213d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3214d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 321524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo BagnaraSourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { 321624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); 321724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara if (size() == 1) 321824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return DIE->getDesignator(0)->getSourceRange(); 321924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(DIE->getDesignator(0)->getStartLocation(), 322024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DIE->getDesignator(size()-1)->getEndLocation()); 322124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara} 322224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 322305c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 322405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 3225d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 3226d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 322705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 3228eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 322905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 323005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 323105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 323205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 3233d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 3234d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 323505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 323605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 323705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 323805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 323905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 324005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 324105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 324205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 324305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 324405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 324505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 324605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 32471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 324805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 324905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 325005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 325105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 325205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 325305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 325405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 325505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 32561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 325705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 325805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 325905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 326005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 326105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 326205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 326305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3264ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 3265ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 3266319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 3268ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 3269ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 3270ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 3271ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 3272ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 3273ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 3274ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 3275ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3276ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 3277ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 3278ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3279ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 3280ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 32811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 3282319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 3283ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 3284ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 3285ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 3286ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 3287ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 3288ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 3289ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3290ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 32911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 32922ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 32935b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceLocation rparenloc) 32945b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, 3295561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, false, false), 3296bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 32972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 3298bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != nexprs; ++i) { 3299bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isTypeDependent()) 3300bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3301bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isValueDependent()) 3302bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3303561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (exprs[i]->isInstantiationDependent()) 3304561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3305bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->containsUnexpandedParameterPack()) 3306bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3307bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 33082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 3309bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 33102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 33112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 3312e996ffd240f20a1048179d7727a6ee3227261921John McCallconst OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { 3313e996ffd240f20a1048179d7727a6ee3227261921John McCall if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) 3314e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ewc->getSubExpr(); 331503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) 331603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor e = m->GetTemporaryExpr(); 3317e996ffd240f20a1048179d7727a6ee3227261921John McCall e = cast<CXXConstructExpr>(e)->getArg(0); 3318e996ffd240f20a1048179d7727a6ee3227261921John McCall while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 3319e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ice->getSubExpr(); 3320e996ffd240f20a1048179d7727a6ee3227261921John McCall return cast<OpaqueValueExpr>(e); 3321e996ffd240f20a1048179d7727a6ee3227261921John McCall} 3322e996ffd240f20a1048179d7727a6ee3227261921John McCall 33234b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &Context, EmptyShell sh, 33244b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs) { 33254b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = Context.Allocate(sizeof(PseudoObjectExpr) + 33264b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + numSemanticExprs) * sizeof(Expr*), 33274b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 33284b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); 33294b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 33304b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33314b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) 33324b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, shell) { 33334b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; 33344b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 33354b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33364b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &C, Expr *syntax, 33374b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantics, 33384b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) { 33394b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(syntax && "no syntactic expression!"); 33404b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics.size() && "no semantic expressions!"); 33414b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33424b9c2d235fb9449e249d74f48ecfec601650de93John McCall QualType type; 33434b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprValueKind VK; 33444b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (resultIndex == NoResult) { 33454b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = C.VoidTy; 33464b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = VK_RValue; 33474b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 33484b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(resultIndex < semantics.size()); 33494b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = semantics[resultIndex]->getType(); 33504b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = semantics[resultIndex]->getValueKind(); 33514b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary); 33524b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 33534b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33544b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = C.Allocate(sizeof(PseudoObjectExpr) + 33554b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + semantics.size()) * sizeof(Expr*), 33564b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 33574b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, 33584b9c2d235fb9449e249d74f48ecfec601650de93John McCall resultIndex); 33594b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 33604b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33614b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, 33624b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntax, ArrayRef<Expr*> semantics, 33634b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) 33644b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, 33654b9c2d235fb9449e249d74f48ecfec601650de93John McCall /*filled in at end of ctor*/ false, false, false, false) { 33664b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; 33674b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.ResultIndex = resultIndex + 1; 33684b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33694b9c2d235fb9449e249d74f48ecfec601650de93John McCall for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { 33704b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *E = (i == 0 ? syntax : semantics[i-1]); 33714b9c2d235fb9449e249d74f48ecfec601650de93John McCall getSubExprsBuffer()[i] = E; 33724b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33734b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isTypeDependent()) 33744b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.TypeDependent = true; 33754b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isValueDependent()) 33764b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ValueDependent = true; 33774b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isInstantiationDependent()) 33784b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.InstantiationDependent = true; 33794b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->containsUnexpandedParameterPack()) 33804b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ContainsUnexpandedParameterPack = true; 33814b9c2d235fb9449e249d74f48ecfec601650de93John McCall 33824b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<OpaqueValueExpr>(E)) 33834b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != 0 && 33844b9c2d235fb9449e249d74f48ecfec601650de93John McCall "opaque-value semantic expressions for pseudo-object " 33854b9c2d235fb9449e249d74f48ecfec601650de93John McCall "operations must have sources"); 33864b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 33874b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 33884b9c2d235fb9449e249d74f48ecfec601650de93John McCall 338905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 3390ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 3391ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 3392ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3393ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 3394ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 3395ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 3396ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 3397ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 3398ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 3399ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 3400ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 3401ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3402ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 340377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 340477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 340577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 3406f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne// UnaryExprOrTypeTraitExpr 3407f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneStmt::child_range UnaryExprOrTypeTraitExpr::children() { 34080518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 34090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 34100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 34110518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 3412f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const VariableArrayType* T = dyn_cast<VariableArrayType>( 34130518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 341463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(T), child_iterator()); 341563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 34160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 341763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Argument.Ex, &Argument.Ex + 1); 34189ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 3419390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3420563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 342163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range ObjCMessageExpr::children() { 342263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin; 342304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 342463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(this + 1); 342563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall else 342663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(getArgs()); 342763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, 342863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); 3429563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 3430563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 3431ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral::ObjCArrayLiteral(llvm::ArrayRef<Expr *> Elements, 3432ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *Method, 3433ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3434ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCArrayLiteralClass, T, VK_RValue, OK_Ordinary, 3435ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false, false, false), 3436ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method) 3437ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3438ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **SaveElements = getElements(); 3439ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0, N = Elements.size(); I != N; ++I) { 3440ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isTypeDependent() || Elements[I]->isValueDependent()) 3441ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3442ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isInstantiationDependent()) 3443ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3444ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->containsUnexpandedParameterPack()) 3445ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3446ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3447ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SaveElements[I] = Elements[I]; 3448ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3449ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3450ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3451ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::Create(ASTContext &C, 3452ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::ArrayRef<Expr *> Elements, 3453ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 3454ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 3455ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3456ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + Elements.size() * sizeof(Expr *)); 3457ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR); 3458ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3459ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3460ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(ASTContext &C, 3461ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements) { 3462ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3463ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3464ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + NumElements * sizeof(Expr *)); 3465ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements); 3466ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3467ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3468ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::ObjCDictionaryLiteral( 3469ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 3470ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 3471ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 3472ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3473ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, T, VK_RValue, OK_Ordinary, false, false, 3474ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false), 3475ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), 3476ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek DictWithObjectsMethod(method) 3477ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3478ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *KeyValues = getKeyValues(); 3479ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *Expansions = getExpansionData(); 3480ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0; I < NumElements; I++) { 3481ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isTypeDependent() || VK[I].Key->isValueDependent() || 3482ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isTypeDependent() || VK[I].Value->isValueDependent()) 3483ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3484ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isInstantiationDependent() || 3485ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isInstantiationDependent()) 3486ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3487ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].EllipsisLoc.isInvalid() && 3488ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (VK[I].Key->containsUnexpandedParameterPack() || 3489ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->containsUnexpandedParameterPack())) 3490ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3491ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3492ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Key = VK[I].Key; 3493ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Value = VK[I].Value; 3494ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansions) { 3495ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].EllipsisLoc = VK[I].EllipsisLoc; 3496ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].NumExpansions) 3497ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = *VK[I].NumExpansions + 1; 3498ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek else 3499ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = 0; 3500ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3501ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3502ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3503ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3504ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 3505ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::Create(ASTContext &C, 3506ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 3507ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 3508ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 3509ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 3510ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 3511ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 3512ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * VK.size(); 3513ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3514ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 3515ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * VK.size() + ExpansionsSize); 3516ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR); 3517ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3518ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3519ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 3520ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::CreateEmpty(ASTContext &C, unsigned NumElements, 3521ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) { 3522ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 3523ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 3524ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * NumElements; 3525ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 3526ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * NumElements + ExpansionsSize); 3527ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(EmptyShell(), NumElements, 3528ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions); 3529ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3530ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3531ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCSubscriptRefExpr *ObjCSubscriptRefExpr::Create(ASTContext &C, 3532ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 3533ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 3534ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 3535ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 3536ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB) { 3537ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCSubscriptRefExpr)); 3538ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCSubscriptRefExpr(base, key, T, VK_LValue, 3539ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek OK_ObjCSubscript, 3540ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getMethod, setMethod, RB); 3541ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3542dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 3543dfa64ba45922e1c28e36341bdf34785fea74659bEli FriedmanAtomicExpr::AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, 3544dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType t, AtomicOp op, SourceLocation RP) 3545dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, 3546dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman false, false, false, false), 3547dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman NumSubExprs(nexpr), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) 3548dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman{ 3549e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith assert(nexpr == getNumSubExprs(op) && "wrong number of subexpressions"); 3550dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman for (unsigned i = 0; i < nexpr; i++) { 3551dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isTypeDependent()) 3552dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.TypeDependent = true; 3553dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isValueDependent()) 3554dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ValueDependent = true; 3555dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isInstantiationDependent()) 3556dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.InstantiationDependent = true; 3557dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->containsUnexpandedParameterPack()) 3558dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ContainsUnexpandedParameterPack = true; 3559dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 3560dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs[i] = args[i]; 3561dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 3562dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman} 3563e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 3564e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smithunsigned AtomicExpr::getNumSubExprs(AtomicOp Op) { 3565e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith switch (Op) { 3566ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_init: 3567ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_load: 3568ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load_n: 3569e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 2; 3570ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3571ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_store: 3572ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_exchange: 3573ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load: 3574ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store: 3575ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store_n: 3576ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange_n: 3577ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_add: 3578ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_sub: 3579ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_and: 3580ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_or: 3581ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_xor: 3582ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_add: 3583ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_sub: 3584ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_and: 3585ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_or: 3586ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_xor: 358751b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_fetch_nand: 3588ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_add_fetch: 3589ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_sub_fetch: 3590ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_and_fetch: 3591ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_or_fetch: 3592ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_xor_fetch: 359351b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_nand_fetch: 3594e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 3; 3595ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3596ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange: 3597ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 4; 3598ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3599ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_strong: 3600ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_weak: 3601e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 5; 3602ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3603ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange: 3604ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange_n: 3605ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 6; 3606e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith } 3607e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith llvm_unreachable("unknown atomic op"); 3608e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith} 3609