Expr.cpp revision b063ef0222a99ee168631afa7b5a882d494b8fde
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 14a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h" 152eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h" 162fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/Attr.h" 1798cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h" 182fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/DeclObjC.h" 19aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 2025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor#include "clang/AST/EvaluatedExprVisitor.h" 212fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/Expr.h" 222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/ExprCXX.h" 2319cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h" 251b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 263f6f51e28231f65de9c2dd150a2d757b2162cfa3Jordan Rose#include "clang/Basic/CharInfo.h" 2708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Basic/SourceManager.h" 28da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 292fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Lex/Lexer.h" 302fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Lex/LiteralSupport.h" 312fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Sema/SemaDiagnostic.h" 32cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 34ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 3564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman#include <cstring> 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 388d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindolaconst CXXRecordDecl *Expr::getBestDynamicClassType() const { 39632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola const Expr *E = ignoreParenBaseCasts(); 400b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 410b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola QualType DerivedType = E->getType(); 420b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola if (const PointerType *PTy = DerivedType->getAs<PointerType>()) 430b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola DerivedType = PTy->getPointeeType(); 440b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 45251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola if (DerivedType->isDependentType()) 46251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola return NULL; 47251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola 480b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola const RecordType *Ty = DerivedType->castAs<RecordType>(); 490b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola Decl *D = Ty->getDecl(); 500b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola return cast<CXXRecordDecl>(D); 510b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola} 520b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 530a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindolaconst Expr * 540a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael EspindolaExpr::skipRValueSubobjectAdjustments( 550a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { 560a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr *E = this; 570a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola while (true) { 580a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = E->IgnoreParens(); 590a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 600a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { 610a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if ((CE->getCastKind() == CK_DerivedToBase || 620a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola CE->getCastKind() == CK_UncheckedDerivedToBase) && 630a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E->getType()->isRecordType()) { 640a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = CE->getSubExpr(); 650a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola CXXRecordDecl *Derived 660a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola = cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl()); 670a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Adjustments.push_back(SubobjectAdjustment(CE, Derived)); 680a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola continue; 690a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 700a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 710a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (CE->getCastKind() == CK_NoOp) { 720a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = CE->getSubExpr(); 730a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola continue; 740a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 750a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { 760a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (!ME->isArrow() && ME->getBase()->isRValue()) { 770a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola assert(ME->getBase()->getType()->isRecordType()); 780a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) { 790a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = ME->getBase(); 800a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Adjustments.push_back(SubobjectAdjustment(Field)); 810a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola continue; 820a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 830a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 840a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 850a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (BO->isPtrMemOp()) { 86ef4b666e841e3917385892713612888ec6c3a056Rafael Espindola assert(BO->getRHS()->isRValue()); 870a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = BO->getLHS(); 880a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const MemberPointerType *MPT = 890a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola BO->getRHS()->getType()->getAs<MemberPointerType>(); 900a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); 910a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 920a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 930a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 940a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // Nothing changed. 950a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola break; 960a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 970a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola return E; 980a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola} 990a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1000a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindolaconst Expr * 1010a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael EspindolaExpr::findMaterializedTemporary(const MaterializeTemporaryExpr *&MTE) const { 1020a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr *E = this; 1030a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // Look through single-element init lists that claim to be lvalues. They're 1040a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // just syntactic wrappers in this case. 1050a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const InitListExpr *ILE = dyn_cast<InitListExpr>(E)) { 1060a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (ILE->getNumInits() == 1 && ILE->isGLValue()) 1070a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = ILE->getInit(0); 1080a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 1090a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1100a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // Look through expressions for materialized temporaries (for now). 1110a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const MaterializeTemporaryExpr *M 1120a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola = dyn_cast<MaterializeTemporaryExpr>(E)) { 1130a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola MTE = M; 1140a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = M->GetTemporaryExpr(); 1150a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 1160a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1170a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const CXXDefaultArgExpr *DAE = dyn_cast<CXXDefaultArgExpr>(E)) 1180a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = DAE->getExpr(); 1190a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola return E; 1200a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola} 1210a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1222b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 1232b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 1242b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 1252b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 1262b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 127f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 128f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1292b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 130f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (E->getType()->isBooleanType()) return true; 131c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 132f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!E->getType()->isIntegralOrEnumerationType()) return false; 133c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 134f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { 1352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 1362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 1372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 1382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 1392b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 1402b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 1412b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 142c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1436907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 1446907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 145f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) 1462b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 148f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 1492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 1502b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 1512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 1522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 1532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 1542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 1552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 1562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 1572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 1582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 1592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 160c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 1622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 1632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 1642b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 1652b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 1662b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 1702b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 1712b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 1722b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 174f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) 1752b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 1762b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 177c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 1792b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 1802b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 18163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// Amusing macro metaprogramming hack: check whether a class provides 18263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// a more specific implementation of getExprLoc(). 18390e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// 18490e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// See also Stmt.cpp:{getLocStart(),getLocEnd()}. 18563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallnamespace { 18663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class provides a custom 18763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// implementation of getExprLoc. 18863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E, class T> 18963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 19063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (T::*v)() const) { 19163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getExprLoc(); 19263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 19463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class doesn't provide 19563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// a custom implementation of getExprLoc. Overload resolution 19663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// should pick it over the implementation above because it's 19763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// more specialized according to function template partial ordering. 19863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E> 19963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 20063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (Expr::*v)() const) { 20190e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar return static_cast<const E*>(expr)->getLocStart(); 20263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 20363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 20463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 20563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallSourceLocation Expr::getExprLoc() const { 20663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall switch (getStmtClass()) { 20763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 20863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(type) 20963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define STMT(type, base) \ 21063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; 21163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define EXPR(type, base) \ 21263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); 21363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#include "clang/AST/StmtNodes.inc" 21463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 21563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall llvm_unreachable("unknown statement kind"); 21663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 21763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 222561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// \brief Compute the type-, value-, and instantiation-dependence of a 223561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// declaration reference 224d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// based on the declaration being referenced. 2253d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarstatic void computeDeclRefDependence(ASTContext &Ctx, NamedDecl *D, QualType T, 226d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &TypeDependent, 227561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &ValueDependent, 228561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 229d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = false; 230d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = false; 231561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = false; 2320da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 2330da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 2340da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 2350da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 236c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 2370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 2380da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 2390da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 240d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2410da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 2420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 243d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (T->isDependentType()) { 244d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 245d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 246561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 247d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 248561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (T->isInstantiationDependentType()) { 249561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 2500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 251d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 253d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (D->getDeclName().getNameKind() 254561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor == DeclarationName::CXXConversionFunctionName) { 255561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualType T = D->getDeclName().getCXXNameType(); 256561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isDependentType()) { 257561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeDependent = true; 258561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ValueDependent = true; 259561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 260561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return; 261561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 262561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 263561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isInstantiationDependentType()) 264561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 2650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 266561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 2670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 268d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<NonTypeTemplateParmDecl>(D)) { 269d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 270561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 271d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 272d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 273d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2740da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 2750da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 276db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - a constant with literal type and is initialized with an 277db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11]. 278db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - FIXME: Missing from the standard: 279db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // - an entity with reference type and is initialized with an 280db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11] 281d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 28280ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if ((Ctx.getLangOpts().CPlusPlus11 ? 283db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isLiteralType() : 284db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isIntegralOrEnumerationType()) && 2854ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie (Var->getType().isConstQualified() || 286db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isReferenceType())) { 28731310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 288561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Init->isValueDependent()) { 289d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 290561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 291561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 292db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 293db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith 294bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 295bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 296bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 297db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith if (Var->isStaticDataMember() && 298db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getDeclContext()->isDependentContext()) { 299d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 300561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 301561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 302d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 303d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 304d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 305d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 306bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 307bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 308bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 309d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { 310d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 311561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 312db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 313d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor} 314d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 3153d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarvoid DeclRefExpr::computeDependence(ASTContext &Ctx) { 316d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 317d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 318561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 3193d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent, 3203d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar ValueDependent, InstantiationDependent); 321d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 322d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 323d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An id-expression is type-dependent if it contains: 324d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 325d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // and 326d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 327d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 328d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An identifier is value-dependent if it is: 329d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (!TypeDependent && !ValueDependent && 330d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor hasExplicitTemplateArgs() && 331d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 332d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getTemplateArgs(), 333561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor getNumTemplateArgs(), 334561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) { 335d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 336d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 337561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 338d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 339d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 340d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 341d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 342561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = InstantiationDependent; 343d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 34410738d36b150aa65206890c1c845cdba076e4200Douglas Gregor // Is the declaration a parameter pack? 345d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (getDecl()->isParameterPack()) 3461fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3470da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 3480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 3493d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel DunbarDeclRefExpr::DeclRefExpr(ASTContext &Ctx, 3503d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NestedNameSpecifierLoc QualifierLoc, 351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 352f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ValueDecl *D, bool RefersToEnclosingLocal, 353f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const DeclarationNameInfo &NameInfo, 3543aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 357561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 358cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 359cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; 3607e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth if (QualifierLoc) 3616857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth getInternalQualifierLoc() = QualifierLoc; 3623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; 3633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 3643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth getInternalFoundDecl() = FoundD; 365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo 366e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0; 367f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExprBits.RefersToEnclosingLocal = RefersToEnclosingLocal; 368561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TemplateArgs) { 369561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 370561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 371561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, 373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 375e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 376561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 377561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(true); 378e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 379e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 380561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 381b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer DeclRefExprBits.HadMultipleCandidates = 0; 382b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer 3833d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDependence(Ctx); 3842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 386a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 38740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 388e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 389dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 390f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 391a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 3920da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 393f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 396e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return Create(Context, QualifierLoc, TemplateKWLoc, D, 397f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 3982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 3993aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth T, VK, FoundD, TemplateArgs); 4002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 4012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4022577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 40340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 404e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 4052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 406f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 4072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 4082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 409f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 4103aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 4112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 4123aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth // Filter out cases where the found Decl is the same as the value refenenced. 4133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (D == FoundD) 4143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth FoundD = 0; 4153aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 416a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 41740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc != 0) 4186857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 4193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 4203aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 421d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 422e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); 423e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 4253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 4263248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 4273d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, 428f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 4293d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NameInfo, FoundD, TemplateArgs, T, VK); 430a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 431a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler CarruthDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, 433def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 4343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 435e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 436663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 437663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 438663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 4396857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 4403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (HasFoundDecl) 4413aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 442e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (HasTemplateKWAndArgsInfo) 443e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 4443aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 4453248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 446663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 447663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 448663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 449396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocStart() const { 450396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasQualifier()) 451396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 452396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocStart(); 453396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 454396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocEnd() const { 455396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 456396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getRAngleLoc(); 457396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocEnd(); 458396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 459a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4603a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 4613a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 462848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 463848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 464848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 4653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 466848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 4673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 4683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 469f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 4703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 4713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 473848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 4743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 4754eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 4764eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 4773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4794e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie PrintingPolicy Policy(Context.getLangOpts()); 480b063ef0222a99ee168631afa7b5a882d494b8fdeBenjamin Kramer std::string Proto; 481abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream POut(Proto); 482b063ef0222a99ee168631afa7b5a882d494b8fdeBenjamin Kramer FD->printQualifiedName(POut, Policy); 4833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 484abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionDecl *Decl = FD; 485abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) 486abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Decl = Pattern; 487abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); 4883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 4893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 4903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 4913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 492abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << "("; 4933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 494abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) { 4953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 4967ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis POut << Decl->getParamDecl(i)->getType().stream(Policy); 4973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 5003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 5013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 5023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 504abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << ")"; 5053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5064eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 5074ae711b5ef292378d5b88cede3d4b708174053e2Argyrios Kyrtzidis const FunctionType *FT = MD->getType()->castAs<FunctionType>(); 5084ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie if (FT->isConst()) 509abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " const"; 5104ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie if (FT->isVolatile()) 511abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " volatile"; 512abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor RefQualifierKind Ref = MD->getRefQualifier(); 513abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Ref == RQ_LValue) 514abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &"; 515abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor else if (Ref == RQ_RValue) 516abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &&"; 517abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 518abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 519abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; 520abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor SpecsTy Specs; 521abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const DeclContext *Ctx = FD->getDeclContext(); 522abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor while (Ctx && isa<NamedDecl>(Ctx)) { 523abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const ClassTemplateSpecializationDecl *Spec 524abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); 525abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Spec && !Spec->isExplicitSpecialization()) 526abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Specs.push_back(Spec); 527abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Ctx = Ctx->getParent(); 528abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 529abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 530abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor std::string TemplateParams; 531abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream TOut(TemplateParams); 532abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend(); 533abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor I != E; ++I) { 534abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList *Params 535abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = (*I)->getSpecializedTemplate()->getTemplateParameters(); 536abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList &Args = (*I)->getTemplateArgs(); 537abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args.size()); 538abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) { 539abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 540abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 541abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 542abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args.get(i).print(Policy, TOut); 543abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 544abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 5454eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 5464eadcc569223135e13353c9381b448986e3f7053Sam Weinig 547abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor FunctionTemplateSpecializationInfo *FSI 548abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FD->getTemplateSpecializationInfo(); 549abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (FSI && !FSI->isExplicitSpecialization()) { 550abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList* Params 551abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FSI->getTemplate()->getTemplateParameters(); 552abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList* Args = FSI->TemplateArguments; 553abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args->size()); 554abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Params->size(); i != e; ++i) { 555abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 556abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 557abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 558abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args->get(i).print(Policy, TOut); 559abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 560abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 561abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 562abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 563abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut.flush(); 564abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (!TemplateParams.empty()) { 565abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor // remove the trailing comma and space 566abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TemplateParams.resize(TemplateParams.size() - 2); 567abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " [" << TemplateParams << "]"; 568abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 569abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 570abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut.flush(); 571abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 5723a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 5733a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 5743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 5763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 5783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 581f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 5823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 5833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 5843a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 585b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 586b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 587b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 588b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 589b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer Out << *ID; 590b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 5913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 592900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 593f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramer Out << '(' << *CID << ')'; 594900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 5953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 5963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 5973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 5983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 6003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 6013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 6023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 6033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 6043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 6053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 6063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 6073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 6083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 6099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 6109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 6119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 6129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 6149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 6159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 6169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 6179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 6189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 6199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 6209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 6219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 6229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 6239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 625478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerIntegerLiteral::IntegerLiteral(ASTContext &C, const llvm::APInt &V, 626478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer QualType type, SourceLocation l) 627478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 628478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer false, false), 629478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer Loc(l) { 630478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 631478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer assert(V.getBitWidth() == C.getIntWidth(type) && 632478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer "Integer type is not the correct size for constant."); 633478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer setValue(C, V); 634478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 635478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 6369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 6379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 6389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 6399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 6409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 6439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 6449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 6459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 647478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerFloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, 648478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer bool isexact, QualType Type, SourceLocation L) 649478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 650478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer false, false), Loc(L) { 6519ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover setSemantics(V.getSemantics()); 652478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsExact = isexact; 653478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer setValue(C, V); 654478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 655478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 656478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerFloatingLiteral::FloatingLiteral(ASTContext &C, EmptyShell Empty) 657478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(FloatingLiteralClass, Empty) { 6589ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover setRawSemantics(IEEEhalf); 659478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsExact = false; 660478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 661478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 6629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 6639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 6649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 6659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 6669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 6699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 67031dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return new (C) FloatingLiteral(C, Empty); 6719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6739ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northoverconst llvm::fltSemantics &FloatingLiteral::getSemantics() const { 6749ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover switch(FloatingLiteralBits.Semantics) { 6759ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEhalf: 6769ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEhalf; 6779ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEsingle: 6789ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEsingle; 6799ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEdouble: 6809ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEdouble; 6819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case x87DoubleExtended: 6829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::x87DoubleExtended; 6839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEquad: 6849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEquad; 6859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case PPCDoubleDouble: 6869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::PPCDoubleDouble; 6879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover } 6889ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover llvm_unreachable("Unrecognised floating semantics"); 6899ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover} 6909ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 6919ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northovervoid FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) { 6929ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover if (&Sem == &llvm::APFloat::IEEEhalf) 6939ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEhalf; 6949ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::IEEEsingle) 6959ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEsingle; 6969ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::IEEEdouble) 6979ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEdouble; 6989ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::x87DoubleExtended) 6999ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = x87DoubleExtended; 7009ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::IEEEquad) 7019ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEquad; 7029ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::PPCDoubleDouble) 7039ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = PPCDoubleDouble; 7049ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else 7059ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover llvm_unreachable("Unknown floating semantics"); 7069ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover} 7079ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 708da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 709da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 710da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 711da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 712da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 713ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 714ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 715ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 716da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 717da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 718da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 7190fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewyckyint StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { 720fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman int CharByteWidth = 0; 7210fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky switch(k) { 72264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Ascii: 72364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF8: 7240fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getCharWidth(); 72564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 72664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Wide: 7270fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getWCharWidth(); 72864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 72964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF16: 7300fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar16Width(); 73164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 73264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF32: 7330fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar32Width(); 734fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman break; 73564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 73664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); 73764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman CharByteWidth /= 8; 7380fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) 73964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "character byte widths supported are 1, 2, and 4 only"); 74064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return CharByteWidth; 74164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman} 74264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 7435f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, 7445cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind Kind, bool Pascal, QualType Ty, 7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 746a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 7472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 7482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 7492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 7502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 7513248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 7522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 75564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->setString(C,Str,Kind,Pascal); 75664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 7572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 7582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 760726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 7612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 7622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 763726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 764726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 765673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 766673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 767673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 7683248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 769673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 77064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->CharByteWidth = 0; 77164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->Length = 0; 772673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 773673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 774673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 775673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 776ae54121c15cdd38f415f6fdda48215ab5e4dcee1Alexander Kornienkovoid StringLiteral::outputString(raw_ostream &OS) const { 7778ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (getKind()) { 7788ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case Ascii: break; // no prefix. 7798ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case Wide: OS << 'L'; break; 7808ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF8: OS << "u8"; break; 7818ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF16: OS << 'u'; break; 7828ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF32: OS << 'U'; break; 7838ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7848ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '"'; 7858ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu static const char Hex[] = "0123456789ABCDEF"; 7868ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7878ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu unsigned LastSlashX = getLength(); 7888ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu for (unsigned I = 0, N = getLength(); I != N; ++I) { 7898ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (uint32_t Char = getCodeUnit(I)) { 7908ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu default: 7918ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // FIXME: Convert UTF-8 back to codepoints before rendering. 7928ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7938ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Convert UTF-16 surrogate pairs back to codepoints before rendering. 7948ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Leave invalid surrogates alone; we'll use \x for those. 7958ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (getKind() == UTF16 && I != N - 1 && Char >= 0xd800 && 7968ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Char <= 0xdbff) { 7978ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu uint32_t Trail = getCodeUnit(I + 1); 7988ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Trail >= 0xdc00 && Trail <= 0xdfff) { 7998ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00); 8008ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu ++I; 8018ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8028ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8038ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8048ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Char > 0xff) { 8058ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // If this is a wide string, output characters over 0xff using \x 8068ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a 8078ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // codepoint: use \x escapes for invalid codepoints. 8088ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (getKind() == Wide || 8098ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) { 8108ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // FIXME: Is this the best way to print wchar_t? 8118ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\x"; 8128ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu int Shift = 28; 8138ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu while ((Char >> Shift) == 0) 8148ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Shift -= 4; 8158ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu for (/**/; Shift >= 0; Shift -= 4) 8168ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << Hex[(Char >> Shift) & 15]; 8178ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu LastSlashX = I; 8188ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 8198ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8208ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8218ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Char > 0xffff) 8228ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\U00" 8238ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 20) & 15] 8248ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 16) & 15]; 8258ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu else 8268ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\u"; 8278ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << Hex[(Char >> 12) & 15] 8288ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 8) & 15] 8298ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 4) & 15] 8308ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 0) & 15]; 8318ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 8328ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8338ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8348ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // If we used \x... for the previous character, and this character is a 8358ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // hexadecimal digit, prevent it being slurped as part of the \x. 8368ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (LastSlashX + 1 == I) { 8378ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (Char) { 8388ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '0': case '1': case '2': case '3': case '4': 8398ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '5': case '6': case '7': case '8': case '9': 8408ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 8418ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 8428ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\"\""; 8438ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8448ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8458ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8468ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu assert(Char <= 0xff && 8478ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu "Characters above 0xff should already have been handled."); 8488ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8493f6f51e28231f65de9c2dd150a2d757b2162cfa3Jordan Rose if (isPrintable(Char)) 8508ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << (char)Char; 8518ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu else // Output anything hard as an octal escape. 8528ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '\\' 8538ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 6) & 7)) 8548ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 3) & 7)) 8558ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 0) & 7)); 8568ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 8578ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Handle some common non-printable cases to make dumps prettier. 8588ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\\': OS << "\\\\"; break; 8598ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '"': OS << "\\\""; break; 8608ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\n': OS << "\\n"; break; 8618ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\t': OS << "\\t"; break; 8628ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\a': OS << "\\a"; break; 8638ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\b': OS << "\\b"; break; 8648ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8658ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8668ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '"'; 8678ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu} 8688ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 86964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedmanvoid StringLiteral::setString(ASTContext &C, StringRef Str, 87064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal) { 87164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman //FIXME: we assume that the string data comes from a target that uses the same 87264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman // code unit size and endianess for the type of string. 87364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->Kind = Kind; 87464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->IsPascal = IsPascal; 87564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 8760fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind); 87764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((Str.size()%CharByteWidth == 0) 87864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "size of data must be multiple of CharByteWidth"); 87964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman Length = Str.size()/CharByteWidth; 88064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 88164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman switch(CharByteWidth) { 88264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 1: { 88364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman char *AStrData = new (C) char[Length]; 88466dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 88564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asChar = AStrData; 88664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 88764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 88864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 2: { 88964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint16_t *AStrData = new (C) uint16_t[Length]; 89066dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 89164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt16 = AStrData; 89264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 89364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 89464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 4: { 89564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t *AStrData = new (C) uint32_t[Length]; 89666dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 89764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt32 = AStrData; 89864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 89964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 90064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman default: 90164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(false && "unsupported CharByteWidth"); 90264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 903673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 904673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 90508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 90608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 90708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 90808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 90908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 91008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 91108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 91208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 91308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 91408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 915df9ef1bc8c3780307ab2ed81bf5e31c23310b936Richard Smith assert((Kind == StringLiteral::Ascii || Kind == StringLiteral::UTF8) && 916df9ef1bc8c3780307ab2ed81bf5e31c23310b936Richard Smith "Only narrow string literals are currently supported"); 9175cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 91808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 91908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 92008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 92108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 92208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 92308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 92408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 92508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 92608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 92708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 92808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 92908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 93008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 93108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 93208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 9335f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 93408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 93508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 93608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 93708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 93808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 93908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 940df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, 941df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Buffer.begin(), StrData, Buffer.end()); 94208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 94308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 94408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 94508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 94608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 94708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 94808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 94908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 95008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 951935a70c1e76d78985f20d422940280161b941299Hans Wennborg (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { 95208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 95308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 95408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 95508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 95608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 95708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 95808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 95908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 96008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 96108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 96208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 96308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 96408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 96508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 96608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 9690bea86307eb8c16339315a1e261fc490eb505c5bDavid BlaikieStringRef UnaryOperator::getOpcodeStr(Opcode Op) { 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 9712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 9722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 9732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 9742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 9752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 9762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 9772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 9782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 9792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 9802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 9812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 9822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 9832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 985561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("Unknown unary operator"); 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 989bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 990bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 991b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("No unary operator for overloaded function"); 9922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 9932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 9942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 9952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 9962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 9972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 9982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 9992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 1000bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 1001bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 1002bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1003bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 1004bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 10052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 10062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 10072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 10082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 10092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 10102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 10112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 10122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 1013bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 1014bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 1015bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 1016bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1017bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1022cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 10233b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 1024f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 1025f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 1026bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 1027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 1028561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 1029bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 10303b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumArgs(args.size()) { 10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10323b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()+PREARGS_START+NumPreArgs]; 1033b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 10343b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); ++i) { 1035bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 1036bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 1037bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 1038bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 1039561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 1040561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1041bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 1042bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1043bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1044cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; 1045bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 1046668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 1047cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 1048b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 1049b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 1050e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 10513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerCallExpr::CallExpr(ASTContext& C, Expr *fn, ArrayRef<Expr*> args, 1052f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 1053f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 1054bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 1055bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 1056561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 1057bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 10583b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumArgs(args.size()) { 1059668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 10603b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()+PREARGS_START]; 106177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 10623b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); ++i) { 1063bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 1064bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 1065bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 1066bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 1067561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 1068561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1069bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 1070bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1071bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1072cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START] = args[i]; 1073bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 1074668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 1075cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 1081bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // FIXME: Why do we allocate this? 1082cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START]; 1083cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 1084cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne} 1085cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1086cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, 1087cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne EmptyShell Empty) 1088cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 1089cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // FIXME: Why do we allocate this? 1090cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; 1091cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 10921f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 10931f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1094d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 1095e8683d6d389def2fce229325435ba3c2b3f75492John McCall Expr *CEE = getCallee()->IgnoreParenImpCasts(); 10961ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 10971ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor while (SubstNonTypeTemplateParmExpr *NTTP 10981ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { 10991ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor CEE = NTTP->getReplacement()->IgnoreParenCasts(); 11001ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor } 11011ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 1102200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 1103200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 1104200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 1105200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 1106200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 1107200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 1108200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 1109200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 11106346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 1111d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 1112cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 1113cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 1114a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1115a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 1116a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 1117a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1118d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 1119caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 1120d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 1121d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1122d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 1123d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 1124d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 11258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 1126d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 1127d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 11281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1129d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 1130d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 1131d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 1132d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 1133d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 1134d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 1135d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 1136cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs = getNumPreArgs(); 1137cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; 1138d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 1139cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) 1140d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 1141d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 1142cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; 1143cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne i != NumArgs+PREARGS_START+NumPreArgs; ++i) 1144d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114688c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 1147d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 1148d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 1149d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 1150d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 1151cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1152cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 1153180f47959a066795cc0f409433023af448bb0328Richard Smithunsigned CallExpr::isBuiltinCall() const { 1154c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 1156c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 1157c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 1158c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 1159cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1161c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 1162c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 1163cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1165bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 1166bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 1167cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11694fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 11704fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 11714fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 11727814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 1173cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 1174bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 1175ba57183965f117279342903edec19766e478c9a8Richard Smithbool CallExpr::isUnevaluatedBuiltinCall(ASTContext &Ctx) const { 1176ba57183965f117279342903edec19766e478c9a8Richard Smith if (unsigned BI = isBuiltinCall()) 1177ba57183965f117279342903edec19766e478c9a8Richard Smith return Ctx.BuiltinInfo.isUnevaluated(BI); 1178ba57183965f117279342903edec19766e478c9a8Richard Smith return false; 1179ba57183965f117279342903edec19766e478c9a8Richard Smith} 1180ba57183965f117279342903edec19766e478c9a8Richard Smith 11816dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 11826dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 11836217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 11846dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 11856217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 11866dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 1187864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) 1188864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // This should never be overloaded and so should never return null. 1189864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall CalleeType = Expr::findBoundMemberType(getCallee()); 11905291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 1191864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall const FunctionType *FnType = CalleeType->castAs<FunctionType>(); 11926dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 11936dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 1194cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 11958fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocStart() const { 11968fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 119765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return cast<CXXOperatorCallExpr>(this)->getLocStart(); 11988fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 11998fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation begin = getCallee()->getLocStart(); 12008fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (begin.isInvalid() && getNumArgs() > 0) 12018fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar begin = getArg(0)->getLocStart(); 12028fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return begin; 12038fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 12048fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocEnd() const { 12058fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 120665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return cast<CXXOperatorCallExpr>(this)->getLocEnd(); 12078fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 12088fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation end = getRParenLoc(); 12098fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (end.isInvalid() && getNumArgs() > 0) 12108fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar end = getArg(getNumArgs() - 1)->getLocEnd(); 12118fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return end; 12128fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 12132882eca5a184c78f793188083f6ce539740a5cf2John McCall 1214c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 12158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 1216c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 12173b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, 12183b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, 12198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 12208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 12213b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(OffsetOfNode) * comps.size() + 12223b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(Expr*) * exprs.size()); 12238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12243b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, 12253b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer RParenLoc); 12268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 12298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 12308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 12318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 12328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 12338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 12348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1236c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 12383b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, 12398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 1240f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 1241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 1242bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType(), 1243561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tsi->getType()->isInstantiationDependentType(), 1244bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tsi->getType()->containsUnexpandedParameterPack()), 1245c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 12463b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumComps(comps.size()), NumExprs(exprs.size()) 12478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 12483b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != comps.size(); ++i) { 12493b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer setComponent(i, comps[i]); 12508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1251c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != exprs.size(); ++i) { 12533b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer if (exprs[i]->isTypeDependent() || exprs[i]->isValueDependent()) 1254bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 12553b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer if (exprs[i]->containsUnexpandedParameterPack()) 1256bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1257bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 12583b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer setIndexExpr(i, exprs[i]); 12598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 12638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 12648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 12658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 1266c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 12688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 127140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1272e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1273f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 1274161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 12752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 1276d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1277f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 1278f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 1279f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 128083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 12816bb8017bb9e828d118e15e59d71c66bba323c364John McCall 128240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor bool hasQualOrFound = (QualifierLoc || 1283161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 1284161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 12856bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 12866bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1288d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 1289e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(targs->size()); 1290e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 1291e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12933248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 1294f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 1295f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 12966bb8017bb9e828d118e15e59d71c66bba323c364John McCall 12976bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 129840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor // FIXME: Wrong. We should be looking at the member declaration we found. 129940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { 13006bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 13016bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 1302561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1303561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1304561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (QualifierLoc && 1305561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) 1306561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1307561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 13086bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 13096bb8017bb9e828d118e15e59d71c66bba323c364John McCall 13106bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 131140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NQ->QualifierLoc = QualifierLoc; 13126bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 13136bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 13146bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1315e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->HasTemplateKWAndArgsInfo = (targs || TemplateKWLoc.isValid()); 1316e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 13176bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 1318561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 1319561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 1320561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 1321e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *targs, 1322e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 1323e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 1324e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 1325561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 1326561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1327e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 1328e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 13296bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 13306bb8017bb9e828d118e15e59d71c66bba323c364John McCall 13316bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 133283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 133383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1334396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocStart() const { 133575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (isImplicitAccess()) { 133675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (hasQualifier()) 1337396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 1338396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 133975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 1340e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1341396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // FIXME: We don't want this to happen. Rather, we should be able to 1342396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // detect all kinds of implicit accesses more cleanly. 1343396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar SourceLocation BaseStartLoc = getBase()->getLocStart(); 1344396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (BaseStartLoc.isValid()) 1345396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return BaseStartLoc; 1346396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 1347396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 1348396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocEnd() const { 134913fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); 1350396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 135113fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara EndLoc = getRAngleLoc(); 135213fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara else if (EndLoc.isInvalid()) 135313fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara EndLoc = getBase()->getLocEnd(); 135413fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara return EndLoc; 135575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 135675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 13571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCallvoid CastExpr::CheckCastConsistency() const { 13581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall switch (getCastKind()) { 13591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBase: 13601d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UncheckedDerivedToBase: 13611d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBaseMemberPointer: 13621d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerived: 13631d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerivedMemberPointer: 13641d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 13651d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 13661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 13681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 13691d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isPointerType()); 13701d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13711d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13721d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 13731d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 13741d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isBlockPointerType()); 13751d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13761d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13774d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 13784d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getType()->isMemberPointerType()); 13794d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getSubExpr()->getType()->isMemberPointerType()); 13804d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall goto CheckNoBasePath; 13814d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 13821d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BitCast: 13831d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Arbitrary casts to C pointer types count as bitcasts. 13841d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Otherwise, we should only have block and ObjC pointer casts 13851d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // here if they stay within the type kind. 13861d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (!getType()->isPointerType()) { 13871d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType() == 13881d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isObjCObjectPointerType()); 13891d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType() == 13901d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isBlockPointerType()); 13911d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 13921d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13931d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13941d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_AnyPointerToBlockPointerCast: 13951d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType()); 13961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isAnyPointerType() && 13971d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall !getSubExpr()->getType()->isBlockPointerType()); 13981d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13991d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1400ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1401ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getType()->isBlockPointerType()); 1402ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getSubExpr()->getType()->isBlockPointerType()); 1403ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor goto CheckNoBasePath; 1404a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 1405a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_FunctionToPointerDecay: 1406a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman assert(getType()->isPointerType()); 1407a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman assert(getSubExpr()->getType()->isFunctionType()); 1408a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman goto CheckNoBasePath; 1409a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 14101d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // These should not have an inheritance path. 14111d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dynamic: 14121d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToUnion: 14131d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ArrayToPointerDecay: 14141d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToMemberPointer: 14151d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToPointer: 14161d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ConstructorConversion: 14171d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToPointer: 14181d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToIntegral: 14191d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToVoid: 14201d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_VectorSplat: 14211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralCast: 14221d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToFloating: 14231d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToIntegral: 14241d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingCast: 14251d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ObjCObjectLValueCast: 14261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingRealToComplex: 14271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToReal: 14281d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexCast: 14291d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToIntegralComplex: 14301d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralRealToComplex: 14311d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToReal: 14321d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexCast: 14331d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToFloatingComplex: 143433e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 143533e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 143633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 143733e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 1438e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case CK_ZeroToOCLEvent: 14391d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 14401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 14411d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 14421d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dependent: 14431d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueToRValue: 14441d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NoOp: 14457a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 14467a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 14471d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToBoolean: 14481d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToBoolean: 14491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToBoolean: 14501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_MemberPointerToBoolean: 14511d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToBoolean: 14521d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToBoolean: 14531d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueBitCast: // -> bool& 14541d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UserDefinedConversion: // operator bool() 1455a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_BuiltinFnToFnPtr: 14561d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CheckNoBasePath: 14571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 14581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 14591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 14601d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall} 14611d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1462f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 1463f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 1464daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 1465daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 14662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 1467f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 14682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 1469e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 14700ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 14710ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall return "LValueToRValue"; 14722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 1473f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 14742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 147511de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 14762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 1477f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 14782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 147923cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 14802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 1481f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 14822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 1483f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 14842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 1485f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 14862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 1487f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 14882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 1489f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 1490404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 1491404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 14922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 1493f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 14942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 14951a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 14964d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 14974d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall return "ReinterpretMemberPointer"; 14982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 1499f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 15002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 1501f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 15022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 15037f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 15042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 15057f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 1506daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 1507daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 15082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 1509ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 15102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 151116a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 15122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 151382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 1514daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 1515daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 15162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 151782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 15182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 151982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 15202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 1521c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 1522daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 1523daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 15242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 1525bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 15261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 15271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "CPointerToObjCPointerCast"; 15281d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 15291d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "BlockPointerToObjCPointerCast"; 15302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 15313b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 15322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 1533569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 15342bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 15352bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 1536f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 1537f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 1538f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 1539f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 15402bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 15412bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 1542f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 1543f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 15442bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 15452bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 1546f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 1547f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 1548f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 1549f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 15502bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 15512bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 1552f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 1553f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 155433e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 155533e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCConsumeObject"; 155633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 155733e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCProduceObject"; 155833e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 155933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCReclaimReturnedObject"; 156033e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 156133e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCCExtendBlockObject"; 15627a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 15637a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "AtomicToNonAtomic"; 15647a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 15657a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "NonAtomicToAtomic"; 1566ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1567ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor return "CopyAndAutoreleaseBlockObject"; 1568a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_BuiltinFnToFnPtr: 1569a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman return "BuiltinFnToFnPtr"; 1570e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case CK_ZeroToOCLEvent: 1571e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei return "ZeroToOCLEvent"; 1572f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15742bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 1575f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 1576f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 15776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 15786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 15796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 15806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 15816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 158203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 158303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Skip through reference binding to temporary. 158403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 158503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) 158603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SubExpr = Materialize->GetTemporaryExpr(); 158703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 15886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 15896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 15906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 1591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 15936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 15942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 15956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 15962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 15976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 1598c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 16006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 1601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 1602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 16046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 16056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 1606f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 1607f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 1608f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 1609f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 1610f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 1611f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 1612f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 1613f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 1614f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 1615f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 1616f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 1617f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1618f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1619f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 1620f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 1621f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 1622f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1623f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1624f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 1625f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 1626f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 16275baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 1628f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1629f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1630f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1631f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 16325baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 1633f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1634f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1635f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1636f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1637f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 1638f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 1639f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1640f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1641f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 1642f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1643f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1644f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1645f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 1646f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 1647f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 1648f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 1649f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 1650f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1651f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1652f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1653f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 1654f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 1655f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1656f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1657f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1658f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1659f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 1660f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1661f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1662f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 1663f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1664f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 16655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 16670bea86307eb8c16339315a1e261fc490eb505c5bDavid BlaikieStringRef BinaryOperator::getOpcodeStr(Opcode Op) { 16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 16692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 16702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 16712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 16722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 16732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 16742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 16752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 16762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 16772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 16782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 16792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 16802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 16812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 16822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 16832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 16842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 16852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 16862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 16872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 16882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 16892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 16902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 16912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 16922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 16932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 16942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 16952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 16962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 16972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 16982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 16992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 17002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1702baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 17033026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid OpCode!"); 17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1707063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1708063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1709b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not an overloadable binary operator"); 17102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 17112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 17122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 17132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 17142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 17152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 17162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 17172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 17182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 17192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 17202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 17212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 17222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 17232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 17242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 17252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 17262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 17272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 17282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 17292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 17302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 17312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 17322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 17332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 17342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 17352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 17362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 17372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 17382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 17392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 17402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1741063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1742063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1743063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1744063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1745063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1746063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1747063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1748063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1749063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1750063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1751063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1752063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1753063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1754063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1755063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1756063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1757063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1758063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1759063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1760063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1761063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1762063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1763063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1764063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1765063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1766063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1767063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1768709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 17693b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) 1770bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, 1771561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 17723b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer InitExprs(C, initExprs.size()), 177323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(0, true) 177432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl{ 177532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl sawArrayRangeDesignator(false); 177632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl setInitializesStdInitializerList(false); 17773b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned I = 0; I != initExprs.size(); ++I) { 1778ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 17798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1780ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 17818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1782561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (initExprs[I]->isInstantiationDependent()) 1783561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1784bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (initExprs[I]->containsUnexpandedParameterPack()) 1785bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 178673460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1787c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 17883b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); 178966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1791709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1792ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1793709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1794fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1795fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1796709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1797709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 17984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 17994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1800709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1801ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1802709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1803ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1804ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 18054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 18061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 18084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 18094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 18104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 18114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 18123e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidisvoid InitListExpr::setArrayFiller(Expr *filler) { 181321f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis assert(!hasArrayFiller() && "Filler already set!"); 18143e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis ArrayFillerOrUnionFieldInit = filler; 18153e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis // Fill out any "holes" in the array due to designated initializers. 18163e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis Expr **inits = getInits(); 18173e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis for (unsigned i = 0, e = getNumInits(); i != e; ++i) 18183e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis if (inits[i] == 0) 18193e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis inits[i] = filler; 18203e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis} 18213e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis 1822fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smithbool InitListExpr::isStringLiteralInit() const { 1823fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith if (getNumInits() != 1) 1824fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1825f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); 1826f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman if (!AT || !AT->getElementType()->isIntegerType()) 1827fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1828f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman const Expr *Init = getInit(0)->IgnoreParens(); 1829fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); 1830fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith} 1831fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith 183265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation InitListExpr::getLocStart() const { 183323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara if (InitListExpr *SyntacticForm = getSyntacticForm()) 183465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SyntacticForm->getLocStart(); 183565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation Beg = LBraceLoc; 1836c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1837c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1838c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1839c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1840c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1841c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1842c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1843c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1844c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1845c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1846c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 184765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Beg; 184865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen} 184965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 185065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation InitListExpr::getLocEnd() const { 185165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen if (InitListExpr *SyntacticForm = getSyntacticForm()) 185265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SyntacticForm->getLocEnd(); 185365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation End = RBraceLoc; 1854c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1855c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1856c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 185765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen E = InitExprs.rend(); 185865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen I != E; ++I) { 1859c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 186065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen End = S->getLocEnd(); 1861c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 186265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 1863c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1864c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 186565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return End; 1866c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1867c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1868bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 18694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 1870a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCallconst FunctionProtoType *BlockExpr::getFunctionType() const { 1871a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall // The block pointer is never sugared, but the function type might be. 1872a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall return cast<BlockPointerType>(getType()) 1873a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall ->getPointeeType()->castAs<FunctionProtoType>(); 18744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 18754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 18761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 187856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 18807297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 18817297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 18821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 18847297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 188556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 188656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 18875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1891026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1892026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1893026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1894026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1895a6115068cde719142eb394db88612c185cabd05bEli Friedmanbool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, 1896a6115068cde719142eb394db88612c185cabd05bEli Friedman SourceRange &R1, SourceRange &R2, 1897a6115068cde719142eb394db88612c185cabd05bEli Friedman ASTContext &Ctx) const { 1898ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1899ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1900ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1901ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 19050faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 19060faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1907a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1908026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1909026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1910026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 19115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1912026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1913a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1914f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 1915f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr()-> 1916a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 19191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1921a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Plus: 1922a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Minus: 1923a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_AddrOf: 1924a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Not: 1925a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_LNot: 1926a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Deref: 1927a6115068cde719142eb394db88612c185cabd05bEli Friedman break; 19282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 19292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 19302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 19312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1932026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 19332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 19342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 19355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1936df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1937df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1938026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1939026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 19402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1941a6115068cde719142eb394db88612c185cabd05bEli Friedman return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1943a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1944026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1945026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1946026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1948e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1949026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1950c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1951c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1952c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 195325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 195425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 19552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1956c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1957c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1958c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1959c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1960c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1961c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 1962a6115068cde719142eb394db88612c185cabd05bEli Friedman return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 196325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 19642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 19652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 1966a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || 1967a6115068cde719142eb394db88612c185cabd05bEli Friedman !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 196825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 196925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1970bf0ee354163f87623a4b60412544243911332343John McCall } 1971026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1972026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1973a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1974026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1975026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1976026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1977026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1978e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1979eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1980c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1981276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman case AtomicExprClass: 1982026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1984ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1985fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // If only one of the LHS or RHS is a warning, the operator might 1986fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // be being used for control flow. Only warn if both the LHS and 1987fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // RHS are warnings. 1988ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 1989a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 1990fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek return false; 1991fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek if (!Exp->getLHS()) 1992026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1993a6115068cde719142eb394db88612c185cabd05bEli Friedman return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1994ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1995ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 19965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1997a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1998026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1999026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 2000026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 2001026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 2004a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2005026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 2006026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 2007026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 2008026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 2009211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 20109b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth case CXXOperatorCallExprClass: { 20119b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // We warn about operator== and operator!= even when user-defined operator 20129b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // overloads as there is no reasonable way to define these such that they 20139b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // have non-trivial, desirable side-effects. See the -Wunused-comparison 20149b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // warning: these operators are commonly typo'ed, and so warning on them 20159b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // provides additional value as well. If this list is updated, 20169b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // DiagnoseUnusedComparison should be as well. 20179b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); 20189b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth if (Op->getOperator() == OO_EqualEqual || 20196e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Op->getOperator() == OO_ExclaimEqual) { 2020a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20216e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Loc = Op->getOperatorLoc(); 20226e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay R1 = Op->getSourceRange(); 20239b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth return true; 20246e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay } 20259b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth 20269b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // Fallthrough for generic call handling. 20279b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth } 20285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 20299fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case CXXMemberCallExprClass: 20309fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case UserDefinedLiteralClass: { 2031026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 2032026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 2033d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 2034026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 2035026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 2036bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 2037bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 2038bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 2039bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 2040bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 2041a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2042bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 2043bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 2044bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 2045bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 2046bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 2047bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 2048bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 2049bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 2050026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 2051026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 2052026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 205358beed91d468863b8c85bce43425422703838d27Anders Carlsson 205484c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay // If we don't know precisely what we're looking at, let's not warn. 205584c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay case UnresolvedLookupExprClass: 205684c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay case CXXUnresolvedConstructExprClass: 205784c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay return false; 205884c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay 205958beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 206058beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 206158beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 206258beed91d468863b8c85bce43425422703838d27Anders Carlsson 2063f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 2064f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 20654e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().ObjCAutoRefCount && 2066f85e193739c953358c865005855253af4f68a497John McCall ME->isInstanceMessage() && 2067f85e193739c953358c865005855253af4f68a497John McCall !ME->getType()->isVoidType() && 2068f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) && 2069f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) 2070f85e193739c953358c865005855253af4f68a497John McCall ->getName().startswith("init")) { 2071a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2072f85e193739c953358c865005855253af4f68a497John McCall Loc = getExprLoc(); 2073f85e193739c953358c865005855253af4f68a497John McCall R1 = ME->getSourceRange(); 2074f85e193739c953358c865005855253af4f68a497John McCall return true; 2075f85e193739c953358c865005855253af4f68a497John McCall } 2076f85e193739c953358c865005855253af4f68a497John McCall 2077f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 2078f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 2079a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2080f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 2081f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 2082f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 2083026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 2084f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 20851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 208612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall case ObjCPropertyRefExprClass: 2087a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20885e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 20895e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 2090a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 209112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 20924b9c2d235fb9449e249d74f48ecfec601650de93John McCall case PseudoObjectExprClass: { 20934b9c2d235fb9449e249d74f48ecfec601650de93John McCall const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 20944b9c2d235fb9449e249d74f48ecfec601650de93John McCall 20954b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Only complain about things that have the form of a getter. 20964b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<UnaryOperator>(PO->getSyntacticForm()) || 20974b9c2d235fb9449e249d74f48ecfec601650de93John McCall isa<BinaryOperator>(PO->getSyntacticForm())) 20984b9c2d235fb9449e249d74f48ecfec601650de93John McCall return false; 20994b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2100a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 21014b9c2d235fb9449e249d74f48ecfec601650de93John McCall Loc = getExprLoc(); 21024b9c2d235fb9449e249d74f48ecfec601650de93John McCall R1 = getSourceRange(); 21034b9c2d235fb9449e249d74f48ecfec601650de93John McCall return true; 21044b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 21054b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2106611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 2107611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 2108611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 2109611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 2110611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 2111611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 2112611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 2113d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 2114611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 2115a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2116d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 2117d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 2118a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2119d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21210faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 21220faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 2123a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2124026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 2125026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 2126026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 2127611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 21286319917b5021e9602389b49ca4f245d235e9b90aEli Friedman case CXXFunctionalCastExprClass: 2129a6115068cde719142eb394db88612c185cabd05bEli Friedman case CStyleCastExprClass: { 21304059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman // Ignore an explicit cast to void unless the operand is a non-trivial 2131a6115068cde719142eb394db88612c185cabd05bEli Friedman // volatile lvalue. 21324059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CastExpr *CE = cast<CastExpr>(this); 2133a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ToVoid) { 2134a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getSubExpr()->isGLValue() && 21354059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman CE->getSubExpr()->getType().isVolatileQualified()) { 21364059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const DeclRefExpr *DRE = 21374059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); 21384059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (!(DRE && isa<VarDecl>(DRE->getDecl()) && 21394059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) { 21404059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, 21414059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1, R2, Ctx); 21424059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 21434059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 21440faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 2145a6115068cde719142eb394db88612c185cabd05bEli Friedman } 21464059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 2147a6115068cde719142eb394db88612c185cabd05bEli Friedman // If this is a cast to a constructor conversion, check the operand. 214858beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 2149a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ConstructorConversion) 2150a6115068cde719142eb394db88612c185cabd05bEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 21514059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 2152a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 21534059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (const CXXFunctionalCastExpr *CXXCE = 21544059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<CXXFunctionalCastExpr>(this)) { 21554059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CXXCE->getTypeBeginLoc(); 21564059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CXXCE->getSubExpr()->getSourceRange(); 21574059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } else { 21584059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); 21594059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CStyleCE->getLParenLoc(); 21604059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CStyleCE->getSubExpr()->getSourceRange(); 21614059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 2162026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 216358beed91d468863b8c85bce43425422703838d27Anders Carlsson } 2164a6115068cde719142eb394db88612c185cabd05bEli Friedman case ImplicitCastExprClass: { 2165a6115068cde719142eb394db88612c185cabd05bEli Friedman const CastExpr *ICE = cast<ImplicitCastExpr>(this); 2166a6115068cde719142eb394db88612c185cabd05bEli Friedman 2167a6115068cde719142eb394db88612c185cabd05bEli Friedman // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. 2168a6115068cde719142eb394db88612c185cabd05bEli Friedman if (ICE->getCastKind() == CK_LValueToRValue && 2169a6115068cde719142eb394db88612c185cabd05bEli Friedman ICE->getSubExpr()->getType().isVolatileQualified()) 2170a6115068cde719142eb394db88612c185cabd05bEli Friedman return false; 21714be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 2172a6115068cde719142eb394db88612c185cabd05bEli Friedman return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2173a6115068cde719142eb394db88612c185cabd05bEli Friedman } 217404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 2175df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 2176a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 21774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 21784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 21794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 21804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 21814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 2182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 21832d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 2184df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 2185a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 21864765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 21874765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return (cast<ExprWithCleanups>(this) 2188a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 21894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 21905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 219244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 21937f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 2194102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 2195f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 2196f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne switch (E->getStmtClass()) { 219744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 219844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 219944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 220044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 2201207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 2202f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 220344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 2204f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 220503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 220603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() 220703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isOBJCGCCandidate(Ctx); 220806b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 2209f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 2210a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 2211f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const Decl *D = cast<DeclRefExpr>(E)->getDecl(); 2212e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian 2213102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 2214102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 2215102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 2216102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 221759a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 221859a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 22197e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 22200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 2221102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 222244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 222344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 222483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 2225f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const MemberExpr *M = cast<MemberExpr>(E); 2226102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 222744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 222844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 2229f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); 223044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 223144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 2232369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 223311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 223411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 223511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 22367eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 223711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 223811ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 2239864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallQualType Expr::findBoundMemberType(const Expr *expr) { 2240e0a22d06888c13989b3f72db319f1d498bf69153John McCall assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); 2241864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2242864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Bound member expressions are always one of these possibilities: 2243864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // x->m x.m x->*y x.*y 2244864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // (possibly parenthesized) 2245864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2246864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall expr = expr->IgnoreParens(); 2247864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { 2248864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<CXXMethodDecl>(mem->getMemberDecl())); 2249864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return mem->getMemberDecl()->getType(); 2250864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2251864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2252864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { 2253864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() 2254864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ->getPointeeType(); 2255864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(type->isFunctionType()); 2256864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return type; 2257864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2258864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2259864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<UnresolvedMemberExpr>(expr)); 2260864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return QualType(); 2261864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 2262864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 22634e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 22644e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 2265b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 2266b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 2267b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2268b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2269b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2270b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2271b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2272b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2273b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2274b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2275b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2276f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2277f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2278f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2279f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2280f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2281f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2282b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 2283b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 22844e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 22854e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 228656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 228756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 228856f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 228956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 229056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 2291b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 229256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2293b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2294b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2295b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 229656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2297b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2298b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2299b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2300b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2301b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2302b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2303b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2304b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2305f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2306f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2307f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2308f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2309f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2310f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 231103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 231203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 231303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 231403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 231503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2316c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2317c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2318c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2319c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2320c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2321b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 232256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 232356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 232456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 23259c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue 23269c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts. This is intended purely as a temporary workaround for code 23279c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// that hasn't yet been rewritten to do the right thing about those 23289c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts, and may disappear along with the last internal use. 2329f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallExpr *Expr::IgnoreParenLValueCasts() { 2330f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *E = this; 23319c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall while (true) { 2332f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2333f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2334f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 23359c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2336f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (P->getCastKind() == CK_LValueToRValue) { 2337f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2338f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2339f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 23409c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 23419c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall if (P->getOpcode() == UO_Extension) { 23429c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall E = P->getSubExpr(); 23439c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall continue; 23449c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } 2345f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2346f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2347f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2348f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2349f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 235003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (MaterializeTemporaryExpr *Materialize 235103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 235203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 235303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 2354c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } else if (SubstNonTypeTemplateParmExpr *NTTP 2355c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2356c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2357c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2358f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2359f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2360f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2361f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return E; 2362f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2363632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 2364632fbaa22fbed7c090eb83775731bfff786c2198Rafael EspindolaExpr *Expr::ignoreParenBaseCasts() { 2365632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola Expr *E = this; 2366632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola while (true) { 2367632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2368632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola E = P->getSubExpr(); 2369632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola continue; 2370632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2371632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (CastExpr *CE = dyn_cast<CastExpr>(E)) { 2372632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (CE->getCastKind() == CK_DerivedToBase || 2373632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola CE->getCastKind() == CK_UncheckedDerivedToBase || 2374632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola CE->getCastKind() == CK_NoOp) { 2375632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola E = CE->getSubExpr(); 2376632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola continue; 2377632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2378632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2379632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 2380632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola return E; 2381632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2382632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola} 2383632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 23842fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 23852fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 23862fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 2387b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 23882fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2389b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2390b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2391b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 23922fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2393b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2394b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2395b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2396b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2397b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2398b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2399b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2400b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2401f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2402f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2403f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2404f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2405f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2406f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 240703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 240803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 240903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 241003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 241103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2412c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2413c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2414c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2415c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2416c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2417b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 24182fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 24192fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 24202fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 24212f072b442879b8bba8c5dea11d7c61bedb1924aeHans WennborgExpr *Expr::IgnoreConversionOperator() { 24222f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) { 242314d251cd62942bf7d56bb87a267ba2ca2f7fae3eChandler Carruth if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) 24242f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return MCE->getImplicitObjectArgument(); 24252f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 24262f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return this; 24272f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg} 24282f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 2429ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 2430ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 2431ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 2432ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 2433ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 2434ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 2435ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2436ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 2437ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2438ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2440ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2441ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 24422ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 2443ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 24441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2445ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 2446ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2447ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2448ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 24491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2450b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 24519d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 2452b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 24539d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 2454ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 2455ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2456ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2457ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2458ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2460b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2461b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2462b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2463b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2464b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2465b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2466b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 2467f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2468f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2469f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2470f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2471f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2472f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2473f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 2474c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2475c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2476c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2477c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2478c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2479c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor 2480ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 2481ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2482ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 2483ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 24846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 24856eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 248603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 248703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 248803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 24896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 24906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 2491c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 24926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 24936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 2494ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 24952f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 24962f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 2497f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 249803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 249903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 250003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 25012f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 25022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 25032f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 25042f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 25052f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 25062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 25072f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 25082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 25092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 25102f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 25112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 25122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 25132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 25142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 25152f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 25162f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 2517f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 2518f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 25192f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 25202f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2521558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 2522558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 2523558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 2524558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 2525558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 25262f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2527f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 25282f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 252958277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 2530db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 2531db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 253212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!isa<ObjCPropertyRefExpr>(E)) 2533db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 2534db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 25352f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 253619e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 253719e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 253819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 253919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 2540558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 2541558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 2542558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 2543558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 2544558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 2545558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 2546558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 2547558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 25482f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 25492f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 255019e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 255119e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 255219e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 255319e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 255432f498a675df990901e6659d610dc740f9423228Eli Friedman if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) 255532f498a675df990901e6659d610dc740f9423228Eli Friedman if (BO->isPtrMemOp()) 255632f498a675df990901e6659d610dc740f9423228Eli Friedman return false; 255732f498a675df990901e6659d610dc740f9423228Eli Friedman 255856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // - opaque values (all) 255956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (isa<OpaqueValueExpr>(E)) 256056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return false; 256156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 2562558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 25632f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 25642f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 256575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregorbool Expr::isImplicitCXXThis() const { 256675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor const Expr *E = this; 256775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 256875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // Strip away parentheses and casts we don't care about. 256975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor while (true) { 257075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { 257175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = Paren->getSubExpr(); 257275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 257375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 257475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 257575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 257675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (ICE->getCastKind() == CK_NoOp || 257775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_LValueToRValue || 257875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_DerivedToBase || 257975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_UncheckedDerivedToBase) { 258075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = ICE->getSubExpr(); 258175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 258275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 258375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 258475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 258575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { 258675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (UnOp->getOpcode() == UO_Extension) { 258775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = UnOp->getSubExpr(); 258875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 258975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 259075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 259175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 259203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M 259303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 259403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 259503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 259603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 259703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 259875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor break; 259975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 260075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 260175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) 260275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return This->isImplicit(); 260375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 260475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return false; 260575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 260675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 2607898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 2608898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 2609cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkobool Expr::hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs) { 261013a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles for (unsigned I = 0; I < Exprs.size(); ++I) 2611898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 2612898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2613898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2614898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2615898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2616898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 26174204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 2618c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 2619c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 2620c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 2621c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 2622c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 2623c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 26244204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 26254204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 26264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 26274204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 26284204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 26294204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 26304204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 26311f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 2632e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 2633c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 26344ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case IntegerLiteralClass: 26354ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case FloatingLiteralClass: 2636e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 263714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 2638eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 2639e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 2640b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 2641b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 2642b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 26434204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 26444204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 2645180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->getConstructor()->isTrivial()) { 2646180f47959a066795cc0f409433023af448bb0328Richard Smith // 1) an application of the trivial default constructor or 2647180f47959a066795cc0f409433023af448bb0328Richard Smith if (!CE->getNumArgs()) return true; 2648180f47959a066795cc0f409433023af448bb0328Richard Smith 2649180f47959a066795cc0f409433023af448bb0328Richard Smith // 2) an elidable trivial copy construction of an operand which is 2650180f47959a066795cc0f409433023af448bb0328Richard Smith // itself a constant initializer. Note that we consider the 2651180f47959a066795cc0f409433023af448bb0328Richard Smith // operand on its own, *not* as a reference binding. 2652180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->isElidable() && 2653180f47959a066795cc0f409433023af448bb0328Richard Smith CE->getArg(0)->isConstantInitializer(Ctx, false)) 2654180f47959a066795cc0f409433023af448bb0328Richard Smith return true; 2655180f47959a066795cc0f409433023af448bb0328Richard Smith } 2656180f47959a066795cc0f409433023af448bb0328Richard Smith 2657180f47959a066795cc0f409433023af448bb0328Richard Smith // 3) a foldable constexpr constructor. 2658180f47959a066795cc0f409433023af448bb0328Richard Smith break; 2659b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 266059b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 26611f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 26621f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 26631f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 266459b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 26654204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 266659b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 2667e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 26681f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 26691f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 26701f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 2671e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 2672e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 2673e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 26744204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 2675e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 2676e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2677c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 2678e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 26793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 26803498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 26813ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 26824204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 26834204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 2684f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 2685f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (cast<GenericSelectionExpr>(this)->isResultDependent()) 2686f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return false; 2687f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr() 2688f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ->isConstantInitializer(Ctx, IsForRef); 26895cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 26905cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 26915cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 2692c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 2693c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 26942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 26954204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 2696c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2697c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 26984204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 2699b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 270081045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 2701d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith case CStyleCastExprClass: { 2702d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith const CastExpr *CE = cast<CastExpr>(this); 2703d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 27047a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // If we're promoting an integer to an _Atomic type then this is constant 27057a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // if the integer is constant. We also need to check the converse in case 27067a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // someone does something like: 27077a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 27087a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // int a = (_Atomic(int))42; 27097a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 27107a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // I doubt anyone would write code like this directly, but it's quite 27117a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // possible as the result of macro expansions. 27127a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall if (CE->getCastKind() == CK_NonAtomicToAtomic || 27137a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall CE->getCastKind() == CK_AtomicToNonAtomic) 27147a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return CE->getSubExpr()->isConstantInitializer(Ctx, false); 27157a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall 2716d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith // Handle bitcasts of vector constants. 2717d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith if (getType()->isVectorType() && CE->getCastKind() == CK_BitCast) 2718d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2719d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 27206bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // Handle misc casts we want to ignore. 27216bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // FIXME: Is it really safe to ignore all these? 27226bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman if (CE->getCastKind() == CK_NoOp || 27236bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_LValueToRValue || 27246bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ToUnion || 27256bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ConstructorConversion) 2726d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2727d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 2728c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2729d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith } 273003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 27315f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() 273203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isConstantInitializer(Ctx, false); 2733e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2734c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 273538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 273638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 27378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smithbool Expr::HasSideEffects(const ASTContext &Ctx) const { 27388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (isInstantiationDependent()) 27398ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27408ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27418ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith switch (getStmtClass()) { 27428ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case NoStmtClass: 27438ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define ABSTRACT_STMT(Type) 27448ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define STMT(Type, Base) case Type##Class: 27458ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define EXPR(Type, Base) 27468ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #include "clang/AST/StmtNodes.inc" 27478ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith llvm_unreachable("unexpected Expr kind"); 27488ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27498ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case DependentScopeDeclRefExprClass: 27508ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXUnresolvedConstructExprClass: 27518ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDependentScopeMemberExprClass: 27528ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnresolvedLookupExprClass: 27538ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnresolvedMemberExprClass: 27548ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PackExpansionExprClass: 27558ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SubstNonTypeTemplateParmPackExprClass: 27569a4db032ecd991626d236a502e770126db32bd31Richard Smith case FunctionParmPackExprClass: 27578ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith llvm_unreachable("shouldn't see dependent / unresolved nodes here"); 27588ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 275960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case DeclRefExprClass: 276060b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case ObjCIvarRefExprClass: 27618ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PredefinedExprClass: 27628ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case IntegerLiteralClass: 27638ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case FloatingLiteralClass: 27648ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ImaginaryLiteralClass: 27658ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case StringLiteralClass: 27668ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CharacterLiteralClass: 27678ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case OffsetOfExprClass: 27688ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ImplicitValueInitExprClass: 27698ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnaryExprOrTypeTraitExprClass: 27708ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AddrLabelExprClass: 27718ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case GNUNullExprClass: 27728ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXBoolLiteralExprClass: 27738ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNullPtrLiteralExprClass: 27748ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXThisExprClass: 27758ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXScalarValueInitExprClass: 27768ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case TypeTraitExprClass: 27778ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnaryTypeTraitExprClass: 27788ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryTypeTraitExprClass: 27798ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ArrayTypeTraitExprClass: 27808ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExpressionTraitExprClass: 27818ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNoexceptExprClass: 27828ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SizeOfPackExprClass: 27838ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCStringLiteralClass: 27848ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCEncodeExprClass: 27858ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBoolLiteralExprClass: 27868ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXUuidofExprClass: 27878ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case OpaqueValueExprClass: 27888ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These never have a side-effect. 27898ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 27908ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27918ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CallExprClass: 27928ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CompoundAssignOperatorClass: 27938ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case VAArgExprClass: 27948ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AtomicExprClass: 27958ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case StmtExprClass: 27968ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXOperatorCallExprClass: 27978ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXMemberCallExprClass: 27988ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UserDefinedLiteralClass: 27998ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXThrowExprClass: 28008ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNewExprClass: 28018ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDeleteExprClass: 28028ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExprWithCleanupsClass: 28038ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXBindTemporaryExprClass: 28048ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BlockExprClass: 28058ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CUDAKernelCallExprClass: 28068ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These always have a side-effect. 28078ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28088ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28098ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ParenExprClass: 28108ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ArraySubscriptExprClass: 28118ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case MemberExprClass: 28128ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ConditionalOperatorClass: 28138ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryConditionalOperatorClass: 28148ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CompoundLiteralExprClass: 28158ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExtVectorElementExprClass: 28168ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case DesignatedInitExprClass: 28178ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ParenListExprClass: 28188ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXPseudoDestructorExprClass: 28198ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SubstNonTypeTemplateParmExprClass: 28208ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case MaterializeTemporaryExprClass: 28218ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ShuffleVectorExprClass: 28228ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AsTypeExprClass: 28238ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These have a side-effect if any subexpression does. 28248ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28258ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 282660b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case UnaryOperatorClass: 282760b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (cast<UnaryOperator>(this)->isIncrementDecrementOp()) 28288ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28298ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28308ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28318ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryOperatorClass: 28328ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (cast<BinaryOperator>(this)->isAssignmentOp()) 28338ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28348ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case InitListExprClass: 28378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: The children for an InitListExpr doesn't include the array filler. 28388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller()) 28398ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (E->HasSideEffects(Ctx)) 28408ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28418ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28428ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28438ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case GenericSelectionExprClass: 28448ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<GenericSelectionExpr>(this)->getResultExpr()-> 28458ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith HasSideEffects(Ctx); 28468ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28478ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ChooseExprClass: 28488ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->HasSideEffects(Ctx); 28498ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28508ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDefaultArgExprClass: 28518ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects(Ctx); 28528ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28538ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDynamicCastExprClass: { 28548ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // A dynamic_cast expression has side-effects if it can throw. 28558ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this); 28568ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (DCE->getTypeAsWritten()->isReferenceType() && 28578ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith DCE->getCastKind() == CK_Dynamic) 28588ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 285960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith } // Fall through. 286060b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case ImplicitCastExprClass: 286160b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CStyleCastExprClass: 286260b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXStaticCastExprClass: 286360b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXReinterpretCastExprClass: 286460b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXConstCastExprClass: 286560b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXFunctionalCastExprClass: { 286660b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith const CastExpr *CE = cast<CastExpr>(this); 286760b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (CE->getCastKind() == CK_LValueToRValue && 286860b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith CE->getSubExpr()->getType().isVolatileQualified()) 286960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith return true; 28708ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28718ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28728ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28730d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith case CXXTypeidExprClass: 28740d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith // typeid might throw if its subexpression is potentially-evaluated, so has 28750d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith // side-effects in that case whether or not its subexpression does. 28760d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); 28778ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28788ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXConstructExprClass: 28798ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXTemporaryObjectExprClass: { 28808ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 288160b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (!CE->getConstructor()->isTrivial()) 28828ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 288360b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith // A trivial constructor does not add any side-effects of its own. Just look 288460b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith // at its arguments. 28858ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28868ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28878ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28888ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case LambdaExprClass: { 28898ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const LambdaExpr *LE = cast<LambdaExpr>(this); 28908ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (LambdaExpr::capture_iterator I = LE->capture_begin(), 28918ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith E = LE->capture_end(); I != E; ++I) 28928ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (I->getCaptureKind() == LCK_ByCopy) 28938ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: Only has a side-effect if the variable is volatile or if 28948ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // the copy would invoke a non-trivial copy constructor. 28958ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28968ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 28978ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28988ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28998ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PseudoObjectExprClass: { 29008ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // Only look for side-effects in the semantic form, and look past 29018ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // OpaqueValueExpr bindings in that form. 29028ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 29038ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), 29048ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith E = PO->semantics_end(); 29058ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith I != E; ++I) { 29068ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const Expr *Subexpr = *I; 29078ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr)) 29088ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith Subexpr = OVE->getSourceExpr(); 29098ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (Subexpr->HasSideEffects(Ctx)) 29108ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 29118ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 29128ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 29138ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 29148ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 29158ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBoxedExprClass: 29168ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCArrayLiteralClass: 29178ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCDictionaryLiteralClass: 29188ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCMessageExprClass: 29198ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCSelectorExprClass: 29208ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCProtocolExprClass: 29218ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCPropertyRefExprClass: 29228ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCIsaExprClass: 29238ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCIndirectCopyRestoreExprClass: 29248ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCSubscriptRefExprClass: 29258ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBridgedCastExprClass: 29268ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: Classify these cases better. 29278ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 29288ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 29298ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 29308ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // Recurse to children. 29318ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (const_child_range SubStmts = children(); SubStmts; ++SubStmts) 29328ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const Stmt *S = *SubStmts) 29338ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (cast<Expr>(S)->HasSideEffects(Ctx)) 29348ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 29358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 29368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 29378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith} 29388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 293925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregornamespace { 294025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// \brief Look for a call to a non-trivial function within an expression. 294125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor class NonTrivialCallFinder : public EvaluatedExprVisitor<NonTrivialCallFinder> 294225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor { 294325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor typedef EvaluatedExprVisitor<NonTrivialCallFinder> Inherited; 294425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 294525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool NonTrivial; 294625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 294725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor public: 294825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor explicit NonTrivialCallFinder(ASTContext &Context) 2949b11e52540166a2958439cfe562c25931e4460759Douglas Gregor : Inherited(Context), NonTrivial(false) { } 295025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 295125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool hasNonTrivialCall() const { return NonTrivial; } 295225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 295325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCallExpr(CallExpr *E) { 295425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (CXXMethodDecl *Method 295525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor = dyn_cast_or_null<CXXMethodDecl>(E->getCalleeDecl())) { 295625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (Method->isTrivial()) { 295725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 295825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 295925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 296025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 296125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 296225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 296325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 296425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 296525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 296625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXConstructExpr(CXXConstructExpr *E) { 296725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getConstructor()->isTrivial()) { 296825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 296925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 297025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 297125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 297225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 297325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 297425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 297525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 297625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 297725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getTemporary()->getDestructor()->isTrivial()) { 297825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 297925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 298025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 298125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 298225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 298325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 298425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor }; 298525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 298625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 298725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregorbool Expr::hasNonTrivialCall(ASTContext &Ctx) { 298825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivialCallFinder Finder(Ctx); 298925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Finder.Visit(this); 299025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return Finder.hasNonTrivialCall(); 299125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 299225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 299382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null 299482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// pointer constant or not, as well as the specific kind of constant detected. 299582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// Null pointer constants can be integer constant expressions with the 299682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// value zero, casts of zero to void*, nullptr (C++0X), or __null 299782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// (a GNU extension). 299882214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::NullPointerConstantKind 299982214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::isNullPointerConstant(ASTContext &Ctx, 300082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const { 3001ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 3002ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 3003ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 3004b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected value dependent expression!"); 3005ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 300682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth if (isTypeDependent() || getType()->isIntegralType(Ctx)) 300750800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroExpression; 300882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth else 300982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 3010c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3011ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 301282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 3013ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 3014ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 3015f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 30160777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 30170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 30184e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) { 30190777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 30206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 30210777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 30220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 30230777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 30240777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 3025ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 30260777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 30275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3028aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 3029aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 3030ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 3031aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 3032aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 3033aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 3034ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 3035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (const GenericSelectionExpr *GE = 3036f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne dyn_cast<GenericSelectionExpr>(this)) { 3037f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); 30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 30398123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 304004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 3041ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 30422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 30432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 304482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_GNUNull; 304503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (const MaterializeTemporaryExpr *M 304603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(this)) { 304703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); 30484b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { 30494b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (const Expr *Source = OVE->getSourceExpr()) 30504b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Source->isNullPointerConstant(Ctx, NPC); 3051aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 30522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 30534e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith // C++11 nullptr_t is always a null pointer constant. 30546e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 30554e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith return NPCK_CXX11_nullptr; 30566e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 3057ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 3058ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 3059ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 3060ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 3061ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 3062ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 3063ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 3064aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 3065c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 30664e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType())) 306782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 30681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 307070488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // test for the value 0. Don't use the C++11 constant expression semantics 307170488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // for this, for now; once the dust settles on core issue 903, we might only 307270488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // allow a literal 0 here in C++11 mode. 307380ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (Ctx.getLangOpts().CPlusPlus11) { 307470488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isCXX98IntegralConstantExpr(Ctx)) 307570488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 307670488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } else { 307770488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isIntegerConstantExpr(Ctx)) 307870488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 307970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } 308082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 308150800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie if (EvaluateKnownConstInt(Ctx) != 0) 308250800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_NotNull; 308350800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie 308450800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie if (isa<IntegerLiteral>(this)) 308550800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroLiteral; 308650800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroExpression; 30875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 308831a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 3089f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// \brief If this expression is an l-value for an Objective C 3090f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// property, find the underlying property reference expression. 3091f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallconst ObjCPropertyRefExpr *Expr::getObjCProperty() const { 3092f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *E = this; 3093f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall while (true) { 3094f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall assert((E->getValueKind() == VK_LValue && 3095f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E->getObjectKind() == OK_ObjCProperty) && 3096f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall "expression is not a property reference"); 3097f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = E->IgnoreParenCasts(); 3098f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 3099f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (BO->getOpcode() == BO_Comma) { 3100f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = BO->getRHS(); 3101f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 3102f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3103f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3104f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3105f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 3106f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3107f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3108f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return cast<ObjCPropertyRefExpr>(E); 3109f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 3110f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3111bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaksbool Expr::isObjCSelfExpr() const { 3112bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const Expr *E = IgnoreParenImpCasts(); 3113bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3114bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); 3115bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!DRE) 3116bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3117bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3118bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); 3119bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!Param) 3120bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3121bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3122bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); 3123bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!M) 3124bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3125bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3126bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return M->getSelfDecl() == Param; 3127bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks} 3128bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 312933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 31306f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 313133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 3132de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 3133f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ICE->getCastKind() == CK_LValueToRValue || 3134f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) 3135de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 3136de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 3137de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 3138de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 3139de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 314027c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 314186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 314233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 314333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 314433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 31450f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 31460f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 31470f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 31480f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 31490f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 315042068e9d420889014ee26894e421fead336b239dEli Friedman if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { 315133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 315233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 315333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 315442068e9d420889014ee26894e421fead336b239dEli Friedman if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) 315542068e9d420889014ee26894e421fead336b239dEli Friedman return BinOp->getRHS()->getBitField(); 315642068e9d420889014ee26894e421fead336b239dEli Friedman } 315742068e9d420889014ee26894e421fead336b239dEli Friedman 315833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 315927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 316027c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 3161093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 3162093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 3163c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3164093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 31655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 31662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 3167093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 3168093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 3169093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 3170093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 3171c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3172093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 3173093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 3174093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 3175093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 3176093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 3177093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 3178093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 3179093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 3180093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 31812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 31822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 31832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 31842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 31852140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 31862140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 3187213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 3188183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 31898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 31908a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 31914d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 31924d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 31938a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 3194213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 3195a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 3196a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 31975f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 3198190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 3199190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 3200150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 3201190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 32021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3203190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 3204150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 3205150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 32061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3207150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 32085f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) 3209fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 3210150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 3211fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 3212fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 3213b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 32148a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 32153b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 32165f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<unsigned> &Elts) const { 32175f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 32184b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 32194b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 32201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32214b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 32224b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 32234b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 32244b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 32251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32268a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 32278a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 32281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32298a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 32308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 32318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 32328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 32338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 32348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 32358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 32368a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 32378a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 32384b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 3239b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 32403b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 3241b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 32428a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 32438a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 324404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(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, 3251207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3252207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 325304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32548d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3255746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3256746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3257f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 3258bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3259561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3260bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 326104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 326204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3263b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(IsInstanceSuper? SuperInstance : SuperClass), 3264746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3265746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SuperLoc(SuperLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 3266c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 3267207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 326804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 326904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 327004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 327104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 327304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 327404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 3275f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 3276207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3277207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 327804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32798d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3280746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3281746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3282f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 3283561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isInstantiationDependentType(), 3284561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->containsUnexpandedParameterPack()), 328504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 328604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3287b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Class), 3288746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3289207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 329004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 3291207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 329204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 329304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 329404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 329504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3296f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 329704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 329804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 3299c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3300207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3301207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 330204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33038d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3304746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3305746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 3307bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->isTypeDependent(), 3308561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Receiver->isInstantiationDependent(), 3309bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->containsUnexpandedParameterPack()), 331004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 331104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3312b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Instance), 3313746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3314207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 331504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 3316207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 331704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 3318207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3319207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3320207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args, 3321207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3322207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK) { 3323207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis setNumArgs(Args.size()); 3324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 33258d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis for (unsigned I = 0; I != Args.size(); ++I) { 3326bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 3327bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3328bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 3329bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3330561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[I]->isInstantiationDependent()) 3331561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3332bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 3333bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3334bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3335bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 3336bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3337207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 333819562c97669532084a71895197f4444305dd432aBenjamin Kramer SelLocsKind = SelLocsK; 33390c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (!isImplicit()) { 33400c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (SelLocsK == SelLoc_NonStandard) 33410c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 33420c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis } 334304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 334404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 334504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3346f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 334704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 334804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 334904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 335004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 3351c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3352951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 335304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33548d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3355746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3356746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3357746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3358746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3359746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3360746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3361746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3362746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3363746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3364746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 3366207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SuperType, Sel, SelLocs, SelLocsK, 3367746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Method, Args, RBracLoc, isImplicit); 336804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 336904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 337004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 337204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 337304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 3374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3375951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 337604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33778d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3378746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3379746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3380746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3381746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3382746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3383746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3384746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3385746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3386746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3387746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3388951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 3389746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 3390746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 339104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 339204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 339304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3394f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 339504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 339604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 3397f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 3398951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 339904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 34008d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3401746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3402746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3403746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3404746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3405746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3406746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3407746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3408746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3409746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3410746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3411951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 3412746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 3413746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 341404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 341504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 3416c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 3417207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 3418207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 3419207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs); 342004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 342104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 3422e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3423207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 3424207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3425207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 3426207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3427207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 3428207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK) { 3429207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocsK = hasStandardSelectorLocs(Sel, SelLocs, Args, RBraceLoc); 3430207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs = (SelLocsK == SelLoc_NonStandard) ? SelLocs.size() 3431207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis : 0; 3432207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return alloc(C, Args.size(), NumStoredSelLocs); 3433207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3434207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3435207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 3436207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 3437207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 3438207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 3439207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis NumArgs * sizeof(Expr *) + NumStoredSelLocs * sizeof(SourceLocation); 3440207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (ObjCMessageExpr *)C.Allocate(Size, 3441207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::AlignOf<ObjCMessageExpr>::Alignment); 3442207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3443207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3444207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::getSelectorLocs( 3445207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVectorImpl<SourceLocation> &SelLocs) const { 3446207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 3447207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs.push_back(getSelectorLoc(i)); 3448207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3449207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3450e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios KyrtzidisSourceRange ObjCMessageExpr::getReceiverRange() const { 3451e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis switch (getReceiverKind()) { 3452e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Instance: 3453e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getInstanceReceiver()->getSourceRange(); 3454e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3455e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Class: 3456e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); 3457e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3458e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperInstance: 3459e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperClass: 3460e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getSuperLoc(); 3461e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis } 3462e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 34633026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid ReceiverKind!"); 3464e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis} 3465e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 346604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 346704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 346804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 346904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 3470c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 347104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 347204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 3473e4a990f34904eb572c8d6aa1deef19465214359cArgyrios KyrtzidisQualType ObjCMessageExpr::getReceiverType() const { 347404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 347504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 3476e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return getInstanceReceiver()->getType(); 347704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 3478e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return getClassReceiver(); 347904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 348004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 3481e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return getSuperType(); 348204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 34830389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 3484e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis llvm_unreachable("unexpected receiver kind"); 3485e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis} 3486e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 3487e4a990f34904eb572c8d6aa1deef19465214359cArgyrios KyrtzidisObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 3488e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis QualType T = getReceiverType(); 3489e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 3490e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis if (const ObjCObjectPointerType *Ptr = T->getAs<ObjCObjectPointerType>()) 3491e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return Ptr->getInterfaceDecl(); 3492e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 3493e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis if (const ObjCObjectType *Ty = T->getAs<ObjCObjectType>()) 3494e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return Ty->getInterface(); 3495e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 349604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 3497eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 34980389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 34995f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef ObjCBridgedCastExpr::getBridgeKindName() const { 3500f85e193739c953358c865005855253af4f68a497John McCall switch (getBridgeKind()) { 3501f85e193739c953358c865005855253af4f68a497John McCall case OBC_Bridge: 3502f85e193739c953358c865005855253af4f68a497John McCall return "__bridge"; 3503f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeTransfer: 3504f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_transfer"; 3505f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeRetained: 3506f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_retained"; 3507f85e193739c953358c865005855253af4f68a497John McCall } 35083026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie 35093026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid BridgeKind!"); 3510f85e193739c953358c865005855253af4f68a497John McCall} 3511f85e193739c953358c865005855253af4f68a497John McCall 35124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ChooseExpr::isConditionTrue(const ASTContext &C) const { 3513a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getCond()->EvaluateKnownConstInt(C) != 0; 351427437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 351527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 35163b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, ArrayRef<Expr*> args, 3517bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor QualType Type, SourceLocation BLoc, 3518bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP) 3519bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 3520bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 3521561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 3522bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->containsUnexpandedParameterPack()), 35233b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) 3524bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor{ 35253b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()]; 35263b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); i++) { 3527bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 3528bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3529bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 3530bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3531561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 3532561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3533bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 3534bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3535bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3536bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs[i] = args[i]; 3537bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3538bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 3539bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3540888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 3541888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 3542888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 3543888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3544888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 354594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 354694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 35471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 3548888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3549f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3550f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 35513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 35523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 35533b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, 3554f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3555f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3556f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex) 3557f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3558f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getType(), 3559f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getValueKind(), 3560f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getObjectKind(), 3561f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isTypeDependent(), 3562f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isValueDependent(), 3563561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor AssocExprs[ResultIndex]->isInstantiationDependent(), 3564f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 35653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), 35663b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), 35673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), 35683b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { 3569f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 35703b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(AssocTypes.size() == AssocExprs.size()); 35713b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); 35723b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); 3573f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3574f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3575f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3576f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 35773b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 35783b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 35793b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, 3580f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3581f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack) 3582f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3583f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Context.DependentTy, 3584f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne VK_RValue, 3585f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne OK_Ordinary, 3586561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isTypeDependent=*/true, 3587561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isValueDependent=*/true, 3588561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isInstantiationDependent=*/true, 3589f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 35903b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), 35913b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), 35923b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc), 35933b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { 3594f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 35953b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(AssocTypes.size() == AssocExprs.size()); 35963b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); 35973b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); 3598f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3599f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 360077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 360105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 360205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 360305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3604b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler CarruthIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 360705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 360805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 360905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 361005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 361105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3612c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 3613319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 3614ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 3616ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 36173b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 36189ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 36191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 3620f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 3621bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->isTypeDependent(), Init->isValueDependent(), 3622561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Init->isInstantiationDependent(), 3623bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->containsUnexpandedParameterPack()), 36241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 36253b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumDesignators(NumDesignators), NumSubExprs(IndexExprs.size() + 1) { 3626319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 36279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36289ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 36297502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall child_range Child = children(); 36309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 36319ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36329ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 36339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 36349ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 36359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 3636ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 36379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36389ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 36399ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 36409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 3641bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->isTypeDependent() || Index->isValueDependent()) 3642bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3643561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Index->isInstantiationDependent()) 3644561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3645bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3646bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->containsUnexpandedParameterPack()) 3647bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 36489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36499ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 36509ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 36519ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 36529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 36539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 36549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 3655bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->isTypeDependent() || Start->isValueDependent() || 3656561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isTypeDependent() || End->isValueDependent()) { 3657bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3658561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3659561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (Start->isInstantiationDependent() || 3660561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isInstantiationDependent()) { 3661561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3662561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 3663561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3664bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3665bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->containsUnexpandedParameterPack() || 3666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->containsUnexpandedParameterPack()) 3667bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 36689ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36699ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 36709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 36719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 36729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 36739ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 36749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36753b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions"); 3676ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3677ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 367805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 36791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 368005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 36813b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 368205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 368305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 3684c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 36853b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(Stmt *) * (IndexExprs.size() + 1), 8); 3686319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 36879ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 36883b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer IndexExprs, Init); 368905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 369005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 3692d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 3693d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3694d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3695d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 3696d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3697d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3698319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 3699319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 3700d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 3701319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 3702d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 3703d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 3704d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 3705d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3706d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 370724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo BagnaraSourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { 370824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); 370924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara if (size() == 1) 371024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return DIE->getDesignator(0)->getSourceRange(); 371165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceRange(DIE->getDesignator(0)->getLocStart(), 371265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen DIE->getDesignator(size()-1)->getLocEnd()); 371324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara} 371424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 371565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation DesignatedInitExpr::getLocStart() const { 371605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 3717d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 3718d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 371905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 3720eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 372105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 372205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 372305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 372405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 3725d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 3726d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 372765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return StartLoc; 372865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen} 372965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 373065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation DesignatedInitExpr::getLocEnd() const { 373165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getInit()->getLocEnd(); 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3734d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri GribenkoExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) const { 373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 3736d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko char *Ptr = static_cast<char *>( 3737d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko const_cast<void *>(static_cast<const void *>(this))); 373805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 374005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 374105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 374205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3743d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri GribenkoExpr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const { 37441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 374505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 3746d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko char *Ptr = static_cast<char *>( 3747d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko const_cast<void *>(static_cast<const void *>(this))); 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 375005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 375205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3753d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri GribenkoExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const { 37541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 375505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 3756d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko char *Ptr = static_cast<char *>( 3757d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko const_cast<void *>(static_cast<const void *>(this))); 375805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 375905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 376005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 376105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 376205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3763ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 3764ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 3765319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 37661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 3767ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 3768ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 3769ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 3770ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 3771ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 3772ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 3773ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 3774ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3775ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 3776ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 3777ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3778ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 3779ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 37801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 3781319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 3782ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 3783ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 3784ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 3785ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 3786ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 3787ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 3788ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3789ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 37901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 37913b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, 37925b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceLocation rparenloc) 37935b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, 3794561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, false, false), 37953b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) { 37963b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer Exprs = new (C) Stmt*[exprs.size()]; 37973b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != exprs.size(); ++i) { 3798bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isTypeDependent()) 3799bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3800bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isValueDependent()) 3801bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3802561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (exprs[i]->isInstantiationDependent()) 3803561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3804bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->containsUnexpandedParameterPack()) 3805bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3806bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 38072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 3808bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 38092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 38102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 3811e996ffd240f20a1048179d7727a6ee3227261921John McCallconst OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { 3812e996ffd240f20a1048179d7727a6ee3227261921John McCall if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) 3813e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ewc->getSubExpr(); 381403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) 381503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor e = m->GetTemporaryExpr(); 3816e996ffd240f20a1048179d7727a6ee3227261921John McCall e = cast<CXXConstructExpr>(e)->getArg(0); 3817e996ffd240f20a1048179d7727a6ee3227261921John McCall while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 3818e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ice->getSubExpr(); 3819e996ffd240f20a1048179d7727a6ee3227261921John McCall return cast<OpaqueValueExpr>(e); 3820e996ffd240f20a1048179d7727a6ee3227261921John McCall} 3821e996ffd240f20a1048179d7727a6ee3227261921John McCall 38224b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &Context, EmptyShell sh, 38234b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs) { 38244b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = Context.Allocate(sizeof(PseudoObjectExpr) + 38254b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + numSemanticExprs) * sizeof(Expr*), 38264b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 38274b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); 38284b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38294b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38304b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) 38314b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, shell) { 38324b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; 38334b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38344b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38354b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &C, Expr *syntax, 38364b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantics, 38374b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) { 38384b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(syntax && "no syntactic expression!"); 38394b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics.size() && "no semantic expressions!"); 38404b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38414b9c2d235fb9449e249d74f48ecfec601650de93John McCall QualType type; 38424b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprValueKind VK; 38434b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (resultIndex == NoResult) { 38444b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = C.VoidTy; 38454b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = VK_RValue; 38464b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 38474b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(resultIndex < semantics.size()); 38484b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = semantics[resultIndex]->getType(); 38494b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = semantics[resultIndex]->getValueKind(); 38504b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary); 38514b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 38524b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38534b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = C.Allocate(sizeof(PseudoObjectExpr) + 38544b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + semantics.size()) * sizeof(Expr*), 38554b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 38564b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, 38574b9c2d235fb9449e249d74f48ecfec601650de93John McCall resultIndex); 38584b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38594b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38604b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, 38614b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntax, ArrayRef<Expr*> semantics, 38624b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) 38634b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, 38644b9c2d235fb9449e249d74f48ecfec601650de93John McCall /*filled in at end of ctor*/ false, false, false, false) { 38654b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; 38664b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.ResultIndex = resultIndex + 1; 38674b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38684b9c2d235fb9449e249d74f48ecfec601650de93John McCall for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { 38694b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *E = (i == 0 ? syntax : semantics[i-1]); 38704b9c2d235fb9449e249d74f48ecfec601650de93John McCall getSubExprsBuffer()[i] = E; 38714b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38724b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isTypeDependent()) 38734b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.TypeDependent = true; 38744b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isValueDependent()) 38754b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ValueDependent = true; 38764b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isInstantiationDependent()) 38774b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.InstantiationDependent = true; 38784b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->containsUnexpandedParameterPack()) 38794b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ContainsUnexpandedParameterPack = true; 38804b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38814b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<OpaqueValueExpr>(E)) 38824b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != 0 && 38834b9c2d235fb9449e249d74f48ecfec601650de93John McCall "opaque-value semantic expressions for pseudo-object " 38844b9c2d235fb9449e249d74f48ecfec601650de93John McCall "operations must have sources"); 38854b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 38864b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38874b9c2d235fb9449e249d74f48ecfec601650de93John McCall 388805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 3889ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 3890ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 3891ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3892ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 3893ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 3894ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 3895ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 3896ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 3897ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 3898ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 3899ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 3900ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3901ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 390277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 390377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 390477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 3905f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne// UnaryExprOrTypeTraitExpr 3906f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneStmt::child_range UnaryExprOrTypeTraitExpr::children() { 39070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 39080518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 39090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 39100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 3911f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const VariableArrayType* T = dyn_cast<VariableArrayType>( 39120518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 391363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(T), child_iterator()); 391463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 39150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 391663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Argument.Ex, &Argument.Ex + 1); 39179ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 3918390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3919563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 392063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range ObjCMessageExpr::children() { 392163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin; 392204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 392363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(this + 1); 392463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall else 392563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(getArgs()); 392663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, 392763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); 3928563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 3929563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 3930cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri GribenkoObjCArrayLiteral::ObjCArrayLiteral(ArrayRef<Expr *> Elements, 3931ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *Method, 3932ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3933ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCArrayLiteralClass, T, VK_RValue, OK_Ordinary, 3934ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false, false, false), 3935ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method) 3936ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3937ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **SaveElements = getElements(); 3938ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0, N = Elements.size(); I != N; ++I) { 3939ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isTypeDependent() || Elements[I]->isValueDependent()) 3940ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3941ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isInstantiationDependent()) 3942ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3943ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->containsUnexpandedParameterPack()) 3944ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3945ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3946ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SaveElements[I] = Elements[I]; 3947ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3948ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3949ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3950ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::Create(ASTContext &C, 3951cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<Expr *> Elements, 3952ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 3953ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 3954ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3955ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + Elements.size() * sizeof(Expr *)); 3956ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR); 3957ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3958ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3959ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(ASTContext &C, 3960ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements) { 3961ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3962ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3963ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + NumElements * sizeof(Expr *)); 3964ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements); 3965ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3966ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3967ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::ObjCDictionaryLiteral( 3968ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 3969ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 3970ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 3971ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3972ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, T, VK_RValue, OK_Ordinary, false, false, 3973ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false), 3974ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), 3975ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek DictWithObjectsMethod(method) 3976ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3977ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *KeyValues = getKeyValues(); 3978ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *Expansions = getExpansionData(); 3979ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0; I < NumElements; I++) { 3980ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isTypeDependent() || VK[I].Key->isValueDependent() || 3981ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isTypeDependent() || VK[I].Value->isValueDependent()) 3982ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3983ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isInstantiationDependent() || 3984ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isInstantiationDependent()) 3985ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3986ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].EllipsisLoc.isInvalid() && 3987ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (VK[I].Key->containsUnexpandedParameterPack() || 3988ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->containsUnexpandedParameterPack())) 3989ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3990ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3991ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Key = VK[I].Key; 3992ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Value = VK[I].Value; 3993ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansions) { 3994ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].EllipsisLoc = VK[I].EllipsisLoc; 3995ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].NumExpansions) 3996ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = *VK[I].NumExpansions + 1; 3997ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek else 3998ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = 0; 3999ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 4000ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 4001ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4002ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4003ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 4004ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::Create(ASTContext &C, 4005ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 4006ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 4007ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 4008ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 4009ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 4010ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 4011ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * VK.size(); 4012ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4013ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 4014ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * VK.size() + ExpansionsSize); 4015ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR); 4016ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4017ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4018ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 4019ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::CreateEmpty(ASTContext &C, unsigned NumElements, 4020ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) { 4021ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 4022ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 4023ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * NumElements; 4024ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 4025ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * NumElements + ExpansionsSize); 4026ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(EmptyShell(), NumElements, 4027ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions); 4028ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4029ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4030ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCSubscriptRefExpr *ObjCSubscriptRefExpr::Create(ASTContext &C, 4031ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 4032ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 4033ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 4034ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 4035ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB) { 4036ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCSubscriptRefExpr)); 4037ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCSubscriptRefExpr(base, key, T, VK_LValue, 4038ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek OK_ObjCSubscript, 4039ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getMethod, setMethod, RB); 4040ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4041dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 40423b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerAtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, 4043dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType t, AtomicOp op, SourceLocation RP) 4044dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, 4045dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman false, false, false, false), 40463b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) 4047dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman{ 40483b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); 40493b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); i++) { 4050dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isTypeDependent()) 4051dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.TypeDependent = true; 4052dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isValueDependent()) 4053dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ValueDependent = true; 4054dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isInstantiationDependent()) 4055dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.InstantiationDependent = true; 4056dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->containsUnexpandedParameterPack()) 4057dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ContainsUnexpandedParameterPack = true; 4058dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4059dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs[i] = args[i]; 4060dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 4061dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman} 4062e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 4063e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smithunsigned AtomicExpr::getNumSubExprs(AtomicOp Op) { 4064e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith switch (Op) { 4065ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_init: 4066ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_load: 4067ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load_n: 4068e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 2; 4069ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4070ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_store: 4071ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_exchange: 4072ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load: 4073ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store: 4074ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store_n: 4075ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange_n: 4076ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_add: 4077ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_sub: 4078ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_and: 4079ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_or: 4080ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_xor: 4081ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_add: 4082ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_sub: 4083ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_and: 4084ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_or: 4085ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_xor: 408651b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_fetch_nand: 4087ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_add_fetch: 4088ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_sub_fetch: 4089ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_and_fetch: 4090ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_or_fetch: 4091ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_xor_fetch: 409251b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_nand_fetch: 4093e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 3; 4094ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4095ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange: 4096ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 4; 4097ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4098ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_strong: 4099ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_weak: 4100e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 5; 4101ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4102ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange: 4103ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange_n: 4104ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 6; 4105e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith } 4106e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith llvm_unreachable("unknown atomic op"); 4107e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith} 4108