Expr.cpp revision 84c3b9745f813a784b5d8ce77f2785750523d9eb
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 368d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindolaconst CXXRecordDecl *Expr::getBestDynamicClassType() const { 37632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola const Expr *E = ignoreParenBaseCasts(); 380b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 390b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola QualType DerivedType = E->getType(); 400b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola if (const PointerType *PTy = DerivedType->getAs<PointerType>()) 410b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola DerivedType = PTy->getPointeeType(); 420b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 43251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola if (DerivedType->isDependentType()) 44251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola return NULL; 45251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola 460b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola const RecordType *Ty = DerivedType->castAs<RecordType>(); 470b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola Decl *D = Ty->getDecl(); 480b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola return cast<CXXRecordDecl>(D); 490b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola} 500b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 542b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 552b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 56f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 57f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 59f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (E->getType()->isBooleanType()) return true; 60c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 61f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!E->getType()->isIntegralOrEnumerationType()) return false; 62c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 63f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { 642b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 662b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 672b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 682b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 692b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 702b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 71c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 726907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 736907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 74f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) 752b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 76c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 77f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 792b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 89c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 932b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 942b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 952b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 96c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 992b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 1002b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 1012b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 102c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 103f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) 1042b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 1052b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 106c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1072b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 1082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 1092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 11063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// Amusing macro metaprogramming hack: check whether a class provides 11163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// a more specific implementation of getExprLoc(). 11290e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// 11390e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// See also Stmt.cpp:{getLocStart(),getLocEnd()}. 11463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallnamespace { 11563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class provides a custom 11663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// implementation of getExprLoc. 11763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E, class T> 11863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 11963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (T::*v)() const) { 12063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getExprLoc(); 12163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 12263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 12363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class doesn't provide 12463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// a custom implementation of getExprLoc. Overload resolution 12563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// should pick it over the implementation above because it's 12663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// more specialized according to function template partial ordering. 12763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E> 12863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 12963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (Expr::*v)() const) { 13090e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar return static_cast<const E*>(expr)->getLocStart(); 13163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 13263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 13363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 13463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallSourceLocation Expr::getExprLoc() const { 13563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall switch (getStmtClass()) { 13663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 13763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(type) 13863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define STMT(type, base) \ 13963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; 14063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define EXPR(type, base) \ 14163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); 14263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#include "clang/AST/StmtNodes.inc" 14363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 14463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall llvm_unreachable("unknown statement kind"); 14563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 14663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// \brief Compute the type-, value-, and instantiation-dependence of a 152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// declaration reference 153d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// based on the declaration being referenced. 1543d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarstatic void computeDeclRefDependence(ASTContext &Ctx, NamedDecl *D, QualType T, 155d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &TypeDependent, 156561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &ValueDependent, 157561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 158d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = false; 159d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = false; 160561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = false; 1610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 1630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 1640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 165c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 1660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 1670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 1680da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 169d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1700da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 1710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 172d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (T->isDependentType()) { 173d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 174d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 176d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 177561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (T->isInstantiationDependentType()) { 178561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1790da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 180d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 182d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (D->getDeclName().getNameKind() 183561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor == DeclarationName::CXXConversionFunctionName) { 184561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualType T = D->getDeclName().getCXXNameType(); 185561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isDependentType()) { 186561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeDependent = true; 187561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ValueDependent = true; 188561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 189561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return; 190561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 191561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 192561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isInstantiationDependentType()) 193561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1940da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 195561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1960da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 197d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<NonTypeTemplateParmDecl>(D)) { 198d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 199561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 200d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 201d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 202d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2030da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 2040da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 205db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - a constant with literal type and is initialized with an 206db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11]. 207db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - FIXME: Missing from the standard: 208db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // - an entity with reference type and is initialized with an 209db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11] 210d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 2114e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if ((Ctx.getLangOpts().CPlusPlus0x ? 212db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isLiteralType() : 213db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isIntegralOrEnumerationType()) && 2144ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie (Var->getType().isConstQualified() || 215db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isReferenceType())) { 21631310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 217561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Init->isValueDependent()) { 218d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 219561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 220561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 221db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 222db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith 223bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 224bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 225bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 226db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith if (Var->isStaticDataMember() && 227db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getDeclContext()->isDependentContext()) { 228d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 229561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 230561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 231d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 232d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 233d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 234d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 235bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 236bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 237bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 238d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { 239d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 240561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 241db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 242d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor} 243d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2443d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarvoid DeclRefExpr::computeDependence(ASTContext &Ctx) { 245d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 246d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 2483d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent, 2493d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar ValueDependent, InstantiationDependent); 250d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 251d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 252d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An id-expression is type-dependent if it contains: 253d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 254d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // and 255d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 256d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 257d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An identifier is value-dependent if it is: 258d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (!TypeDependent && !ValueDependent && 259d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor hasExplicitTemplateArgs() && 260d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 261d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getTemplateArgs(), 262561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor getNumTemplateArgs(), 263561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) { 264d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 265d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 266561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 267d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 268d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 269d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 270d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 271561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = InstantiationDependent; 272d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 27310738d36b150aa65206890c1c845cdba076e4200Douglas Gregor // Is the declaration a parameter pack? 274d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (getDecl()->isParameterPack()) 2751fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 2770da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 2783d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel DunbarDeclRefExpr::DeclRefExpr(ASTContext &Ctx, 2793d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NestedNameSpecifierLoc QualifierLoc, 280e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 281f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ValueDecl *D, bool RefersToEnclosingLocal, 282f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const DeclarationNameInfo &NameInfo, 2833aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 2842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 285f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 286561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 287cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 288cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; 2897e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth if (QualifierLoc) 2906857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth getInternalQualifierLoc() = QualifierLoc; 2913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; 2923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 2933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth getInternalFoundDecl() = FoundD; 294e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo 295e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0; 296f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExprBits.RefersToEnclosingLocal = RefersToEnclosingLocal; 297561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TemplateArgs) { 298561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 300561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 301e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, 302e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 303e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 304e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 305561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 306561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(true); 307e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 308e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 309561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 310b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer DeclRefExprBits.HadMultipleCandidates = 0; 311b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer 3123d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDependence(Ctx); 3132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 315a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 31640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 317e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 318dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 319f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 320a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 3210da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 322f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3233aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3240da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 325e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return Create(Context, QualifierLoc, TemplateKWLoc, D, 326f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 3272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 3283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth T, VK, FoundD, TemplateArgs); 3292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3312577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 33240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 333e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 3342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 335f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 3362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 3372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 338f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 3413aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth // Filter out cases where the found Decl is the same as the value refenenced. 3423aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (D == FoundD) 3433aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth FoundD = 0; 3443aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 345a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 34640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc != 0) 3476857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 3483aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 3493aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 350d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); 352e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 353e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 3543aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 3553248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 3563d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, 357f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 3583d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NameInfo, FoundD, TemplateArgs, T, VK); 359a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 360a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler CarruthDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, 362def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 3633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 364e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 365663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 366663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 367663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 3686857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 3693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (HasFoundDecl) 3703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 371e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (HasTemplateKWAndArgsInfo) 372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 3733aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 3743248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 375663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 376663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 377663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 378a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 3792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange R = getNameInfo().getSourceRange(); 380a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 38140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor R.setBegin(getQualifierLoc().getBeginLoc()); 382096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 383a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 384a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 385a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 386396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocStart() const { 387396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasQualifier()) 388396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 389396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocStart(); 390396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 391396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocEnd() const { 392396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 393396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getRAngleLoc(); 394396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocEnd(); 395396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 396a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 3983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 399848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 400848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 401848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 4023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 403848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 4043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 4053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 406f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 4073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 4083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 410848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 4113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 4124eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 4134eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 4143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4164e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie PrintingPolicy Policy(Context.getLangOpts()); 4173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 418abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream POut(Proto); 4193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 420abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionDecl *Decl = FD; 421abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) 422abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Decl = Pattern; 423abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); 4243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 4253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 4263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 4273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 428abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << "("; 4293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 430abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) { 4313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 4327ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis POut << Decl->getParamDecl(i)->getType().stream(Policy); 4333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 4363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 4373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 4383a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4393a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 440abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << ")"; 4413a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4424eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 4434ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie const FunctionType *FT = cast<FunctionType>(MD->getType().getTypePtr()); 4444ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie if (FT->isConst()) 445abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " const"; 4464ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie if (FT->isVolatile()) 447abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " volatile"; 448abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor RefQualifierKind Ref = MD->getRefQualifier(); 449abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Ref == RQ_LValue) 450abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &"; 451abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor else if (Ref == RQ_RValue) 452abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &&"; 453abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 454abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 455abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; 456abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor SpecsTy Specs; 457abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const DeclContext *Ctx = FD->getDeclContext(); 458abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor while (Ctx && isa<NamedDecl>(Ctx)) { 459abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const ClassTemplateSpecializationDecl *Spec 460abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); 461abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Spec && !Spec->isExplicitSpecialization()) 462abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Specs.push_back(Spec); 463abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Ctx = Ctx->getParent(); 464abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 465abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 466abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor std::string TemplateParams; 467abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream TOut(TemplateParams); 468abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend(); 469abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor I != E; ++I) { 470abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList *Params 471abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = (*I)->getSpecializedTemplate()->getTemplateParameters(); 472abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList &Args = (*I)->getTemplateArgs(); 473abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args.size()); 474abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) { 475abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 476abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 477abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 478abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args.get(i).print(Policy, TOut); 479abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 480abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 4814eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 4824eadcc569223135e13353c9381b448986e3f7053Sam Weinig 483abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor FunctionTemplateSpecializationInfo *FSI 484abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FD->getTemplateSpecializationInfo(); 485abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (FSI && !FSI->isExplicitSpecialization()) { 486abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList* Params 487abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FSI->getTemplate()->getTemplateParameters(); 488abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList* Args = FSI->TemplateArguments; 489abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args->size()); 490abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Params->size(); i != e; ++i) { 491abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 492abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 493abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 494abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args->get(i).print(Policy, TOut); 495abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 496abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 497abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 498abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 499abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut.flush(); 500abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (!TemplateParams.empty()) { 501abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor // remove the trailing comma and space 502abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TemplateParams.resize(TemplateParams.size() - 2); 503abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " [" << TemplateParams << "]"; 504abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 505abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 506abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut.flush(); 507abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 5083a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 5093a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 5103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 5123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5133a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 5143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 517f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 5183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 5193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 5203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 521b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 522b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 523b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 524b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 525b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer Out << *ID; 526b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 5273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 528900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 529f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramer Out << '(' << *CID << ')'; 530900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 5313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 5323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 5333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 5343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 5363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5383a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 5393a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 5403a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 5413a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5423a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 5433a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 5443a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 5469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 5479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 5489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 5509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 5519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 5529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 5539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 5549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 5559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 5569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 5579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 5589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 5599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 561478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerIntegerLiteral::IntegerLiteral(ASTContext &C, const llvm::APInt &V, 562478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer QualType type, SourceLocation l) 563478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 564478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer false, false), 565478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer Loc(l) { 566478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 567478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer assert(V.getBitWidth() == C.getIntWidth(type) && 568478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer "Integer type is not the correct size for constant."); 569478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer setValue(C, V); 570478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 571478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 5729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 5739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 5749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 5759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 5769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 5799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 5809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 5819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 583478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerFloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, 584478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer bool isexact, QualType Type, SourceLocation L) 585478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 586478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer false, false), Loc(L) { 587478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsIEEE = 588478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; 589478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsExact = isexact; 590478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer setValue(C, V); 591478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 592478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 593478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerFloatingLiteral::FloatingLiteral(ASTContext &C, EmptyShell Empty) 594478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(FloatingLiteralClass, Empty) { 595478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsIEEE = 596478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; 597478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsExact = false; 598478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 599478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 6009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 6019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 6029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 6039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 6049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 6079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 60831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return new (C) FloatingLiteral(C, Empty); 6099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 611da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 612da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 613da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 614da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 615da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 616ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 617ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 618ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 619da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 620da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 621da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 6220fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewyckyint StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { 623fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman int CharByteWidth = 0; 6240fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky switch(k) { 62564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Ascii: 62664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF8: 6270fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getCharWidth(); 62864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 62964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Wide: 6300fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getWCharWidth(); 63164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 63264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF16: 6330fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar16Width(); 63464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 63564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF32: 6360fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar32Width(); 637fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman break; 63864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 63964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); 64064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman CharByteWidth /= 8; 6410fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) 64264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "character byte widths supported are 1, 2, and 4 only"); 64364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return CharByteWidth; 64464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman} 64564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 6465f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, 6475cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind Kind, bool Pascal, QualType Ty, 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 649a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 6502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 6512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 6522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 6532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 6543248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 6552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 6561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 65864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->setString(C,Str,Kind,Pascal); 65964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 6602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 6612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 663726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 6642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 6652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 666726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 667726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 668673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 669673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 670673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 6713248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 672673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 67364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->CharByteWidth = 0; 67464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->Length = 0; 675673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 676673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 677673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 678673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 6798ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieuvoid StringLiteral::outputString(raw_ostream &OS) { 6808ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (getKind()) { 6818ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case Ascii: break; // no prefix. 6828ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case Wide: OS << 'L'; break; 6838ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF8: OS << "u8"; break; 6848ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF16: OS << 'u'; break; 6858ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF32: OS << 'U'; break; 6868ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 6878ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '"'; 6888ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu static const char Hex[] = "0123456789ABCDEF"; 6898ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 6908ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu unsigned LastSlashX = getLength(); 6918ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu for (unsigned I = 0, N = getLength(); I != N; ++I) { 6928ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (uint32_t Char = getCodeUnit(I)) { 6938ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu default: 6948ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // FIXME: Convert UTF-8 back to codepoints before rendering. 6958ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 6968ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Convert UTF-16 surrogate pairs back to codepoints before rendering. 6978ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Leave invalid surrogates alone; we'll use \x for those. 6988ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (getKind() == UTF16 && I != N - 1 && Char >= 0xd800 && 6998ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Char <= 0xdbff) { 7008ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu uint32_t Trail = getCodeUnit(I + 1); 7018ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Trail >= 0xdc00 && Trail <= 0xdfff) { 7028ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00); 7038ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu ++I; 7048ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7058ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7068ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7078ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Char > 0xff) { 7088ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // If this is a wide string, output characters over 0xff using \x 7098ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a 7108ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // codepoint: use \x escapes for invalid codepoints. 7118ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (getKind() == Wide || 7128ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) { 7138ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // FIXME: Is this the best way to print wchar_t? 7148ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\x"; 7158ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu int Shift = 28; 7168ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu while ((Char >> Shift) == 0) 7178ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Shift -= 4; 7188ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu for (/**/; Shift >= 0; Shift -= 4) 7198ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << Hex[(Char >> Shift) & 15]; 7208ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu LastSlashX = I; 7218ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 7228ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7238ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7248ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Char > 0xffff) 7258ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\U00" 7268ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 20) & 15] 7278ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 16) & 15]; 7288ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu else 7298ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\u"; 7308ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << Hex[(Char >> 12) & 15] 7318ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 8) & 15] 7328ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 4) & 15] 7338ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 0) & 15]; 7348ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 7358ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7368ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7378ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // If we used \x... for the previous character, and this character is a 7388ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // hexadecimal digit, prevent it being slurped as part of the \x. 7398ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (LastSlashX + 1 == I) { 7408ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (Char) { 7418ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '0': case '1': case '2': case '3': case '4': 7428ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '5': case '6': case '7': case '8': case '9': 7438ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 7448ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 7458ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\"\""; 7468ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7478ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7488ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7498ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu assert(Char <= 0xff && 7508ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu "Characters above 0xff should already have been handled."); 7518ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7528ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (isprint(Char)) 7538ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << (char)Char; 7548ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu else // Output anything hard as an octal escape. 7558ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '\\' 7568ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 6) & 7)) 7578ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 3) & 7)) 7588ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 0) & 7)); 7598ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 7608ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Handle some common non-printable cases to make dumps prettier. 7618ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\\': OS << "\\\\"; break; 7628ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '"': OS << "\\\""; break; 7638ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\n': OS << "\\n"; break; 7648ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\t': OS << "\\t"; break; 7658ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\a': OS << "\\a"; break; 7668ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\b': OS << "\\b"; break; 7678ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7688ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7698ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '"'; 7708ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu} 7718ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 77264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedmanvoid StringLiteral::setString(ASTContext &C, StringRef Str, 77364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal) { 77464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman //FIXME: we assume that the string data comes from a target that uses the same 77564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman // code unit size and endianess for the type of string. 77664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->Kind = Kind; 77764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->IsPascal = IsPascal; 77864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 7790fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind); 78064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((Str.size()%CharByteWidth == 0) 78164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "size of data must be multiple of CharByteWidth"); 78264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman Length = Str.size()/CharByteWidth; 78364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 78464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman switch(CharByteWidth) { 78564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 1: { 78664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman char *AStrData = new (C) char[Length]; 78766dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 78864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asChar = AStrData; 78964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 79064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 79164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 2: { 79264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint16_t *AStrData = new (C) uint16_t[Length]; 79366dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 79464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt16 = AStrData; 79564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 79664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 79764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 4: { 79864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t *AStrData = new (C) uint32_t[Length]; 79966dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 80064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt32 = AStrData; 80164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 80264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 80364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman default: 80464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(false && "unsupported CharByteWidth"); 80564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 806673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 807673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 80808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 80908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 81008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 81108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 81208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 81308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 81408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 81508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 81608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 81708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 818df9ef1bc8c3780307ab2ed81bf5e31c23310b936Richard Smith assert((Kind == StringLiteral::Ascii || Kind == StringLiteral::UTF8) && 819df9ef1bc8c3780307ab2ed81bf5e31c23310b936Richard Smith "Only narrow string literals are currently supported"); 8205cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 82108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 82208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 82308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 82408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 82508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 82608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 82708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 82808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 82908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 83008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 83108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 83208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 83308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 83408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 83508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 8365f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 83708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 83808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 83908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 84008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 84108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 84208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 843df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, 844df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Buffer.begin(), StrData, Buffer.end()); 84508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 84608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 84708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 84808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 84908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 85008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 85108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 85208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 85308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 854935a70c1e76d78985f20d422940280161b941299Hans Wennborg (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { 85508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 85608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 85708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 85808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 85908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 86008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 86108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 86208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 86308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 86408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 86508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 86608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 86708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 86808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 86908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 8720bea86307eb8c16339315a1e261fc490eb505c5bDavid BlaikieStringRef UnaryOperator::getOpcodeStr(Opcode Op) { 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 8742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 8752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 8762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 8772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 8782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 8792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 8802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 8812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 8822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 8832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 8842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 8852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 8862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 888561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("Unknown unary operator"); 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 892bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 893bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 894b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("No unary operator for overloaded function"); 8952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 8962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 8972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 8982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 8992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 9002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 9012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 9022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 903bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 904bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 905bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 906bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 907bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 9082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 9092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 9102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 9112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 9122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 9132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 9142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 9152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 916bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 917bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 918bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 919bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 920bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 925cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 9263b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 927f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 928f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 929bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 930bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 931561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 932bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 9333b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumArgs(args.size()) { 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9353b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()+PREARGS_START+NumPreArgs]; 936b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 9373b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); ++i) { 938bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 939bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 940bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 941bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 942561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 943561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 944bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 945bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 946bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 947cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; 948bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 949668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 950cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 951b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 952b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 953e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 9543b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerCallExpr::CallExpr(ASTContext& C, Expr *fn, ArrayRef<Expr*> args, 955f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 956f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 957bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 958bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 959561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 960bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 9613b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumArgs(args.size()) { 962668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 9633b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()+PREARGS_START]; 96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 9653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); ++i) { 966bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 967bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 968bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 969bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 970561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 971561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 972bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 973bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 974bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 975cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START] = args[i]; 976bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 977668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 978cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 984bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // FIXME: Why do we allocate this? 985cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START]; 986cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 987cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne} 988cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 989cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, 990cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne EmptyShell Empty) 991cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 992cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // FIXME: Why do we allocate this? 993cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; 994cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 9951f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 9961f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 997d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 998e8683d6d389def2fce229325435ba3c2b3f75492John McCall Expr *CEE = getCallee()->IgnoreParenImpCasts(); 9991ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 10001ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor while (SubstNonTypeTemplateParmExpr *NTTP 10011ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { 10021ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor CEE = NTTP->getReplacement()->IgnoreParenCasts(); 10031ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor } 10041ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 1005200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 1006200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 1007200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 1008200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 1009200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 1010200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 1011200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 1012200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 10136346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 1014d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 1015cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 1016cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 1017a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1018a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 1019a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 1020a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1021d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 1022caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 1023d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 1024d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1025d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 1026d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 1027d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 10288189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 1029d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 1030d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1032d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 1033d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 1034d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 1035d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 1036d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 1037d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 1038d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 1039cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs = getNumPreArgs(); 1040cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; 1041d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 1042cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) 1043d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 1044d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 1045cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; 1046cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne i != NumArgs+PREARGS_START+NumPreArgs; ++i) 1047d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104988c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 1050d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 1051d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 1052d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 1053d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 1054cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1055cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 1056180f47959a066795cc0f409433023af448bb0328Richard Smithunsigned CallExpr::isBuiltinCall() const { 1057c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 10581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 1059c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 1060c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 1061c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 1062cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1064c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 1065c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 1066cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1068bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 1069bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 1070cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10724fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 10734fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 10744fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 10757814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 1076cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 1077bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 10786dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 10796dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 10806217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 10816dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 10826217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 10836dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 1084864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) 1085864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // This should never be overloaded and so should never return null. 1086864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall CalleeType = Expr::findBoundMemberType(getCallee()); 10875291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 1088864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall const FunctionType *FnType = CalleeType->castAs<FunctionType>(); 10896dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 10906dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 1091cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 10922882eca5a184c78f793188083f6ce539740a5cf2John McCallSourceRange CallExpr::getSourceRange() const { 10932882eca5a184c78f793188083f6ce539740a5cf2John McCall if (isa<CXXOperatorCallExpr>(this)) 10942882eca5a184c78f793188083f6ce539740a5cf2John McCall return cast<CXXOperatorCallExpr>(this)->getSourceRange(); 10952882eca5a184c78f793188083f6ce539740a5cf2John McCall 10962882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceLocation begin = getCallee()->getLocStart(); 10972882eca5a184c78f793188083f6ce539740a5cf2John McCall if (begin.isInvalid() && getNumArgs() > 0) 10982882eca5a184c78f793188083f6ce539740a5cf2John McCall begin = getArg(0)->getLocStart(); 10992882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceLocation end = getRParenLoc(); 11002882eca5a184c78f793188083f6ce539740a5cf2John McCall if (end.isInvalid() && getNumArgs() > 0) 11012882eca5a184c78f793188083f6ce539740a5cf2John McCall end = getArg(getNumArgs() - 1)->getLocEnd(); 11022882eca5a184c78f793188083f6ce539740a5cf2John McCall return SourceRange(begin, end); 11032882eca5a184c78f793188083f6ce539740a5cf2John McCall} 11048fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocStart() const { 11058fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 11068fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return cast<CXXOperatorCallExpr>(this)->getSourceRange().getBegin(); 11078fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 11088fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation begin = getCallee()->getLocStart(); 11098fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (begin.isInvalid() && getNumArgs() > 0) 11108fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar begin = getArg(0)->getLocStart(); 11118fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return begin; 11128fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 11138fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocEnd() const { 11148fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 11158fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return cast<CXXOperatorCallExpr>(this)->getSourceRange().getEnd(); 11168fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 11178fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation end = getRParenLoc(); 11188fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (end.isInvalid() && getNumArgs() > 0) 11198fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar end = getArg(getNumArgs() - 1)->getLocEnd(); 11208fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return end; 11218fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 11222882eca5a184c78f793188083f6ce539740a5cf2John McCall 1123c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 11248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 1125c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 11263b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, 11273b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, 11288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 11298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 11303b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(OffsetOfNode) * comps.size() + 11313b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(Expr*) * exprs.size()); 11328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11333b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, 11343b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer RParenLoc); 11358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 11368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 11388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 11398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 11408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 11418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 11428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 11438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 11448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1145c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 11468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 11473b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, 11488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 1149f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 1150f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 1151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType(), 1152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tsi->getType()->isInstantiationDependentType(), 1153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tsi->getType()->containsUnexpandedParameterPack()), 1154c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 11553b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumComps(comps.size()), NumExprs(exprs.size()) 11568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 11573b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != comps.size(); ++i) { 11583b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer setComponent(i, comps[i]); 11598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1160c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11613b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != exprs.size(); ++i) { 11623b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer if (exprs[i]->isTypeDependent() || exprs[i]->isValueDependent()) 1163bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 11643b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer if (exprs[i]->containsUnexpandedParameterPack()) 1165bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1166bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 11673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer setIndexExpr(i, exprs[i]); 11688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 11698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 11708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 11728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 11738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 11748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 1175c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 11778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 11788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 118040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1181e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1182f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 1183161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 11842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 1185d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1186f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 1187f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 1188f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 118983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 11906bb8017bb9e828d118e15e59d71c66bba323c364John McCall 119140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor bool hasQualOrFound = (QualifierLoc || 1192161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 1193161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 11946bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 11956bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1197d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 1198e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(targs->size()); 1199e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 1200e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12023248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 1203f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 1204f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 12056bb8017bb9e828d118e15e59d71c66bba323c364John McCall 12066bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 120740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor // FIXME: Wrong. We should be looking at the member declaration we found. 120840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { 12096bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 12106bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 1211561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1212561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1213561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (QualifierLoc && 1214561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) 1215561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1216561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 12176bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 12186bb8017bb9e828d118e15e59d71c66bba323c364John McCall 12196bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 122040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NQ->QualifierLoc = QualifierLoc; 12216bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 12226bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 12236bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1224e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->HasTemplateKWAndArgsInfo = (targs || TemplateKWLoc.isValid()); 1225e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 12266bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 1227561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 1228561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 1229561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 1230e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *targs, 1231e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 1232e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 1233e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 1234561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 1235561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1236e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 1237e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 12386bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 12396bb8017bb9e828d118e15e59d71c66bba323c364John McCall 12406bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 124183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 124283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 124375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas GregorSourceRange MemberExpr::getSourceRange() const { 1244396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return SourceRange(getLocStart(), getLocEnd()); 1245396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 1246396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocStart() const { 124775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (isImplicitAccess()) { 124875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (hasQualifier()) 1249396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 1250396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 125175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 1252e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1253396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // FIXME: We don't want this to happen. Rather, we should be able to 1254396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // detect all kinds of implicit accesses more cleanly. 1255396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar SourceLocation BaseStartLoc = getBase()->getLocStart(); 1256396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (BaseStartLoc.isValid()) 1257396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return BaseStartLoc; 1258396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 1259396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 1260396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocEnd() const { 1261396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 1262396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getRAngleLoc(); 1263396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getMemberNameInfo().getEndLoc(); 126475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 126575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 12661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCallvoid CastExpr::CheckCastConsistency() const { 12671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall switch (getCastKind()) { 12681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBase: 12691d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UncheckedDerivedToBase: 12701d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBaseMemberPointer: 12711d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerived: 12721d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerivedMemberPointer: 12731d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 12741d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 12751d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 12761d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 12771d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 12781d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isPointerType()); 12791d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 12801d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 12811d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 12821d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 12831d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isBlockPointerType()); 12841d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 12851d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 12864d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 12874d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getType()->isMemberPointerType()); 12884d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getSubExpr()->getType()->isMemberPointerType()); 12894d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall goto CheckNoBasePath; 12904d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 12911d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BitCast: 12921d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Arbitrary casts to C pointer types count as bitcasts. 12931d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Otherwise, we should only have block and ObjC pointer casts 12941d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // here if they stay within the type kind. 12951d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (!getType()->isPointerType()) { 12961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType() == 12971d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isObjCObjectPointerType()); 12981d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType() == 12991d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isBlockPointerType()); 13001d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 13011d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13021d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13031d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_AnyPointerToBlockPointerCast: 13041d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType()); 13051d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isAnyPointerType() && 13061d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall !getSubExpr()->getType()->isBlockPointerType()); 13071d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13081d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1309ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1310ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getType()->isBlockPointerType()); 1311ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getSubExpr()->getType()->isBlockPointerType()); 1312ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor goto CheckNoBasePath; 1313a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 1314a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_FunctionToPointerDecay: 1315a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman assert(getType()->isPointerType()); 1316a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman assert(getSubExpr()->getType()->isFunctionType()); 1317a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman goto CheckNoBasePath; 1318a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 13191d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // These should not have an inheritance path. 13201d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dynamic: 13211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToUnion: 13221d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ArrayToPointerDecay: 13231d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToMemberPointer: 13241d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToPointer: 13251d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ConstructorConversion: 13261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToPointer: 13271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToIntegral: 13281d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToVoid: 13291d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_VectorSplat: 13301d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralCast: 13311d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToFloating: 13321d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToIntegral: 13331d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingCast: 13341d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ObjCObjectLValueCast: 13351d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingRealToComplex: 13361d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToReal: 13371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexCast: 13381d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToIntegralComplex: 13391d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralRealToComplex: 13401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToReal: 13411d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexCast: 13421d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToFloatingComplex: 134333e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 134433e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 134533e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 134633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 13471d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 13481d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dependent: 13511d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueToRValue: 13521d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NoOp: 13537a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 13547a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 13551d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToBoolean: 13561d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToBoolean: 13571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToBoolean: 13581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_MemberPointerToBoolean: 13591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToBoolean: 13601d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToBoolean: 13611d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueBitCast: // -> bool& 13621d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UserDefinedConversion: // operator bool() 1363a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_BuiltinFnToFnPtr: 13641d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CheckNoBasePath: 13651d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 13661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 13671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 13681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall} 13691d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1370f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 1371f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 1372daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 1373daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 13742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 1375f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 13762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 1377e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 13780ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 13790ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall return "LValueToRValue"; 13802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 1381f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 13822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 138311de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 13842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 1385f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 13862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 138723cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 13882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 1389f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 13902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 1391f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 13922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 1393f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 13942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 1395f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 13962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 1397f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 1398404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 1399404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 14002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 1401f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 14022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 14031a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 14044d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 14054d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall return "ReinterpretMemberPointer"; 14062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 1407f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 14082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 1409f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 14102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 14117f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 14122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 14137f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 1414daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 1415daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 14162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 1417ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 14182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 141916a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 14202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 142182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 1422daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 1423daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 14242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 142582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 14262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 142782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 14282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 1429c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 1430daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 1431daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 14322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 1433bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 14341d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 14351d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "CPointerToObjCPointerCast"; 14361d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 14371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "BlockPointerToObjCPointerCast"; 14382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 14393b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 14402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 1441569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 14422bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 14432bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 1444f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 1445f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 1446f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 1447f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 14482bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 14492bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 1450f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 1451f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 14522bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 14532bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 1454f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 1455f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 1456f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 1457f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 14582bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 14592bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 1460f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 1461f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 146233e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 146333e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCConsumeObject"; 146433e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 146533e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCProduceObject"; 146633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 146733e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCReclaimReturnedObject"; 146833e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 146933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCCExtendBlockObject"; 14707a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 14717a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "AtomicToNonAtomic"; 14727a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 14737a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "NonAtomicToAtomic"; 1474ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1475ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor return "CopyAndAutoreleaseBlockObject"; 1476a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_BuiltinFnToFnPtr: 1477a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman return "BuiltinFnToFnPtr"; 1478f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14802bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 1481f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 1482f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 14836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 14846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 14856eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 14866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 14876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 148803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 148903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Skip through reference binding to temporary. 149003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 149103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) 149203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SubExpr = Materialize->GetTemporaryExpr(); 149303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 14946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 14956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 14966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 1497c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 14996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 15002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 15016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 15022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 15036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 1504c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 15066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 1507c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 1508c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 15106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 15116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 1512f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 1513f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 1514f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 1515f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 1516f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 1517f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 1518f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 1519f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 1520f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 1521f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 1522f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 1523f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1524f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1525f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 1526f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 1527f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 1528f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1529f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1530f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 1531f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 1532f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 15335baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 1534f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1535f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1536f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1537f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 15385baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 1539f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1540f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1541f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1542f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1543f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 1544f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 1545f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1546f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1547f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 1548f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1549f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1550f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1551f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 1552f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 1553f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 1554f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 1555f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 1556f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1557f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1558f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1559f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 1560f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 1561f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1562f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1563f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1564f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1565f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 1566f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1567f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1568f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 1569f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1570f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 15730bea86307eb8c16339315a1e261fc490eb505c5bDavid BlaikieStringRef BinaryOperator::getOpcodeStr(Opcode Op) { 15745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 15752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 15762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 15772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 15782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 15792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 15802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 15812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 15822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 15832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 15842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 15852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 15862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 15872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 15882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 15892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 15902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 15912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 15922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 15932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 15942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 15952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 15962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 15972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 15982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 15992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 16002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 16012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 16022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 16032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 16042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 16052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 16062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 16075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1608baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 16093026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid OpCode!"); 16105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1613063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1614063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1615b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not an overloadable binary operator"); 16162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 16172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 16182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 16192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 16202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 16212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 16222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 16232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 16242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 16252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 16262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 16272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 16282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 16292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 16302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 16312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 16322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 16332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 16342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 16352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 16362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 16372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 16382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 16392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 16402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 16412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 16422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 16432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 16442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 16452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 16462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1647063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1648063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1649063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1650063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1651063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1652063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1653063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1654063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1655063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1656063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1657063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1658063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1659063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1660063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1661063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1662063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1663063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1664063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1665063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1666063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1667063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1668063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1669063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1670063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1671063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1672063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1673063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1674709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 16753b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) 1676bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, 1677561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 16783b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer InitExprs(C, initExprs.size()), 167932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0) 168032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl{ 168132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl sawArrayRangeDesignator(false); 168232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl setInitializesStdInitializerList(false); 16833b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned I = 0; I != initExprs.size(); ++I) { 1684ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 16858e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1686ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 16878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1688561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (initExprs[I]->isInstantiationDependent()) 1689561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1690bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (initExprs[I]->containsUnexpandedParameterPack()) 1691bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 169273460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1693c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16943b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); 169566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1697709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1698ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1699709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1700fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1701fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1702709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1703709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 17044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 17054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1706709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1707ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1708709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1709ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1710ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 17114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 17144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 17154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 17164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 17174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 17183e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidisvoid InitListExpr::setArrayFiller(Expr *filler) { 171921f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis assert(!hasArrayFiller() && "Filler already set!"); 17203e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis ArrayFillerOrUnionFieldInit = filler; 17213e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis // Fill out any "holes" in the array due to designated initializers. 17223e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis Expr **inits = getInits(); 17233e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis for (unsigned i = 0, e = getNumInits(); i != e; ++i) 17243e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis if (inits[i] == 0) 17253e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis inits[i] = filler; 17263e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis} 17273e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis 1728fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smithbool InitListExpr::isStringLiteralInit() const { 1729fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith if (getNumInits() != 1) 1730fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1731f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); 1732f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman if (!AT || !AT->getElementType()->isIntegerType()) 1733fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1734f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman const Expr *Init = getInit(0)->IgnoreParens(); 1735fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); 1736fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith} 1737fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith 1738c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted KremenekSourceRange InitListExpr::getSourceRange() const { 1739c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (SyntacticForm) 1740c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SyntacticForm->getSourceRange(); 1741c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek SourceLocation Beg = LBraceLoc, End = RBraceLoc; 1742c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1743c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1744c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1745c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1746c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1747c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1748c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1749c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1750c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1751c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1752c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1753c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1754c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1755c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 1756c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.rend(); 1757c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1758c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1759c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek End = S->getSourceRange().getEnd(); 1760c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1761c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1762c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1763c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1764c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SourceRange(Beg, End); 1765c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1766c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1767bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 17684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 1769a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCallconst FunctionProtoType *BlockExpr::getFunctionType() const { 1770a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall // The block pointer is never sugared, but the function type might be. 1771a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall return cast<BlockPointerType>(getType()) 1772a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall ->getPointeeType()->castAs<FunctionProtoType>(); 17734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 17744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 17751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 177756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 17781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 17797297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 17807297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 17811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 17821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 17837297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 178456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 178556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 17885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1790026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1791026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1792026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1793026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1794a6115068cde719142eb394db88612c185cabd05bEli Friedmanbool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, 1795a6115068cde719142eb394db88612c185cabd05bEli Friedman SourceRange &R1, SourceRange &R2, 1796a6115068cde719142eb394db88612c185cabd05bEli Friedman ASTContext &Ctx) const { 1797ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1798ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1799ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1800ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 18035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 18040faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 18050faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1806a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1807026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1808026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1809026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 18105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1811026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1812a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1813f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 1814f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr()-> 1815a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 18175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1820a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Plus: 1821a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Minus: 1822a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_AddrOf: 1823a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Not: 1824a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_LNot: 1825a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Deref: 1826a6115068cde719142eb394db88612c185cabd05bEli Friedman break; 18272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 18282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 18292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 18302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1831026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 18322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 18332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 18345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1835df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1836df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1837026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1838026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 18392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1840a6115068cde719142eb394db88612c185cabd05bEli Friedman return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 18415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1842a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1843026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1844026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1845026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1847e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1848026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1849c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1850c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1851c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 185225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 185325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 18542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1855c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1856c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1857c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1858c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1859c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1860c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 1861a6115068cde719142eb394db88612c185cabd05bEli Friedman return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 186225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 18632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 18642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 1865a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || 1866a6115068cde719142eb394db88612c185cabd05bEli Friedman !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 186725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 186825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1869bf0ee354163f87623a4b60412544243911332343John McCall } 1870026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1871026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1872a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1873026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1874026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1875026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1876026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1877e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1878eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1879c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1880276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman case AtomicExprClass: 1881026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1883ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1884fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // If only one of the LHS or RHS is a warning, the operator might 1885fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // be being used for control flow. Only warn if both the LHS and 1886fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // RHS are warnings. 1887ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 1888a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 1889fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek return false; 1890fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek if (!Exp->getLHS()) 1891026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1892a6115068cde719142eb394db88612c185cabd05bEli Friedman return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1893ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1894ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 18955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1896a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1897026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1898026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1899026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1900026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 19011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 1903a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1904026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 1905026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 1906026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 1907026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1908211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 19099b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth case CXXOperatorCallExprClass: { 19109b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // We warn about operator== and operator!= even when user-defined operator 19119b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // overloads as there is no reasonable way to define these such that they 19129b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // have non-trivial, desirable side-effects. See the -Wunused-comparison 19139b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // warning: these operators are commonly typo'ed, and so warning on them 19149b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // provides additional value as well. If this list is updated, 19159b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // DiagnoseUnusedComparison should be as well. 19169b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); 19179b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth if (Op->getOperator() == OO_EqualEqual || 19186e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Op->getOperator() == OO_ExclaimEqual) { 1919a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 19206e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Loc = Op->getOperatorLoc(); 19216e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay R1 = Op->getSourceRange(); 19229b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth return true; 19236e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay } 19249b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth 19259b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // Fallthrough for generic call handling. 19269b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth } 19275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 19289fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case CXXMemberCallExprClass: 19299fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case UserDefinedLiteralClass: { 1930026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 1931026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 1932d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 1933026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 1934026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 1935bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 1936bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 1937bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 1938bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 1939bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 1940a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1941bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 1942bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 1943bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 1944bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 1945bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 1946bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 1947bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 1948bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1949026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 1950026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1951026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 195258beed91d468863b8c85bce43425422703838d27Anders Carlsson 195384c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay // If we don't know precisely what we're looking at, let's not warn. 195484c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay case UnresolvedLookupExprClass: 195584c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay case CXXUnresolvedConstructExprClass: 195684c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay return false; 195784c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay 195858beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 195958beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 196058beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 196158beed91d468863b8c85bce43425422703838d27Anders Carlsson 1962f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 1963f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 19644e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().ObjCAutoRefCount && 1965f85e193739c953358c865005855253af4f68a497John McCall ME->isInstanceMessage() && 1966f85e193739c953358c865005855253af4f68a497John McCall !ME->getType()->isVoidType() && 1967f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) && 1968f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) 1969f85e193739c953358c865005855253af4f68a497John McCall ->getName().startswith("init")) { 1970a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1971f85e193739c953358c865005855253af4f68a497John McCall Loc = getExprLoc(); 1972f85e193739c953358c865005855253af4f68a497John McCall R1 = ME->getSourceRange(); 1973f85e193739c953358c865005855253af4f68a497John McCall return true; 1974f85e193739c953358c865005855253af4f68a497John McCall } 1975f85e193739c953358c865005855253af4f68a497John McCall 1976f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 1977f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 1978a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1979f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 1980f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 1981f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 1982026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1983f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 198512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall case ObjCPropertyRefExprClass: 1986a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 19875e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 19885e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 1989a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 199012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 19914b9c2d235fb9449e249d74f48ecfec601650de93John McCall case PseudoObjectExprClass: { 19924b9c2d235fb9449e249d74f48ecfec601650de93John McCall const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 19934b9c2d235fb9449e249d74f48ecfec601650de93John McCall 19944b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Only complain about things that have the form of a getter. 19954b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<UnaryOperator>(PO->getSyntacticForm()) || 19964b9c2d235fb9449e249d74f48ecfec601650de93John McCall isa<BinaryOperator>(PO->getSyntacticForm())) 19974b9c2d235fb9449e249d74f48ecfec601650de93John McCall return false; 19984b9c2d235fb9449e249d74f48ecfec601650de93John McCall 1999a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20004b9c2d235fb9449e249d74f48ecfec601650de93John McCall Loc = getExprLoc(); 20014b9c2d235fb9449e249d74f48ecfec601650de93John McCall R1 = getSourceRange(); 20024b9c2d235fb9449e249d74f48ecfec601650de93John McCall return true; 20034b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 20044b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2005611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 2006611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 2007611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 2008611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 2009611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 2010611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 2011611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 2012d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 2013611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 2014a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2015d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 2016d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 2017a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2018d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 20191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20200faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 20210faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 2022a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2023026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 2024026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 2025026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 2026611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 20276319917b5021e9602389b49ca4f245d235e9b90aEli Friedman case CXXFunctionalCastExprClass: 2028a6115068cde719142eb394db88612c185cabd05bEli Friedman case CStyleCastExprClass: { 20294059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman // Ignore an explicit cast to void unless the operand is a non-trivial 2030a6115068cde719142eb394db88612c185cabd05bEli Friedman // volatile lvalue. 20314059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CastExpr *CE = cast<CastExpr>(this); 2032a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ToVoid) { 2033a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getSubExpr()->isGLValue() && 20344059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman CE->getSubExpr()->getType().isVolatileQualified()) { 20354059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const DeclRefExpr *DRE = 20364059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); 20374059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (!(DRE && isa<VarDecl>(DRE->getDecl()) && 20384059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) { 20394059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, 20404059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1, R2, Ctx); 20414059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 20424059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 20430faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 2044a6115068cde719142eb394db88612c185cabd05bEli Friedman } 20454059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 2046a6115068cde719142eb394db88612c185cabd05bEli Friedman // If this is a cast to a constructor conversion, check the operand. 204758beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 2048a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ConstructorConversion) 2049a6115068cde719142eb394db88612c185cabd05bEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 20504059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 2051a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20524059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (const CXXFunctionalCastExpr *CXXCE = 20534059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<CXXFunctionalCastExpr>(this)) { 20544059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CXXCE->getTypeBeginLoc(); 20554059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CXXCE->getSubExpr()->getSourceRange(); 20564059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } else { 20574059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); 20584059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CStyleCE->getLParenLoc(); 20594059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CStyleCE->getSubExpr()->getSourceRange(); 20604059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 2061026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 206258beed91d468863b8c85bce43425422703838d27Anders Carlsson } 2063a6115068cde719142eb394db88612c185cabd05bEli Friedman case ImplicitCastExprClass: { 2064a6115068cde719142eb394db88612c185cabd05bEli Friedman const CastExpr *ICE = cast<ImplicitCastExpr>(this); 2065a6115068cde719142eb394db88612c185cabd05bEli Friedman 2066a6115068cde719142eb394db88612c185cabd05bEli Friedman // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. 2067a6115068cde719142eb394db88612c185cabd05bEli Friedman if (ICE->getCastKind() == CK_LValueToRValue && 2068a6115068cde719142eb394db88612c185cabd05bEli Friedman ICE->getSubExpr()->getType().isVolatileQualified()) 2069a6115068cde719142eb394db88612c185cabd05bEli Friedman return false; 20704be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 2071a6115068cde719142eb394db88612c185cabd05bEli Friedman return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2072a6115068cde719142eb394db88612c185cabd05bEli Friedman } 207304421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 2074df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 2075a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 20764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 20774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 20784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 20794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 20804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 2081026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 20822d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 2083df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 2084a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 20854765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 20864765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return (cast<ExprWithCleanups>(this) 2087a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 20884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 20895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 20905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 209144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 20927f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 2093102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 2094f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 2095f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne switch (E->getStmtClass()) { 209644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 209744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 209844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 209944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 2100207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 2101f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 210244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 2103f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 210403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 210503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() 210603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isOBJCGCCandidate(Ctx); 210706b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 2108f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 2109a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 2110f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const Decl *D = cast<DeclRefExpr>(E)->getDecl(); 2111e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian 2112102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 2113102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 2114102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 2115102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 211659a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 211759a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 21187e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 21190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 2120102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 212144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 212244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 212383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 2124f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const MemberExpr *M = cast<MemberExpr>(E); 2125102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 212644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 212744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 2128f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); 212944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 213044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 2131369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 213211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 213311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 213411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 21357eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 213611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 213711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 2138864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallQualType Expr::findBoundMemberType(const Expr *expr) { 2139e0a22d06888c13989b3f72db319f1d498bf69153John McCall assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); 2140864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2141864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Bound member expressions are always one of these possibilities: 2142864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // x->m x.m x->*y x.*y 2143864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // (possibly parenthesized) 2144864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2145864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall expr = expr->IgnoreParens(); 2146864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { 2147864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<CXXMethodDecl>(mem->getMemberDecl())); 2148864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return mem->getMemberDecl()->getType(); 2149864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2150864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2151864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { 2152864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() 2153864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ->getPointeeType(); 2154864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(type->isFunctionType()); 2155864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return type; 2156864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2157864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2158864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<UnresolvedMemberExpr>(expr)); 2159864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return QualType(); 2160864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 2161864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 21624e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 21634e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 2164b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 2165b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 2166b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2167b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2168b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2169b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2170b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2171b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2172b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2173b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2174b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2175f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2176f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2177f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2178f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2179f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2180f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2181b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 2182b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 21834e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 21844e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 218556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 218656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 218756f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 218856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 218956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 2190b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 219156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2192b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2193b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2194b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 219556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2196b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2197b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2198b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2199b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2200b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2201b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2202b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2203b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2204f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2205f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2206f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2207f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2208f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2209f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 221003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 221103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 221203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 221303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 221403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2215c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2216c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2217c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2218c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2219c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2220b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 222156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 222256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 222356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 22249c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue 22259c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts. This is intended purely as a temporary workaround for code 22269c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// that hasn't yet been rewritten to do the right thing about those 22279c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts, and may disappear along with the last internal use. 2228f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallExpr *Expr::IgnoreParenLValueCasts() { 2229f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *E = this; 22309c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall while (true) { 2231f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2232f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2233f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 22349c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2235f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (P->getCastKind() == CK_LValueToRValue) { 2236f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2237f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2238f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 22399c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 22409c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall if (P->getOpcode() == UO_Extension) { 22419c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall E = P->getSubExpr(); 22429c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall continue; 22439c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } 2244f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2245f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2246f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2247f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2248f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 224903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (MaterializeTemporaryExpr *Materialize 225003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 225103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 225203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 2253c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } else if (SubstNonTypeTemplateParmExpr *NTTP 2254c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2255c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2256c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2257f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2258f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2259f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2260f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return E; 2261f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2262632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 2263632fbaa22fbed7c090eb83775731bfff786c2198Rafael EspindolaExpr *Expr::ignoreParenBaseCasts() { 2264632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola Expr *E = this; 2265632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola while (true) { 2266632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2267632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola E = P->getSubExpr(); 2268632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola continue; 2269632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2270632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (CastExpr *CE = dyn_cast<CastExpr>(E)) { 2271632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (CE->getCastKind() == CK_DerivedToBase || 2272632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola CE->getCastKind() == CK_UncheckedDerivedToBase || 2273632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola CE->getCastKind() == CK_NoOp) { 2274632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola E = CE->getSubExpr(); 2275632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola continue; 2276632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2277632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2278632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 2279632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola return E; 2280632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2281632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola} 2282632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 22832fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 22842fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 22852fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 2286b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 22872fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2288b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2289b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2290b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 22912fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2292b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2293b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2294b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2295b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2296b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2297b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2298b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2299b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2300f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2301f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2302f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2303f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2304f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2305f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 230603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 230703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 230803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 230903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 231003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2311c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2312c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2313c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2314c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2315c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2316b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 23172fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 23182fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 23192fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 23202f072b442879b8bba8c5dea11d7c61bedb1924aeHans WennborgExpr *Expr::IgnoreConversionOperator() { 23212f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) { 232214d251cd62942bf7d56bb87a267ba2ca2f7fae3eChandler Carruth if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) 23232f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return MCE->getImplicitObjectArgument(); 23242f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 23252f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return this; 23262f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg} 23272f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 2328ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 2329ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 2330ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 2331ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 2332ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 2333ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 2334ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2335ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 2336ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2337ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 23381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2339ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2340ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 23412ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 2342ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 23431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2344ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 2345ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2346ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2347ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 23481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2349b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 23509d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 2351b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 23529d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 2353ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 2354ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2355ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2356ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2357ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2359b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2360b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2361b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2362b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2363b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2364b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2365b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 2366f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2367f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2368f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2369f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2370f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2371f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2372f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 2373c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2374c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2375c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2376c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2377c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2378c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor 2379ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 2380ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2381ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 2382ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 23836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 23846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 238503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 238603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 238703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 23886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 23896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 2390c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 23916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 23926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 2393ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 23942f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 23952f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 2396f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 239703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 239803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 239903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 24002f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 24012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 24022f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 24032f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 24042f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 24052f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 24062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 24072f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 24082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 24092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 24102f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 24112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 24122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 24132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 24142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 24152f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 2416f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 2417f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 24182f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 24192f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2420558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 2421558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 2422558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 2423558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 2424558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 24252f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2426f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 24272f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 242858277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 2429db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 2430db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 243112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!isa<ObjCPropertyRefExpr>(E)) 2432db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 2433db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 24342f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 243519e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 243619e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 243719e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 243819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 2439558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 2440558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 2441558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 2442558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 2443558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 2444558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 2445558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 2446558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 24472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 24482f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 244919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 245019e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 245119e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 245219e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 245332f498a675df990901e6659d610dc740f9423228Eli Friedman if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) 245432f498a675df990901e6659d610dc740f9423228Eli Friedman if (BO->isPtrMemOp()) 245532f498a675df990901e6659d610dc740f9423228Eli Friedman return false; 245632f498a675df990901e6659d610dc740f9423228Eli Friedman 245756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // - opaque values (all) 245856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (isa<OpaqueValueExpr>(E)) 245956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return false; 246056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 2461558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 24622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 24632f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 246475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregorbool Expr::isImplicitCXXThis() const { 246575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor const Expr *E = this; 246675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 246775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // Strip away parentheses and casts we don't care about. 246875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor while (true) { 246975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { 247075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = Paren->getSubExpr(); 247175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 247275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 247375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 247475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 247575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (ICE->getCastKind() == CK_NoOp || 247675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_LValueToRValue || 247775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_DerivedToBase || 247875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_UncheckedDerivedToBase) { 247975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = ICE->getSubExpr(); 248075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 248175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 248275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 248375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 248475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { 248575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (UnOp->getOpcode() == UO_Extension) { 248675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = UnOp->getSubExpr(); 248775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 248875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 248975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 249075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 249103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M 249203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 249303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 249403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 249503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 249603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 249775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor break; 249875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 249975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 250075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) 250175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return This->isImplicit(); 250275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 250375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return false; 250475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 250575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 2506898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 2507898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 250813a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charlesbool Expr::hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs) { 250913a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles for (unsigned I = 0; I < Exprs.size(); ++I) 2510898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 2511898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2512898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2513898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2514898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2515898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 25164204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 2517c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 2518c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 2519c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 2520c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 2521c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 2522c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 25234204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 25244204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 25254204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 25264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 25274204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 25284204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 25294204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 25301f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 2531e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 2532c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 25334ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case IntegerLiteralClass: 25344ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case FloatingLiteralClass: 2535e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 253614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 2537eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 2538e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 2539b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 2540b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 2541b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 25424204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 25434204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 2544180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->getConstructor()->isTrivial()) { 2545180f47959a066795cc0f409433023af448bb0328Richard Smith // 1) an application of the trivial default constructor or 2546180f47959a066795cc0f409433023af448bb0328Richard Smith if (!CE->getNumArgs()) return true; 2547180f47959a066795cc0f409433023af448bb0328Richard Smith 2548180f47959a066795cc0f409433023af448bb0328Richard Smith // 2) an elidable trivial copy construction of an operand which is 2549180f47959a066795cc0f409433023af448bb0328Richard Smith // itself a constant initializer. Note that we consider the 2550180f47959a066795cc0f409433023af448bb0328Richard Smith // operand on its own, *not* as a reference binding. 2551180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->isElidable() && 2552180f47959a066795cc0f409433023af448bb0328Richard Smith CE->getArg(0)->isConstantInitializer(Ctx, false)) 2553180f47959a066795cc0f409433023af448bb0328Richard Smith return true; 2554180f47959a066795cc0f409433023af448bb0328Richard Smith } 2555180f47959a066795cc0f409433023af448bb0328Richard Smith 2556180f47959a066795cc0f409433023af448bb0328Richard Smith // 3) a foldable constexpr constructor. 2557180f47959a066795cc0f409433023af448bb0328Richard Smith break; 2558b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 255959b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 25601f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 25611f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 25621f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 256359b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 25644204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 256559b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 2566e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 25671f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 25681f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 25691f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 2570e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 2571e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 2572e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 25734204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 2574e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 2575e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2576c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 2577e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 25783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 25793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 25803ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 25814204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 25824204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 2583f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 2584f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (cast<GenericSelectionExpr>(this)->isResultDependent()) 2585f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return false; 2586f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr() 2587f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ->isConstantInitializer(Ctx, IsForRef); 25885cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 25895cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 25905cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 2591c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 2592c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 25932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 25944204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 2595c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2596c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 25974204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 2598b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 259981045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 2600d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith case CStyleCastExprClass: { 2601d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith const CastExpr *CE = cast<CastExpr>(this); 2602d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 26037a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // If we're promoting an integer to an _Atomic type then this is constant 26047a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // if the integer is constant. We also need to check the converse in case 26057a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // someone does something like: 26067a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 26077a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // int a = (_Atomic(int))42; 26087a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 26097a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // I doubt anyone would write code like this directly, but it's quite 26107a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // possible as the result of macro expansions. 26117a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall if (CE->getCastKind() == CK_NonAtomicToAtomic || 26127a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall CE->getCastKind() == CK_AtomicToNonAtomic) 26137a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return CE->getSubExpr()->isConstantInitializer(Ctx, false); 26147a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall 2615d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith // Handle bitcasts of vector constants. 2616d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith if (getType()->isVectorType() && CE->getCastKind() == CK_BitCast) 2617d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2618d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 26196bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // Handle misc casts we want to ignore. 26206bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // FIXME: Is it really safe to ignore all these? 26216bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman if (CE->getCastKind() == CK_NoOp || 26226bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_LValueToRValue || 26236bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ToUnion || 26246bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ConstructorConversion) 2625d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2626d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 2627c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2628d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith } 262903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 26305f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() 263103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isConstantInitializer(Ctx, false); 2632e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2633c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 263438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 263538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 26368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smithbool Expr::HasSideEffects(const ASTContext &Ctx) const { 26378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (isInstantiationDependent()) 26388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 26398ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 26408ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith switch (getStmtClass()) { 26418ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case NoStmtClass: 26428ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define ABSTRACT_STMT(Type) 26438ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define STMT(Type, Base) case Type##Class: 26448ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define EXPR(Type, Base) 26458ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #include "clang/AST/StmtNodes.inc" 26468ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith llvm_unreachable("unexpected Expr kind"); 26478ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 26488ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case DependentScopeDeclRefExprClass: 26498ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXUnresolvedConstructExprClass: 26508ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDependentScopeMemberExprClass: 26518ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnresolvedLookupExprClass: 26528ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnresolvedMemberExprClass: 26538ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PackExpansionExprClass: 26548ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SubstNonTypeTemplateParmPackExprClass: 26559a4db032ecd991626d236a502e770126db32bd31Richard Smith case FunctionParmPackExprClass: 26568ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith llvm_unreachable("shouldn't see dependent / unresolved nodes here"); 26578ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 265860b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case DeclRefExprClass: 265960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case ObjCIvarRefExprClass: 26608ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PredefinedExprClass: 26618ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case IntegerLiteralClass: 26628ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case FloatingLiteralClass: 26638ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ImaginaryLiteralClass: 26648ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case StringLiteralClass: 26658ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CharacterLiteralClass: 26668ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case OffsetOfExprClass: 26678ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ImplicitValueInitExprClass: 26688ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnaryExprOrTypeTraitExprClass: 26698ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AddrLabelExprClass: 26708ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case GNUNullExprClass: 26718ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXBoolLiteralExprClass: 26728ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNullPtrLiteralExprClass: 26738ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXThisExprClass: 26748ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXScalarValueInitExprClass: 26758ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case TypeTraitExprClass: 26768ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnaryTypeTraitExprClass: 26778ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryTypeTraitExprClass: 26788ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ArrayTypeTraitExprClass: 26798ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExpressionTraitExprClass: 26808ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNoexceptExprClass: 26818ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SizeOfPackExprClass: 26828ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCStringLiteralClass: 26838ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCEncodeExprClass: 26848ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBoolLiteralExprClass: 26858ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXUuidofExprClass: 26868ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case OpaqueValueExprClass: 26878ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These never have a side-effect. 26888ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 26898ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 26908ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CallExprClass: 26918ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CompoundAssignOperatorClass: 26928ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case VAArgExprClass: 26938ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AtomicExprClass: 26948ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case StmtExprClass: 26958ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXOperatorCallExprClass: 26968ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXMemberCallExprClass: 26978ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UserDefinedLiteralClass: 26988ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXThrowExprClass: 26998ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNewExprClass: 27008ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDeleteExprClass: 27018ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExprWithCleanupsClass: 27028ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXBindTemporaryExprClass: 27038ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BlockExprClass: 27048ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CUDAKernelCallExprClass: 27058ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These always have a side-effect. 27068ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27078ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27088ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ParenExprClass: 27098ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ArraySubscriptExprClass: 27108ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case MemberExprClass: 27118ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ConditionalOperatorClass: 27128ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryConditionalOperatorClass: 27138ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CompoundLiteralExprClass: 27148ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExtVectorElementExprClass: 27158ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case DesignatedInitExprClass: 27168ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ParenListExprClass: 27178ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXPseudoDestructorExprClass: 27188ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SubstNonTypeTemplateParmExprClass: 27198ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case MaterializeTemporaryExprClass: 27208ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ShuffleVectorExprClass: 27218ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AsTypeExprClass: 27228ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These have a side-effect if any subexpression does. 27238ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 27248ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 272560b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case UnaryOperatorClass: 272660b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (cast<UnaryOperator>(this)->isIncrementDecrementOp()) 27278ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27288ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 27298ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27308ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryOperatorClass: 27318ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (cast<BinaryOperator>(this)->isAssignmentOp()) 27328ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27338ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 27348ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case InitListExprClass: 27368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: The children for an InitListExpr doesn't include the array filler. 27378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller()) 27388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (E->HasSideEffects(Ctx)) 27398ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27408ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 27418ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27428ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case GenericSelectionExprClass: 27438ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<GenericSelectionExpr>(this)->getResultExpr()-> 27448ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith HasSideEffects(Ctx); 27458ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27468ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ChooseExprClass: 27478ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->HasSideEffects(Ctx); 27488ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27498ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDefaultArgExprClass: 27508ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects(Ctx); 27518ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27528ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDynamicCastExprClass: { 27538ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // A dynamic_cast expression has side-effects if it can throw. 27548ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this); 27558ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (DCE->getTypeAsWritten()->isReferenceType() && 27568ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith DCE->getCastKind() == CK_Dynamic) 27578ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 275860b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith } // Fall through. 275960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case ImplicitCastExprClass: 276060b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CStyleCastExprClass: 276160b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXStaticCastExprClass: 276260b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXReinterpretCastExprClass: 276360b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXConstCastExprClass: 276460b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXFunctionalCastExprClass: { 276560b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith const CastExpr *CE = cast<CastExpr>(this); 276660b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (CE->getCastKind() == CK_LValueToRValue && 276760b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith CE->getSubExpr()->getType().isVolatileQualified()) 276860b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith return true; 27698ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 27708ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 27718ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27720d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith case CXXTypeidExprClass: 27730d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith // typeid might throw if its subexpression is potentially-evaluated, so has 27740d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith // side-effects in that case whether or not its subexpression does. 27750d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); 27768ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27778ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXConstructExprClass: 27788ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXTemporaryObjectExprClass: { 27798ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 278060b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (!CE->getConstructor()->isTrivial()) 27818ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 278260b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith // A trivial constructor does not add any side-effects of its own. Just look 278360b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith // at its arguments. 27848ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 27858ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 27868ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27878ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case LambdaExprClass: { 27888ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const LambdaExpr *LE = cast<LambdaExpr>(this); 27898ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (LambdaExpr::capture_iterator I = LE->capture_begin(), 27908ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith E = LE->capture_end(); I != E; ++I) 27918ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (I->getCaptureKind() == LCK_ByCopy) 27928ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: Only has a side-effect if the variable is volatile or if 27938ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // the copy would invoke a non-trivial copy constructor. 27948ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27958ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 27968ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 27978ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27988ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PseudoObjectExprClass: { 27998ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // Only look for side-effects in the semantic form, and look past 28008ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // OpaqueValueExpr bindings in that form. 28018ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 28028ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), 28038ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith E = PO->semantics_end(); 28048ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith I != E; ++I) { 28058ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const Expr *Subexpr = *I; 28068ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr)) 28078ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith Subexpr = OVE->getSourceExpr(); 28088ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (Subexpr->HasSideEffects(Ctx)) 28098ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28108ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28118ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 28128ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28138ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28148ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBoxedExprClass: 28158ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCArrayLiteralClass: 28168ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCDictionaryLiteralClass: 28178ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCMessageExprClass: 28188ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCSelectorExprClass: 28198ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCProtocolExprClass: 28208ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCPropertyRefExprClass: 28218ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCIsaExprClass: 28228ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCIndirectCopyRestoreExprClass: 28238ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCSubscriptRefExprClass: 28248ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBridgedCastExprClass: 28258ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: Classify these cases better. 28268ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28278ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28288ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28298ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // Recurse to children. 28308ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (const_child_range SubStmts = children(); SubStmts; ++SubStmts) 28318ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const Stmt *S = *SubStmts) 28328ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (cast<Expr>(S)->HasSideEffects(Ctx)) 28338ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28348ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 28368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith} 28378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 283825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregornamespace { 283925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// \brief Look for a call to a non-trivial function within an expression. 284025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor class NonTrivialCallFinder : public EvaluatedExprVisitor<NonTrivialCallFinder> 284125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor { 284225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor typedef EvaluatedExprVisitor<NonTrivialCallFinder> Inherited; 284325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 284425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool NonTrivial; 284525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 284625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor public: 284725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor explicit NonTrivialCallFinder(ASTContext &Context) 2848b11e52540166a2958439cfe562c25931e4460759Douglas Gregor : Inherited(Context), NonTrivial(false) { } 284925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 285025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool hasNonTrivialCall() const { return NonTrivial; } 285125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 285225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCallExpr(CallExpr *E) { 285325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (CXXMethodDecl *Method 285425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor = dyn_cast_or_null<CXXMethodDecl>(E->getCalleeDecl())) { 285525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (Method->isTrivial()) { 285625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 285725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 285825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 285925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 286025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 286125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 286225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 286325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 286425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 286525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXConstructExpr(CXXConstructExpr *E) { 286625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getConstructor()->isTrivial()) { 286725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 286825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 286925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 287025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 287125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 287225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 287325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 287425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 287525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 287625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getTemporary()->getDestructor()->isTrivial()) { 287725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 287825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 287925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 288025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 288125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 288225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 288325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor }; 288425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 288525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 288625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregorbool Expr::hasNonTrivialCall(ASTContext &Ctx) { 288725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivialCallFinder Finder(Ctx); 288825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Finder.Visit(this); 288925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return Finder.hasNonTrivialCall(); 289025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 289125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 289282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null 289382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// pointer constant or not, as well as the specific kind of constant detected. 289482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// Null pointer constants can be integer constant expressions with the 289582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// value zero, casts of zero to void*, nullptr (C++0X), or __null 289682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// (a GNU extension). 289782214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::NullPointerConstantKind 289882214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::isNullPointerConstant(ASTContext &Ctx, 289982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const { 2900ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 2901ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 2902ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 2903b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected value dependent expression!"); 2904ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 290582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth if (isTypeDependent() || getType()->isIntegralType(Ctx)) 290650800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroExpression; 290782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth else 290882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2909c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2910ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 291182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2912ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2913ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2914f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 29150777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 29160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 29174e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) { 29180777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 29196217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 29200777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 29210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 29220777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 29230777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 2924ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 29250777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 29265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2927aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 2928aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 2929ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2930aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 2931aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 2932aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 2933ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2934f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (const GenericSelectionExpr *GE = 2935f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne dyn_cast<GenericSelectionExpr>(this)) { 2936f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); 29371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 29388123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 293904421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 2940ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 29412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 29422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 294382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_GNUNull; 294403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (const MaterializeTemporaryExpr *M 294503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(this)) { 294603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); 29474b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { 29484b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (const Expr *Source = OVE->getSourceExpr()) 29494b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Source->isNullPointerConstant(Ctx, NPC); 2950aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 29512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 29526e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 29536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 295482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_CXX0X_nullptr; 29556e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2956ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 2957ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 2958ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 2959ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 2960ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 2961ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 2962ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 2963aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 2964c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 29654e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType())) 296682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 29671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 296970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // test for the value 0. Don't use the C++11 constant expression semantics 297070488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // for this, for now; once the dust settles on core issue 903, we might only 297170488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // allow a literal 0 here in C++11 mode. 29724e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().CPlusPlus0x) { 297370488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isCXX98IntegralConstantExpr(Ctx)) 297470488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 297570488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } else { 297670488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isIntegerConstantExpr(Ctx)) 297770488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 297870488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } 297982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 298050800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie if (EvaluateKnownConstInt(Ctx) != 0) 298150800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_NotNull; 298250800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie 298350800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie if (isa<IntegerLiteral>(this)) 298450800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroLiteral; 298550800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroExpression; 29865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 298731a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 2988f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// \brief If this expression is an l-value for an Objective C 2989f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// property, find the underlying property reference expression. 2990f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallconst ObjCPropertyRefExpr *Expr::getObjCProperty() const { 2991f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *E = this; 2992f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall while (true) { 2993f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall assert((E->getValueKind() == VK_LValue && 2994f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E->getObjectKind() == OK_ObjCProperty) && 2995f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall "expression is not a property reference"); 2996f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = E->IgnoreParenCasts(); 2997f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 2998f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (BO->getOpcode() == BO_Comma) { 2999f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = BO->getRHS(); 3000f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 3001f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3002f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3003f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3004f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 3005f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3006f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3007f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return cast<ObjCPropertyRefExpr>(E); 3008f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 3009f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3010bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaksbool Expr::isObjCSelfExpr() const { 3011bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const Expr *E = IgnoreParenImpCasts(); 3012bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3013bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); 3014bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!DRE) 3015bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3016bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3017bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); 3018bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!Param) 3019bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3020bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3021bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); 3022bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!M) 3023bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3024bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3025bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return M->getSelfDecl() == Param; 3026bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks} 3027bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 302833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 30296f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 303033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 3031de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 3032f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ICE->getCastKind() == CK_LValueToRValue || 3033f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) 3034de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 3035de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 3036de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 3037de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 3038de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 303927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 304086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 304133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 304233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 304333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 30440f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 30450f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 30460f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 30470f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 30480f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 304942068e9d420889014ee26894e421fead336b239dEli Friedman if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { 305033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 305133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 305233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 305342068e9d420889014ee26894e421fead336b239dEli Friedman if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) 305442068e9d420889014ee26894e421fead336b239dEli Friedman return BinOp->getRHS()->getBitField(); 305542068e9d420889014ee26894e421fead336b239dEli Friedman } 305642068e9d420889014ee26894e421fead336b239dEli Friedman 305733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 305827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 305927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 3060093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 3061093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 3062c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3063093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 30645baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 30652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 3066093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 3067093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 3068093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 3069093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 3070c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3071093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 3072093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 3073093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 3074093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 3075093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 3076093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 3077093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 3078093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 3079093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 30802140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 30812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 30822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 30832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 30842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 30852140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 3086213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 3087183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 30888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 30898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 30904d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 30914d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 30928a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 3093213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 3094a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 3095a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 30965f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 3097190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 3098190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 3099150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 3100190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 31011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3102190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 3103150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 3104150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 31051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3106150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 31075f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) 3108fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 3109150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 3110fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 3111fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 3112b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 31138a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 31143b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 31155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<unsigned> &Elts) const { 31165f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 31174b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 31184b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 31191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31204b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 31214b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 31224b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 31234b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 31241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31258a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 31268a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 31271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31288a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 31298a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 31308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 31318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 31328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 31338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 31348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 31358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 31368a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 31374b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 3138b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 31393b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 3140b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 31418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 31428a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 314304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3144f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 314504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 314604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 314704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 314804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 3149c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3150207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3151207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 315204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 31538d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3154746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3155746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3156f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 3157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3158561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 316004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 316104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3162b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(IsInstanceSuper? SuperInstance : SuperClass), 3163746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3164746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SuperLoc(SuperLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 3165c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 3166207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 316704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 316804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 316904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 317004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3171f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 317204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 317304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 3174f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 3175207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3176207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 317704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 31788d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3179746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3180746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3181f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 3182561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isInstantiationDependentType(), 3183561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->containsUnexpandedParameterPack()), 318404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 318504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3186b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Class), 3187746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3188207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 318904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 3190207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 319104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 319204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 319304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 319404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3195f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 319604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 319704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 3198c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3199207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3200207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 320104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32028d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3203746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3204746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3205f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 3206bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->isTypeDependent(), 3207561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Receiver->isInstantiationDependent(), 3208bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->containsUnexpandedParameterPack()), 320904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 321004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3211b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Instance), 3212746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3213207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 321404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 3215207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 321604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 3217207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3218207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3219207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args, 3220207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3221207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK) { 3222207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis setNumArgs(Args.size()); 3223aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 32248d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis for (unsigned I = 0; I != Args.size(); ++I) { 3225bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 3226bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3227bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 3228bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3229561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[I]->isInstantiationDependent()) 3230561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3231bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 3232bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3233bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3234bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 3235bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3236207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 323719562c97669532084a71895197f4444305dd432aBenjamin Kramer SelLocsKind = SelLocsK; 32380c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (!isImplicit()) { 32390c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (SelLocsK == SelLoc_NonStandard) 32400c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 32410c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis } 324204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 324304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 324404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3245f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 324604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 324704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 324804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 324904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 3250c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3251951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 325204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32538d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3254746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3255746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3256746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3257746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3258746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3259746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3260746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3261746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3262746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3263746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3264f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 3265207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SuperType, Sel, SelLocs, SelLocsK, 3266746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Method, Args, RBracLoc, isImplicit); 326704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 326804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 326904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 327104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 327204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 3273c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3274951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 327504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32768d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3277746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3278746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3279746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3280746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3281746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3282746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3283746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3284746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3285746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3286746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3287951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 3288746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 3289746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 329004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 329104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 329204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3293f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 329404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 329504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 3296f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 3297951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 329804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32998d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3300746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3301746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3302746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3303746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3304746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3305746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3306746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3307746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3308746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3309746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3310951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 3311746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 3312746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 331304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 331404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 3315c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 3316207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 3317207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 3318207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs); 331904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 332004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 3321e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3322207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 3323207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3324207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 3325207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3326207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 3327207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK) { 3328207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocsK = hasStandardSelectorLocs(Sel, SelLocs, Args, RBraceLoc); 3329207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs = (SelLocsK == SelLoc_NonStandard) ? SelLocs.size() 3330207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis : 0; 3331207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return alloc(C, Args.size(), NumStoredSelLocs); 3332207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3333207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3334207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 3335207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 3336207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 3337207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 3338207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis NumArgs * sizeof(Expr *) + NumStoredSelLocs * sizeof(SourceLocation); 3339207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (ObjCMessageExpr *)C.Allocate(Size, 3340207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::AlignOf<ObjCMessageExpr>::Alignment); 3341207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3342207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3343207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::getSelectorLocs( 3344207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVectorImpl<SourceLocation> &SelLocs) const { 3345207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 3346207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs.push_back(getSelectorLoc(i)); 3347207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3348207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3349e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios KyrtzidisSourceRange ObjCMessageExpr::getReceiverRange() const { 3350e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis switch (getReceiverKind()) { 3351e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Instance: 3352e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getInstanceReceiver()->getSourceRange(); 3353e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3354e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Class: 3355e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); 3356e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3357e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperInstance: 3358e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperClass: 3359e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getSuperLoc(); 3360e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis } 3361e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 33623026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid ReceiverKind!"); 3363e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis} 3364e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 336504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 336604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 336704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 336804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 3369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 337004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 337104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 337204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 337304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 337404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 337504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 337604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) 337704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 337804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 33794df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 338004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 3381c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *Ty 3382c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall = getClassReceiver()->getAs<ObjCObjectType>()) 3383c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Ty->getInterface(); 338404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 33854df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 338604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 338704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 338804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 338904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 339004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 3391c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 339204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 3393ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis if (const ObjCObjectType *Iface 3394ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis = getSuperType()->getAs<ObjCObjectType>()) 3395ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis return Iface->getInterface(); 339604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 339704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 33980389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 339904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 3400eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 34010389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 34025f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef ObjCBridgedCastExpr::getBridgeKindName() const { 3403f85e193739c953358c865005855253af4f68a497John McCall switch (getBridgeKind()) { 3404f85e193739c953358c865005855253af4f68a497John McCall case OBC_Bridge: 3405f85e193739c953358c865005855253af4f68a497John McCall return "__bridge"; 3406f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeTransfer: 3407f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_transfer"; 3408f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeRetained: 3409f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_retained"; 3410f85e193739c953358c865005855253af4f68a497John McCall } 34113026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie 34123026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid BridgeKind!"); 3413f85e193739c953358c865005855253af4f68a497John McCall} 3414f85e193739c953358c865005855253af4f68a497John McCall 34154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ChooseExpr::isConditionTrue(const ASTContext &C) const { 3416a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getCond()->EvaluateKnownConstInt(C) != 0; 341727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 341827437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 34193b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, ArrayRef<Expr*> args, 3420bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor QualType Type, SourceLocation BLoc, 3421bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP) 3422bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 3423bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 3424561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 3425bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->containsUnexpandedParameterPack()), 34263b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) 3427bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor{ 34283b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()]; 34293b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); i++) { 3430bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 3431bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3432bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 3433bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3434561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 3435561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3436bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 3437bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3438bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3439bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs[i] = args[i]; 3440bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3441bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 3442bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3443888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 3444888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 3445888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 3446888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3447888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 344894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 344994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 34501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 3451888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3452f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3453f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 34543b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 34553b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 34563b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, 3457f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3458f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3459f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex) 3460f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3461f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getType(), 3462f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getValueKind(), 3463f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getObjectKind(), 3464f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isTypeDependent(), 3465f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isValueDependent(), 3466561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor AssocExprs[ResultIndex]->isInstantiationDependent(), 3467f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 34683b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), 34693b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), 34703b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), 34713b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { 3472f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 34733b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(AssocTypes.size() == AssocExprs.size()); 34743b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); 34753b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); 3476f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3477f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3478f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3479f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 34803b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 34813b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 34823b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, 3483f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3484f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack) 3485f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3486f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Context.DependentTy, 3487f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne VK_RValue, 3488f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne OK_Ordinary, 3489561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isTypeDependent=*/true, 3490561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isValueDependent=*/true, 3491561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isInstantiationDependent=*/true, 3492f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 34933b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), 34943b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), 34953b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc), 34963b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { 3497f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 34983b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(AssocTypes.size() == AssocExprs.size()); 34993b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); 35003b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); 3501f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3502f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 350377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 350405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 350505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 350605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3507b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler CarruthIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { 350805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 350905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 351005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 351105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 351205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 351305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 351405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3515c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 3516319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 3517ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 35181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 3519ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 35203b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 35219ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 35221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 3523f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 3524bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->isTypeDependent(), Init->isValueDependent(), 3525561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Init->isInstantiationDependent(), 3526bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->containsUnexpandedParameterPack()), 35271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 35283b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumDesignators(NumDesignators), NumSubExprs(IndexExprs.size() + 1) { 3529319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 35309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 35319ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 35327502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall child_range Child = children(); 35339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 35349ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 35359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 35369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 35379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 35389ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 3539ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 35409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 35419ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 35429ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 35439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 3544bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->isTypeDependent() || Index->isValueDependent()) 3545bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3546561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Index->isInstantiationDependent()) 3547561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3549bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->containsUnexpandedParameterPack()) 3550bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 35519ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 35529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 35539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 35549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 35559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 35569ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 35579ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 3558bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->isTypeDependent() || Start->isValueDependent() || 3559561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isTypeDependent() || End->isValueDependent()) { 3560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3561561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3562561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (Start->isInstantiationDependent() || 3563561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isInstantiationDependent()) { 3564561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3565561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 3566561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3567bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3568bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->containsUnexpandedParameterPack() || 3569bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->containsUnexpandedParameterPack()) 3570bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 35719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 35729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 35739ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 35749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 35759ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 35769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 35779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 35783b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions"); 3579ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3580ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 358105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 35821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 358305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 35843b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 358505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 358605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 3587c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 35883b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(Stmt *) * (IndexExprs.size() + 1), 8); 3589319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 35909ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 35913b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer IndexExprs, Init); 359205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 359305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 35941eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 3595d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 3596d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3597d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3598d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 3599d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3600d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3601319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 3602319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 3603d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 3604319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 3605d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 3606d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 3607d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 3608d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3609d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 361024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo BagnaraSourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { 361124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); 361224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara if (size() == 1) 361324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return DIE->getDesignator(0)->getSourceRange(); 361424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(DIE->getDesignator(0)->getStartLocation(), 361524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DIE->getDesignator(size()-1)->getEndLocation()); 361624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara} 361724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 361805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 361905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 3620d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 3621d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 362205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 3623eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 362405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 362505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 362605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 362705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 3628d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 3629d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 363005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 363105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 363205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 363305c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 363405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 363505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 363605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 363705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 363805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 363905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 364005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 364105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 36421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 364305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 364405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 364505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 364605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 364705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 364805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 364905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 36511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 365205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 365305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 365405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 365505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 365605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 365705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 365805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3659ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 3660ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 3661319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 36621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 3663ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 3664ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 3665ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 3666ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 3667ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 3668ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 3669ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 3670ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3671ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 3672ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 3673ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3674ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 3675ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 36761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 3677319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 3678ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 3679ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 3680ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 3681ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 3682ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 3683ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 3684ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3685ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 36861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 36873b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, 36885b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceLocation rparenloc) 36895b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, 3690561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, false, false), 36913b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) { 36923b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer Exprs = new (C) Stmt*[exprs.size()]; 36933b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != exprs.size(); ++i) { 3694bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isTypeDependent()) 3695bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3696bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isValueDependent()) 3697bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3698561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (exprs[i]->isInstantiationDependent()) 3699561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3700bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->containsUnexpandedParameterPack()) 3701bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3702bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 37032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 3704bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 37052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 37062ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 3707e996ffd240f20a1048179d7727a6ee3227261921John McCallconst OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { 3708e996ffd240f20a1048179d7727a6ee3227261921John McCall if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) 3709e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ewc->getSubExpr(); 371003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) 371103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor e = m->GetTemporaryExpr(); 3712e996ffd240f20a1048179d7727a6ee3227261921John McCall e = cast<CXXConstructExpr>(e)->getArg(0); 3713e996ffd240f20a1048179d7727a6ee3227261921John McCall while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 3714e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ice->getSubExpr(); 3715e996ffd240f20a1048179d7727a6ee3227261921John McCall return cast<OpaqueValueExpr>(e); 3716e996ffd240f20a1048179d7727a6ee3227261921John McCall} 3717e996ffd240f20a1048179d7727a6ee3227261921John McCall 37184b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &Context, EmptyShell sh, 37194b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs) { 37204b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = Context.Allocate(sizeof(PseudoObjectExpr) + 37214b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + numSemanticExprs) * sizeof(Expr*), 37224b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 37234b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); 37244b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 37254b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37264b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) 37274b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, shell) { 37284b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; 37294b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 37304b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37314b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &C, Expr *syntax, 37324b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantics, 37334b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) { 37344b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(syntax && "no syntactic expression!"); 37354b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics.size() && "no semantic expressions!"); 37364b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37374b9c2d235fb9449e249d74f48ecfec601650de93John McCall QualType type; 37384b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprValueKind VK; 37394b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (resultIndex == NoResult) { 37404b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = C.VoidTy; 37414b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = VK_RValue; 37424b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 37434b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(resultIndex < semantics.size()); 37444b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = semantics[resultIndex]->getType(); 37454b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = semantics[resultIndex]->getValueKind(); 37464b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary); 37474b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 37484b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37494b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = C.Allocate(sizeof(PseudoObjectExpr) + 37504b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + semantics.size()) * sizeof(Expr*), 37514b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 37524b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, 37534b9c2d235fb9449e249d74f48ecfec601650de93John McCall resultIndex); 37544b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 37554b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37564b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, 37574b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntax, ArrayRef<Expr*> semantics, 37584b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) 37594b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, 37604b9c2d235fb9449e249d74f48ecfec601650de93John McCall /*filled in at end of ctor*/ false, false, false, false) { 37614b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; 37624b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.ResultIndex = resultIndex + 1; 37634b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37644b9c2d235fb9449e249d74f48ecfec601650de93John McCall for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { 37654b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *E = (i == 0 ? syntax : semantics[i-1]); 37664b9c2d235fb9449e249d74f48ecfec601650de93John McCall getSubExprsBuffer()[i] = E; 37674b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37684b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isTypeDependent()) 37694b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.TypeDependent = true; 37704b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isValueDependent()) 37714b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ValueDependent = true; 37724b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isInstantiationDependent()) 37734b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.InstantiationDependent = true; 37744b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->containsUnexpandedParameterPack()) 37754b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ContainsUnexpandedParameterPack = true; 37764b9c2d235fb9449e249d74f48ecfec601650de93John McCall 37774b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<OpaqueValueExpr>(E)) 37784b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != 0 && 37794b9c2d235fb9449e249d74f48ecfec601650de93John McCall "opaque-value semantic expressions for pseudo-object " 37804b9c2d235fb9449e249d74f48ecfec601650de93John McCall "operations must have sources"); 37814b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 37824b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 37834b9c2d235fb9449e249d74f48ecfec601650de93John McCall 378405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 3785ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 3786ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 3787ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3788ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 3789ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 3790ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 3791ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 3792ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 3793ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 3794ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 3795ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 3796ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3797ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 379877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 379977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 380077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 3801f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne// UnaryExprOrTypeTraitExpr 3802f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneStmt::child_range UnaryExprOrTypeTraitExpr::children() { 38030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 38040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 38050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 38060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 3807f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const VariableArrayType* T = dyn_cast<VariableArrayType>( 38080518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 380963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(T), child_iterator()); 381063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 38110518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 381263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Argument.Ex, &Argument.Ex + 1); 38139ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 3814390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3815563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 381663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range ObjCMessageExpr::children() { 381763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin; 381804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 381963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(this + 1); 382063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall else 382163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(getArgs()); 382263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, 382363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); 3824563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 3825563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 3826ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral::ObjCArrayLiteral(llvm::ArrayRef<Expr *> Elements, 3827ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *Method, 3828ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3829ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCArrayLiteralClass, T, VK_RValue, OK_Ordinary, 3830ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false, false, false), 3831ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method) 3832ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3833ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **SaveElements = getElements(); 3834ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0, N = Elements.size(); I != N; ++I) { 3835ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isTypeDependent() || Elements[I]->isValueDependent()) 3836ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3837ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isInstantiationDependent()) 3838ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3839ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->containsUnexpandedParameterPack()) 3840ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3841ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3842ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SaveElements[I] = Elements[I]; 3843ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3844ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3845ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3846ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::Create(ASTContext &C, 3847ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::ArrayRef<Expr *> Elements, 3848ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 3849ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 3850ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3851ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + Elements.size() * sizeof(Expr *)); 3852ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR); 3853ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3854ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3855ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(ASTContext &C, 3856ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements) { 3857ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3858ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3859ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + NumElements * sizeof(Expr *)); 3860ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements); 3861ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3862ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3863ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::ObjCDictionaryLiteral( 3864ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 3865ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 3866ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 3867ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3868ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, T, VK_RValue, OK_Ordinary, false, false, 3869ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false), 3870ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), 3871ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek DictWithObjectsMethod(method) 3872ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3873ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *KeyValues = getKeyValues(); 3874ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *Expansions = getExpansionData(); 3875ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0; I < NumElements; I++) { 3876ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isTypeDependent() || VK[I].Key->isValueDependent() || 3877ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isTypeDependent() || VK[I].Value->isValueDependent()) 3878ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3879ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isInstantiationDependent() || 3880ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isInstantiationDependent()) 3881ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3882ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].EllipsisLoc.isInvalid() && 3883ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (VK[I].Key->containsUnexpandedParameterPack() || 3884ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->containsUnexpandedParameterPack())) 3885ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3886ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3887ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Key = VK[I].Key; 3888ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Value = VK[I].Value; 3889ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansions) { 3890ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].EllipsisLoc = VK[I].EllipsisLoc; 3891ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].NumExpansions) 3892ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = *VK[I].NumExpansions + 1; 3893ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek else 3894ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = 0; 3895ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3896ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3897ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3898ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3899ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 3900ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::Create(ASTContext &C, 3901ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 3902ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 3903ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 3904ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 3905ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 3906ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 3907ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * VK.size(); 3908ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3909ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 3910ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * VK.size() + ExpansionsSize); 3911ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR); 3912ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3913ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3914ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 3915ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::CreateEmpty(ASTContext &C, unsigned NumElements, 3916ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) { 3917ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 3918ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 3919ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * NumElements; 3920ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 3921ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * NumElements + ExpansionsSize); 3922ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(EmptyShell(), NumElements, 3923ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions); 3924ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3925ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3926ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCSubscriptRefExpr *ObjCSubscriptRefExpr::Create(ASTContext &C, 3927ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 3928ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 3929ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 3930ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 3931ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB) { 3932ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCSubscriptRefExpr)); 3933ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCSubscriptRefExpr(base, key, T, VK_LValue, 3934ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek OK_ObjCSubscript, 3935ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getMethod, setMethod, RB); 3936ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3937dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 39383b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerAtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, 3939dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType t, AtomicOp op, SourceLocation RP) 3940dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, 3941dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman false, false, false, false), 39423b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) 3943dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman{ 39443b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); 39453b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); i++) { 3946dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isTypeDependent()) 3947dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.TypeDependent = true; 3948dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isValueDependent()) 3949dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ValueDependent = true; 3950dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isInstantiationDependent()) 3951dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.InstantiationDependent = true; 3952dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->containsUnexpandedParameterPack()) 3953dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ContainsUnexpandedParameterPack = true; 3954dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 3955dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs[i] = args[i]; 3956dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 3957dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman} 3958e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 3959e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smithunsigned AtomicExpr::getNumSubExprs(AtomicOp Op) { 3960e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith switch (Op) { 3961ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_init: 3962ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_load: 3963ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load_n: 3964e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 2; 3965ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3966ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_store: 3967ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_exchange: 3968ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load: 3969ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store: 3970ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store_n: 3971ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange_n: 3972ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_add: 3973ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_sub: 3974ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_and: 3975ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_or: 3976ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_xor: 3977ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_add: 3978ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_sub: 3979ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_and: 3980ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_or: 3981ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_xor: 398251b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_fetch_nand: 3983ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_add_fetch: 3984ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_sub_fetch: 3985ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_and_fetch: 3986ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_or_fetch: 3987ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_xor_fetch: 398851b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_nand_fetch: 3989e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 3; 3990ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3991ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange: 3992ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 4; 3993ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3994ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_strong: 3995ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_weak: 3996e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 5; 3997ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 3998ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange: 3999ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange_n: 4000ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 6; 4001e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith } 4002e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith llvm_unreachable("unknown atomic op"); 4003e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith} 4004